[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/418: Add account settings page and sign out functionality
parent
0943be85d8
commit
8dd8fe8169
@ -0,0 +1,55 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
|
||||
private lateinit var job: Job
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.Main + job
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
job = Job()
|
||||
(activity as AppCompatActivity).title = getString(R.string.preferences_account_settings)
|
||||
(activity as AppCompatActivity).supportActionBar?.show()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.account_settings_preferences, rootKey)
|
||||
|
||||
val signIn = context?.getPreferenceKey(R.string.pref_key_sign_out)
|
||||
val preferenceSignOut = findPreference<Preference>(signIn)
|
||||
preferenceSignOut.onPreferenceClickListener = getClickListenerForSignOut()
|
||||
}
|
||||
|
||||
private fun getClickListenerForSignOut(): Preference.OnPreferenceClickListener {
|
||||
return Preference.OnPreferenceClickListener {
|
||||
launch {
|
||||
requireComponents.backgroundServices.accountManager.logout().await()
|
||||
Navigation.findNavController(view!!).popBackStack()
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<androidx.preference.Preference
|
||||
android:key="@string/pref_key_sync_now"
|
||||
android:title="@string/preferences_sync_now"
|
||||
android:enabled = "false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/preferences_sync_category">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="@string/pref_key_sync_history"
|
||||
android:defaultValue="true"
|
||||
android:enabled="false"
|
||||
android:title="@string/preferences_sync_history" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<androidx.preference.Preference
|
||||
android:key="@string/pref_key_sign_out"
|
||||
android:title="@string/preferences_sign_out" />
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue