Use Account.getDisplayName() when appropriate

This commit is contained in:
cketti 2022-02-08 01:34:00 +01:00
parent 19829eb2a2
commit bfc708df19
19 changed files with 26 additions and 40 deletions

View file

@ -264,7 +264,7 @@ public class Account implements BaseAccount {
}
public String getDisplayName() {
return name != null ? name : getEmail();
return name != null && name.length() != 0 ? name : getEmail();
}
public synchronized String getSenderName() {

View file

@ -15,7 +15,7 @@ internal open class AuthenticationErrorNotificationController(
val notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming)
val editServerSettingsPendingIntent = createContentIntent(account, incoming)
val title = resourceProvider.authenticationErrorTitle()
val text = resourceProvider.authenticationErrorBody(account.name)
val text = resourceProvider.authenticationErrorBody(account.displayName)
val notificationBuilder = notificationHelper
.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS)

View file

@ -13,7 +13,7 @@ internal class BaseNotificationDataCreator {
return BaseNotificationData(
account = account,
groupKey = NotificationGroupKeys.getGroupKey(account),
accountName = getAccountName(account),
accountName = account.displayName,
color = account.chipColor,
newMessagesCount = notificationData.newMessagesCount,
lockScreenNotificationData = createLockScreenNotificationData(notificationData),
@ -21,11 +21,6 @@ internal class BaseNotificationDataCreator {
)
}
private fun getAccountName(account: Account): String {
val accountDescription = account.name?.takeIf { it.isNotEmpty() }
return accountDescription ?: account.email
}
private fun createLockScreenNotificationData(data: NotificationData): LockScreenNotificationData {
return when (K9.lockScreenNotificationVisibility) {
LockScreenNotificationVisibility.NOTHING -> LockScreenNotificationData.None

View file

@ -14,7 +14,7 @@ internal open class CertificateErrorNotificationController(
fun showCertificateErrorNotification(account: Account, incoming: Boolean) {
val notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming)
val editServerSettingsPendingIntent = createContentIntent(account, incoming)
val title = resourceProvider.certificateErrorTitle(account.name)
val title = resourceProvider.certificateErrorTitle(account.displayName)
val text = resourceProvider.certificateErrorBody()
val notificationBuilder = notificationHelper

View file

@ -54,11 +54,6 @@ class NotificationHelper(
}
}
fun getAccountName(account: Account): String {
val accountDescription = account.name
return if (TextUtils.isEmpty(accountDescription)) account.email else accountDescription
}
fun getContext(): Context {
return context
}

View file

@ -14,7 +14,7 @@ internal class SyncNotificationController(
private val resourceProvider: NotificationResourceProvider
) {
fun showSendingNotification(account: Account) {
val accountName = notificationHelper.getAccountName(account)
val accountName = account.displayName
val title = resourceProvider.sendingMailTitle()
val tickerText = resourceProvider.sendingMailBody(accountName)
@ -56,7 +56,7 @@ internal class SyncNotificationController(
}
fun showFetchingMailNotification(account: Account, folder: LocalFolder) {
val accountName = account.name
val accountName = account.displayName
val folderId = folder.databaseId
val folderName = folder.name
val tickerText = resourceProvider.checkingMailTicker(accountName, folderName)
@ -99,7 +99,7 @@ internal class SyncNotificationController(
fun showEmptyFetchingMailNotification(account: Account) {
val title = resourceProvider.checkingMailTitle()
val text = account.name
val text = account.displayName
val notificationId = NotificationIds.getFetchingMailNotificationId(account)
val notificationBuilder = notificationHelper

View file

@ -596,7 +596,7 @@ public class SettingsImporter {
continue;
}
if (account.getName().equals(name)) {
if (account.getDisplayName().equals(name)) {
return true;
}
}

View file

@ -107,7 +107,7 @@ class AuthenticationErrorNotificationControllerTest : RobolectricTest() {
private fun createFakeAccount(): Account {
return mock {
on { accountNumber } doReturn ACCOUNT_NUMBER
on { name } doReturn ACCOUNT_NAME
on { displayName } doReturn ACCOUNT_NAME
}
}

View file

@ -107,7 +107,7 @@ class CertificateErrorNotificationControllerTest : RobolectricTest() {
private fun createFakeAccount(): Account {
return mock {
on { accountNumber } doReturn ACCOUNT_NUMBER
on { name } doReturn ACCOUNT_NAME
on { displayName } doReturn ACCOUNT_NAME
on { uuid } doReturn "test-uuid"
}
}

View file

@ -126,7 +126,6 @@ class SyncNotificationControllerTest : RobolectricTest() {
on { getContext() } doReturn ApplicationProvider.getApplicationContext()
on { getNotificationManager() } doReturn notificationManager
on { createNotificationBuilder(any(), any()) }.doReturn(notificationBuilder, lockScreenNotificationBuilder)
on { getAccountName(any()) } doReturn ACCOUNT_NAME
}
}
@ -134,6 +133,7 @@ class SyncNotificationControllerTest : RobolectricTest() {
return mock {
on { accountNumber } doReturn ACCOUNT_NUMBER
on { name } doReturn ACCOUNT_NAME
on { displayName } doReturn ACCOUNT_NAME
on { outboxFolderId } doReturn 33L
}
}

View file

@ -62,7 +62,7 @@ class ImapBackendFactory(
private fun createImapStoreConfig(account: Account): ImapStoreConfig {
return object : ImapStoreConfig {
override val logLabel
get() = account.name
get() = account.uuid
override fun isSubscribedFoldersOnly() = account.isSubscribedFoldersOnly

View file

@ -408,7 +408,7 @@ public class MessageProvider extends ContentProvider {
public static class AccountExtractor implements FieldExtractor<MessageInfoHolder, String> {
@Override
public String getField(MessageInfoHolder source) {
return source.message.getAccount().getName();
return source.message.getAccount().getDisplayName();
}
}
@ -599,7 +599,7 @@ public class MessageProvider extends ContentProvider {
if (AccountColumns.ACCOUNT_NUMBER.equals(field)) {
values[fieldIndex] = account.getAccountNumber();
} else if (AccountColumns.ACCOUNT_NAME.equals(field)) {
values[fieldIndex] = account.getName();
values[fieldIndex] = account.getDisplayName();
} else if (AccountColumns.ACCOUNT_UUID.equals(field)) {
values[fieldIndex] = account.getUuid();
} else if (AccountColumns.ACCOUNT_COLOR.equals(field)) {
@ -662,7 +662,7 @@ public class MessageProvider extends ContentProvider {
for (Account account : accounts) {
if (account.getAccountNumber() == accountNumber) {
myAccount = account;
values[0] = myAccount.getName();
values[0] = myAccount.getDisplayName();
values[1] = controller.getUnreadMessageCount(account);
cursor.addRow(values);
}

View file

@ -139,10 +139,7 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() {
val selectedAccount = preferences.getAccount(selectedAccountUuid!!)
?: error("Account $selectedAccountUuid not found")
val accountDescription: String? = selectedAccount.name
val summary = if (accountDescription.isNullOrEmpty()) selectedAccount.email else accountDescription
unreadAccount.summary = summary
unreadAccount.summary = selectedAccount.displayName
unreadFolderEnabled.isEnabled = true
unreadFolder.isEnabled = true
}

View file

@ -49,7 +49,7 @@ class UnreadWidgetDataProvider(
private fun loadAccountData(configuration: UnreadWidgetConfiguration): UnreadWidgetData? {
val account = preferences.getAccount(configuration.accountUuid) ?: return null
val title = account.name
val title = account.displayName
val unreadCount = messagingController.getUnreadMessageCount(account)
val clickIntent = getClickIntentForAccount(account)
@ -66,7 +66,7 @@ class UnreadWidgetDataProvider(
val account = preferences.getAccount(accountUuid) ?: return null
val folderId = configuration.folderId ?: return null
val accountName = account.name
val accountName = account.displayName
val folderDisplayName = getFolderDisplayName(account, folderId)
val title = context.getString(R.string.unread_widget_title, accountName, folderDisplayName)

View file

@ -56,7 +56,7 @@ class UnreadWidgetDataProviderTest : AppRobolectricTest() {
val widgetData = provider.loadUnreadWidgetData(configuration)
with(widgetData!!) {
assertThat(title).isEqualTo(ACCOUNT_DESCRIPTION)
assertThat(title).isEqualTo(ACCOUNT_NAME)
assertThat(unreadCount).isEqualTo(ACCOUNT_UNREAD_COUNT)
}
}
@ -68,7 +68,7 @@ class UnreadWidgetDataProviderTest : AppRobolectricTest() {
val widgetData = provider.loadUnreadWidgetData(configuration)
with(widgetData!!) {
assertThat(title).isEqualTo("$ACCOUNT_DESCRIPTION - $LOCALIZED_FOLDER_NAME")
assertThat(title).isEqualTo("$ACCOUNT_NAME - $LOCALIZED_FOLDER_NAME")
assertThat(unreadCount).isEqualTo(FOLDER_UNREAD_COUNT)
}
}
@ -84,7 +84,7 @@ class UnreadWidgetDataProviderTest : AppRobolectricTest() {
fun createAccount(): Account = mock {
on { uuid } doReturn ACCOUNT_UUID
on { name } doReturn ACCOUNT_DESCRIPTION
on { displayName } doReturn ACCOUNT_NAME
}
fun createPreferences(): Preferences = mock {
@ -120,7 +120,7 @@ class UnreadWidgetDataProviderTest : AppRobolectricTest() {
companion object {
const val ACCOUNT_UUID = "00000000-0000-0000-0000-000000000000"
const val ACCOUNT_DESCRIPTION = "Test account"
const val ACCOUNT_NAME = "Test account"
const val FOLDER_ID = 23L
const val SEARCH_ACCOUNT_UNREAD_COUNT = 1
const val ACCOUNT_UNREAD_COUNT = 2

View file

@ -207,8 +207,7 @@ public class UpgradeDatabases extends K9Activity {
Account account = mPreferences.getAccount(accountUuid);
if (account != null) {
String formatString = getString(R.string.upgrade_database_format);
String upgradeStatus = String.format(formatString, account.getName());
String upgradeStatus = getString(R.string.upgrade_database_format, account.getDisplayName());
mUpgradeText.setText(upgradeStatus);
}

View file

@ -97,7 +97,7 @@ public class IdentityAdapter extends BaseAdapter {
Account account = (Account) item;
AccountHolder holder = (AccountHolder) view.getTag();
holder.name.setText(account.getName());
holder.name.setText(account.getDisplayName());
holder.chip.setBackgroundColor(account.getChipColor());
} else if (item instanceof IdentityContainer) {
if (convertView != null && convertView.getTag() instanceof IdentityHolder) {

View file

@ -340,7 +340,7 @@ class MessageListFragment :
if (account == null || isUnifiedInbox || preferences.accounts.size == 1) {
null
} else {
account.name
account.displayName
}
}

View file

@ -380,7 +380,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
val dialogFragment = ConfirmationDialogFragment.newInstance(
DIALOG_DELETE_ACCOUNT,
getString(R.string.account_delete_dlg_title),
getString(R.string.account_delete_dlg_instructions_fmt, getAccount().name),
getString(R.string.account_delete_dlg_instructions_fmt, getAccount().displayName),
getString(R.string.okay_action),
getString(R.string.cancel_action)
)