99import java .util .List ;
1010import java .util .Locale ;
1111import java .util .Map ;
12+ import java .util .Objects ;
1213import java .util .Set ;
1314import java .util .regex .Pattern ;
1415import android .annotation .SuppressLint ;
5859import com .bumptech .glide .Glide ;
5960import com .bumptech .glide .load .engine .DiskCacheStrategy ;
6061import com .fsck .k9 .activity .compose .MessageComposeInAppNotificationFragment ;
62+ import com .fsck .k9 .ui .settings .account .AccountSettingsActivity ;
63+ import com .fsck .k9 .ui .settings .account .AccountSettingsFragment ;
6164import kotlin .Unit ;
6265import net .thunderbird .core .android .account .LegacyAccountDto ;
6366import app .k9mail .legacy .di .DI ;
133136import net .thunderbird .core .outcome .OutcomeKt ;
134137import net .thunderbird .core .preference .GeneralSettingsManager ;
135138import net .thunderbird .core .ui .theme .manager .ThemeManager ;
139+ import net .thunderbird .feature .mail .message .composer .dialog .SentFolderNotFoundConfirmationDialogFragmentFactory ;
136140import net .thunderbird .feature .notification .api .command .outcome .CommandExecutionFailed ;
137141import net .thunderbird .feature .notification .api .content .NotificationFactoryCoroutineCompat ;
138142import net .thunderbird .feature .notification .api .content .SentFolderNotFoundNotification ;
147151import static com .fsck .k9 .activity .compose .AttachmentPresenter .REQUEST_CODE_ATTACHMENT_URI ;
148152import static app .k9mail .core .android .common .camera .CameraCaptureHandler .CAMERA_PERMISSION_REQUEST_CODE ;
149153import static app .k9mail .core .android .common .camera .CameraCaptureHandler .REQUEST_IMAGE_CAPTURE ;
154+ import static net .thunderbird .feature .mail .message .composer .dialog .SentFolderNotFoundConfirmationDialogFragmentFactory .ACCOUNT_UUID_ARG ;
155+ import static net .thunderbird .feature .mail .message .composer .dialog .SentFolderNotFoundConfirmationDialogFragmentFactory .RESULT_CODE_ASSIGN_SENT_FOLDER_REQUEST_KEY ;
156+ import static net .thunderbird .feature .mail .message .composer .dialog .SentFolderNotFoundConfirmationDialogFragmentFactory .RESULT_CODE_SEND_AND_DELETE_REQUEST_KEY ;
150157import static net .thunderbird .feature .notification .api .content .SentFolderNotFoundNotificationKt .SentFolderNotFoundNotification ;
151158
152159
@@ -227,7 +234,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
227234 private final NotificationSenderCompat notificationSenderCompat = new NotificationSenderCompat (notificationSender );
228235 private final NotificationDismisser notificationDismisser = DI .get (NotificationDismisser .class );
229236 private final NotificationDismisserCompat notificationDismisserCompat =
230- new NotificationDismisserCompat (notificationDismisser );
237+ new NotificationDismisserCompat (notificationDismisser );
238+ private final SentFolderNotFoundConfirmationDialogFragmentFactory sentFolderNotFoundDialogFragmentFactory =
239+ DI .get (SentFolderNotFoundConfirmationDialogFragmentFactory .class );
231240
232241 private final Set <Integer > activeInAppNotifications = new HashSet <>();
233242
@@ -285,6 +294,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
285294 private boolean navigateUp ;
286295
287296 private boolean sendMessageHasBeenTriggered = false ;
297+ private boolean ignoreSentFolderNotAssigned = false ;
288298
289299 @ Override
290300 public void onCreate (Bundle savedInstanceState ) {
@@ -551,6 +561,32 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
551561 setProgressBarIndeterminateVisibility (true );
552562 currentMessageBuilder .reattachCallback (this );
553563 }
564+ setupSentFolderNotFoundDialogResults ();
565+ }
566+
567+ private void setupSentFolderNotFoundDialogResults () {
568+ getSupportFragmentManager ().setFragmentResultListener (
569+ RESULT_CODE_ASSIGN_SENT_FOLDER_REQUEST_KEY ,
570+ this ,
571+ (requestKey , result ) -> {
572+ if (RESULT_CODE_ASSIGN_SENT_FOLDER_REQUEST_KEY .equals (requestKey )) {
573+ final String accountUuid = result .getString (ACCOUNT_UUID_ARG );
574+ AccountSettingsActivity .start (this ,
575+ Objects .requireNonNull (accountUuid ),
576+ AccountSettingsFragment .PREFERENCE_FOLDERS );
577+ }
578+ }
579+ );
580+ getSupportFragmentManager ().setFragmentResultListener (
581+ RESULT_CODE_SEND_AND_DELETE_REQUEST_KEY ,
582+ this ,
583+ (requestKey , result ) -> {
584+ if (RESULT_CODE_SEND_AND_DELETE_REQUEST_KEY .equals (requestKey )) {
585+ ignoreSentFolderNotAssigned = true ;
586+ performSendAfterChecks ();
587+ }
588+ }
589+ );
554590 }
555591
556592 private void fetchAccount (Intent intent ) {
@@ -582,46 +618,46 @@ protected void onResume() {
582618 private void triggerIfNeededSentFolderNotFoundInAppNotification () {
583619 if (account != null && account .getSentFolderId () == null ) {
584620 final SentFolderNotFoundNotification notification = NotificationFactoryCoroutineCompat .create (
585- continuation -> SentFolderNotFoundNotification (account .getUuid (), continuation )
621+ continuation -> SentFolderNotFoundNotification (account .getUuid (), continuation )
586622 );
587623 notificationSenderCompat .send (notification , outcome -> {
588624 OutcomeKt .handle (
625+ outcome ,
626+ success -> {
627+ activeInAppNotifications .add (success .getRawNotificationId ());
628+ return Unit .INSTANCE ;
629+ },
630+ failure -> {
631+ final Throwable throwable = failure instanceof CommandExecutionFailed <?>
632+ ? ((CommandExecutionFailed <?>) failure ).getThrowable ()
633+ : null ;
634+ Log .e (throwable , "Failed to send in-app notification. Failure = " + failure );
635+ return Unit .INSTANCE ;
636+ });
637+ });
638+ }
639+ }
640+
641+ private void dismissActiveInAppNotifications () {
642+ for (Integer notificationId : activeInAppNotifications ) {
643+ notificationDismisserCompat .dismiss (
644+ notificationId ,
645+ outcome -> {
646+ OutcomeKt .handle (
589647 outcome ,
590648 success -> {
591- activeInAppNotifications .add (success .getRawNotificationId ());
649+ activeInAppNotifications .remove (success .getRawNotificationId ());
592650 return Unit .INSTANCE ;
593651 },
594652 failure -> {
595653 final Throwable throwable = failure instanceof CommandExecutionFailed <?>
596654 ? ((CommandExecutionFailed <?>) failure ).getThrowable ()
597655 : null ;
598- Log .e (throwable , "Failed to send in-app notification. Failure = " + failure );
656+ Log .e (throwable , "Failed to dismiss in-app notification. Failure = " + failure );
599657 return Unit .INSTANCE ;
600- });
601- });
602- }
603- }
604-
605- private void dismissActiveInAppNotifications () {
606- for (Integer notificationId : activeInAppNotifications ) {
607- notificationDismisserCompat .dismiss (
608- notificationId ,
609- outcome -> {
610- OutcomeKt .handle (
611- outcome ,
612- success -> {
613- activeInAppNotifications .remove (success .getRawNotificationId ());
614- return Unit .INSTANCE ;
615- },
616- failure -> {
617- final Throwable throwable = failure instanceof CommandExecutionFailed <?>
618- ? ((CommandExecutionFailed <?>) failure ).getThrowable ()
619- : null ;
620- Log .e (throwable , "Failed to dismiss in-app notification. Failure = " + failure );
621- return Unit .INSTANCE ;
622- }
623- );
624- });
658+ }
659+ );
660+ });
625661 }
626662 }
627663
@@ -833,6 +869,11 @@ public void performSendAfterChecks() {
833869 return ;
834870 }
835871
872+ if (!ignoreSentFolderNotAssigned && !account .hasSentFolder ()) {
873+ sentFolderNotFoundDialogFragmentFactory .show (account .getUuid (), getSupportFragmentManager ());
874+ return ;
875+ }
876+
836877 currentMessageBuilder = createMessageBuilder (false );
837878 if (currentMessageBuilder != null ) {
838879 sendMessageHasBeenTriggered = true ;
@@ -1831,8 +1872,8 @@ private void initializeActionBar() {
18311872
18321873 private void initializeInAppNotificationFragment () {
18331874 if (FeatureFlagProviderCompat
1834- .provide (featureFlagProvider , "display_in_app_notifications" )
1835- .isDisabledOrUnavailable ()) {
1875+ .provide (featureFlagProvider , "display_in_app_notifications" )
1876+ .isDisabledOrUnavailable ()) {
18361877 return ;
18371878 }
18381879
@@ -1843,7 +1884,7 @@ private void initializeInAppNotificationFragment() {
18431884 }
18441885 final FragmentManager fragmentManager = getSupportFragmentManager ();
18451886 final Fragment currentFragment = fragmentManager
1846- .findFragmentByTag (MessageComposeInAppNotificationFragment .FRAGMENT_TAG );
1887+ .findFragmentByTag (MessageComposeInAppNotificationFragment .FRAGMENT_TAG );
18471888
18481889 if (currentFragment != null ) {
18491890 return ;
@@ -1854,7 +1895,7 @@ private void initializeInAppNotificationFragment() {
18541895 uuids .add (legacyAccountDto .getUuid ());
18551896 }
18561897 final MessageComposeInAppNotificationFragment inAppNotificationFragment =
1857- MessageComposeInAppNotificationFragment .newInstance (uuids );
1898+ MessageComposeInAppNotificationFragment .newInstance (uuids );
18581899 fragmentManager
18591900 .beginTransaction ()
18601901 .add (R .id .message_compose_in_app_notifications_container , inAppNotificationFragment ,
0 commit comments