mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-15 05:23:48 +02:00
Added collapsing of nav menu folders
This commit is contained in:
@@ -427,13 +427,30 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
public void onClick(View v) {
|
||||
boolean nav_account = prefs.getBoolean("nav_account", true);
|
||||
boolean nav_folder = prefs.getBoolean("nav_folder", true);
|
||||
nav_account = !(nav_account || nav_folder);
|
||||
boolean nav_quick = prefs.getBoolean("nav_quick", true);
|
||||
boolean expanded = (nav_account || nav_folder);
|
||||
|
||||
if (expanded && nav_quick && adapterNavAccount.hasFolders())
|
||||
nav_quick = false;
|
||||
else {
|
||||
expanded = !expanded;
|
||||
if (expanded)
|
||||
nav_quick = true;
|
||||
}
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean("nav_account", nav_account)
|
||||
.putBoolean("nav_folder", false)
|
||||
.putBoolean("nav_account", expanded)
|
||||
.putBoolean("nav_folder", expanded)
|
||||
.putBoolean("nav_quick", nav_quick)
|
||||
.apply();
|
||||
ibExpanderAccount.setImageLevel(nav_account ? 0 /* less */ : 1 /* more */);
|
||||
rvAccount.setVisibility(nav_account ? View.VISIBLE : View.GONE);
|
||||
|
||||
adapterNavAccount.setFolders(nav_quick);
|
||||
|
||||
if (expanded && nav_quick && adapterNavAccount.hasFolders())
|
||||
ibExpanderAccount.setImageLevel(2 /* unfold less */);
|
||||
else
|
||||
ibExpanderAccount.setImageLevel(expanded ? 0 /* less */ : 1 /* more */);
|
||||
rvAccount.setVisibility(expanded ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -736,13 +753,25 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
// Live data
|
||||
|
||||
DB db = DB.getInstance(this);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
db.account().liveAccountFolder().observe(owner, new Observer<List<TupleAccountFolder>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<TupleAccountFolder> accounts) {
|
||||
if (accounts == null)
|
||||
accounts = new ArrayList<>();
|
||||
adapterNavAccount.set(accounts, nav_expanded);
|
||||
|
||||
boolean nav_account = prefs.getBoolean("nav_account", true);
|
||||
boolean nav_folder = prefs.getBoolean("nav_folder", true);
|
||||
boolean nav_quick = prefs.getBoolean("nav_quick", true);
|
||||
boolean expanded = (nav_account || nav_folder);
|
||||
|
||||
adapterNavAccount.set(accounts, nav_expanded, nav_quick);
|
||||
|
||||
if (expanded && nav_quick && adapterNavAccount.hasFolders())
|
||||
ibExpanderAccount.setImageLevel(2 /* unfold less */);
|
||||
else
|
||||
ibExpanderAccount.setImageLevel(expanded ? 0 /* less */ : 1 /* more */);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
|
||||
private int colorWarning;
|
||||
|
||||
private boolean expanded = true;
|
||||
private boolean folders = true;
|
||||
private List<TupleAccountFolder> all = new ArrayList<>();
|
||||
private List<TupleAccountFolder> items = new ArrayList<>();
|
||||
|
||||
private NumberFormat NF = NumberFormat.getNumberInstance();
|
||||
@@ -276,7 +278,7 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
|
||||
setHasStableIds(false);
|
||||
}
|
||||
|
||||
public void set(@NonNull List<TupleAccountFolder> accounts, boolean expanded) {
|
||||
public void set(@NonNull List<TupleAccountFolder> accounts, boolean expanded, boolean folders) {
|
||||
Log.i("Set nav accounts=" + accounts.size());
|
||||
|
||||
if (accounts.size() > 0) {
|
||||
@@ -328,6 +330,14 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
|
||||
});
|
||||
}
|
||||
|
||||
all = accounts;
|
||||
if (!folders) {
|
||||
accounts = new ArrayList<>();
|
||||
for (TupleAccountFolder item : all)
|
||||
if (item.folderName == null)
|
||||
accounts.add(item);
|
||||
}
|
||||
|
||||
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, accounts), false);
|
||||
|
||||
this.expanded = expanded;
|
||||
@@ -362,6 +372,20 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setFolders(boolean folders) {
|
||||
if (this.folders != folders) {
|
||||
this.folders = folders;
|
||||
set(all, expanded, folders);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFolders() {
|
||||
for (TupleAccountFolder item : all)
|
||||
if (item.folderName != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class DiffCallback extends DiffUtil.Callback {
|
||||
private List<TupleAccountFolder> prev = new ArrayList<>();
|
||||
private List<TupleAccountFolder> next = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user