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
parent 05f9a17e7a
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"

View File

@ -144,6 +144,12 @@
<item>bottom</item>
</string-array>
<string-array name="pref_show_self_username_values">
<item>always</item>
<item>disambiguate</item>
<item>never</item>
</string-array>
<string name="description_status" translatable="false">
<!-- Display name, cw?, content?, poll? relative date, reposted by?, reposted?, favorited?, bookmarked?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %14$s %4$s, %5$s; %6$s, %7$s, %8$s, %9$s, %10$s; %11$s, %12$s, %13$s

View File

@ -23,4 +23,10 @@
<item>@string/post_text_size_largest</item>
</string-array>
<string-array name="pref_show_self_username_names">
<item>@string/pref_show_self_username_always</item>
<item>@string/pref_show_self_username_disambiguate</item>
<item>@string/pref_show_self_username_never</item>
</string-array>
</resources>

View File

@ -293,6 +293,10 @@
<string name="post_text_size_large">Large</string>
<string name="post_text_size_largest">Largest</string>
<string name="pref_show_self_username_always">Always</string>
<string name="pref_show_self_username_disambiguate">When multiple accounts logged in</string>
<string name="pref_show_self_username_never">Never</string>
<string name="notification_mention_name">New Mentions</string>
<string name="notification_mention_descriptions">Notifications about new mentions</string>
<string name="notification_follow_name">New Followers</string>
@ -618,6 +622,7 @@
<string name="no_scheduled_posts">You don\'t have any scheduled posts.</string>
<string name="no_announcements">There are no announcements.</string>
<string name="warning_scheduling_interval">Mastodon has a minimum scheduling interval of 5 minutes.</string>
<string name="pref_title_show_self_username">Show username in toolbars</string>
<string name="pref_title_show_cards_in_timelines">Show link previews in timelines</string>
<string name="pref_title_confirm_reblogs">Show confirmation dialog before boosting</string>
<string name="pref_title_confirm_favourites">Show confirmation dialog before favoriting</string>