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:
parent
05f9a17e7a
commit
85a6b2d96b
9 changed files with 48 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue