Added enable action to disabled snackbar

This commit is contained in:
M66B 2019-02-19 19:47:23 +00:00
parent 0bc172aab0
commit 7f6a7033a7
3 changed files with 30 additions and 7 deletions

View File

@ -1521,7 +1521,7 @@ public class FragmentCompose extends FragmentBase {
if (draft == null || draft.ui_hide) {
// New draft
if ("edit".equals(action))
throw new IllegalStateException("Draft not found hide=" + (draft != null));
throw new IllegalArgumentException("Draft not found hide=" + (draft != null));
List<TupleIdentityEx> identities = db.identity().getComposableIdentities(null);
@ -1741,7 +1741,7 @@ public class FragmentCompose extends FragmentBase {
} else {
if (!draft.content) {
if (draft.uid == null)
throw new IllegalStateException("Draft without uid");
throw new IllegalArgumentException("Draft without uid");
EntityOperation.queue(context, db, draft, EntityOperation.BODY);
}
@ -2118,7 +2118,7 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!prefs.getBoolean("enabled", true))
throw new IllegalArgumentException(context.getString(R.string.title_sync_disabled));
throw new IllegalStateException(context.getString(R.string.title_sync_disabled));
// Delete draft (cannot move to outbox)
EntityOperation.queue(context, db, draft, EntityOperation.DELETE);
@ -2198,7 +2198,18 @@ public class FragmentCompose extends FragmentBase {
finish();
else if (ex instanceof IllegalArgumentException || ex instanceof AddressException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
else if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_enable, new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("enabled", true).apply();
ServiceSynchronize.reload(getContext(), "compose/disabled");
}
});
snackbar.show();
} else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
};

View File

@ -493,7 +493,7 @@ public class FragmentMessages extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!prefs.getBoolean("enabled", true))
throw new IllegalArgumentException(context.getString(R.string.title_sync_disabled));
throw new IllegalStateException(context.getString(R.string.title_sync_disabled));
DB db = DB.getInstance(context);
try {
@ -546,7 +546,18 @@ public class FragmentMessages extends FragmentBase {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
else if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_enable, new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("enabled", true).apply();
ServiceSynchronize.reload(getContext(), "refresh/disabled");
}
});
snackbar.show();
} else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentMessages.this, args, "messages:refresh");

View File

@ -360,7 +360,6 @@
<string name="title_ask_show_html">Showing the original message can leak privacy sensitive information</string>
<string name="title_ask_show_image">Showing images can leak privacy sensitive information</string>
<string name="title_ask_edit_ref">Edit reformatted replied/forwarded message text?</string>
<string name="title_fix">Fix</string>
<string name="title_compose">Compose</string>
<string name="title_from">From:</string>
@ -521,6 +520,8 @@
<string name="title_browse">Browse</string>
<string name="title_info">Info</string>
<string name="title_report">Report</string>
<string name="title_fix">Fix</string>
<string name="title_enable">Enable</string>
<string name="title_no_ask_again">Do not ask this again</string>
<string name="title_no_adobe">Adobe Acrobat reader cannot open safely shared files, see the FAQ for more information</string>
<string name="title_no_body">No message text found</string>