Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split legacy - part 4 #8056

Merged
merged 13 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@file:JvmName("ContextHelper")

package com.fsck.k9.ui.helper
package app.k9mail.core.android.common.activity

import android.app.Activity
import android.content.Context
import android.content.ContextWrapper

// Source: https://stackoverflow.com/a/58249983
tailrec fun Context.findActivity(): Activity? {
return this as? Activity ?: (this as? ContextWrapper)?.baseContext?.findActivity()
}
tailrec fun Context.findActivity(): Activity? = this as? Activity
?: (this as? ContextWrapper)?.baseContext?.findActivity()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.k9mail.feature.widget.message.list

import com.fsck.k9.controller.MessageReference
import app.k9mail.legacy.message.controller.MessageReference

internal data class MessageListItem(
val displayName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.k9mail.feature.widget.message.list
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.mailstore.MessageDetailsAccessor
import app.k9mail.legacy.mailstore.MessageMapper
import com.fsck.k9.controller.MessageReference
import app.k9mail.legacy.message.controller.MessageReference
import com.fsck.k9.helper.MessageHelper
import com.fsck.k9.ui.helper.DisplayAddressHelper
import java.util.Calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package app.k9mail.feature.widget.message.list

import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.Account.SortType
import app.k9mail.legacy.mailstore.MessageListRepository
import com.fsck.k9.Preferences
import com.fsck.k9.helper.MessageHelper
import com.fsck.k9.mailstore.MessageColumns
import com.fsck.k9.mailstore.MessageListRepository
import com.fsck.k9.search.SqlQueryBuilder
import com.fsck.k9.search.getAccounts
import timber.log.Timber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import app.k9mail.legacy.mailstore.MessageListChangedListener
import app.k9mail.legacy.mailstore.MessageListRepository
import com.fsck.k9.core.BuildConfig
import com.fsck.k9.mailstore.MessageListChangedListener
import com.fsck.k9.mailstore.MessageListRepository
import timber.log.Timber

class MessageListWidgetManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package app.k9mail.feature.widget.unread
import android.content.Context
import android.content.Intent
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.mailstore.FolderRepository
import app.k9mail.legacy.message.controller.MessageCountsProvider
import app.k9mail.legacy.search.LocalSearch
import app.k9mail.legacy.search.SearchAccount
import app.k9mail.legacy.ui.folder.FolderNameFormatter
import com.fsck.k9.CoreResourceProvider
import com.fsck.k9.Preferences
import com.fsck.k9.activity.MessageList
import com.fsck.k9.controller.MessageCountsProvider
import com.fsck.k9.mailstore.FolderRepository
import com.fsck.k9.ui.messagelist.DefaultFolderProvider
import timber.log.Timber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.content.SharedPreferences
import androidx.core.content.edit
import app.k9mail.feature.widget.unread.UnreadWidgetRepository.Companion.PREFS_VERSION
import app.k9mail.feature.widget.unread.UnreadWidgetRepository.Companion.PREF_VERSION_KEY
import app.k9mail.legacy.mailstore.FolderRepository
import com.fsck.k9.Preferences
import com.fsck.k9.mailstore.FolderRepository

internal class UnreadWidgetMigrations(
private val accountRepository: Preferences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.k9mail.feature.widget.unread

import app.k9mail.legacy.account.Account
import com.fsck.k9.controller.SimpleMessagingListener
import app.k9mail.legacy.message.controller.SimpleMessagingListener
import com.fsck.k9.mail.Message
import timber.log.Timber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import android.content.Context
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.folder.Folder
import app.k9mail.legacy.folder.FolderType
import app.k9mail.legacy.mailstore.FolderRepository
import app.k9mail.legacy.message.controller.MessageCounts
import app.k9mail.legacy.message.controller.MessageCountsProvider
import app.k9mail.legacy.search.SearchAccount
import app.k9mail.legacy.ui.folder.FolderNameFormatter
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNull
import com.fsck.k9.CoreResourceProvider
import com.fsck.k9.Preferences
import com.fsck.k9.controller.MessageCounts
import com.fsck.k9.controller.MessageCountsProvider
import com.fsck.k9.mailstore.FolderRepository
import com.fsck.k9.ui.messagelist.DefaultFolderProvider
import org.junit.Before
import org.junit.Test
Expand Down
2 changes: 1 addition & 1 deletion legacy/common/src/main/java/com/fsck/k9/CommonApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import android.content.res.Configuration
import android.content.res.Resources
import app.k9mail.feature.widget.message.list.MessageListWidgetManager
import app.k9mail.legacy.di.DI
import app.k9mail.legacy.ui.theme.ThemeManager
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.job.WorkManagerConfigurationProvider
import com.fsck.k9.notification.NotificationChannelManager
import com.fsck.k9.ui.base.AppLanguageManager
import com.fsck.k9.ui.base.ThemeManager
import com.fsck.k9.ui.base.extensions.currentLocale
import java.util.Locale
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.fsck.k9

import com.fsck.k9.controller.MessagingListener
import app.k9mail.legacy.message.controller.MessagingListener

class MessagingListenerProvider(val listeners: List<MessagingListener>)
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import androidx.core.app.PendingIntentCompat
import app.k9mail.feature.launcher.FeatureLauncherActivity
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.mailstore.MessageStoreManager
import app.k9mail.legacy.message.controller.MessageReference
import app.k9mail.legacy.search.LocalSearch
import com.fsck.k9.K9
import com.fsck.k9.activity.MessageList
import com.fsck.k9.activity.compose.MessageActions
import com.fsck.k9.controller.MessageReference
import com.fsck.k9.ui.messagelist.DefaultFolderProvider
import com.fsck.k9.ui.notification.DeleteConfirmationActivity

Expand Down
1 change: 1 addition & 0 deletions legacy/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
api(projects.legacy.mailstore)
api(projects.legacy.message)
api(projects.legacy.notification)
api(projects.legacy.preferences)
api(projects.legacy.search)

implementation(projects.plugins.openpgpApiLib.openpgpApi)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fsck.k9.controller

import app.k9mail.legacy.message.controller.MessagingListener
import com.fsck.k9.backend.BackendManager

interface ControllerExtension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.fsck.k9.controller
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.AccountManager
import app.k9mail.legacy.mailstore.MessageStoreManager
import app.k9mail.legacy.message.controller.MessageCounts
import app.k9mail.legacy.message.controller.MessageCountsProvider
import app.k9mail.legacy.search.ConditionsTreeNode
import app.k9mail.legacy.search.LocalSearch
import app.k9mail.legacy.search.SearchAccount
Expand All @@ -11,14 +13,6 @@ import com.fsck.k9.search.getAccounts
import com.fsck.k9.search.limitToDisplayableFolders
import timber.log.Timber

interface MessageCountsProvider {
fun getMessageCounts(account: Account): MessageCounts
fun getMessageCounts(searchAccount: SearchAccount): MessageCounts
fun getUnreadMessageCount(account: Account, folderId: Long): Int
}

data class MessageCounts(val unread: Int, val starred: Int)

internal class DefaultMessageCountsProvider(
private val accountManager: AccountManager,
private val messageStoreManager: MessageStoreManager,
Expand Down Expand Up @@ -47,6 +41,7 @@ internal class DefaultMessageCountsProvider(
return MessageCounts(unreadCount, starredCount)
}

@Suppress("TooGenericExceptionCaught")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a strategy to remove some of these suppressions in the future? Maybe some good first bugs to file?

Copy link
Member Author

@wmontwe wmontwe Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific warning is generated by our detekt code quality tool, which is desired to be reported in general. But there are cases where it is wrong or it's hard to provide the exact exception. Especially as our legacy code is designed to rely on try/catch constructs quite a lot. This is something we need to address when we touch that code base, but it's not easy to do.

override fun getUnreadMessageCount(account: Account, folderId: Long): Int {
return try {
val messageStore = messageStoreManager.getMessageStore(account)
Expand All @@ -61,6 +56,7 @@ internal class DefaultMessageCountsProvider(
}
}

@Suppress("TooGenericExceptionCaught")
private fun getMessageCounts(account: Account, conditions: ConditionsTreeNode?): MessageCounts {
return try {
val messageStore = messageStoreManager.getMessageStore(account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.fsck.k9.controller

import android.content.Context
import app.k9mail.legacy.mailstore.MessageStoreManager
import app.k9mail.legacy.message.controller.MessageCountsProvider
import app.k9mail.legacy.message.controller.MessagingControllerRegistry
import com.fsck.k9.Preferences
import com.fsck.k9.backend.BackendManager
import com.fsck.k9.mailstore.LocalStoreProvider
Expand Down Expand Up @@ -29,6 +31,8 @@ val controllerModule = module {
)
}

single<MessagingControllerRegistry> { get<MessagingController>() }

single<MessageCountsProvider> {
DefaultMessageCountsProvider(
accountManager = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.Map.Entry;

import app.k9mail.legacy.account.Account;
import app.k9mail.legacy.message.controller.MessagingListener;
import app.k9mail.legacy.message.controller.SimpleMessagingListener;


class MemorizingMessagingListener extends SimpleMessagingListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;

import app.k9mail.legacy.message.controller.MessageReference;
import timber.log.Timber;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import app.k9mail.legacy.account.Account;
import app.k9mail.legacy.account.Account.DeletePolicy;
import app.k9mail.legacy.di.DI;
import app.k9mail.legacy.message.controller.MessageReference;
import app.k9mail.legacy.message.controller.MessagingControllerMailChecker;
import app.k9mail.legacy.message.controller.MessagingControllerRegistry;
import app.k9mail.legacy.message.controller.MessagingListener;
import app.k9mail.legacy.message.controller.SimpleMessagingListener;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.backend.BackendManager;
Expand Down Expand Up @@ -102,7 +107,7 @@
* it removes itself. Thus, any commands that that activity submitted are
* removed from the queue once the activity is no longer active.
*/
public class MessagingController {
public class MessagingController implements MessagingControllerRegistry, MessagingControllerMailChecker {
public static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);

private static final long FOLDER_LIST_STALENESS_THRESHOLD = 30 * 60 * 1000L;
Expand Down Expand Up @@ -283,7 +288,7 @@ private long getFolderId(Account account, String folderServerId) {
return folderId;
}

public void addListener(MessagingListener listener) {
public void addListener(@NonNull MessagingListener listener) {
listeners.add(listener);
refreshListener(listener);
}
Expand All @@ -294,7 +299,7 @@ public void refreshListener(MessagingListener listener) {
}
}

public void removeListener(MessagingListener listener) {
public void removeListener(@NonNull MessagingListener listener) {
listeners.remove(listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.fsck.k9.controller.push

import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.Account.FolderMode
import app.k9mail.legacy.mailstore.FolderRepository
import com.fsck.k9.Preferences
import com.fsck.k9.backend.BackendManager
import com.fsck.k9.backend.api.BackendPusher
import com.fsck.k9.backend.api.BackendPusherCallback
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.mailstore.FolderRepository
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.fsck.k9.controller.push

import app.k9mail.legacy.account.Account
import app.k9mail.legacy.mailstore.FolderRepository
import com.fsck.k9.Preferences
import com.fsck.k9.backend.BackendManager
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.mailstore.FolderRepository

internal class AccountPushControllerFactory(
private val backendManager: BackendManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.fsck.k9.controller.push
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.Account.FolderMode
import app.k9mail.legacy.account.AccountManager
import app.k9mail.legacy.preferences.BackgroundSync
import app.k9mail.legacy.preferences.GeneralSettingsManager
import com.fsck.k9.backend.BackendManager
import com.fsck.k9.network.ConnectivityChangeListener
import com.fsck.k9.network.ConnectivityManager
Expand All @@ -12,8 +14,6 @@ import com.fsck.k9.notification.PushNotificationState.ALARM_PERMISSION_MISSING
import com.fsck.k9.notification.PushNotificationState.LISTENING
import com.fsck.k9.notification.PushNotificationState.WAIT_BACKGROUND_SYNC
import com.fsck.k9.notification.PushNotificationState.WAIT_NETWORK
import com.fsck.k9.preferences.BackgroundSync
import com.fsck.k9.preferences.GeneralSettingsManager
import java.util.concurrent.Executors
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fsck.k9.mailstore

import app.k9mail.legacy.account.Account
import app.k9mail.legacy.mailstore.FolderRepository
import com.fsck.k9.Preferences

/**
Expand Down
Loading