Added option to filter trashed messages / conversation

pull/194/merge
M66B 3 years ago
parent 931044657c
commit 6f527c792b

@ -209,6 +209,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private String sort;
private boolean ascending;
private boolean filter_duplicates;
private boolean filter_trash;
private IProperties properties;
private Context context;
@ -5894,7 +5895,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
AdapterMessage(Fragment parentFragment,
String type, boolean found, ViewType viewType,
boolean compact, int zoom, String sort, boolean ascending, boolean filter_duplicates,
boolean compact, int zoom, String sort, boolean ascending,
boolean filter_duplicates, boolean filter_trash,
final IProperties properties) {
this.parentFragment = parentFragment;
this.type = type;
@ -5905,6 +5907,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.sort = sort;
this.ascending = ascending;
this.filter_duplicates = filter_duplicates;
this.filter_trash = filter_trash;
this.properties = properties;
this.context = parentFragment.getContext();
@ -6619,6 +6622,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
}
void setFilterTrash(boolean filter_trash) {
if (this.filter_trash != filter_trash) {
this.filter_trash = filter_trash;
properties.refresh();
}
}
void checkInternet() {
ConnectionHelper.NetworkState state = ConnectionHelper.getNetworkState(context);
if (this.suitable != state.isSuitable() || this.unmetered != state.isUnmetered()) {
@ -6651,6 +6661,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (filter_duplicates && message.duplicate)
return R.layout.item_message_duplicate;
if (filter_trash && differ.getItemCount() > 1 &&
EntityFolder.TRASH.equals(message.folderType))
return R.layout.item_message_duplicate;
return (compact ? R.layout.item_message_compact : R.layout.item_message_normal);
}
@ -6696,11 +6710,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
holder.itemView.setLayoutParams(lparam);
}
if (filter_duplicates && message.duplicate) {
if ((filter_duplicates && message.duplicate) ||
(filter_trash && differ.getItemCount() > 1 &&
EntityFolder.TRASH.equals(message.folderType))) {
holder.card.setCardBackgroundColor(message.folderColor == null
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(message.folderColor, 128));
holder.tvFolder.setText(context.getString(R.string.title_duplicate_in, message.getFolderName(context)));
if (filter_duplicates && message.duplicate)
holder.tvFolder.setText(context.getString(R.string.title_duplicate_in,
message.getFolderName(context)));
else
holder.tvFolder.setText(context.getString(R.string.title_trashed_from,
MessageHelper.formatAddresses(message.from, false, false)));
holder.tvFolder.setTypeface(message.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
holder.tvFolder.setTextColor(message.unseen > 0 ? colorUnread : colorRead);
holder.tvFolder.setAlpha(Helper.LOW_LIGHT);

@ -843,10 +843,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
boolean ascending = prefs.getBoolean(
viewType == AdapterMessage.ViewType.THREAD ? "ascending_thread" : "ascending_list", false);
boolean filter_duplicates = prefs.getBoolean("filter_duplicates", true);
boolean filter_trash = prefs.getBoolean("filter_trash", false);
if (viewType != AdapterMessage.ViewType.THREAD)
filter_trash = false;
adapter = new AdapterMessage(
this, type, found, viewType,
compact, zoom, sort, ascending, filter_duplicates,
compact, zoom, sort, ascending,
filter_duplicates, filter_trash,
iProperties);
if (viewType == AdapterMessage.ViewType.THREAD)
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT);
@ -4427,6 +4432,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
boolean filter_unknown = prefs.getBoolean(getFilter("unknown", type), false);
boolean filter_snoozed = prefs.getBoolean(getFilter("snoozed", type), true);
boolean filter_duplicates = prefs.getBoolean("filter_duplicates", true);
boolean filter_trash = prefs.getBoolean("filter_trash", false);
boolean language_detection = prefs.getBoolean("language_detection", false);
String filter_language = prefs.getString("filter_language", null);
boolean compact = prefs.getBoolean("compact", false);
@ -4517,6 +4523,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
menu.findItem(R.id.menu_filter_unknown).setVisible(folder && !drafts && !sent);
menu.findItem(R.id.menu_filter_snoozed).setVisible(folder && !drafts);
menu.findItem(R.id.menu_filter_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_filter_trash).setVisible(viewType == AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_filter_seen).setChecked(filter_seen);
menu.findItem(R.id.menu_filter_unflagged).setChecked(filter_unflagged);
@ -4524,6 +4531,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
menu.findItem(R.id.menu_filter_snoozed).setChecked(filter_snoozed);
menu.findItem(R.id.menu_filter_language).setVisible(language_detection && folder);
menu.findItem(R.id.menu_filter_duplicates).setChecked(filter_duplicates);
menu.findItem(R.id.menu_filter_trash).setChecked(filter_trash);
SpannableStringBuilder ssbZoom = new SpannableStringBuilder(getString(R.string.title_zoom));
ssbZoom.append(' ');
@ -4647,6 +4655,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} else if (itemId == R.id.menu_filter_duplicates) {
onMenuFilterDuplicates(!item.isChecked());
return true;
} else if (itemId == R.id.menu_filter_trash) {
onMenuFilterTrash(!item.isChecked());
return true;
} else if (itemId == R.id.menu_zoom) {
onMenuZoom();
return true;
@ -4895,6 +4906,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
adapter.setFilterDuplicates(filter);
}
private void onMenuFilterTrash(boolean filter) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("filter_trash", filter).apply();
invalidateOptionsMenu();
adapter.setFilterTrash(filter);
}
private void onMenuZoom() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = prefs.getBoolean("compact", false);

@ -120,6 +120,11 @@
android:id="@+id/menu_filter_duplicates"
android:checkable="true"
android:title="@string/title_filter_duplicates" />
<item
android:id="@+id/menu_filter_trash"
android:checkable="true"
android:title="@string/title_filter_trash" />
</menu>
</item>
</group>

@ -1016,6 +1016,7 @@
<string name="title_no_messages">No messages</string>
<string name="title_filters_active">One or more filters active</string>
<string name="title_duplicate_in">Duplicate message in %1$s</string>
<string name="title_trashed_from">Trashed message from %1$s</string>
<string name="title_subject_reply">Re: %1$s</string>
<string name="title_subject_forward">Fwd: %1$s</string>
@ -1391,6 +1392,7 @@
<string name="title_filter_unknown">Unknown senders</string>
<string name="title_filter_hidden">Hidden</string>
<string name="title_filter_duplicates">Duplicates</string>
<string name="title_filter_trash">Trashed</string>
<string name="title_compact">Compact view</string>
<string name="title_zoom">Text size</string>

Loading…
Cancel
Save