Commit 51912b09 authored by Thomas Markiewicz's avatar Thomas Markiewicz
Browse files

Picking up social.librem.one tokens from system-wide Librem One accounts if...

Picking up social.librem.one tokens from system-wide Librem One accounts if any exist and automatically going to the main activityin that case
parent 2ce897f7
Pipeline #50618 passed with stages
in 14 minutes and 11 seconds
......@@ -8,6 +8,9 @@
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.USE_CREDENTIALS"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" /> <!-- For notifications -->
<uses-permission
......
......@@ -15,6 +15,7 @@
package com.keylesspalace.tusky
import android.accounts.AccountManager
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
......@@ -89,9 +90,23 @@ class LoginActivity : BaseActivity(), Injectable {
supportActionBar?.setDisplayShowTitleEnabled(false)
} else {
toolbar.visibility = View.GONE
}
// 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()) {
for (a in accounts) {
// hardcoding domain "social.librem.one" for now
// also assuming this token IS in fact for social
// TODO: figure out how to tell from code
var token = am.blockingGetAuthToken(a, "social", true)
accountManager.addAccount(token, "social.librem.one")
}
startMainActivity()
}
}
}
override fun requiresLogin(): Boolean {
......@@ -391,6 +406,10 @@ class LoginActivity : BaseActivity(), Injectable {
accountManager.addAccount(accessToken, domain)
startMainActivity()
}
private fun startMainActivity() {
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
......
......@@ -46,16 +46,6 @@ class OnboardingActivity : AppCompatActivity() {
findViewById<Button>(R.id.buttonLogin).setOnClickListener {
// 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?
val intent = Intent(this, LoginActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment