Merge pull request #5018 from k9mail/cleanup

Minor cleanup
This commit is contained in:
cketti 2020-10-20 04:07:54 +02:00 committed by GitHub
commit 9afa8b0afd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 67 deletions

View file

@ -1,11 +1,10 @@
package com.fsck.k9.controller
import android.content.Context
import com.fsck.k9.CoreResourceProvider
import com.fsck.k9.Preferences
import com.fsck.k9.backend.BackendManager
import com.fsck.k9.mailstore.LocalStoreProvider
import com.fsck.k9.mailstore.MessagesStoreProvider
import com.fsck.k9.mailstore.MessageStoreProvider
import com.fsck.k9.notification.NotificationController
import com.fsck.k9.notification.NotificationStrategy
import org.koin.core.qualifier.named
@ -19,10 +18,9 @@ val controllerModule = module {
get<NotificationStrategy>(),
get<LocalStoreProvider>(),
get<UnreadMessageCountProvider>(),
get<CoreResourceProvider>(),
get<BackendManager>(),
get<Preferences>(),
get<MessagesStoreProvider>(),
get<MessageStoreProvider>(),
get(named("controllerExtensions"))
)
}

View file

@ -70,7 +70,7 @@ import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.MessageStore;
import com.fsck.k9.mailstore.MessagesStoreProvider;
import com.fsck.k9.mailstore.MessageStoreProvider;
import com.fsck.k9.mailstore.OutboxState;
import com.fsck.k9.mailstore.OutboxStateRepository;
import com.fsck.k9.mailstore.SendState;
@ -116,7 +116,7 @@ public class MessagingController {
private final LocalStoreProvider localStoreProvider;
private final BackendManager backendManager;
private final Preferences preferences;
private final MessagesStoreProvider messagesStoreProvider;
private final MessageStoreProvider messageStoreProvider;
private final Thread controllerThread;
@ -125,7 +125,6 @@ public class MessagingController {
private final ExecutorService threadPool = Executors.newCachedThreadPool();
private final MemorizingMessagingListener memorizingMessagingListener = new MemorizingMessagingListener();
private final UnreadMessageCountProvider unreadMessageCountProvider;
private final CoreResourceProvider resourceProvider;
private final DraftOperations draftOperations;
@ -140,18 +139,17 @@ public class MessagingController {
MessagingController(Context context, NotificationController notificationController,
NotificationStrategy notificationStrategy, LocalStoreProvider localStoreProvider,
UnreadMessageCountProvider unreadMessageCountProvider, CoreResourceProvider resourceProvider,
BackendManager backendManager, Preferences preferences, MessagesStoreProvider messagesStoreProvider,
UnreadMessageCountProvider unreadMessageCountProvider, BackendManager backendManager,
Preferences preferences, MessageStoreProvider messageStoreProvider,
List<ControllerExtension> controllerExtensions) {
this.context = context;
this.notificationController = notificationController;
this.notificationStrategy = notificationStrategy;
this.localStoreProvider = localStoreProvider;
this.unreadMessageCountProvider = unreadMessageCountProvider;
this.resourceProvider = resourceProvider;
this.backendManager = backendManager;
this.preferences = preferences;
this.messagesStoreProvider = messagesStoreProvider;
this.messageStoreProvider = messageStoreProvider;
controllerThread = new Thread(new Runnable() {
@Override
@ -729,7 +727,8 @@ public class MessagingController {
try {
for (PendingCommand command : commands) {
processingCommand = command;
Timber.d("Processing pending command '%s'", command);
String commandName = command.getCommandName();
Timber.d("Processing pending command '%s'", commandName);
/*
* We specifically do not catch any exceptions here. If a command fails it is
@ -741,16 +740,16 @@ public class MessagingController {
localStore.removePendingCommand(command);
Timber.d("Done processing pending command '%s'", command);
Timber.d("Done processing pending command '%s'", commandName);
} catch (MessagingException me) {
if (me.isPermanentFailure()) {
Timber.e(me, "Failure of command '%s' was permanent, removing command from queue", command);
Timber.e(me, "Failure of command '%s' was permanent, removing command from queue", commandName);
localStore.removePendingCommand(processingCommand);
} else {
throw me;
}
} catch (Exception e) {
Timber.e(e, "Unexpected exception with command '%s', removing command from queue", command);
Timber.e(e, "Unexpected exception with command '%s', removing command from queue", commandName);
localStore.removePendingCommand(processingCommand);
if (K9.DEVELOPER_MODE) {
@ -1556,7 +1555,7 @@ public class MessagingController {
for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, outboxFolderId, progress, todo);
}
moveOrDeleteSentMessage(account, localStore, localFolder, message);
moveOrDeleteSentMessage(account, localStore, message);
outboxStateRepository.removeOutboxState(messageId);
} catch (AuthenticationFailedException e) {
@ -1618,8 +1617,8 @@ public class MessagingController {
}
}
private void moveOrDeleteSentMessage(Account account, LocalStore localStore,
LocalFolder localFolder, LocalMessage message) throws MessagingException {
private void moveOrDeleteSentMessage(Account account, LocalStore localStore, LocalMessage message)
throws MessagingException {
if (!account.hasSentFolder() || !account.isUploadSentMessages()) {
Timber.i("Not uploading sent message; deleting local message");
message.destroy();
@ -1630,7 +1629,7 @@ public class MessagingController {
String sentFolderServerId = sentFolder.getServerId();
Timber.i("Moving sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
MessageStore messageStore = messagesStoreProvider.getMessageStore(account);
MessageStore messageStore = messageStoreProvider.getMessageStore(account);
long destinationMessageId = messageStore.moveMessage(message.getDatabaseId(), sentFolderId);
Timber.i("Moved sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
@ -1836,7 +1835,7 @@ public class MessagingController {
}
}
} else {
MessageStore messageStore = messagesStoreProvider.getMessageStore(account);
MessageStore messageStore = messageStoreProvider.getMessageStore(account);
List<Long> messageIds = new ArrayList<>();
Map<Long, String> messageIdToUidMapping = new HashMap<>();
@ -2049,7 +2048,7 @@ public class MessagingController {
Timber.d("Deleting messages in normal folder, moving");
localTrashFolder = localStore.getFolder(trashFolderId);
MessageStore messageStore = messagesStoreProvider.getMessageStore(account);
MessageStore messageStore = messageStoreProvider.getMessageStore(account);
List<Long> messageIds = new ArrayList<>();
Map<Long, String> messageIdToUidMapping = new HashMap<>();

View file

@ -10,5 +10,5 @@ val mailStoreModule = module {
single { SpecialFolderSelectionStrategy() }
single { K9BackendStorageFactory(get(), get(), get(), get()) }
factory { SpecialLocalFoldersCreator(preferences = get(), localStoreProvider = get()) }
single { MessagesStoreProvider(messageStoreFactory = get()) }
single { MessageStoreProvider(messageStoreFactory = get()) }
}

View file

@ -3,7 +3,7 @@ package com.fsck.k9.mailstore
import com.fsck.k9.Account
import java.util.concurrent.ConcurrentHashMap
class MessagesStoreProvider(private val messageStoreFactory: MessageStoreFactory) {
class MessageStoreProvider(private val messageStoreFactory: MessageStoreFactory) {
private val messageStores = ConcurrentHashMap<String, MessageStore>()
fun getMessageStore(account: Account): MessageStore {

View file

@ -12,7 +12,6 @@ import android.content.Context;
import com.fsck.k9.Account;
import com.fsck.k9.AccountPreferenceSerializer;
import com.fsck.k9.CoreResourceProvider;
import com.fsck.k9.DI;
import com.fsck.k9.K9;
import com.fsck.k9.K9RobolectricTest;
@ -29,7 +28,7 @@ import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.MessagesStoreProvider;
import com.fsck.k9.mailstore.MessageStoreProvider;
import com.fsck.k9.mailstore.OutboxState;
import com.fsck.k9.mailstore.OutboxStateRepository;
import com.fsck.k9.mailstore.SendState;
@ -86,7 +85,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
@Mock
private LocalStoreProvider localStoreProvider;
@Mock
private MessagesStoreProvider messagesStoreProvider;
private MessageStoreProvider messageStoreProvider;
@Mock
private SimpleMessagingListener listener;
@Mock
@ -141,9 +140,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
Preferences preferences = Preferences.getPreferences(appContext);
controller = new MessagingController(appContext, notificationController, notificationStrategy,
localStoreProvider,
unreadMessageCountProvider, mock(CoreResourceProvider.class), backendManager, preferences,
messagesStoreProvider, Collections.<ControllerExtension>emptyList());
localStoreProvider, unreadMessageCountProvider, backendManager, preferences, messageStoreProvider,
Collections.<ControllerExtension>emptyList());
configureAccount();
configureBackendManager();

View file

@ -178,6 +178,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private final MessageLoaderHelperFactory messageLoaderHelperFactory = DI.get(MessageLoaderHelperFactory.class);
private final DefaultFolderProvider defaultFolderProvider = DI.get(DefaultFolderProvider.class);
private final MessagingController messagingController = DI.get(MessagingController.class);
private final Preferences preferences = DI.get(Preferences.class);
private final PermissionUiHelper permissionUiHelper = new K9PermissionUiHelper(this);
@ -279,10 +281,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
relatedMessageReference.getAccountUuid() :
intent.getStringExtra(EXTRA_ACCOUNT);
account = Preferences.getPreferences(this).getAccount(accountUuid);
account = preferences.getAccount(accountUuid);
if (account == null) {
account = Preferences.getPreferences(this).getDefaultAccount();
account = preferences.getDefaultAccount();
}
if (account == null) {
@ -578,13 +580,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override
protected void onResume() {
super.onResume();
MessagingController.getInstance(this).addListener(messagingListener);
messagingController.addListener(messagingListener);
}
@Override
public void onPause() {
super.onPause();
MessagingController.getInstance(this).removeListener(messagingListener);
messagingController.removeListener(messagingListener);
boolean isPausingOnConfigurationChange = (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION)
== ActivityInfo.CONFIG_ORIENTATION;
@ -786,7 +788,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private void onDiscard() {
if (draftMessageId != null) {
MessagingController.getInstance(getApplication()).deleteDraft(account, draftMessageId);
messagingController.deleteDraft(account, draftMessageId);
draftMessageId = null;
}
internalMessageHandler.sendEmptyMessage(MSG_DISCARDED_DRAFT);
@ -880,8 +882,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
if (previousDraftId != null) {
Timber.v("Account switch, deleting draft from previous account: %d", previousDraftId);
MessagingController.getInstance(getApplication()).deleteDraft(previousAccount,
previousDraftId);
messagingController.deleteDraft(previousAccount, previousDraftId);
}
} else {
this.account = account;
@ -1323,7 +1324,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private void processDraftMessage(MessageViewInfo messageViewInfo) {
Message message = messageViewInfo.message;
draftMessageId = MessagingController.getInstance(getApplication()).getId(message);
draftMessageId = messagingController.getId(message);
subjectView.setText(messageViewInfo.subject);
recipientPresenter.initFromDraftMessage(message);
@ -1390,8 +1391,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
if (messageReference != null) {
// Check if this is a valid account in our database
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Account account = prefs.getAccount(messageReference.getAccountUuid());
Account account = preferences.getAccount(messageReference.getAccountUuid());
if (account != null) {
relatedMessageReference = messageReference;
}
@ -1407,7 +1407,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
static class SendMessageTask extends AsyncTask<Void, Void, Void> {
final Context context;
final MessagingController messagingController;
final Preferences preferences;
final Account account;
final Contacts contacts;
final Message message;
@ -1415,9 +1416,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
final String plaintextSubject;
final MessageReference messageReference;
SendMessageTask(Context context, Account account, Contacts contacts, Message message,
Long draftId, String plaintextSubject, MessageReference messageReference) {
this.context = context;
SendMessageTask(MessagingController messagingController, Preferences preferences, Account account,
Contacts contacts, Message message, Long draftId, String plaintextSubject,
MessageReference messageReference) {
this.messagingController = messagingController;
this.preferences = preferences;
this.account = account;
this.contacts = contacts;
this.message = message;
@ -1437,10 +1440,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
Timber.e(e, "Failed to mark contact as contacted.");
}
MessagingController.getInstance(context).sendMessage(account, message, plaintextSubject, null);
messagingController.sendMessage(account, message, plaintextSubject, null);
if (draftId != null) {
// TODO set draft id to invalid in MessageCompose!
MessagingController.getInstance(context).deleteDraft(account, draftId);
messagingController.deleteDraft(account, draftId);
}
return null;
@ -1452,14 +1455,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private void updateReferencedMessage() {
if (messageReference != null && messageReference.getFlag() != null) {
String accountUuid = messageReference.getAccountUuid();
Account account = Preferences.getPreferences(context).getAccount(accountUuid);
Account account = preferences.getAccount(accountUuid);
long folderId = messageReference.getFolderId();
String sourceMessageUid = messageReference.getUid();
Flag flag = messageReference.getFlag();
Timber.d("Setting referenced message (%d, %s) flag to %s", folderId, sourceMessageUid, flag);
MessagingController messagingController = MessagingController.getInstance(context);
messagingController.setFlag(account, folderId, sourceMessageUid, flag, true);
}
}
@ -1535,8 +1537,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
changesMadeSinceLastSave = false;
currentMessageBuilder = null;
new SaveMessageTask(getApplicationContext(), account, contacts, internalMessageHandler,
message, draftMessageId, plaintextSubject).execute();
new SaveMessageTask(messagingController, account, internalMessageHandler, message, draftMessageId,
plaintextSubject).execute();
if (finishAfterDraftSaved) {
finish();
} else {
@ -1544,7 +1546,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
} else {
currentMessageBuilder = null;
new SendMessageTask(getApplicationContext(), account, contacts, message,
new SendMessageTask(messagingController, preferences, account, contacts, message,
draftMessageId, plaintextSubject, relatedMessageReference).execute();
finish();
}

View file

@ -1,42 +1,39 @@
package com.fsck.k9.activity.compose;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import com.fsck.k9.Account;
import com.fsck.k9.activity.MessageCompose;
import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.mail.Message;
public class SaveMessageTask extends AsyncTask<Void, Void, Void> {
Context context;
Account account;
Contacts contacts;
Handler handler;
Message message;
Long draftId;
String plaintextSubject;
private final MessagingController messagingController;
private final Account account;
private final Handler handler;
private final Message message;
private final Long existingDraftId;
private final String plaintextSubject;
public SaveMessageTask(Context context, Account account, Contacts contacts, Handler handler, Message message,
Long draftId, String plaintextSubject) {
this.context = context;
public SaveMessageTask(MessagingController messagingController, Account account, Handler handler, Message message,
Long existingDraftId, String plaintextSubject) {
this.messagingController = messagingController;
this.account = account;
this.contacts = contacts;
this.handler = handler;
this.message = message;
this.draftId = draftId;
this.existingDraftId = existingDraftId;
this.plaintextSubject = plaintextSubject;
}
@Override
protected Void doInBackground(Void... params) {
final MessagingController messagingController = MessagingController.getInstance(context);
draftId = messagingController.saveDraft(account, message, draftId, plaintextSubject);
Long messageId = messagingController.saveDraft(account, message, existingDraftId, plaintextSubject);
android.os.Message msg = android.os.Message.obtain(handler, MessageCompose.MSG_SAVED_DRAFT, draftId);
android.os.Message msg = android.os.Message.obtain(handler, MessageCompose.MSG_SAVED_DRAFT, messageId);
handler.sendMessage(msg);
return null;
}
}