|
| 1 | +package net.thunderbird.feature.mail.message.composer.dialog |
| 2 | + |
| 3 | +import android.os.Bundle |
| 4 | +import android.view.LayoutInflater |
| 5 | +import android.view.View |
| 6 | +import android.view.ViewGroup |
| 7 | +import android.view.Window |
| 8 | +import androidx.compose.ui.platform.ComposeView |
| 9 | +import androidx.core.os.bundleOf |
| 10 | +import androidx.fragment.app.DialogFragment |
| 11 | +import androidx.fragment.app.FragmentManager |
| 12 | +import androidx.fragment.app.setFragmentResult |
| 13 | +import net.thunderbird.core.ui.theme.api.FeatureThemeProvider |
| 14 | +import net.thunderbird.feature.mail.message.composer.dialog.SentFolderNotFoundConfirmationDialogFragmentFactory.Companion.ACCOUNT_UUID_ARG |
| 15 | +import net.thunderbird.feature.mail.message.composer.dialog.SentFolderNotFoundConfirmationDialogFragmentFactory.Companion.RESULT_CODE_ASSIGN_SENT_FOLDER_REQUEST_KEY |
| 16 | +import net.thunderbird.feature.mail.message.composer.dialog.SentFolderNotFoundConfirmationDialogFragmentFactory.Companion.RESULT_CODE_SEND_AND_DELETE_REQUEST_KEY |
| 17 | +import org.koin.android.ext.android.inject |
| 18 | + |
| 19 | +class SentFolderNotFoundConfirmationDialogFragment : DialogFragment() { |
| 20 | + private val themeProvider: FeatureThemeProvider by inject<FeatureThemeProvider>() |
| 21 | + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
| 22 | + val accountUuid = requireNotNull(requireArguments().getString(ACCOUNT_UUID_ARG)) { |
| 23 | + "The $ACCOUNT_UUID_ARG argument is missing from the arguments bundle." |
| 24 | + } |
| 25 | + dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE) |
| 26 | + return ComposeView(requireContext()).apply { |
| 27 | + setContent { |
| 28 | + themeProvider.WithTheme { |
| 29 | + SentFolderNotFoundConfirmationDialog( |
| 30 | + showDialog = true, |
| 31 | + onAssignSentFolderClick = { |
| 32 | + dismiss() |
| 33 | + setFragmentResult( |
| 34 | + requestKey = RESULT_CODE_ASSIGN_SENT_FOLDER_REQUEST_KEY, |
| 35 | + result = bundleOf(ACCOUNT_UUID_ARG to accountUuid), |
| 36 | + ) |
| 37 | + }, |
| 38 | + onSendAndDeleteClick = { |
| 39 | + dismiss() |
| 40 | + setFragmentResult( |
| 41 | + requestKey = RESULT_CODE_SEND_AND_DELETE_REQUEST_KEY, |
| 42 | + result = bundleOf(ACCOUNT_UUID_ARG to accountUuid), |
| 43 | + ) |
| 44 | + }, |
| 45 | + onDismiss = ::dismiss, |
| 46 | + ) |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + companion object Factory : SentFolderNotFoundConfirmationDialogFragmentFactory { |
| 53 | + private const val TAG = "SentFolderNotFoundConfirmationDialogFragment" |
| 54 | + override fun show(accountUuid: String, fragmentManager: FragmentManager) { |
| 55 | + SentFolderNotFoundConfirmationDialogFragment().apply { |
| 56 | + arguments = bundleOf(ACCOUNT_UUID_ARG to accountUuid) |
| 57 | + show(fragmentManager, TAG) |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +interface SentFolderNotFoundConfirmationDialogFragmentFactory { |
| 64 | + companion object { |
| 65 | + const val RESULT_CODE_ASSIGN_SENT_FOLDER_REQUEST_KEY = |
| 66 | + "SentFolderNotFoundConfirmationDialogFragmentFactory_assign_sent_folder" |
| 67 | + const val RESULT_CODE_SEND_AND_DELETE_REQUEST_KEY = |
| 68 | + "SentFolderNotFoundConfirmationDialogFragmentFactory_send_and_delete" |
| 69 | + const val ACCOUNT_UUID_ARG = "SetupArchiveFolderDialogFragmentFactory_accountUuid" |
| 70 | + } |
| 71 | + |
| 72 | + fun show(accountUuid: String, fragmentManager: FragmentManager) |
| 73 | +} |
0 commit comments