Added option to hide duplicate messages in thread view

pull/153/head
M66B 6 years ago
parent 3c63f4bfe3
commit 137fb05c45

@ -143,6 +143,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean subject_italic;
private int zoom;
private String sort;
private boolean duplicates;
private boolean suitable;
private IProperties properties;
@ -462,6 +463,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
setDisplacement(0);
pbLoading.setVisibility(View.GONE);
if (viewType == ViewType.THREAD)
view.setVisibility(duplicates || !message.duplicate ? View.VISIBLE : View.GONE);
// Text size
if (textSize != 0) {
tvDay.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
@ -2923,7 +2927,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
AdapterMessage(Context context, LifecycleOwner owner,
ViewType viewType, boolean compact, int zoom, String sort, IProperties properties) {
ViewType viewType, boolean compact, int zoom, String sort, boolean duplicates, IProperties properties) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.context = context;
@ -2935,6 +2939,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.subject_italic = prefs.getBoolean("subject_italic", true);
this.zoom = zoom;
this.sort = sort;
this.duplicates = duplicates;
this.suitable = Helper.getNetworkState(context).isSuitable();
this.properties = properties;
@ -3016,6 +3021,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
}
void setDuplicates(boolean duplicates) {
if (this.duplicates != duplicates) {
this.duplicates = duplicates;
notifyDataSetChanged();
}
}
void checkInternet() {
boolean suitable = Helper.getNetworkState(context).isSuitable();
if (this.suitable != suitable) {

@ -312,10 +312,11 @@ public class FragmentMessages extends FragmentBase {
boolean compact = prefs.getBoolean("compact", false);
int zoom = prefs.getInt("zoom", compact ? 0 : 1);
String sort = prefs.getString("sort", "time");
boolean duplicates = prefs.getBoolean("duplicates", true);
adapter = new AdapterMessage(
getContext(), getViewLifecycleOwner(),
viewType, compact, zoom, sort, iProperties);
viewType, compact, zoom, sort, duplicates, iProperties);
rvMessage.setAdapter(adapter);
@ -1835,6 +1836,9 @@ public class FragmentMessages extends FragmentBase {
(viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER));
menu.findItem(R.id.menu_snoozed).setChecked(prefs.getBoolean("snoozed", false));
menu.findItem(R.id.menu_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_duplicates).setChecked(prefs.getBoolean("duplicates", true));
super.onPrepareOptionsMenu(menu);
}
@ -1883,6 +1887,10 @@ public class FragmentMessages extends FragmentBase {
onMenuSnoozed();
return true;
case R.id.menu_duplicates:
onMenuDuplicates();
return true;
default:
return super.onOptionsItemSelected(item);
}
@ -1939,6 +1947,13 @@ public class FragmentMessages extends FragmentBase {
loadMessages();
}
private void onMenuDuplicates() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean duplicates = prefs.getBoolean("duplicates", true);
prefs.edit().putBoolean("duplicates", !duplicates).apply();
adapter.setDuplicates(!duplicates);
}
private void loadMessages() {
if (viewType == AdapterMessage.ViewType.THREAD && autonext) {
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);

@ -58,4 +58,10 @@
android:checkable="true"
android:title="@string/title_snoozed"
app:showAsAction="never" />
<item
android:id="@+id/menu_duplicates"
android:checkable="true"
android:title="@string/title_duplicates"
app:showAsAction="never" />
</menu>

@ -433,6 +433,7 @@
<string name="title_address_unsent">Unsent:</string>
<string name="title_address_invalid">Invalid:</string>
<string name="title_snoozed">Snoozed</string>
<string name="title_duplicates">Show duplicates</string>
<string name="title_previous">Previous</string>
<string name="title_next">Next</string>

Loading…
Cancel
Save