From 269de117b3972de3f8db20fd7dd10fbfb52be5ed Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Tue, 5 Dec 2023 14:39:14 +0530 Subject: [PATCH] Introduce a new AccountsFragment to store accounts related prefs Add a new fragment to host preferences that concern accounts or data related to them. * Show currently logged in accounts as a simple list on top * Relocate add account preference below. * Add a new preference to quickly open account settings page to manage all accounts. Issue: calyxos#712 Signed-off-by: Aayush Gupta Change-Id: Ifd00fe1295cc42077e835dd9afa829c444a5af97 --- .../org/microg/gms/ui/AccountsFragment.kt | 53 +++++++++++++++++++ .../org/microg/gms/ui/SettingsFragment.kt | 5 ++ .../src/main/res/navigation/nav_settings.xml | 7 +++ .../src/main/res/values/strings.xml | 7 +++ .../src/main/res/xml/preferences_accounts.xml | 27 ++++++++++ .../src/main/res/xml/preferences_start.xml | 9 ++-- 6 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 play-services-core/src/main/java/org/microg/gms/ui/AccountsFragment.kt create mode 100644 play-services-core/src/main/res/xml/preferences_accounts.xml diff --git a/play-services-core/src/main/java/org/microg/gms/ui/AccountsFragment.kt b/play-services-core/src/main/java/org/microg/gms/ui/AccountsFragment.kt new file mode 100644 index 0000000000..b9dc737c12 --- /dev/null +++ b/play-services-core/src/main/java/org/microg/gms/ui/AccountsFragment.kt @@ -0,0 +1,53 @@ +package org.microg.gms.ui + +import android.accounts.AccountManager +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import android.util.Log +import android.view.View +import androidx.core.content.ContextCompat +import androidx.preference.Preference +import androidx.preference.PreferenceCategory +import androidx.preference.PreferenceFragmentCompat +import com.google.android.gms.R +import org.microg.gms.auth.AuthConstants + +class AccountsFragment : PreferenceFragmentCompat() { + + private val TAG = AccountsFragment::class.java.simpleName + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.preferences_accounts) + + val accountManager = AccountManager.get(requireContext()) + val accounts = accountManager.getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE) + + findPreference("pref_current_accounts_none")?.isVisible = accounts.isEmpty() + val preferenceCategory = findPreference("prefcat_current_accounts") + accounts.forEach { + Preference(requireContext()).apply { + title = it.name + icon = ContextCompat.getDrawable( + requireContext(), + R.drawable.proprietary_auth_gls_ic_google_minitab_selected + ) + preferenceCategory?.addPreference(this) + } + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + findPreference("pref_manage_accounts")?.setOnPreferenceClickListener { + try { + startActivity(Intent(Settings.ACTION_SYNC_SETTINGS)) + } catch (activityNotFoundException: ActivityNotFoundException) { + Log.e(TAG, "Failed to launch sync settings", activityNotFoundException) + } + true + } + } +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt index 703f80914a..f38290eabb 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt @@ -27,6 +27,10 @@ class SettingsFragment : ResourceSettingsFragment() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { super.onCreatePreferences(savedInstanceState, rootKey) + findPreference(PREF_ACCOUNTS)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { + findNavController().navigate(requireContext(), R.id.accountManagerFragment) + true + } findPreference(PREF_CHECKIN)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { findNavController().navigate(requireContext(), R.id.openCheckinSettings) true @@ -131,6 +135,7 @@ class SettingsFragment : ResourceSettingsFragment() { const val PREF_LOCATION = "pref_location" const val PREF_CHECKIN = "pref_checkin" const val PREF_VENDING = "pref_vending" + const val PREF_ACCOUNTS = "pref_accounts" } init { diff --git a/play-services-core/src/main/res/navigation/nav_settings.xml b/play-services-core/src/main/res/navigation/nav_settings.xml index d9a7fc3938..f66a0370b1 100644 --- a/play-services-core/src/main/res/navigation/nav_settings.xml +++ b/play-services-core/src/main/res/navigation/nav_settings.xml @@ -44,6 +44,13 @@ android:name="org.microg.gms.ui.SelfCheckFragment" android:label="@string/self_check_title" /> + + + + Status More + Accounts + Add and manage Google accounts + Settings + Currently signed-in accounts + Manage accounts + Manage existing accounts settings Account Add Google account + Cloud Messaging is a push notification provider used by many third-party applications. To use it you must enable device registration. Cloud Messaging heartbeat interval The interval in seconds for the system to heartbeat the Google servers. Increasing this number will reduce battery consumption, but might cause delays on push messages.\nDeprecated, will be replaced in future release. diff --git a/play-services-core/src/main/res/xml/preferences_accounts.xml b/play-services-core/src/main/res/xml/preferences_accounts.xml new file mode 100644 index 0000000000..e22aa90a52 --- /dev/null +++ b/play-services-core/src/main/res/xml/preferences_accounts.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/play-services-core/src/main/res/xml/preferences_start.xml b/play-services-core/src/main/res/xml/preferences_start.xml index c2b618367f..b49c37336c 100644 --- a/play-services-core/src/main/res/xml/preferences_start.xml +++ b/play-services-core/src/main/res/xml/preferences_start.xml @@ -29,12 +29,9 @@ - - + android:key="pref_accounts" + android:summary="@string/pref_accounts_summary" + android:title="@string/pref_accounts_title" />