Remove UnreadMessageCountProvider
This commit is contained in:
parent
106c132d8d
commit
74a0ed8b93
4 changed files with 16 additions and 88 deletions
|
@ -18,7 +18,6 @@ val controllerModule = module {
|
|||
get<NotificationController>(),
|
||||
get<NotificationStrategy>(),
|
||||
get<LocalStoreProvider>(),
|
||||
get<UnreadMessageCountProvider>(),
|
||||
get<MessageCountsProvider>(),
|
||||
get<BackendManager>(),
|
||||
get<Preferences>(),
|
||||
|
@ -27,6 +26,12 @@ val controllerModule = module {
|
|||
get(named("controllerExtensions"))
|
||||
)
|
||||
}
|
||||
single<UnreadMessageCountProvider> { DefaultUnreadMessageCountProvider(get(), get(), get(), get()) }
|
||||
single<MessageCountsProvider> { DefaultMessageCountsProvider(get(), get(), get(), get()) }
|
||||
single<MessageCountsProvider> {
|
||||
DefaultMessageCountsProvider(
|
||||
context = get(),
|
||||
preferences = get(),
|
||||
accountSearchConditions = get(),
|
||||
localStoreProvider = get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,6 @@ public class MessagingController {
|
|||
private final Set<MessagingListener> listeners = new CopyOnWriteArraySet<>();
|
||||
private final ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||
private final MemorizingMessagingListener memorizingMessagingListener = new MemorizingMessagingListener();
|
||||
private final UnreadMessageCountProvider unreadMessageCountProvider;
|
||||
private final MessageCountsProvider messageCountsProvider;
|
||||
private final DraftOperations draftOperations;
|
||||
|
||||
|
@ -141,14 +140,13 @@ public class MessagingController {
|
|||
|
||||
MessagingController(Context context, NotificationController notificationController,
|
||||
NotificationStrategy notificationStrategy, LocalStoreProvider localStoreProvider,
|
||||
UnreadMessageCountProvider unreadMessageCountProvider, MessageCountsProvider messageCountsProvider,
|
||||
BackendManager backendManager, Preferences preferences, MessageStoreManager messageStoreManager,
|
||||
MessageCountsProvider messageCountsProvider, BackendManager backendManager,
|
||||
Preferences preferences, MessageStoreManager messageStoreManager,
|
||||
SaveMessageDataCreator saveMessageDataCreator, List<ControllerExtension> controllerExtensions) {
|
||||
this.context = context;
|
||||
this.notificationController = notificationController;
|
||||
this.notificationStrategy = notificationStrategy;
|
||||
this.localStoreProvider = localStoreProvider;
|
||||
this.unreadMessageCountProvider = unreadMessageCountProvider;
|
||||
this.messageCountsProvider = messageCountsProvider;
|
||||
this.backendManager = backendManager;
|
||||
this.preferences = preferences;
|
||||
|
@ -1678,11 +1676,13 @@ public class MessagingController {
|
|||
}
|
||||
|
||||
public int getUnreadMessageCount(Account account) {
|
||||
return unreadMessageCountProvider.getUnreadMessageCount(account);
|
||||
MessageCounts messageCounts = messageCountsProvider.getMessageCounts(account);
|
||||
return messageCounts.getUnread();
|
||||
}
|
||||
|
||||
public int getUnreadMessageCount(SearchAccount searchAccount) {
|
||||
return unreadMessageCountProvider.getUnreadMessageCount(searchAccount);
|
||||
MessageCounts messageCounts = messageCountsProvider.getMessageCounts(searchAccount);
|
||||
return messageCounts.getUnread();
|
||||
}
|
||||
|
||||
public int getFolderUnreadMessageCount(Account account, Long folderId) throws MessagingException {
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package com.fsck.k9.controller
|
||||
|
||||
import android.content.Context
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.Preferences
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mailstore.LocalStoreProvider
|
||||
import com.fsck.k9.search.AccountSearchConditions
|
||||
import com.fsck.k9.search.LocalSearch
|
||||
import com.fsck.k9.search.SearchAccount
|
||||
import com.fsck.k9.search.getAccounts
|
||||
import timber.log.Timber
|
||||
|
||||
interface UnreadMessageCountProvider {
|
||||
fun getUnreadMessageCount(account: Account): Int
|
||||
fun getUnreadMessageCount(searchAccount: SearchAccount): Int
|
||||
}
|
||||
|
||||
internal class DefaultUnreadMessageCountProvider(
|
||||
private val context: Context,
|
||||
private val preferences: Preferences,
|
||||
private val accountSearchConditions: AccountSearchConditions,
|
||||
private val localStoreProvider: LocalStoreProvider
|
||||
) : UnreadMessageCountProvider {
|
||||
override fun getUnreadMessageCount(account: Account): Int {
|
||||
if (!account.isAvailable(context)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return try {
|
||||
val localStore = localStoreProvider.getInstance(account)
|
||||
|
||||
val search = LocalSearch()
|
||||
accountSearchConditions.excludeSpecialFolders(account, search)
|
||||
accountSearchConditions.limitToDisplayableFolders(account, search)
|
||||
|
||||
localStore.getUnreadMessageCount(search)
|
||||
} catch (e: MessagingException) {
|
||||
Timber.e(e, "Unable to getUnreadMessageCount for account: %s", account)
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
override fun getUnreadMessageCount(searchAccount: SearchAccount): Int {
|
||||
val search = searchAccount.relatedSearch
|
||||
val accounts = search.getAccounts(preferences)
|
||||
|
||||
var unreadMessageCount = 0
|
||||
for (account in accounts) {
|
||||
unreadMessageCount += getUnreadMessageCountWithLocalSearch(account, search)
|
||||
}
|
||||
|
||||
return unreadMessageCount
|
||||
}
|
||||
|
||||
private fun getUnreadMessageCountWithLocalSearch(account: Account, search: LocalSearch): Int {
|
||||
return try {
|
||||
val localStore = localStoreProvider.getInstance(account)
|
||||
localStore.getUnreadMessageCount(search)
|
||||
} catch (e: MessagingException) {
|
||||
Timber.e(e, "Unable to getUnreadMessageCount for account: %s", account)
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
|
@ -110,18 +110,6 @@ public class MessagingControllerTest extends K9RobolectricTest {
|
|||
private LocalMessage localMessageToSend1;
|
||||
private volatile boolean hasFetchedMessage = false;
|
||||
|
||||
private UnreadMessageCountProvider unreadMessageCountProvider = new UnreadMessageCountProvider() {
|
||||
@Override
|
||||
public int getUnreadMessageCount(@NotNull SearchAccount searchAccount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnreadMessageCount(@NotNull Account account) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
private MessageCountsProvider messageCountsProvider = new MessageCountsProvider() {
|
||||
@Override
|
||||
public MessageCounts getMessageCounts(@NotNull SearchAccount searchAccount) {
|
||||
|
@ -147,8 +135,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
|
|||
preferences = Preferences.getPreferences(appContext);
|
||||
|
||||
controller = new MessagingController(appContext, notificationController, notificationStrategy,
|
||||
localStoreProvider, unreadMessageCountProvider, messageCountsProvider, backendManager, preferences,
|
||||
messageStoreManager, saveMessageDataCreator, Collections.<ControllerExtension>emptyList());
|
||||
localStoreProvider, messageCountsProvider, backendManager, preferences, messageStoreManager,
|
||||
saveMessageDataCreator, Collections.<ControllerExtension>emptyList());
|
||||
|
||||
configureAccount();
|
||||
configureBackendManager();
|
||||
|
|
Loading…
Reference in a new issue