From ab7e3d073e5d27d2a600d612003dfb939e34cf6d Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 4 Apr 2019 12:31:09 +0200 Subject: [PATCH] Added option to hide folders --- .../java/eu/faircode/email/AdapterFolder.java | 84 +++++++++++++------ .../eu/faircode/email/FragmentFolders.java | 38 ++++++++- app/src/main/res/layout/item_folder.xml | 16 +--- app/src/main/res/menu/menu_folders.xml | 6 ++ app/src/main/res/values/strings.xml | 3 +- 5 files changed, 102 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 3a115e2fd6..1d685162cf 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -24,8 +24,11 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Rect; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.TextUtils; import android.util.TypedValue; @@ -49,7 +52,6 @@ import java.util.Locale; import androidx.annotation.NonNull; import androidx.appcompat.widget.PopupMenu; -import androidx.constraintlayout.widget.Group; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.Observer; import androidx.localbroadcastmanager.content.LocalBroadcastManager; @@ -64,6 +66,7 @@ public class AdapterFolder extends RecyclerView.Adapter 0 && folder.childs > 0) { - if (folder.collapsed) { - grpChilds.setVisibility(View.GONE); - childs.set(account, folder, level + 1, new ArrayList()); - } else { - DB db = DB.getInstance(context); - cowner.start(); - grpChilds.setVisibility(View.VISIBLE); - childs.set(folder.account, folder, level + 1, properties.getChilds(folder.id)); - db.folder().liveFolders(folder.account, folder.id).observe(cowner, new Observer>() { - @Override - public void onChanged(List folders) { - if (folders == null) - folders = new ArrayList<>(); - properties.setChilds(folder.id, folders); - childs.set(account, folder, level + 1, folders); - } - }); - } + if (account > 0 && folder.childs > 0 && !folder.collapsed) { + DB db = DB.getInstance(context); + cowner.start(); + rvChilds.setVisibility(View.VISIBLE); + childs.set(folder.account, folder, level + 1, properties.getChilds(folder.id)); + db.folder().liveFolders(folder.account, folder.id).observe(cowner, new Observer>() { + @Override + public void onChanged(List folders) { + if (folders == null) + folders = new ArrayList<>(); + properties.setChilds(folder.id, folders); + childs.set(account, folder, level + 1, folders); + } + }); } else { - grpChilds.setVisibility(View.GONE); - childs.set(account, null, 0, new ArrayList()); + rvChilds.setVisibility(View.GONE); + childs.set(folder.account, folder, level + 1, new ArrayList()); } } @@ -539,10 +561,11 @@ public class AdapterFolder extends RecyclerView.Adapter prev = new ArrayList<>(); private List next = new ArrayList<>(); diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index 28dab09fdc..6595998851 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; +import android.graphics.Rect; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; @@ -67,6 +68,7 @@ public class FragmentFolders extends FragmentBase { private FloatingActionButton fab; private long account; + private boolean show_hidden = false; private String searching = null; private AdapterFolder adapter; @@ -133,11 +135,19 @@ public class FragmentFolders extends FragmentBase { LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvFolder.setLayoutManager(llm); - DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()); + DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()) { + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + if (view.findViewById(R.id.clItem).getVisibility() == View.GONE) + outRect.setEmpty(); + else + super.getItemOffsets(outRect, view, parent, state); + } + }; itemDecorator.setDrawable(getContext().getDrawable(R.drawable.divider)); rvFolder.addItemDecoration(itemDecorator); - adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), new AdapterFolder.IProperties() { + adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), show_hidden, new AdapterFolder.IProperties() { @Override public void setChilds(long parent, List childs) { parentChilds.put(parent, childs); @@ -375,4 +385,28 @@ public class FragmentFolders extends FragmentBase { super.onCreateOptionsMenu(menu, inflater); } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + menu.findItem(R.id.menu_show_hidden).setChecked(show_hidden); + super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_show_hidden: + onMenuShowHidden(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private void onMenuShowHidden() { + show_hidden = !show_hidden; + parentChilds.clear(); + getActivity().invalidateOptionsMenu(); + adapter.setShowHidden(show_hidden); + } } diff --git a/app/src/main/res/layout/item_folder.xml b/app/src/main/res/layout/item_folder.xml index 212725f618..1e82135dd3 100644 --- a/app/src/main/res/layout/item_folder.xml +++ b/app/src/main/res/layout/item_folder.xml @@ -190,26 +190,12 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - - - + app:layout_constraintTop_toBottomOf="@id/paddingBottom" /> \ No newline at end of file diff --git a/app/src/main/res/menu/menu_folders.xml b/app/src/main/res/menu/menu_folders.xml index 38f71a0ad1..b621a2ae0d 100644 --- a/app/src/main/res/menu/menu_folders.xml +++ b/app/src/main/res/menu/menu_folders.xml @@ -8,4 +8,10 @@ android:title="@string/title_search" app:actionViewClass="androidx.appcompat.widget.SearchView" app:showAsAction="collapseActionView|always" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2946a83fa1..196d88e7df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -293,7 +293,8 @@ Folder name Display name - Hide from menus + Show hidden folders + Hide folder Show in unified inbox Synchronize (receive messages) Check periodically instead of continuous synchronize