Merge pull request #6236 from thundernest/fix_warnings

Code cleanup; fix some warnings
This commit is contained in:
cketti 2022-08-10 13:35:17 +02:00 committed by GitHub
commit 7a35120a7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 111 additions and 126 deletions

View file

@ -45,7 +45,7 @@ object Core : EarlyInit {
@JvmStatic @JvmStatic
fun setServicesEnabled(context: Context) { fun setServicesEnabled(context: Context) {
val appContext = context.applicationContext val appContext = context.applicationContext
val acctLength = Preferences.getPreferences(appContext).accounts.size val acctLength = Preferences.getPreferences().accounts.size
val enable = acctLength > 0 val enable = acctLength > 0
setServicesEnabled(appContext, enable) setServicesEnabled(appContext, enable)

View file

@ -48,11 +48,11 @@ class LocalKeyStoreManager(
* certificates for the incoming and outgoing servers. * certificates for the incoming and outgoing servers.
*/ */
fun deleteCertificates(account: Account) { fun deleteCertificates(account: Account) {
account.incomingServerSettings?.let { serverSettings -> account.incomingServerSettings.let { serverSettings ->
localKeyStore.deleteCertificate(serverSettings.host!!, serverSettings.port) localKeyStore.deleteCertificate(serverSettings.host!!, serverSettings.port)
} }
account.outgoingServerSettings?.let { serverSettings -> account.outgoingServerSettings.let { serverSettings ->
localKeyStore.deleteCertificate(serverSettings.host!!, serverSettings.port) localKeyStore.deleteCertificate(serverSettings.host!!, serverSettings.port)
} }
} }

View file

@ -1,6 +1,5 @@
package com.fsck.k9 package com.fsck.k9
import android.content.Context
import androidx.annotation.GuardedBy import androidx.annotation.GuardedBy
import androidx.annotation.RestrictTo import androidx.annotation.RestrictTo
import com.fsck.k9.mail.MessagingException import com.fsck.k9.mail.MessagingException
@ -291,8 +290,8 @@ class Preferences internal constructor(
companion object { companion object {
@JvmStatic @JvmStatic
fun getPreferences(context: Context): Preferences { fun getPreferences(): Preferences {
return DI.get(Preferences::class.java) return DI.get()
} }
} }
} }

View file

@ -227,7 +227,7 @@ public class LocalStore {
} }
protected Preferences getPreferences() { protected Preferences getPreferences() {
return Preferences.getPreferences(context); return Preferences.getPreferences();
} }
public OutboxStateRepository getOutboxStateRepository() { public OutboxStateRepository getOutboxStateRepository() {

View file

@ -188,7 +188,7 @@ public class SettingsImporter {
Imported imported = parseSettings(inputStream, globalSettings, accountUuids, false); Imported imported = parseSettings(inputStream, globalSettings, accountUuids, false);
Preferences preferences = Preferences.getPreferences(context); Preferences preferences = Preferences.getPreferences();
Storage storage = preferences.getStorage(); Storage storage = preferences.getStorage();
if (globalSettings) { if (globalSettings) {
@ -331,7 +331,7 @@ public class SettingsImporter {
AccountDescription original = new AccountDescription(account.name, account.uuid); AccountDescription original = new AccountDescription(account.name, account.uuid);
Preferences prefs = Preferences.getPreferences(context); Preferences prefs = Preferences.getPreferences();
List<Account> accounts = prefs.getAccounts(); List<Account> accounts = prefs.getAccounts();
String uuid = account.uuid; String uuid = account.uuid;

View file

@ -96,7 +96,7 @@ public class AttachmentProvider extends ContentProvider {
final AttachmentInfo attachmentInfo; final AttachmentInfo attachmentInfo;
try { try {
final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid); final Account account = Preferences.getPreferences().getAccount(accountUuid);
attachmentInfo = DI.get(LocalStoreProvider.class).getInstance(account).getAttachmentInfo(id); attachmentInfo = DI.get(LocalStoreProvider.class).getInstance(account).getAttachmentInfo(id);
} catch (MessagingException e) { } catch (MessagingException e) {
Timber.e(e, "Unable to retrieve attachment info from local store for ID: %s", id); Timber.e(e, "Unable to retrieve attachment info from local store for ID: %s", id);
@ -143,7 +143,7 @@ public class AttachmentProvider extends ContentProvider {
private String getType(String accountUuid, String id, String mimeType) { private String getType(String accountUuid, String id, String mimeType) {
String type; String type;
final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid); final Account account = Preferences.getPreferences().getAccount(accountUuid);
try { try {
final LocalStore localStore = DI.get(LocalStoreProvider.class).getInstance(account); final LocalStore localStore = DI.get(LocalStoreProvider.class).getInstance(account);
@ -182,7 +182,7 @@ public class AttachmentProvider extends ContentProvider {
@Nullable @Nullable
private OpenPgpDataSource getAttachmentDataSource(String accountUuid, String attachmentId) throws MessagingException { private OpenPgpDataSource getAttachmentDataSource(String accountUuid, String attachmentId) throws MessagingException {
final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid); final Account account = Preferences.getPreferences().getAccount(accountUuid);
LocalStore localStore = DI.get(LocalStoreProvider.class).getInstance(account); LocalStore localStore = DI.get(LocalStoreProvider.class).getInstance(account);
return localStore.getAttachmentDataSource(attachmentId); return localStore.getAttachmentDataSource(attachmentId);
} }

View file

@ -505,8 +505,7 @@ public class EmailProvider extends ContentProvider {
private Account getAccount(String accountUuid) { private Account getAccount(String accountUuid) {
if (mPreferences == null) { if (mPreferences == null) {
Context appContext = getContext().getApplicationContext(); mPreferences = Preferences.getPreferences();
mPreferences = Preferences.getPreferences(appContext);
} }
Account account = mPreferences.getAccount(accountUuid); Account account = mPreferences.getAccount(accountUuid);

View file

@ -174,7 +174,7 @@ public class RawMessageProvider extends ContentProvider {
long folderId = messageReference.getFolderId(); long folderId = messageReference.getFolderId();
String uid = messageReference.getUid(); String uid = messageReference.getUid();
Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid); Account account = Preferences.getPreferences().getAccount(accountUuid);
if (account == null) { if (account == null) {
Timber.w("Account not found: %s", accountUuid); Timber.w("Account not found: %s", accountUuid);
return null; return null;

View file

@ -179,7 +179,7 @@ public class DatabaseUpgradeService extends Service {
* Upgrade the accounts' databases. * Upgrade the accounts' databases.
*/ */
private void upgradeDatabases() { private void upgradeDatabases() {
Preferences preferences = Preferences.getPreferences(this); Preferences preferences = Preferences.getPreferences();
List<Account> accounts = preferences.getAccounts(); List<Account> accounts = preferences.getAccounts();
mProgressEnd = accounts.size(); mProgressEnd = accounts.size();

View file

@ -23,7 +23,7 @@ public class AutocryptHeaderParserTest extends RobolectricTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.getCacheDir()); BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.getApplication().getCacheDir());
} }
// Test cases taken from: https://github.com/mailencrypt/autocrypt/tree/master/src/tests/data // Test cases taken from: https://github.com/mailencrypt/autocrypt/tree/master/src/tests/data

View file

@ -4,6 +4,7 @@ package com.fsck.k9.cache;
import java.util.Collections; import java.util.Collections;
import java.util.UUID; import java.util.UUID;
import android.content.Context;
import android.net.Uri; import android.net.Uri;
import com.fsck.k9.RobolectricTest; import com.fsck.k9.RobolectricTest;
@ -26,6 +27,7 @@ import static org.mockito.Mockito.when;
public class EmailProviderCacheTest extends RobolectricTest { public class EmailProviderCacheTest extends RobolectricTest {
private final Context context = RuntimeEnvironment.getApplication();
private EmailProviderCache cache; private EmailProviderCache cache;
@Mock @Mock
@ -40,7 +42,7 @@ public class EmailProviderCacheTest extends RobolectricTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
EmailProvider.CONTENT_URI = Uri.parse("content://test.provider.email"); EmailProvider.CONTENT_URI = Uri.parse("content://test.provider.email");
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application); cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), context);
when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId); when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId);
when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder); when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder);
when(mockLocalMessageFolder.getDatabaseId()).thenReturn(localMessageFolderId); when(mockLocalMessageFolder.getDatabaseId()).thenReturn(localMessageFolderId);
@ -48,16 +50,16 @@ public class EmailProviderCacheTest extends RobolectricTest {
@Test @Test
public void getCache_returnsDifferentCacheForEachUUID() { public void getCache_returnsDifferentCacheForEachUUID() {
EmailProviderCache cache = EmailProviderCache.getCache("u001", RuntimeEnvironment.application); EmailProviderCache cache = EmailProviderCache.getCache("u001", context);
EmailProviderCache cache2 = EmailProviderCache.getCache("u002", RuntimeEnvironment.application); EmailProviderCache cache2 = EmailProviderCache.getCache("u002", context);
assertNotEquals(cache, cache2); assertNotEquals(cache, cache2);
} }
@Test @Test
public void getCache_returnsSameCacheForAUUID() { public void getCache_returnsSameCacheForAUUID() {
EmailProviderCache cache = EmailProviderCache.getCache("u001", RuntimeEnvironment.application); EmailProviderCache cache = EmailProviderCache.getCache("u001", context);
EmailProviderCache cache2 = EmailProviderCache.getCache("u001", RuntimeEnvironment.application); EmailProviderCache cache2 = EmailProviderCache.getCache("u001", context);
assertSame(cache, cache2); assertSame(cache, cache2);
} }

View file

@ -137,9 +137,9 @@ public class MessagingControllerTest extends K9RobolectricTest {
public void setUp() throws MessagingException { public void setUp() throws MessagingException {
ShadowLog.stream = System.out; ShadowLog.stream = System.out;
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
appContext = RuntimeEnvironment.application; appContext = RuntimeEnvironment.getApplication();
preferences = Preferences.getPreferences(appContext); preferences = Preferences.getPreferences();
controller = new MessagingController(appContext, notificationController, notificationStrategy, controller = new MessagingController(appContext, notificationController, notificationStrategy,
localStoreProvider, messageCountsProvider, backendManager, preferences, messageStoreManager, localStoreProvider, messageCountsProvider, backendManager, preferences, messageStoreManager,

View file

@ -22,7 +22,7 @@ public class MessageHelperTest extends RobolectricTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
Context context = RuntimeEnvironment.application; Context context = RuntimeEnvironment.getApplication();
contacts = new Contacts(context); contacts = new Contacts(context);
contactsWithFakeContact = new Contacts(context) { contactsWithFakeContact = new Contacts(context) {
@Override public String getNameForAddress(String address) { @Override public String getNameForAddress(String address) {

View file

@ -73,7 +73,7 @@ public class MessageViewInfoExtractorTest extends K9RobolectricTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
context = RuntimeEnvironment.application; context = RuntimeEnvironment.getApplication();
HtmlProcessor htmlProcessor = createFakeHtmlProcessor(); HtmlProcessor htmlProcessor = createFakeHtmlProcessor();
attachmentInfoExtractor = spy(DI.get(AttachmentInfoExtractor.class)); attachmentInfoExtractor = spy(DI.get(AttachmentInfoExtractor.class));

View file

@ -41,7 +41,7 @@ public class AttachmentInfoExtractorTest extends RobolectricTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
AttachmentProvider.CONTENT_URI = Uri.parse("content://test.attachmentprovider"); AttachmentProvider.CONTENT_URI = Uri.parse("content://test.attachmentprovider");
context = RuntimeEnvironment.application; context = RuntimeEnvironment.getApplication();
attachmentInfoExtractor = new AttachmentInfoExtractor(context); attachmentInfoExtractor = new AttachmentInfoExtractor(context);
} }

View file

@ -15,7 +15,7 @@ import org.mockito.kotlin.mock
import org.robolectric.RuntimeEnvironment import org.robolectric.RuntimeEnvironment
class SettingsExporterTest : K9RobolectricTest() { class SettingsExporterTest : K9RobolectricTest() {
private val contentResolver = RuntimeEnvironment.application.contentResolver private val contentResolver = RuntimeEnvironment.getApplication().contentResolver
private val preferences: Preferences by inject() private val preferences: Preferences by inject()
private val folderSettingsProvider: FolderSettingsProvider by inject() private val folderSettingsProvider: FolderSettingsProvider by inject()
private val folderRepository: FolderRepository by inject() private val folderRepository: FolderRepository by inject()

View file

@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import android.content.Context;
import com.fsck.k9.K9RobolectricTest; import com.fsck.k9.K9RobolectricTest;
import com.fsck.k9.Preferences; import com.fsck.k9.Preferences;
import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.AuthType;
@ -20,6 +22,7 @@ import static org.junit.Assert.assertTrue;
public class SettingsImporterTest extends K9RobolectricTest { public class SettingsImporterTest extends K9RobolectricTest {
private final Context context = RuntimeEnvironment.getApplication();
@Before @Before
public void before() { public void before() {
@ -27,7 +30,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
} }
private void deletePreExistingAccounts() { private void deletePreExistingAccounts() {
Preferences preferences = Preferences.getPreferences(RuntimeEnvironment.application); Preferences preferences = Preferences.getPreferences();
preferences.clearAccounts(); preferences.clearAccounts();
} }
@ -36,7 +39,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf(""); InputStream inputStream = inputStreamOf("");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test(expected = SettingsImportExportException.class) @Test(expected = SettingsImportExportException.class)
@ -44,7 +47,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings version=\"1\"></k9settings>"); InputStream inputStream = inputStreamOf("<k9settings version=\"1\"></k9settings>");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test(expected = SettingsImportExportException.class) @Test(expected = SettingsImportExportException.class)
@ -52,7 +55,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings version=\"1\" format=\"A\"></k9settings>"); InputStream inputStream = inputStreamOf("<k9settings version=\"1\" format=\"A\"></k9settings>");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test(expected = SettingsImportExportException.class) @Test(expected = SettingsImportExportException.class)
@ -60,7 +63,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings version=\"1\" format=\"0\"></k9settings>"); InputStream inputStream = inputStreamOf("<k9settings version=\"1\" format=\"0\"></k9settings>");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test(expected = SettingsImportExportException.class) @Test(expected = SettingsImportExportException.class)
@ -68,7 +71,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings format=\"1\"></k9settings>"); InputStream inputStream = inputStreamOf("<k9settings format=\"1\"></k9settings>");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test(expected = SettingsImportExportException.class) @Test(expected = SettingsImportExportException.class)
@ -76,7 +79,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings format=\"1\" version=\"A\"></k9settings>"); InputStream inputStream = inputStreamOf("<k9settings format=\"1\" version=\"A\"></k9settings>");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test(expected = SettingsImportExportException.class) @Test(expected = SettingsImportExportException.class)
@ -84,7 +87,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings format=\"1\" version=\"0\"></k9settings>"); InputStream inputStream = inputStreamOf("<k9settings format=\"1\" version=\"0\"></k9settings>");
List<String> accountUuids = new ArrayList<>(); List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true); SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
} }
@Test @Test
@ -162,7 +165,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
accountUuids.add(validUUID); accountUuids.add(validUUID);
SettingsImporter.ImportResults results = SettingsImporter.importSettings( SettingsImporter.ImportResults results = SettingsImporter.importSettings(
RuntimeEnvironment.application, inputStream, true, accountUuids, false); context, inputStream, true, accountUuids, false);
assertEquals(0, results.erroneousAccounts.size()); assertEquals(0, results.erroneousAccounts.size());
assertEquals(1, results.importedAccounts.size()); assertEquals(1, results.importedAccounts.size());

View file

@ -149,7 +149,7 @@ public class MessageProvider extends ContentProvider {
// get account // get account
Account myAccount = null; Account myAccount = null;
for (Account account : Preferences.getPreferences(getContext()).getAccounts()) { for (Account account : Preferences.getPreferences().getAccounts()) {
if (account.getAccountNumber() == accountId) { if (account.getAccountNumber() == accountId) {
myAccount = account; myAccount = account;
} }
@ -601,7 +601,7 @@ public class MessageProvider extends ContentProvider {
MatrixCursor cursor = new MatrixCursor(projection); MatrixCursor cursor = new MatrixCursor(projection);
for (Account account : Preferences.getPreferences(getContext()).getAccounts()) { for (Account account : Preferences.getPreferences().getAccounts()) {
Object[] values = new Object[projection.length]; Object[] values = new Object[projection.length];
int fieldIndex = 0; int fieldIndex = 0;
@ -667,7 +667,7 @@ public class MessageProvider extends ContentProvider {
Context context = getContext(); Context context = getContext();
MessagingController controller = MessagingController.getInstance(context); MessagingController controller = MessagingController.getInstance(context);
Collection<Account> accounts = Preferences.getPreferences(context).getAccounts(); Collection<Account> accounts = Preferences.getPreferences().getAccounts();
for (Account account : accounts) { for (Account account : accounts) {
if (account.getAccountNumber() == accountNumber) { if (account.getAccountNumber() == accountNumber) {

View file

@ -35,7 +35,7 @@ class UnreadWidgetDataProvider(
private fun loadSearchAccountData(configuration: UnreadWidgetConfiguration): UnreadWidgetData { private fun loadSearchAccountData(configuration: UnreadWidgetConfiguration): UnreadWidgetData {
val searchAccount = getSearchAccount(configuration.accountUuid) val searchAccount = getSearchAccount(configuration.accountUuid)
val title = searchAccount.name ?: searchAccount.email val title = searchAccount.name
val unreadCount = messagingController.getUnreadMessageCount(searchAccount) val unreadCount = messagingController.getUnreadMessageCount(searchAccount)
val clickIntent = MessageList.intentDisplaySearch(context, searchAccount.relatedSearch, false, true, true) val clickIntent = MessageList.intentDisplaySearch(context, searchAccount.relatedSearch, false, true, true)

View file

@ -1,6 +1,5 @@
package com.fsck.k9 package com.fsck.k9
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import com.fsck.k9.ui.changelog.ChangeLogMode import com.fsck.k9.ui.changelog.ChangeLogMode
import com.fsck.k9.ui.changelog.ChangelogViewModel import com.fsck.k9.ui.changelog.ChangelogViewModel
@ -26,10 +25,10 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class) @RunWith(RobolectricTestRunner::class)
@Config(application = App::class) @Config(application = App::class)
class DependencyInjectionTest : AutoCloseKoinTest() { class DependencyInjectionTest : AutoCloseKoinTest() {
val lifecycleOwner = mock<LifecycleOwner> { private val lifecycleOwner = mock<LifecycleOwner> {
on { lifecycle } doReturn mock<Lifecycle>() on { lifecycle } doReturn mock()
} }
val autocryptTransferView = mock<AutocryptKeyTransferActivity>() private val autocryptTransferView = mock<AutocryptKeyTransferActivity>()
@KoinInternalApi @KoinInternalApi
@Test @Test
@ -38,9 +37,9 @@ class DependencyInjectionTest : AutoCloseKoinTest() {
getKoin().checkModules { getKoin().checkModules {
withParameter<OpenPgpApiManager> { lifecycleOwner } withParameter<OpenPgpApiManager> { lifecycleOwner }
create<AutocryptKeyTransferPresenter> { parametersOf(lifecycleOwner, autocryptTransferView) } withParameters<AutocryptKeyTransferPresenter> { parametersOf(lifecycleOwner, autocryptTransferView) }
withParameter<FolderNameFormatter> { RuntimeEnvironment.application } withParameter<FolderNameFormatter> { RuntimeEnvironment.getApplication() }
withParameter<SizeFormatter> { RuntimeEnvironment.application } withParameter<SizeFormatter> { RuntimeEnvironment.getApplication() }
withParameter<ChangelogViewModel> { ChangeLogMode.CHANGE_LOG } withParameter<ChangelogViewModel> { ChangeLogMode.CHANGE_LOG }
} }
} }

View file

@ -21,7 +21,7 @@ import org.mockito.kotlin.mock
import org.robolectric.RuntimeEnvironment import org.robolectric.RuntimeEnvironment
class UnreadWidgetDataProviderTest : AppRobolectricTest() { class UnreadWidgetDataProviderTest : AppRobolectricTest() {
val context: Context = RuntimeEnvironment.application val context: Context = RuntimeEnvironment.getApplication()
val account = createAccount() val account = createAccount()
val preferences = createPreferences() val preferences = createPreferences()
val messagingController = createMessagingController() val messagingController = createMessagingController()

View file

@ -15,7 +15,7 @@ internal class FlagMessageOperations(private val lockableDatabase: LockableDatab
if (flag in SPECIAL_FLAGS) { if (flag in SPECIAL_FLAGS) {
setSpecialFlags(messageIds, flag, set) setSpecialFlags(messageIds, flag, set)
} else { } else {
rebuildFlagsColumnValue(messageIds, flag, set) throw UnsupportedOperationException("not implemented")
} }
} }
@ -54,10 +54,6 @@ internal class FlagMessageOperations(private val lockableDatabase: LockableDatab
} }
} }
private fun rebuildFlagsColumnValue(messageIds: Collection<Long>, flag: Flag, set: Boolean) {
throw UnsupportedOperationException("not implemented")
}
private fun rebuildFlagsColumnValue(folderId: Long, messageServerId: String, flag: Flag, set: Boolean) { private fun rebuildFlagsColumnValue(folderId: Long, messageServerId: String, flag: Flag, set: Boolean) {
lockableDatabase.execute(true) { database -> lockableDatabase.execute(true) { database ->
val oldFlags = database.readFlagsColumn(folderId, messageServerId) val oldFlags = database.readFlagsColumn(folderId, messageServerId)

View file

@ -18,7 +18,7 @@ import org.mockito.kotlin.verifyNoMoreInteractions
import org.robolectric.RuntimeEnvironment import org.robolectric.RuntimeEnvironment
class StoragePersisterTest : K9RobolectricTest() { class StoragePersisterTest : K9RobolectricTest() {
private var context: Context = RuntimeEnvironment.application private var context: Context = RuntimeEnvironment.getApplication()
private var storagePersister = K9StoragePersister(context) private var storagePersister = K9StoragePersister(context)
@Test @Test

View file

@ -45,7 +45,7 @@ public class StoreSchemaDefinitionTest extends K9RobolectricTest {
public void setUp() throws MessagingException { public void setUp() throws MessagingException {
ShadowLog.stream = System.out; ShadowLog.stream = System.out;
Application application = RuntimeEnvironment.application; Application application = RuntimeEnvironment.getApplication();
StorageManager.getInstance(application); StorageManager.getInstance(application);
storeSchemaDefinition = createStoreSchemaDefinition(); storeSchemaDefinition = createStoreSchemaDefinition();

View file

@ -155,7 +155,7 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
class LoadAccounts extends AsyncTask<Void, Void, List<Account>> { class LoadAccounts extends AsyncTask<Void, Void, List<Account>> {
@Override @Override
protected List<Account> doInBackground(Void... params) { protected List<Account> doInBackground(Void... params) {
return Preferences.getPreferences(getApplicationContext()).getAccounts(); return Preferences.getPreferences().getAccounts();
} }
@Override @Override

View file

@ -37,7 +37,7 @@ public class ChooseIdentity extends K9ListActivity {
getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
Intent intent = getIntent(); Intent intent = getIntent();
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);

View file

@ -35,7 +35,7 @@ class EditIdentity : K9Activity() {
identityIndex = intent.getIntExtra(EXTRA_IDENTITY_INDEX, -1) identityIndex = intent.getIntExtra(EXTRA_IDENTITY_INDEX, -1)
val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT) ?: error("Missing account UUID") val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT) ?: error("Missing account UUID")
account = Preferences.getPreferences(this).getAccount(accountUuid) ?: error("Couldn't find account") account = Preferences.getPreferences().getAccount(accountUuid) ?: error("Couldn't find account")
identity = when { identity = when {
savedInstanceState != null -> savedInstanceState.getParcelable(EXTRA_IDENTITY) ?: error("Missing state") savedInstanceState != null -> savedInstanceState.getParcelable(EXTRA_IDENTITY) ?: error("Missing state")
@ -91,7 +91,7 @@ class EditIdentity : K9Activity() {
identities.add(identityIndex, identity) identities.add(identityIndex, identity)
} }
Preferences.getPreferences(applicationContext).saveAccount(account) Preferences.getPreferences().saveAccount(account)
finish() finish()
} }

View file

@ -139,7 +139,7 @@ public class ManageIdentities extends ChooseIdentity {
private void saveIdentities() { private void saveIdentities() {
if (mIdentitiesChanged) { if (mIdentitiesChanged) {
mAccount.setIdentities(identities); mAccount.setIdentities(identities);
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount); Preferences.getPreferences().saveAccount(mAccount);
} }
finish(); finish();
} }

View file

@ -936,7 +936,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
updateSignature(); updateSignature();
updateMessageFormat(); updateMessageFormat();
replyToPresenter.setIdentity(identity); replyToPresenter.setIdentity(identity);
recipientPresenter.onSwitchIdentity(identity); recipientPresenter.onSwitchIdentity();
} }
private void updateFrom() { private void updateFrom() {

View file

@ -973,8 +973,8 @@ open class MessageList :
progressBar!!.visibility = if (enable) View.VISIBLE else View.INVISIBLE progressBar!!.visibility = if (enable) View.VISIBLE else View.INVISIBLE
} }
override fun setMessageListProgress(progress: Int) { override fun setMessageListProgress(level: Int) {
progressBar!!.progress = progress progressBar!!.progress = level
} }
override fun openMessage(messageReference: MessageReference) { override fun openMessage(messageReference: MessageReference) {

View file

@ -115,7 +115,7 @@ public class MessageLoaderHelper {
public void asyncStartOrResumeLoadingMessage(MessageReference messageReference, Parcelable cachedDecryptionResult) { public void asyncStartOrResumeLoadingMessage(MessageReference messageReference, Parcelable cachedDecryptionResult) {
onlyLoadMetadata = false; onlyLoadMetadata = false;
this.messageReference = messageReference; this.messageReference = messageReference;
this.account = Preferences.getPreferences(context).getAccount(messageReference.getAccountUuid()); this.account = Preferences.getPreferences().getAccount(messageReference.getAccountUuid());
if (cachedDecryptionResult != null) { if (cachedDecryptionResult != null) {
if (cachedDecryptionResult instanceof OpenPgpDecryptionResult) { if (cachedDecryptionResult instanceof OpenPgpDecryptionResult) {
@ -132,7 +132,7 @@ public class MessageLoaderHelper {
public void asyncStartOrResumeLoadingMessageMetadata(MessageReference messageReference) { public void asyncStartOrResumeLoadingMessageMetadata(MessageReference messageReference) {
onlyLoadMetadata = true; onlyLoadMetadata = true;
this.messageReference = messageReference; this.messageReference = messageReference;
this.account = Preferences.getPreferences(context).getAccount(messageReference.getAccountUuid()); this.account = Preferences.getPreferences().getAccount(messageReference.getAccountUuid());
startOrResumeLocalMessageLoader(); startOrResumeLocalMessageLoader();
} }

View file

@ -115,7 +115,7 @@ public class UpgradeDatabases extends K9Activity {
return; return;
} }
mPreferences = Preferences.getPreferences(getApplicationContext()); mPreferences = Preferences.getPreferences();
initializeLayout(); initializeLayout();

View file

@ -32,7 +32,7 @@ public class IdentityAdapter extends BaseAdapter {
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
List<Object> items = new ArrayList<>(); List<Object> items = new ArrayList<>();
Preferences prefs = Preferences.getPreferences(context.getApplicationContext()); Preferences prefs = Preferences.getPreferences();
Collection<Account> accounts = prefs.getAccounts(); Collection<Account> accounts = prefs.getAccounts();
for (Account account : accounts) { for (Account account : accounts) {
items.add(account); items.add(account);

View file

@ -17,7 +17,7 @@ public class MessageActions {
* activity. * activity.
*/ */
public static void actionCompose(Context context, Account account) { public static void actionCompose(Context context, Account account) {
Account defaultAccount = Preferences.getPreferences(context).getDefaultAccount(); Account defaultAccount = Preferences.getPreferences().getDefaultAccount();
if (account == null && defaultAccount == null) { if (account == null && defaultAccount == null) {
AccountSetupBasics.actionNewAccount(context); AccountSetupBasics.actionNewAccount(context);
} else { } else {

View file

@ -12,7 +12,6 @@ import android.view.Menu
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.loader.app.LoaderManager import androidx.loader.app.LoaderManager
import com.fsck.k9.Account import com.fsck.k9.Account
import com.fsck.k9.Identity
import com.fsck.k9.K9 import com.fsck.k9.K9
import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState
import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState
@ -323,7 +322,7 @@ class RecipientPresenter(
openPgpApiManager.setOpenPgpProvider(openPgpProvider, openPgpCallback) openPgpApiManager.setOpenPgpProvider(openPgpProvider, openPgpCallback)
} }
fun onSwitchIdentity(identity: Identity) { fun onSwitchIdentity() {
// TODO decide what actually to do on identity switch? // TODO decide what actually to do on identity switch?
asyncUpdateCryptoStatus() asyncUpdateCryptoStatus()
} }
@ -623,14 +622,12 @@ class RecipientPresenter(
SendErrorState.ENABLED_ERROR -> recipientMvpView.showOpenPgpEnabledErrorDialog(false) SendErrorState.ENABLED_ERROR -> recipientMvpView.showOpenPgpEnabledErrorDialog(false)
SendErrorState.PROVIDER_ERROR -> recipientMvpView.showErrorOpenPgpConnection() SendErrorState.PROVIDER_ERROR -> recipientMvpView.showErrorOpenPgpConnection()
SendErrorState.KEY_CONFIG_ERROR -> recipientMvpView.showErrorNoKeyConfigured() SendErrorState.KEY_CONFIG_ERROR -> recipientMvpView.showErrorNoKeyConfigured()
else -> throw AssertionError("not all error states handled, this is a bug!")
} }
} }
fun showPgpAttachError(attachErrorState: AttachErrorState) { fun showPgpAttachError(attachErrorState: AttachErrorState) {
when (attachErrorState) { when (attachErrorState) {
AttachErrorState.IS_INLINE -> recipientMvpView.showErrorInlineAttach() AttachErrorState.IS_INLINE -> recipientMvpView.showErrorInlineAttach()
else -> throw AssertionError("not all error states handled, this is a bug!")
} }
} }

View file

@ -46,7 +46,7 @@ public class AccountSetupComposition extends K9Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
setLayout(R.layout.account_setup_composition); setLayout(R.layout.account_setup_composition);
setTitle(R.string.account_settings_composition_title); setTitle(R.string.account_settings_composition_title);
@ -61,7 +61,7 @@ public class AccountSetupComposition extends K9Activity {
*/ */
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
} }
mAccountName = findViewById(R.id.account_name); mAccountName = findViewById(R.id.account_name);
@ -129,7 +129,7 @@ public class AccountSetupComposition extends K9Activity {
mAccount.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText); mAccount.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText);
} }
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount); Preferences.getPreferences().saveAccount(mAccount);
} }
@Override @Override

View file

@ -158,7 +158,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789")); mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
/* /*
@ -167,7 +167,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
*/ */
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
} }
boolean oAuthSupported = mAccount.getIncomingServerSettings().type.equals(Protocols.IMAP); boolean oAuthSupported = mAccount.getIncomingServerSettings().type.equals(Protocols.IMAP);
@ -539,7 +539,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (Intent.ACTION_EDIT.equals(getIntent().getAction())) { if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount); Preferences.getPreferences().saveAccount(mAccount);
finish(); finish();
} else { } else {
/* /*

View file

@ -65,7 +65,7 @@ public class AccountSetupNames extends K9Activity implements OnClickListener {
mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS)); mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS));
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
String senderName = mAccount.getSenderName(); String senderName = mAccount.getSenderName();
if (senderName != null) { if (senderName != null) {
@ -88,7 +88,7 @@ public class AccountSetupNames extends K9Activity implements OnClickListener {
} }
mAccount.setSenderName(mName.getText().toString()); mAccount.setSenderName(mName.getText().toString());
mAccount.markSetupFinished(); mAccount.markSetupFinished();
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount); Preferences.getPreferences().saveAccount(mAccount);
finishAffinity(); finishAffinity();
MessageList.launch(this, mAccount); MessageList.launch(this, mAccount);
} }

View file

@ -92,7 +92,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener {
mDisplayCountView.setAdapter(displayCountsAdapter); mDisplayCountView.setAdapter(displayCountsAdapter);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
mNotifyView.setChecked(mAccount.isNotifyNewMail()); mNotifyView.setChecked(mAccount.isNotifyNewMail());
SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, mAccount SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, mAccount
@ -111,7 +111,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener {
mAccount.setFolderPushMode(Account.FolderMode.NONE); mAccount.setFolderPushMode(Account.FolderMode.NONE);
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount); Preferences.getPreferences().saveAccount(mAccount);
Core.setServicesEnabled(this); Core.setServicesEnabled(this);
AccountSetupNames.actionSetNames(this, mAccount); AccountSetupNames.actionSetNames(this, mAccount);
} }

View file

@ -101,7 +101,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
setTitle(R.string.account_setup_outgoing_title); setTitle(R.string.account_setup_outgoing_title);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
ServerSettings incomingServerSettings = mAccount.getIncomingServerSettings(); ServerSettings incomingServerSettings = mAccount.getIncomingServerSettings();
if (incomingServerSettings.type.equals(Protocols.WEBDAV)) { if (incomingServerSettings.type.equals(Protocols.WEBDAV)) {
@ -138,7 +138,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
//FIXME: get Account object again? //FIXME: get Account object again?
accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
/* /*
* If we're being reloaded we override the original account with the one * If we're being reloaded we override the original account with the one
@ -146,7 +146,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
*/ */
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mAccount = Preferences.getPreferences().getAccount(accountUuid);
} }
boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction()); boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());
@ -495,7 +495,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (Intent.ACTION_EDIT.equals(getIntent().getAction())) { if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount); Preferences.getPreferences().saveAccount(mAccount);
finish(); finish();
} else { } else {
AccountSetupOptions.actionOptions(this, mAccount); AccountSetupOptions.actionOptions(this, mAccount);

View file

@ -86,7 +86,7 @@ public class AttachmentController {
private void downloadAttachment(LocalPart localPart, final Runnable attachmentDownloadedCallback) { private void downloadAttachment(LocalPart localPart, final Runnable attachmentDownloadedCallback) {
String accountUuid = localPart.getAccountUuid(); String accountUuid = localPart.getAccountUuid();
Account account = Preferences.getPreferences(context).getAccount(accountUuid); Account account = Preferences.getPreferences().getAccount(accountUuid);
LocalMessage message = localPart.getMessage(); LocalMessage message = localPart.getMessage();
messageViewFragment.showAttachmentLoadingDialog(); messageViewFragment.showAttachmentLoadingDialog();
@ -220,11 +220,6 @@ public class AttachmentController {
private class ViewAttachmentAsyncTask extends AsyncTask<Void, Void, Intent> { private class ViewAttachmentAsyncTask extends AsyncTask<Void, Void, Intent> {
@Override
protected void onPreExecute() {
messageViewFragment.disableAttachmentButtons(attachment);
}
@Override @Override
protected Intent doInBackground(Void... params) { protected Intent doInBackground(Void... params) {
return getBestViewIntent(); return getBestViewIntent();
@ -233,7 +228,6 @@ public class AttachmentController {
@Override @Override
protected void onPostExecute(Intent intent) { protected void onPostExecute(Intent intent) {
viewAttachment(intent); viewAttachment(intent);
messageViewFragment.enableAttachmentButtons(attachment);
} }
private void viewAttachment(Intent intent) { private void viewAttachment(Intent intent) {
@ -250,11 +244,6 @@ public class AttachmentController {
private class SaveAttachmentAsyncTask extends AsyncTask<Uri, Void, Boolean> { private class SaveAttachmentAsyncTask extends AsyncTask<Uri, Void, Boolean> {
@Override
protected void onPreExecute() {
messageViewFragment.disableAttachmentButtons(attachment);
}
@Override @Override
protected Boolean doInBackground(Uri... params) { protected Boolean doInBackground(Uri... params) {
try { try {
@ -269,7 +258,6 @@ public class AttachmentController {
@Override @Override
protected void onPostExecute(Boolean success) { protected void onPostExecute(Boolean success) {
messageViewFragment.enableAttachmentButtons(attachment);
if (!success) { if (!success) {
displayAttachmentNotSavedMessage(); displayAttachmentNotSavedMessage();
} }

View file

@ -736,10 +736,6 @@ class MessageViewFragment :
startActivity(intent) startActivity(intent)
} }
fun disableAttachmentButtons(attachment: AttachmentViewInfo?) = Unit
fun enableAttachmentButtons(attachment: AttachmentViewInfo?) = Unit
fun runOnMainThread(runnable: Runnable) { fun runOnMainThread(runnable: Runnable) {
requireActivity().runOnUiThread(runnable) requireActivity().runOnUiThread(runnable)
} }

View file

@ -66,7 +66,7 @@ public class OpenPgpAppSelectDialog extends K9Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
account = Preferences.getPreferences(this).getAccount(accountUuid); account = Preferences.getPreferences().getAccount(accountUuid);
} }
@Override @Override
@ -283,7 +283,7 @@ public class OpenPgpAppSelectDialog extends K9Activity {
private void persistOpenPgpProviderSetting(String selectedPackage) { private void persistOpenPgpProviderSetting(String selectedPackage) {
account.setOpenPgpProvider(selectedPackage); account.setOpenPgpProvider(selectedPackage);
Preferences.getPreferences(getApplicationContext()).saveAccount(account); Preferences.getPreferences().saveAccount(account);
} }
private static class OpenPgpProviderEntry { private static class OpenPgpProviderEntry {

View file

@ -77,7 +77,7 @@ public class RecipientLoaderTest extends RobolectricTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
Application application = RuntimeEnvironment.application; Application application = RuntimeEnvironment.getApplication();
shadowApp = Shadows.shadowOf(application); shadowApp = Shadows.shadowOf(application);
shadowApp.grantPermissions(Manifest.permission.READ_CONTACTS); shadowApp.grantPermissions(Manifest.permission.READ_CONTACTS);
shadowApp.grantPermissions(Manifest.permission.WRITE_CONTACTS); shadowApp.grantPermissions(Manifest.permission.WRITE_CONTACTS);

View file

@ -81,7 +81,7 @@ class PgpMessageBuilderTest : K9RobolectricTest() {
@Before @Before
@Throws(Exception::class) @Throws(Exception::class)
fun setUp() { fun setUp() {
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.cacheDir) BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.getApplication().cacheDir)
`when`(autocryptOpenPgpApiInteractor.getKeyMaterialForKeyId(openPgpApi, TEST_KEY_ID, SENDER_EMAIL)) `when`(autocryptOpenPgpApiInteractor.getKeyMaterialForKeyId(openPgpApi, TEST_KEY_ID, SENDER_EMAIL))
.thenReturn(AUTOCRYPT_KEY_MATERIAL) .thenReturn(AUTOCRYPT_KEY_MATERIAL)
} }

View file

@ -8,7 +8,7 @@ import org.robolectric.RuntimeEnvironment
class K9DrawerTest : RobolectricTest() { class K9DrawerTest : RobolectricTest() {
@Test @Test
fun testAccountColorLengthEqualsDrawerColorLength() { fun testAccountColorLengthEqualsDrawerColorLength() {
val resources = RuntimeEnvironment.application.resources val resources = RuntimeEnvironment.getApplication().resources
val lightColors = resources.getIntArray(R.array.account_colors) val lightColors = resources.getIntArray(R.array.account_colors)
val darkColors = resources.getIntArray(R.array.drawer_account_accent_color_dark_theme) val darkColors = resources.getIntArray(R.array.drawer_account_accent_color_dark_theme)

View file

@ -70,7 +70,7 @@ public class MessageCryptoHelperTest extends RobolectricTest {
when(openPgpApiFactory.createOpenPgpApi(any(Context.class), nullable(IOpenPgpService2.class))) when(openPgpApiFactory.createOpenPgpApi(any(Context.class), nullable(IOpenPgpService2.class)))
.thenReturn(openPgpApi); .thenReturn(openPgpApi);
messageCryptoHelper = new MessageCryptoHelper(RuntimeEnvironment.application, openPgpApiFactory, messageCryptoHelper = new MessageCryptoHelper(RuntimeEnvironment.getApplication(), openPgpApiFactory,
autocryptOperations, "org.example.dummy"); autocryptOperations, "org.example.dummy");
messageCryptoCallback = mock(MessageCryptoCallback.class); messageCryptoCallback = mock(MessageCryptoCallback.class);
} }

View file

@ -16,7 +16,7 @@ import org.robolectric.annotation.Config
@Config(qualifiers = "en") @Config(qualifiers = "en")
class RelativeDateTimeFormatterTest : RobolectricTest() { class RelativeDateTimeFormatterTest : RobolectricTest() {
private val context = RuntimeEnvironment.application.applicationContext private val context = RuntimeEnvironment.getApplication().applicationContext
private val clock = TestClock() private val clock = TestClock()
private val dateTimeFormatter = RelativeDateTimeFormatter(context, clock) private val dateTimeFormatter = RelativeDateTimeFormatter(context, clock)

View file

@ -8,7 +8,7 @@ import org.robolectric.annotation.Config
@Config(qualifiers = "en") @Config(qualifiers = "en")
class SizeFormatterTest : RobolectricTest() { class SizeFormatterTest : RobolectricTest() {
private val sizeFormatter = SizeFormatter(RuntimeEnvironment.application.resources) private val sizeFormatter = SizeFormatter(RuntimeEnvironment.getApplication().resources)
@Test @Test
fun bytes_lower_bound() { fun bytes_lower_bound() {

View file

@ -21,7 +21,7 @@ interface Backend {
fun refreshFolderList() fun refreshFolderList()
// TODO: Add a way to cancel the sync process // TODO: Add a way to cancel the sync process
fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) fun sync(folderServerId: String, syncConfig: SyncConfig, listener: SyncListener)
@Throws(MessagingException::class) @Throws(MessagingException::class)
fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String)

View file

@ -51,8 +51,8 @@ class ImapBackend(
commandRefreshFolderList.refreshFolderList() commandRefreshFolderList.refreshFolderList()
} }
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) { override fun sync(folderServerId: String, syncConfig: SyncConfig, listener: SyncListener) {
imapSync.sync(folder, syncConfig, listener) imapSync.sync(folderServerId, syncConfig, listener)
} }
override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) { override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) {

View file

@ -45,8 +45,8 @@ class JmapBackend(
commandRefreshFolderList.refreshFolderList() commandRefreshFolderList.refreshFolderList()
} }
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) { override fun sync(folderServerId: String, syncConfig: SyncConfig, listener: SyncListener) {
commandSync.sync(folder, syncConfig, listener) commandSync.sync(folderServerId, syncConfig, listener)
} }
override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) { override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) {

View file

@ -18,6 +18,7 @@ internal inline fun <reified T : MethodResponse> JmapRequest.Call.getMainRespons
return methodResponses.getMainResponseBlocking() return methodResponses.getMainResponseBlocking()
} }
@Suppress("NOTHING_TO_INLINE")
internal inline fun <T> ListenableFuture<T>.futureGetOrThrow(): T { internal inline fun <T> ListenableFuture<T>.futureGetOrThrow(): T {
return try { return try {
get() get()

View file

@ -38,8 +38,8 @@ class Pop3Backend(
commandRefreshFolderList.refreshFolderList() commandRefreshFolderList.refreshFolderList()
} }
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) { override fun sync(folderServerId: String, syncConfig: SyncConfig, listener: SyncListener) {
pop3Sync.sync(folder, syncConfig, listener) pop3Sync.sync(folderServerId, syncConfig, listener)
} }
override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) { override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) {

View file

@ -35,11 +35,13 @@ class InMemoryBackendStorage : BackendStorage {
} }
private inner class InMemoryBackendFolderUpdater : BackendFolderUpdater { private inner class InMemoryBackendFolderUpdater : BackendFolderUpdater {
override fun createFolders(foldersToCreate: List<FolderInfo>) { override fun createFolders(folders: List<FolderInfo>) {
foldersToCreate.forEach { folder -> folders.forEach { folder ->
if (folders.containsKey(folder.serverId)) error("Folder ${folder.serverId} already present") if (this@InMemoryBackendStorage.folders.containsKey(folder.serverId)) {
error("Folder ${folder.serverId} already present")
}
folders[folder.serverId] = InMemoryBackendFolder(folder.name, folder.type) this@InMemoryBackendStorage.folders[folder.serverId] = InMemoryBackendFolder(folder.name, folder.type)
} }
} }

View file

@ -42,8 +42,8 @@ class WebDavBackend(
commandGetFolders.refreshFolderList() commandGetFolders.refreshFolderList()
} }
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) { override fun sync(folderServerId: String, syncConfig: SyncConfig, listener: SyncListener) {
webDavSync.sync(folder, syncConfig, listener) webDavSync.sync(folderServerId, syncConfig, listener)
} }
override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) { override fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String) {

View file

@ -68,7 +68,7 @@ object Timber {
@JvmStatic @JvmStatic
fun e(message: String?, vararg args: Any?) { fun e(message: String?, vararg args: Any?) {
logger.e(message) logger.e(message, *args)
} }
@JvmStatic @JvmStatic

View file

@ -2,6 +2,8 @@ package org.openintents.openpgp;
import android.app.PendingIntent; import android.app.PendingIntent;
import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle.Event; import androidx.lifecycle.Lifecycle.Event;
import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@ -224,6 +226,7 @@ public class OpenPgpApiManager implements LifecycleObserver {
return openPgpProviderName != null ? openPgpProviderName : openPgpProvider; return openPgpProviderName != null ? openPgpProviderName : openPgpProvider;
} }
@NonNull
public OpenPgpProviderState getOpenPgpProviderState() { public OpenPgpProviderState getOpenPgpProviderState() {
return openPgpProviderState; return openPgpProviderState;
} }