Skip to content

Commit 396bc2b

Browse files
committed
Added a new message state. Added an ability to retry sending of the message which is failed to send.| #328
1 parent 478ccd7 commit 396bc2b

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/database/MessageState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public enum MessageState {
2424
NEW_FORWARDED(7),
2525
ERROR_DURING_CREATION(8),
2626
ERROR_ORIGINAL_MESSAGE_MISSING(9),
27-
ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND(10);
27+
ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND(10),
28+
ERROR_SENDING_FAILED(11);
2829

2930
private int value;
3031

FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/MessagesSenderJobService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,12 @@ private void sendQueuedMessages(Context context, AccountDao accountDao, MessageD
275275
}
276276
} catch (Exception e) {
277277
e.printStackTrace();
278-
MessageState newMessageState;
278+
MessageState newMessageState = MessageState.ERROR_SENDING_FAILED;
279279

280280
if (e.getCause() != null) {
281281
if (e.getCause() instanceof FileNotFoundException) {
282282
newMessageState = MessageState.ERROR_CACHE_PROBLEM;
283-
} else {
284-
newMessageState = MessageState.QUEUED;
285283
}
286-
} else {
287-
newMessageState = MessageState.QUEUED;
288284
}
289285

290286
messageDaoSource.updateMessageState(context,

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ private void updateViews() {
406406
case ERROR_DURING_CREATION:
407407
case ERROR_ORIGINAL_MESSAGE_MISSING:
408408
case ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND:
409+
case ERROR_SENDING_FAILED:
409410
actionBarSubTitle = getString(R.string.an_error_has_occurred);
410411
break;
411412
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/EmailListFragment.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.flowcrypt.email.database.dao.source.AccountDao;
4646
import com.flowcrypt.email.database.dao.source.AccountDaoSource;
4747
import com.flowcrypt.email.database.dao.source.imap.MessageDaoSource;
48+
import com.flowcrypt.email.jobscheduler.MessagesSenderJobService;
4849
import com.flowcrypt.email.ui.activity.MessageDetailsActivity;
4950
import com.flowcrypt.email.ui.activity.base.BaseSyncActivity;
5051
import com.flowcrypt.email.ui.activity.fragment.base.BaseSyncFragment;
@@ -78,6 +79,7 @@ public class EmailListFragment extends BaseSyncFragment implements AdapterView.O
7879

7980
private static final int REQUEST_CODE_SHOW_MESSAGE_DETAILS = 10;
8081
private static final int REQUEST_CODE_DELETE_MESSAGES = 11;
82+
private static final int REQUEST_CODE_RETRY_TO_SEND_MESSAGES = 12;
8183

8284
private static final int TIMEOUT_BETWEEN_REQUESTS = 500;
8385
private static final int LOADING_SHIFT_IN_ITEMS = 5;
@@ -94,6 +96,7 @@ public class EmailListFragment extends BaseSyncFragment implements AdapterView.O
9496
private BaseSyncActivity baseSyncActivity;
9597
private ActionMode actionMode;
9698
private SparseBooleanArray checkedItemPositions;
99+
private GeneralMessageDetails activeMsgDetails;
97100

98101
private boolean isMessagesFetchedIfNotExistInCache;
99102
private boolean isNewMessagesLoadingNow;
@@ -313,6 +316,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
313316
}
314317
break;
315318

319+
case REQUEST_CODE_RETRY_TO_SEND_MESSAGES:
320+
switch (resultCode) {
321+
case Activity.RESULT_OK:
322+
if (activeMsgDetails != null) {
323+
new MessageDaoSource().updateMessageState(getContext(),
324+
activeMsgDetails.getEmail(), activeMsgDetails.getLabel(),
325+
activeMsgDetails.getUid(), MessageState.QUEUED);
326+
MessagesSenderJobService.schedule(getContext());
327+
}
328+
break;
329+
}
330+
break;
331+
316332
default:
317333
super.onActivityResult(requestCode, resultCode, data);
318334
break;
@@ -321,32 +337,33 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
321337

322338
@Override
323339
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
324-
GeneralMessageDetails generalMessageDetails = (GeneralMessageDetails) parent.getAdapter().getItem(position);
325-
if (generalMessageDetails != null) {
340+
activeMsgDetails = (GeneralMessageDetails) parent.getAdapter().getItem(position);
341+
if (activeMsgDetails != null) {
326342
if (JavaEmailConstants.FOLDER_OUTBOX.equalsIgnoreCase(onManageEmailsListener.getCurrentFolder()
327343
.getServerFullFolderName())
328-
|| !TextUtils.isEmpty(generalMessageDetails.getRawMessageWithoutAttachments())
344+
|| !TextUtils.isEmpty(activeMsgDetails.getRawMessageWithoutAttachments())
329345
|| GeneralUtil.isInternetConnectionAvailable(getContext())) {
330346

331-
if (generalMessageDetails.getMessageState() != null) {
332-
switch (generalMessageDetails.getMessageState()) {
347+
if (activeMsgDetails.getMessageState() != null) {
348+
switch (activeMsgDetails.getMessageState()) {
333349
case ERROR_ORIGINAL_MESSAGE_MISSING:
334350
case ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND:
335351
case ERROR_CACHE_PROBLEM:
336352
case ERROR_DURING_CREATION:
337-
handleOutgoingMessageWhichHasSomeError(generalMessageDetails);
353+
case ERROR_SENDING_FAILED:
354+
handleOutgoingMessageWhichHasSomeError(activeMsgDetails);
338355
break;
339356

340357
default:
341358
startActivityForResult(MessageDetailsActivity.getIntent(getContext(),
342-
onManageEmailsListener.getCurrentFolder(), generalMessageDetails),
359+
onManageEmailsListener.getCurrentFolder(), activeMsgDetails),
343360
REQUEST_CODE_SHOW_MESSAGE_DETAILS);
344361
break;
345362
}
346363

347364
} else {
348365
startActivityForResult(MessageDetailsActivity.getIntent(getContext(),
349-
onManageEmailsListener.getCurrentFolder(), generalMessageDetails),
366+
onManageEmailsListener.getCurrentFolder(), activeMsgDetails),
350367
REQUEST_CODE_SHOW_MESSAGE_DETAILS);
351368
}
352369
} else {
@@ -742,7 +759,7 @@ private void handleOutgoingMessageWhichHasSomeError(final GeneralMessageDetails
742759
switch (generalMessageDetails.getMessageState()) {
743760
case ERROR_ORIGINAL_MESSAGE_MISSING:
744761
case ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND:
745-
message = getString(R.string.message_filed_to_forward);
762+
message = getString(R.string.message_failed_to_forward);
746763
break;
747764

748765
case ERROR_CACHE_PROBLEM:
@@ -753,6 +770,14 @@ private void handleOutgoingMessageWhichHasSomeError(final GeneralMessageDetails
753770
message = getString(R.string.error_happened_during_creation,
754771
getString(R.string.support_email));
755772
break;
773+
774+
case ERROR_SENDING_FAILED:
775+
TwoWayDialogFragment twoWayDialogFragment = TwoWayDialogFragment.newInstance("",
776+
getString(R.string.message_failed_to_send), getString(R.string.retry),
777+
getString(R.string.cancel), true);
778+
twoWayDialogFragment.setTargetFragment(this, REQUEST_CODE_RETRY_TO_SEND_MESSAGES);
779+
twoWayDialogFragment.show(getFragmentManager(), TwoWayDialogFragment.class.getSimpleName());
780+
return;
756781
}
757782

758783
InfoDialogFragment infoDialogFragment = InfoDialogFragment.newInstance(null, message, true);

FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MessageListAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ private CharSequence generateOutboxStatus(Context context, MessageState messageS
292292
case ERROR_DURING_CREATION:
293293
case ERROR_ORIGINAL_MESSAGE_MISSING:
294294
case ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND:
295+
case ERROR_SENDING_FAILED:
295296
stateTextColor = ContextCompat.getColor(context, R.color.red);
296297

297298
switch (messageState) {
@@ -310,6 +311,10 @@ private CharSequence generateOutboxStatus(Context context, MessageState messageS
310311
case ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND:
311312
state = context.getString(R.string.original_attachment_not_found);
312313
break;
314+
315+
case ERROR_SENDING_FAILED:
316+
state = context.getString(R.string.cannot_send_message_unknown_error);
317+
break;
313318
}
314319

315320
break;

FlowCrypt/src/main/res/values/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ icelanders prefer real sauna</font>
384384
<string name="original_message_missing">Could not forward: original message missing</string>
385385
<string name="original_attachment_not_found">Could not forward: some attachments are not available</string>
386386
<string name="could_not_create">Could not create: an unknown error</string>
387-
<string name="message_filed_to_forward">Message failed to send. Please forward the message again</string>
387+
<string name="message_failed_to_forward">Message failed to send. Please forward the message again</string>
388388
<string name="there_is_problem_with_cache">There is a problem with a temp cache directory. Please create the message again</string>
389389
<string name="error_happened_during_creation">Sorry, we could not create a message. Please write %1$s for help.</string>
390390
<string name="sent">Sent</string>
@@ -398,4 +398,6 @@ icelanders prefer real sauna</font>
398398
<item quantity="one">Delete this message?</item>
399399
<item quantity="other">Delete these %1$d messages?</item>
400400
</plurals>
401+
<string name="cannot_send_message_unknown_error">Can\'t send a message: an unknown error</string>
402+
<string name="message_failed_to_send">Message failed to send. An unknown error has happened.</string>
401403
</resources>

0 commit comments

Comments
 (0)