Mark all read "don't ask again"

pull/197/head
M66B 4 years ago
parent b2481213a0
commit 3a25f87d06

@ -360,6 +360,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
static final int REQUEST_PICK_CONTACT = 23; static final int REQUEST_PICK_CONTACT = 23;
static final int REQUEST_BUTTONS = 24; static final int REQUEST_BUTTONS = 24;
private static final int REQUEST_ASKED_RAW = 25; private static final int REQUEST_ASKED_RAW = 25;
private static final int REQUEST_ALL_READ = 26;
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW"; static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT"; static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
@ -4482,60 +4483,70 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onMenuMarkAllRead() { private void onMenuMarkAllRead() {
new AlertDialog.Builder(getContext()) SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
.setTitle(R.string.title_mark_all_read) boolean all_read_asked = prefs.getBoolean("all_read_asked", false);
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { if (all_read_asked) {
@Override markAllRead();
public void onClick(DialogInterface dialog, int which) { return;
Bundle args = new Bundle(); }
args.putString("type", type);
args.putLong("folder", folder);
new SimpleTask<Void>() { Bundle args = new Bundle();
@Override args.putString("question", getString(R.string.title_mark_all_read));
protected Void onExecute(Context context, Bundle args) throws Throwable { args.putString("notagain", "all_read_asked");
String type = args.getString("type");
long folder = args.getLong("folder");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); FragmentDialogAsk ask = new FragmentDialogAsk();
boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false); ask.setArguments(args);
boolean filter_unknown = prefs.getBoolean("filter_unknown", false); ask.setTargetFragment(FragmentMessages.this, REQUEST_ALL_READ);
boolean filter_snoozed = prefs.getBoolean("filter_snoozed", true); ask.show(getParentFragmentManager(), "messages:allread");
boolean language_detection = prefs.getBoolean("language_detection", false);
String filter_language = prefs.getString("filter_language", null);
DB db = DB.getInstance(context); }
try {
db.beginTransaction();
List<Long> ids = db.message().getMessageUnseen(
folder < 0 ? null : folder,
folder < 0 ? type : null,
filter_unflagged, filter_unknown, filter_snoozed,
language_detection ? filter_language : null);
for (long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message != null)
EntityOperation.queue(context, message, EntityOperation.SEEN, true);
}
db.setTransactionSuccessful(); private void markAllRead() {
} finally { Bundle args = new Bundle();
db.endTransaction(); args.putString("type", type);
} args.putLong("folder", folder);
return null; new SimpleTask<Void>() {
} @Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
String type = args.getString("type");
long folder = args.getLong("folder");
@Override SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
protected void onException(Bundle args, Throwable ex) { boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false);
Log.unexpectedError(getParentFragmentManager(), ex); boolean filter_unknown = prefs.getBoolean("filter_unknown", false);
} boolean filter_snoozed = prefs.getBoolean("filter_snoozed", true);
}.execute(FragmentMessages.this, args, "message:read"); boolean language_detection = prefs.getBoolean("language_detection", false);
String filter_language = prefs.getString("filter_language", null);
DB db = DB.getInstance(context);
try {
db.beginTransaction();
List<Long> ids = db.message().getMessageUnseen(
folder < 0 ? null : folder,
folder < 0 ? type : null,
filter_unflagged, filter_unknown, filter_snoozed,
language_detection ? filter_language : null);
for (long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message != null)
EntityOperation.queue(context, message, EntityOperation.SEEN, true);
} }
})
.setNegativeButton(android.R.string.cancel, null) db.setTransactionSuccessful();
.show(); } finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "messages:allread");
} }
private void onMenuSyncMore() { private void onMenuSyncMore() {
@ -6047,6 +6058,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (resultCode == RESULT_OK) if (resultCode == RESULT_OK)
_onActionRaw(); _onActionRaw();
break; break;
case REQUEST_ALL_READ:
if (requestCode == RESULT_OK)
markAllRead();
break;
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);

@ -151,7 +151,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"selected_folders", "move_1_confirmed", "move_n_confirmed", "selected_folders", "move_1_confirmed", "move_n_confirmed",
"last_search_senders", "last_search_recipients", "last_search_subject", "last_search_keywords", "last_search_message", "last_search", "last_search_senders", "last_search_recipients", "last_search_subject", "last_search_keywords", "last_search_message", "last_search",
"identities_asked", "identities_primary_hint", "identities_asked", "identities_primary_hint",
"raw_asked", "raw_asked", "all_read_asked",
"cc_bcc", "inline_image_hint", "compose_reference", "send_dialog", "cc_bcc", "inline_image_hint", "compose_reference", "send_dialog",
"setup_reminder", "setup_advanced" "setup_reminder", "setup_advanced"
}; };

Loading…
Cancel
Save