Skip to content

Commit

Permalink
Hide "logged in" if have none account in list
Browse files Browse the repository at this point in the history
  • Loading branch information
WSTxda committed Aug 7, 2024
1 parent 51227a8 commit c17e18a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,36 @@ class AccountsFragment : PreferenceFragmentCompat() {
clearAccountPreferences()

val preferenceCategory = findPreference<PreferenceCategory>("prefcat_current_accounts")

lifecycleScope.launch(Dispatchers.Main) {
accounts.forEach { account ->
val photo = PeopleManager.getOwnerAvatarBitmap(context, account.name, false)
val newPreference = Preference(requireContext()).apply {
title = getDisplayName(account)
summary = account.name
icon = getCircleBitmapDrawable(photo)
key = "account:${account.name}"
order = 0

setOnPreferenceClickListener {
showConfirmationDialog(account.name)
true
}
}

if (preferenceCategory?.findPreference<Preference>(newPreference.key) == null) {
if (photo == null) {
withContext(Dispatchers.IO) {
PeopleManager.getOwnerAvatarBitmap(context, account.name, true)
}?.let { newPreference.icon = getCircleBitmapDrawable(it) }
val accountsCategoryVisible = accounts.isNotEmpty()

preferenceCategory?.let {
it.isVisible = accountsCategoryVisible
if (accountsCategoryVisible) {
lifecycleScope.launch(Dispatchers.Main) {
accounts.forEach { account ->
val photo = PeopleManager.getOwnerAvatarBitmap(context, account.name, false)
val newPreference = Preference(requireContext()).apply {
title = getDisplayName(account)
summary = account.name
icon = getCircleBitmapDrawable(photo)
key = "account:${account.name}"
order = 0

setOnPreferenceClickListener {
showConfirmationDialog(account.name)
true
}
}

if (preferenceCategory.findPreference<Preference>(newPreference.key) == null) {
if (photo == null) {
withContext(Dispatchers.IO) {
PeopleManager.getOwnerAvatarBitmap(context, account.name, true)
}?.let { newPreference.icon = getCircleBitmapDrawable(it) }
}
preferenceCategory.addPreference(newPreference)
}
}
preferenceCategory?.addPreference(newPreference)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Isso pode levar alguns minutos."</string>
<string name="dialog_message_remove_account">Tem certeza de que deseja remover esta conta?\n\nAlguns serviços e funções não estarão disponíveis\n\nSeus dados não serão perdidos</string>
<string name="dialog_confirm_button">Remover</string>
<string name="dialog_cancel_button">Cancelar</string>
<string name="toast_remove_account_success">%s removida</string>
<string name="toast_remove_account_success">Conta %s removida</string>

<!-- Settings options strings-->

Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ This can take a couple of minutes"</string>
<string name="dialog_message_remove_account">Are you sure you want to remove this account?\n\nSome services and functions will be unavailable\n\nYour data will not be lost</string>
<string name="dialog_confirm_button">Remove</string>
<string name="dialog_cancel_button">Cancel</string>
<string name="toast_remove_account_success">%s removed</string>
<string name="toast_remove_account_success">Account %s removed</string>

<!-- Settings options strings-->

Expand Down
7 changes: 3 additions & 4 deletions play-services-core/src/main/res/xml/preferences_accounts.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory
android:key="prefcat_current_accounts"
Expand All @@ -27,13 +26,13 @@
<PreferenceCategory android:title="@string/prefcat_youtube_activity">

<Preference
android:key="pref_manage_history"
android:icon="@drawable/ic_youtube_history"
android:key="pref_manage_history"
android:title="@string/pref_manage_all_history" />

<Preference
android:key="pref_your_data"
android:icon="@drawable/ic_youtube_data"
android:key="pref_your_data"
android:title="@string/pref_data_in_youtube" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit c17e18a

Please sign in to comment.