0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 12:12:15 +02:00

Replace MessagingController.getAccountStats() with getUnreadMessageCount()

This commit is contained in:
cketti 2019-11-06 16:26:39 +01:00
parent c41382e3d4
commit 24a22beccc
4 changed files with 15 additions and 40 deletions

View File

@ -1748,8 +1748,14 @@ public class MessagingController {
}
}
public AccountStats getAccountStats(Account account) throws MessagingException {
return accountStatsCollector.getStats(account);
public int getUnreadMessageCount(Account account) {
try {
AccountStats stats = accountStatsCollector.getStats(account);
return (stats == null) ? 0 : stats.unreadMessageCount;
} catch (MessagingException e) {
Timber.e(e, "Unable to getUnreadMessageCount for account: %s", account);
return 0;
}
}
public AccountStats getSearchAccountStatsSynchronous(SearchAccount searchAccount) {
@ -2536,13 +2542,8 @@ public class MessagingController {
Timber.v("Clearing notification flag for %s", account.getDescription());
account.setRingNotified(false);
try {
AccountStats stats = getAccountStats(account);
if (stats == null || stats.unreadMessageCount == 0) {
notificationController.clearNewMailNotifications(account);
}
} catch (MessagingException e) {
Timber.e(e, "Unable to getUnreadMessageCount for account: %s", account);
if (getUnreadMessageCount(account) == 0) {
notificationController.clearNewMailNotifications(account);
}
}
}
@ -2996,17 +2997,7 @@ public class MessagingController {
this.listener = listener;
this.localStore = getLocalStoreOrThrow(account);
previousUnreadMessageCount = getUnreadMessageCount();
}
private int getUnreadMessageCount() {
try {
AccountStats stats = getAccountStats(account);
return stats.unreadMessageCount;
} catch (MessagingException e) {
Timber.e(e, "Unable to getUnreadMessageCount for account: %s", account);
return 0;
}
previousUnreadMessageCount = getUnreadMessageCount(account);
}
@Override

View File

@ -658,7 +658,6 @@ public class MessageProvider extends ContentProvider {
MatrixCursor cursor = new MatrixCursor(UNREAD_PROJECTION);
Account myAccount;
AccountStats myAccountStats;
Object[] values = new Object[2];
@ -669,19 +668,8 @@ public class MessageProvider extends ContentProvider {
for (Account account : accounts) {
if (account.getAccountNumber() == accountNumber) {
myAccount = account;
try {
myAccountStats = controller.getAccountStats(account);
values[0] = myAccount.getDescription();
if (myAccountStats == null) {
values[1] = 0;
} else {
values[1] = myAccountStats.unreadMessageCount;
}
} catch (MessagingException e) {
Timber.e(e.getMessage());
values[0] = "Unknown";
values[1] = 0;
}
values[0] = myAccount.getDescription();
values[1] = controller.getUnreadMessageCount(account);
cursor.addRow(values);
}
}

View File

@ -44,12 +44,8 @@ class UnreadWidgetDataProvider(
private fun loadAccountData(configuration: UnreadWidgetConfiguration): UnreadWidgetData? {
val account = preferences.getAccount(configuration.accountUuid) ?: return null
val title = account.description
val stats = messagingController.getAccountStats(account)
val unreadCount = stats.unreadMessageCount
val unreadCount = messagingController.getUnreadMessageCount(account)
val clickIntent = getClickIntentForAccount(account)
return UnreadWidgetData(configuration, title, unreadCount, clickIntent)

View File

@ -85,7 +85,7 @@ class UnreadWidgetDataProviderTest : AppRobolectricTest() {
fun createMessagingController(): MessagingController = mock {
on { getSearchAccountStatsSynchronous(any()) } doReturn SEARCH_ACCOUNT_STATS
on { getAccountStats(account) } doReturn ACCOUNT_STATS
on { getUnreadMessageCount(account) } doReturn ACCOUNT_UNREAD_COUNT
on { getFolderUnreadMessageCount(eq(account), eq(FOLDER_SERVER_ID)) } doReturn FOLDER_UNREAD_COUNT
}