Loading feature/widget/unread/src/main/kotlin/app/k9mail/feature/widget/unread/UnreadWidgetConfigurationFragment.kt +14 −20 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import androidx.preference.Preference import app.k9mail.legacy.search.SearchAccount import com.fsck.k9.Preferences import com.fsck.k9.ui.choosefolder.ChooseFolderActivity import com.fsck.k9.ui.choosefolder.ChooseFolderResultContract import com.takisoft.preferencex.PreferenceFragmentCompat import org.koin.android.ext.android.inject Loading @@ -28,6 +29,15 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { registerForActivityResult(UnreadWidgetChooseAccountResultContract()) { accountUuid -> handleChooseAccount(accountUuid) } private val chooseFolderResultLauncher: ActivityResultLauncher<ChooseFolderResultContract.Input> = registerForActivityResult(ChooseFolderResultContract(action = ChooseFolderActivity.Action.CHOOSE)) { result -> if (result != null) { handleChooseFolder( folderId = result.folderId, folderDisplayName = result.folderDisplayName, ) } } private var appWidgetId: Int = AppWidgetManager.INVALID_APPWIDGET_ID private lateinit var unreadAccount: Preference Loading Loading @@ -60,12 +70,11 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { unreadFolder = findPreference(PREFERENCE_UNREAD_FOLDER)!! unreadFolder.onPreferenceClickListener = Preference.OnPreferenceClickListener { val intent = ChooseFolderActivity.buildLaunchIntent( context = requireContext(), action = ChooseFolderActivity.Action.CHOOSE, chooseFolderResultLauncher.launch( input = ChooseFolderResultContract.Input( accountUuid = selectedAccountUuid!!, ), ) startActivityForResult(intent, REQUEST_CHOOSE_FOLDER) false } Loading Loading @@ -93,19 +102,6 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (resultCode == Activity.RESULT_OK && data != null) { when (requestCode) { REQUEST_CHOOSE_FOLDER -> { val folderId = data.getLongExtra(ChooseFolderActivity.RESULT_SELECTED_FOLDER_ID, -1L) val folderDisplayName = data.getStringExtra(ChooseFolderActivity.RESULT_FOLDER_DISPLAY_NAME)!! handleChooseFolder(folderId, folderDisplayName) } } } super.onActivityResult(requestCode, resultCode, data) } private fun handleChooseAccount(accountUuid: String?) { val userSelectedSameAccount = accountUuid == selectedAccountUuid if (userSelectedSameAccount) { Loading Loading @@ -210,8 +206,6 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { private const val PREFERENCE_UNREAD_FOLDER_ENABLED = "unread_folder_enabled" private const val PREFERENCE_UNREAD_FOLDER = "unread_folder" private const val REQUEST_CHOOSE_FOLDER = 1 private const val STATE_SELECTED_ACCOUNT_UUID = "com.fsck.k9.widget.unread.selectedAccountUuid" private const val STATE_SELECTED_FOLDER_ID = "com.fsck.k9.widget.unread.selectedFolderId" private const val STATE_SELECTED_FOLDER_DISPLAY_NAME = "com.fsck.k9.widget.unread.selectedFolderDisplayName" Loading legacy/ui/legacy/src/main/java/com/fsck/k9/ui/choosefolder/ChooseFolderResultContract.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line package com.fsck.k9.ui.choosefolder import android.app.Activity import android.content.Context import android.content.Intent import androidx.activity.result.contract.ActivityResultContract import app.k9mail.legacy.message.controller.MessageReference import com.fsck.k9.ui.choosefolder.ChooseFolderActivity.Action class ChooseFolderResultContract( private val action: Action, ) : ActivityResultContract<ChooseFolderResultContract.Input, ChooseFolderResultContract.Result?>() { override fun createIntent(context: Context, input: Input): Intent { return ChooseFolderActivity.buildLaunchIntent( context = context, action = action, accountUuid = input.accountUuid, currentFolderId = input.currentFolderId, scrollToFolderId = input.scrollToFolderId, messageReference = input.messageReference, ) } override fun parseResult(resultCode: Int, intent: Intent?): Result? { return intent.takeIf { resultCode == Activity.RESULT_OK }?.let { Result( folderId = it.getLongExtra(ChooseFolderActivity.RESULT_SELECTED_FOLDER_ID, -1L), folderDisplayName = it.getStringExtra(ChooseFolderActivity.RESULT_FOLDER_DISPLAY_NAME)!!, messageReference = it.getStringExtra(ChooseFolderActivity.RESULT_MESSAGE_REFERENCE), ) } } data class Input( val accountUuid: String, val currentFolderId: Long? = null, val scrollToFolderId: Long? = null, val messageReference: MessageReference? = null, ) data class Result( val folderId: Long, val folderDisplayName: String, val messageReference: String?, ) } Loading
feature/widget/unread/src/main/kotlin/app/k9mail/feature/widget/unread/UnreadWidgetConfigurationFragment.kt +14 −20 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import androidx.preference.Preference import app.k9mail.legacy.search.SearchAccount import com.fsck.k9.Preferences import com.fsck.k9.ui.choosefolder.ChooseFolderActivity import com.fsck.k9.ui.choosefolder.ChooseFolderResultContract import com.takisoft.preferencex.PreferenceFragmentCompat import org.koin.android.ext.android.inject Loading @@ -28,6 +29,15 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { registerForActivityResult(UnreadWidgetChooseAccountResultContract()) { accountUuid -> handleChooseAccount(accountUuid) } private val chooseFolderResultLauncher: ActivityResultLauncher<ChooseFolderResultContract.Input> = registerForActivityResult(ChooseFolderResultContract(action = ChooseFolderActivity.Action.CHOOSE)) { result -> if (result != null) { handleChooseFolder( folderId = result.folderId, folderDisplayName = result.folderDisplayName, ) } } private var appWidgetId: Int = AppWidgetManager.INVALID_APPWIDGET_ID private lateinit var unreadAccount: Preference Loading Loading @@ -60,12 +70,11 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { unreadFolder = findPreference(PREFERENCE_UNREAD_FOLDER)!! unreadFolder.onPreferenceClickListener = Preference.OnPreferenceClickListener { val intent = ChooseFolderActivity.buildLaunchIntent( context = requireContext(), action = ChooseFolderActivity.Action.CHOOSE, chooseFolderResultLauncher.launch( input = ChooseFolderResultContract.Input( accountUuid = selectedAccountUuid!!, ), ) startActivityForResult(intent, REQUEST_CHOOSE_FOLDER) false } Loading Loading @@ -93,19 +102,6 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (resultCode == Activity.RESULT_OK && data != null) { when (requestCode) { REQUEST_CHOOSE_FOLDER -> { val folderId = data.getLongExtra(ChooseFolderActivity.RESULT_SELECTED_FOLDER_ID, -1L) val folderDisplayName = data.getStringExtra(ChooseFolderActivity.RESULT_FOLDER_DISPLAY_NAME)!! handleChooseFolder(folderId, folderDisplayName) } } } super.onActivityResult(requestCode, resultCode, data) } private fun handleChooseAccount(accountUuid: String?) { val userSelectedSameAccount = accountUuid == selectedAccountUuid if (userSelectedSameAccount) { Loading Loading @@ -210,8 +206,6 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() { private const val PREFERENCE_UNREAD_FOLDER_ENABLED = "unread_folder_enabled" private const val PREFERENCE_UNREAD_FOLDER = "unread_folder" private const val REQUEST_CHOOSE_FOLDER = 1 private const val STATE_SELECTED_ACCOUNT_UUID = "com.fsck.k9.widget.unread.selectedAccountUuid" private const val STATE_SELECTED_FOLDER_ID = "com.fsck.k9.widget.unread.selectedFolderId" private const val STATE_SELECTED_FOLDER_DISPLAY_NAME = "com.fsck.k9.widget.unread.selectedFolderDisplayName" Loading
legacy/ui/legacy/src/main/java/com/fsck/k9/ui/choosefolder/ChooseFolderResultContract.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line package com.fsck.k9.ui.choosefolder import android.app.Activity import android.content.Context import android.content.Intent import androidx.activity.result.contract.ActivityResultContract import app.k9mail.legacy.message.controller.MessageReference import com.fsck.k9.ui.choosefolder.ChooseFolderActivity.Action class ChooseFolderResultContract( private val action: Action, ) : ActivityResultContract<ChooseFolderResultContract.Input, ChooseFolderResultContract.Result?>() { override fun createIntent(context: Context, input: Input): Intent { return ChooseFolderActivity.buildLaunchIntent( context = context, action = action, accountUuid = input.accountUuid, currentFolderId = input.currentFolderId, scrollToFolderId = input.scrollToFolderId, messageReference = input.messageReference, ) } override fun parseResult(resultCode: Int, intent: Intent?): Result? { return intent.takeIf { resultCode == Activity.RESULT_OK }?.let { Result( folderId = it.getLongExtra(ChooseFolderActivity.RESULT_SELECTED_FOLDER_ID, -1L), folderDisplayName = it.getStringExtra(ChooseFolderActivity.RESULT_FOLDER_DISPLAY_NAME)!!, messageReference = it.getStringExtra(ChooseFolderActivity.RESULT_MESSAGE_REFERENCE), ) } } data class Input( val accountUuid: String, val currentFolderId: Long? = null, val scrollToFolderId: Long? = null, val messageReference: MessageReference? = null, ) data class Result( val folderId: Long, val folderDisplayName: String, val messageReference: String?, ) }