Added menu item to disable folders for accounts

pull/214/head
M66B 10 months ago
parent 74f11a1872
commit c9d5568dc6

@ -79,6 +79,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private Fragment parentFragment;
private boolean settings;
private boolean compact;
private boolean show_folders;
private Context context;
private LifecycleOwner owner;
@ -92,6 +93,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private int textColorTertiary;
private boolean debug;
private List<TupleAccountFolder> all = new ArrayList<>();
private List<TupleAccountFolder> items = new ArrayList<>();
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -858,10 +860,11 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
}
}
AdapterAccount(final Fragment parentFragment, boolean settings, boolean compact) {
AdapterAccount(final Fragment parentFragment, boolean settings, boolean compact, boolean folders) {
this.parentFragment = parentFragment;
this.settings = settings;
this.compact = compact;
this.show_folders = folders;
this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner();
@ -897,12 +900,24 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
public void set(@NonNull List<TupleAccountFolder> accounts) {
Log.i("Set accounts=" + accounts.size());
if (accounts.size() > 0)
TupleAccountFolder.sort(accounts, true, context);
this.all = accounts;
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, accounts), false);
List<TupleAccountFolder> filtered;
if (show_folders)
filtered = all;
else {
filtered = new ArrayList<>();
for (TupleAccountFolder account : accounts)
if (account.folderName == null)
filtered.add(account);
}
if (filtered.size() > 0)
TupleAccountFolder.sort(filtered, true, context);
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, filtered), false);
items = accounts;
items = filtered;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
@ -938,6 +953,13 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
this.compact = compact;
}
void setShowFolders(boolean show_folders) {
if (this.show_folders != show_folders) {
this.show_folders = show_folders;
set(all);
}
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleAccountFolder> prev = new ArrayList<>();
private List<TupleAccountFolder> next = new ArrayList<>();

@ -58,12 +58,9 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class FragmentAccounts extends FragmentBase {
@ -72,6 +69,7 @@ public class FragmentAccounts extends FragmentBase {
private boolean cards;
private boolean dividers;
private boolean compact;
private boolean show_folders;
private ViewGroup view;
private SwipeRefreshLayout swipeRefresh;
@ -97,6 +95,7 @@ public class FragmentAccounts extends FragmentBase {
cards = prefs.getBoolean("cards", true);
dividers = prefs.getBoolean("dividers", true);
compact = prefs.getBoolean("compact_accounts", false) && !settings;
show_folders = prefs.getBoolean("folders_accounts", true) && !settings;
}
@Override
@ -222,7 +221,7 @@ public class FragmentAccounts extends FragmentBase {
};
rvAccount.addItemDecoration(categoryDecorator);
adapter = new AdapterAccount(this, settings, compact);
adapter = new AdapterAccount(this, settings, compact, show_folders);
rvAccount.setAdapter(adapter);
fab.setOnClickListener(new View.OnClickListener() {
@ -359,6 +358,8 @@ public class FragmentAccounts extends FragmentBase {
menu.findItem(R.id.menu_outbox).setVisible(!settings);
menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_compact).setVisible(!settings);
menu.findItem(R.id.menu_show_folders).setChecked(show_folders);
menu.findItem(R.id.menu_show_folders).setVisible(!settings);
menu.findItem(R.id.menu_theme).setVisible(!settings);
menu.findItem(R.id.menu_force_sync).setVisible(!settings);
@ -380,6 +381,9 @@ public class FragmentAccounts extends FragmentBase {
} else if (itemId == R.id.menu_compact) {
onMenuCompact();
return true;
} else if (itemId == R.id.menu_show_folders) {
onMenuShowFolders();
return true;
} else if (itemId == R.id.menu_theme) {
onMenuTheme();
return true;
@ -433,6 +437,16 @@ public class FragmentAccounts extends FragmentBase {
});
}
private void onMenuShowFolders() {
show_folders = !show_folders;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("folders_accounts", show_folders).apply();
invalidateOptionsMenu();
adapter.setShowFolders(show_folders);
}
private void onMenuTheme() {
new FragmentDialogTheme().show(getParentFragmentManager(), "messages:theme");
}

@ -27,6 +27,12 @@
android:title="@string/title_compact"
app:showAsAction="never" />
<item
android:id="@+id/menu_show_folders"
android:checkable="true"
android:title="@string/page_folders"
app:showAsAction="never" />
<item
android:id="@+id/menu_theme"
android:title="@string/title_setup_theme"

Loading…
Cancel
Save