Preference to disable multiple-login usernames (#2718)

* Preference to disable multiple-login usernames (with problems)

* Fix problem where 'show self username disambiguation' does not take effect immediately because MainActivity needed to be restarted

* Make 'show username in toolbars' a 3-option selector, default when multiple accounts logged in

* Move SHOW_SELF_USERNAME higher in preference fragment
This commit is contained in:
mcclure 2022-10-18 13:38:17 -04:00 committed by GitHub
commit 85a6b2d96b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 3 deletions

View file

@ -834,7 +834,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
header.clear()
header.profiles = profiles
header.setActiveProfile(accountManager.activeAccount!!.id)
binding.mainToolbar.subtitle = if (accountManager.accounts.size > 1) {
binding.mainToolbar.subtitle = if (accountManager.shouldDisplaySelfUsername(this)) {
accountManager.activeAccount!!.fullName
} else null
}

View file

@ -244,7 +244,7 @@ class ComposeActivity :
viewModel.setup(composeOptions)
if (accountManager.accounts.size > 1) {
if (accountManager.shouldDisplaySelfUsername(this)) {
binding.composeUsernameView.text = getString(
R.string.compose_active_account_description,
activeAccount.fullName

View file

@ -125,7 +125,7 @@ class PreferencesActivity :
this.restartCurrentActivity()
}
"statusTextSize", "absoluteTimeView", "showBotOverlay", "animateGifAvatars", "useBlurhash",
"showCardsInTimelines", "confirmReblogs", "confirmFavourites",
"showSelfUsername", "showCardsInTimelines", "confirmReblogs", "confirmFavourites",
"enableSwipeForTabs", "mainNavPosition", PrefKeys.HIDE_TOP_TOOLBAR -> {
restartActivitiesOnExit = true
}

View file

@ -96,6 +96,16 @@ class PreferencesFragment : PreferenceFragmentCompat(), Injectable {
setTitle(R.string.pref_main_nav_position)
}
listPreference {
setDefaultValue("disambiguate")
setEntries(R.array.pref_show_self_username_names)
setEntryValues(R.array.pref_show_self_username_values)
key = PrefKeys.SHOW_SELF_USERNAME
setSummaryProvider { entry }
setTitle(R.string.pref_title_show_self_username)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.HIDE_TOP_TOOLBAR

View file

@ -15,9 +15,12 @@
package com.keylesspalace.tusky.db
import android.content.Context
import android.util.Log
import androidx.preference.PreferenceManager
import com.keylesspalace.tusky.entity.Account
import com.keylesspalace.tusky.entity.Status
import com.keylesspalace.tusky.settings.PrefKeys
import java.util.Locale
import javax.inject.Inject
import javax.inject.Singleton
@ -225,4 +228,18 @@ class AccountManager @Inject constructor(db: AppDatabase) {
identifier == it.identifier
}
}
/**
* @return true if the name of the currently-selected account should be displayed in UIs
*/
fun shouldDisplaySelfUsername(context: Context): Boolean {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val showUsernamePreference = sharedPreferences.getString(PrefKeys.SHOW_SELF_USERNAME, "disambiguate")
if (showUsernamePreference == "always")
return true
if (showUsernamePreference == "never")
return false
return accounts.size > 1 // "disambiguate"
}
}

View file

@ -27,6 +27,7 @@ object PrefKeys {
const val SHOW_BOT_OVERLAY = "showBotOverlay"
const val ANIMATE_GIF_AVATARS = "animateGifAvatars"
const val USE_BLURHASH = "useBlurhash"
const val SHOW_SELF_USERNAME = "showSelfUsername"
const val SHOW_NOTIFICATIONS_FILTER = "showNotificationsFilter"
const val SHOW_CARDS_IN_TIMELINES = "showCardsInTimelines"
const val CONFIRM_REBLOGS = "confirmReblogs"