Commit bbad9fcf authored by Thomas Markiewicz's avatar Thomas Markiewicz
Browse files

Install Librem One on startup if not already installed

parent a82945b6
Pipeline #51969 failed with stages
in 7 minutes and 19 seconds
...@@ -5,14 +5,15 @@ import android.accounts.AccountManagerCallback ...@@ -5,14 +5,15 @@ import android.accounts.AccountManagerCallback
import android.accounts.AccountManagerFuture import android.accounts.AccountManagerFuture
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Message
import android.widget.Button import android.widget.Button
import androidx.appcompat.app.AlertDialog
import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.di.Injectable
import javax.security.auth.callback.Callback
class OnboardingActivity : BaseActivity(), Injectable { class OnboardingActivity : BaseActivity(), Injectable {
...@@ -23,7 +24,6 @@ class OnboardingActivity : BaseActivity(), Injectable { ...@@ -23,7 +24,6 @@ class OnboardingActivity : BaseActivity(), Injectable {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_onboarding) setContentView(R.layout.activity_onboarding)
findViewById<Button>(R.id.buttonLoginLibremOne).setOnClickListener { findViewById<Button>(R.id.buttonLoginLibremOne).setOnClickListener {
// TODO: use system Librem One account // TODO: use system Librem One account
...@@ -50,39 +50,66 @@ class OnboardingActivity : BaseActivity(), Injectable { ...@@ -50,39 +50,66 @@ class OnboardingActivity : BaseActivity(), Injectable {
} else { } else {
am.addAccount( if( !isLibremOneInstalled() ) {
"librem.one", askToInstallLibremOne()
"social", } else {
null, am.addAccount(
null, "librem.one",
this, "social",
OnTokenAcquired(), null,
null null,
) this,
OnTokenAcquired(),
null
)
}
} }
}
/* findViewById<Button>(R.id.buttonLoginOther).setOnClickListener {
startLoginActivity()
NOTE: }
}
remove from the account manager by calling invalidateAuthToken() method.
After removing the token from account manager, you need to call getAuthToken method passing account, account type, and account manager callback to get new token. override fun requiresLogin(): Boolean {
return false
}
private fun isLibremOneInstalled(): Boolean {
var found = true
*/ try {
packageManager.getPackageInfo("one.librem.one", 0)
} catch (e: PackageManager.NameNotFoundException) {
found = false
} }
return found
}
private fun askToInstallLibremOne() {
val builder = AlertDialog.Builder(this)
builder.setMessage(R.string.install_librem_one_message)
.setTitle(R.string.install_librem_one)
.setPositiveButton(R.string.install,
DialogInterface.OnClickListener { dialog, id ->
startInstallLibremOneActivity()
})
.setNegativeButton(R.string.cancel,
DialogInterface.OnClickListener { dialog, id ->
// User cancelled the dialog
})
// Create the AlertDialog object and show it
builder.create().show()
findViewById<Button>(R.id.buttonLoginOther).setOnClickListener {
startLoginActivity();
}
} }
override fun requiresLogin(): Boolean { private fun startInstallLibremOneActivity() {
return false val goToMarket = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("https://play.google.com/store/apps/details?id=one.librem.one"))
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(goToMarket)
} }
private fun startLoginActivity() { private fun startLoginActivity() {
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:visibility="gone" android:visibility="gone"
style="@style/Widget.MaterialComponents.Button.TextButton" style="@style/Widget.MaterialComponents.Button.TextButton"
android:text="@string/install_librem_hub" /> android:text="@string/install_librem_one" />
<Button <Button
android:id="@+id/buttonLoginLibremOne" android:id="@+id/buttonLoginLibremOne"
......
...@@ -286,7 +286,10 @@ ...@@ -286,7 +286,10 @@
<string name="support">Support</string> <string name="support">Support</string>
<string name="policy">Policy</string> <string name="policy">Policy</string>
<string name="stay_safe">Stay safe</string> <string name="stay_safe">Stay safe</string>
<string name="install_librem_hub">Install Librem Hub</string> <string name="install_librem_one">Install Librem One</string>
<string name="install_librem_one_message">Librem One app is required to manage system-wide accounts. Please install it and try again.</string>
<string name="install">Install</string>
<string name="cancel">Cancel</string>
<string name="about_title_activity">About</string> <string name="about_title_activity">About</string>
<string name="about_tusky_version">Librem Social %s</string> <string name="about_tusky_version">Librem Social %s</string>
<string name="about_tusky_license"> <string name="about_tusky_license">
......
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