OnboardingActivity.kt 2.41 KB
Newer Older
Thomas Markiewicz's avatar
Thomas Markiewicz committed
1 2
package com.keylesspalace.tusky

3
import android.accounts.AccountManager
Thomas Markiewicz's avatar
Thomas Markiewicz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.webkit.WebView
import android.widget.Button
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity

class OnboardingActivity : AppCompatActivity() {

    companion object {
        @JvmStatic
        fun getIntent(context: Context): Intent {
            val intent = Intent(context, OnboardingActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
            return intent
        }
    }

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

        findViewById<Button>(R.id.buttonRegister).setOnClickListener {
            displayInWebView(R.string.register_url)
        }

        findViewById<Button>(R.id.buttonSupport).setOnClickListener {
            displayInWebView(R.string.support_url)
        }

        findViewById<Button>(R.id.buttonPolicy).setOnClickListener {
            displayInWebView(R.string.policy_url)
        }

        findViewById<Button>(R.id.buttonPolicy).setOnClickListener {
            displayInWebView(R.string.policy_url)
        }

        findViewById<Button>(R.id.buttonStaySafe).setOnClickListener {
            displayInWebView(R.string.stay_safe_url)
        }

        findViewById<Button>(R.id.buttonLogin).setOnClickListener {
48 49 50 51 52 53 54 55 56 57 58

            // TODO: use system Librem One account
            //  SEE: https://developer.android.com/reference/android/accounts/AccountManager

            val am = AccountManager.get(this)
            val accounts = am.getAccountsByType("Librem One")
            if( accounts.isNotEmpty()) {
                val account = accounts[0]
            }
            // TODO: why does it come back empty?

Thomas Markiewicz's avatar
Thomas Markiewicz committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
            val intent = Intent(this, LoginActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
            finish()
        }
    }

    private fun displayInWebView(id: Int) {
        val url = this.getString(id)
        val wv = WebView(this)
        wv.loadUrl(url)
        AlertDialog.Builder(this)
                .setView(wv)
                .setPositiveButton(android.R.string.ok, null)
                .show()
    }
}