package nice3point.by.schedule.Settings

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.util.Log
import android.widget.TextView
import android.widget.Toast
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdView
import com.google.firebase.iid.FirebaseInstanceId
import nice3point.by.schedule.R


class Settings : AppCompatActivity() {

    private lateinit var mAdView: AdView
    private var click = 0

    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.settings_layout)

        val secret_key = findViewById<TextView>(R.id.settings_secret_key)
        val bar = findViewById<Toolbar>(R.id.settings_toolbar)
        mAdView = findViewById(R.id.adView)

        setSupportActionBar(bar)

        val adRequest = AdRequest.Builder()    //Реклама
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("B6D5BA81AAD3AFD48C1780287F5BDB4D")
                .build()
        mAdView.loadAd(adRequest)

        fragmentManager.beginTransaction()
                .replace(R.id.settings_container, SettingsFragment())
                .commit()

        bar.setNavigationOnClickListener { finish() }
        secret_key.setOnClickListener {
            click++
            if (click == 3) {
                click = 0
                try {
                    val token = FirebaseInstanceId.getInstance().token
                    Toast.makeText(this@Settings, token, Toast.LENGTH_SHORT).show()
                    Log.d("TOKEN", token)
                } catch (e: Exception) {
                    Toast.makeText(this@Settings, "Failed to get token", Toast.LENGTH_SHORT).show()
                }

            }
        }
    }

    override fun onPause() {
        super.onPause()
        mAdView.pause()
    }

    override fun onResume() {
        super.onResume()
        mAdView.resume()
    }

    override fun onDestroy() {
        super.onDestroy()
        mAdView.destroy()
    }


}
