add toolbar menu option to show display name instead of email

pull/543/head
akliuxingyuan 1 year ago
parent 7aeee0df4f
commit 2805a67e9d

@ -23,6 +23,16 @@ class FenixAccountManager(context: Context) {
null
}
/**
* Returns the Firefox Account displayName if authenticated in the app, `null` otherwise.
*/
val accountProfileDisplayName: String?
get() = if (accountState == AccountState.AUTHENTICATED) {
accountManager.accountProfile()?.displayName
} else {
null
}
/**
* The current state of the Firefox Account. See [AccountState].
*/

@ -352,7 +352,13 @@ open class DefaultToolbarMenu(
private fun syncMenuItem(): BrowserMenuImageText? {
val syncItemTitle =
if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) {
accountManager.accountProfileEmail ?: context.getString(R.string.sync_menu_sync_and_save_data)
if (context.settings().showDisplayNameInsteadofEmail) {
accountManager.accountProfileDisplayName
?: context.getString(R.string.sync_menu_sync_and_save_data)
} else {
accountManager.accountProfileEmail
?: context.getString(R.string.sync_menu_sync_and_save_data)
}
} else {
null
}

@ -100,7 +100,13 @@ class HomeMenu(
private fun syncSignInMenuItem(): BrowserMenuImageText? {
val syncItemTitle =
if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) {
accountManager.accountProfileEmail ?: context.getString(R.string.sync_menu_sync_and_save_data)
if (context.settings().showDisplayNameInsteadofEmail) {
accountManager.accountProfileDisplayName
?: context.getString(R.string.sync_menu_sync_and_save_data)
} else {
accountManager.accountProfileEmail
?: context.getString(R.string.sync_menu_sync_and_save_data)
}
} else {
null
}

@ -60,6 +60,12 @@ class CustomizationFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater()
}
requirePreference<SwitchPreference>(R.string.pref_key_show_displayname_insteadof_email).apply {
isChecked = requireContext().settings().showDisplayNameInsteadofEmail
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}
private fun setupRadioGroups() {

@ -745,6 +745,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = true,
)
var showDisplayNameInsteadofEmail by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_show_displayname_insteadof_email),
default = true,
)
var shouldRelinquishMemoryUnderPressure by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_relinquish_memory_under_pressure),
default = true,

@ -604,6 +604,8 @@
<string name="preference_top_toolbar">顶部</string>
<!-- Preference for using bottom toolbar -->
<string name="preference_bottom_toolbar">底部</string>
<!-- Preference for showing display name instead of email -->
<string name="preferences_show_displayname_insteadof_email">展示显示名而不是邮件</string>
<!-- Theme Preferences -->
<!-- Preference for using light theme -->

@ -599,6 +599,8 @@
<string name="preference_top_toolbar">頂端</string>
<!-- Preference for using bottom toolbar -->
<string name="preference_bottom_toolbar">底端</string>
<!-- Preference for showing display name instead of email -->
<string name="preferences_show_displayname_insteadof_email">展示顯示名而不是郵件</string>
<!-- Theme Preferences -->
<!-- Preference for using light theme -->

@ -124,6 +124,7 @@
<string name="pref_key_toolbar_top" translatable="false">pref_key_toolbar_top</string>
<string name="pref_key_toolbar_bottom" translatable="false">pref_key_toolbar_bottom</string>
<string name="pref_key_strip_url" translatable="false">pref_key_strip_url</string>
<string name="pref_key_show_displayname_insteadof_email" translatable="false">pref_key_show_displayname_insteadof_email</string>
<!-- Privacy Pop Window -->
<string name="pref_key_privacy_pop_window" translatable="false">pref_key_privacy_pop_window</string>
@ -141,12 +142,12 @@
<string name="pref_key_swipe_toolbar_show_tabs" translatable="false">pref_key_swipe_toolbar_show_tabs</string>
<string name="pref_key_recent_tabs" translatable="false">pref_key_recent_tabs</string>
<string name="pref_key_recent_bookmarks" translatable="false">pref_key_recent_bookmarks</string>
<!-- Add-ons Source Customization Settings -->
<string name="pref_addons_settings_category" translatable="false">pref_addons_settings_category</string>
<string name="pref_key_addons_custom_account" translatable="false">pref_key_addons_custom_account</string>
<string name="pref_key_addons_custom_collection" translatable="false">pref_key_addons_custom_collection</string>
<!-- System Customization Settings -->
<string name="pref_system_behavior_settings_category" translatable="false">pref_system_behavior_settings_category</string>
<string name="pref_key_relinquish_memory_under_pressure" translatable="false">pref_key_relinquish_memory_under_pressure</string>

@ -590,6 +590,8 @@
<string name="preference_top_toolbar">Top</string>
<!-- Preference for using bottom toolbar -->
<string name="preference_bottom_toolbar">Bottom</string>
<!-- Preference for showing display name instead of email -->
<string name="preferences_show_displayname_insteadof_email">Show Display name instead of email</string>
<!-- Theme Preferences -->
<!-- Preference for using light theme -->
@ -1859,7 +1861,7 @@
<string name="addons_custom_source_account">Set custom add-ons account</string>
<!-- Label for add-ons custom source collection preference -->
<string name="addons_custom_source_collection">Set custom add-ons collection</string>
<!-- Preference category for system behavior customization -->
<string name="preferences_system_behavior">Configure system behavior</string>
<!-- Title for relinquish memory preference in customization settings -->

@ -46,6 +46,10 @@
android:key="@string/pref_key_strip_url"
android:summary="@string/preferences_strip_url_description"
android:title="@string/preferences_strip_url_title" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_show_displayname_insteadof_email"
android:title="@string/preferences_show_displayname_insteadof_email" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
@ -67,7 +71,7 @@
android:title="@string/preference_gestures_swipe_toolbar_show_tabs"
app:isPreferenceVisible="false" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_addons_settings_category"
android:layout="@layout/preference_cat_style"
@ -81,7 +85,7 @@
android:key="@string/pref_key_addons_custom_collection"
android:title="@string/addons_custom_source_collection" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_system_behavior_settings_category"
android:layout="@layout/preference_cat_style"
@ -94,5 +98,5 @@
android:summary="@string/preferences_relinquish_memory_description"
android:title="@string/preferences_relinquish_memory_title" />
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>

Loading…
Cancel
Save