1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 12:44:42 +00:00

Filter on junk contacts

This commit is contained in:
M66B 2021-09-18 19:08:58 +02:00
parent 935882fb19
commit c2c2d131c8
3 changed files with 51 additions and 4 deletions

View file

@ -77,6 +77,8 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
private int textColorSecondary;
private String search = null;
private List<Integer> types = new ArrayList<>();
private List<TupleContactEx> all = new ArrayList<>();
private List<TupleContactEx> selected = new ArrayList<>();
@ -369,17 +371,28 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
}
public void set(@NonNull List<TupleContactEx> contacts) {
Log.i("Set contacts=" + contacts.size() + " search=" + search);
Log.i("Set contacts=" + contacts.size() +
" search=" + search + " types=" + types.size());
all = contacts;
List<TupleContactEx> filtered;
if (types.size() == 0)
filtered = all;
else {
filtered = new ArrayList<>();
for (TupleContactEx contact : all)
if (types.contains(contact.type))
filtered.add(contact);
}
List<TupleContactEx> items;
if (TextUtils.isEmpty(search))
items = all;
items = filtered;
else {
items = new ArrayList<>();
String query = search.toLowerCase().trim();
for (TupleContactEx contact : contacts)
for (TupleContactEx contact : filtered)
if (contact.email.toLowerCase().contains(query) ||
(contact.name != null && contact.name.toLowerCase().contains(query)))
items.add(contact);
@ -419,6 +432,11 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
set(all);
}
public void filter(List<Integer> types) {
this.types = types;
set(all);
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleContactEx> prev = new ArrayList<>();
private List<TupleContactEx> next = new ArrayList<>();

View file

@ -44,6 +44,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FragmentContacts extends FragmentBase {
@ -51,6 +52,7 @@ public class FragmentContacts extends FragmentBase {
private ContentLoadingProgressBar pbWait;
private Group grpReady;
private boolean junk = BuildConfig.DEBUG;
private String searching = null;
private AdapterContact adapter;
@ -85,6 +87,7 @@ public class FragmentContacts extends FragmentBase {
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean("fair:junk", junk);
outState.putString("fair:searching", searching);
super.onSaveInstanceState(outState);
}
@ -93,8 +96,11 @@ public class FragmentContacts extends FragmentBase {
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null)
if (savedInstanceState != null) {
junk = savedInstanceState.getBoolean("fair:junk");
searching = savedInstanceState.getString("fair:searching");
}
onMenuJunk(junk);
adapter.search(searching);
DB db = DB.getInstance(getContext());
@ -148,6 +154,12 @@ public class FragmentContacts extends FragmentBase {
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_junk).setChecked(junk);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
@ -157,6 +169,10 @@ public class FragmentContacts extends FragmentBase {
} else if (itemId == R.id.menu_delete) {
new FragmentDelete().show(getParentFragmentManager(), "contacts:delete");
return true;
} else if (itemId == R.id.menu_junk) {
item.setChecked(!item.isChecked());
onMenuJunk(item.isChecked());
return true;
}
return super.onOptionsItemSelected(item);
}
@ -165,6 +181,13 @@ public class FragmentContacts extends FragmentBase {
Helper.viewFAQ(getContext(), 84);
}
private void onMenuJunk(boolean junk) {
this.junk = junk;
adapter.filter(junk
? Arrays.asList(EntityContact.TYPE_JUNK, EntityContact.TYPE_NO_JUNK)
: new ArrayList<>());
}
public static class FragmentDelete extends FragmentDialogBase {
@NonNull
@Override

View file

@ -19,4 +19,10 @@
android:icon="@drawable/twotone_delete_24"
android:title="@string/title_delete"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_junk"
android:checkable="true"
android:icon="@drawable/twotone_report_24"
android:title="@string/title_spam" />
</menu>