Added option to hide folders

pull/153/head
M66B 6 years ago
parent e770f00c58
commit ab7e3d073e

@ -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<AdapterFolder.ViewHolder
private Context context;
private LayoutInflater inflater;
private LifecycleOwner owner;
private boolean show_hidden;
private long account;
private int level;
@ -98,7 +101,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private TextView tvError;
private View vwRipple;
private RecyclerView rvChilds;
private Group grpChilds;
private AdapterFolder childs;
private TwoStateOwner cowner = new TwoStateOwner(owner, "AdapterFolder");
@ -129,18 +131,40 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvKeywords = itemView.findViewById(R.id.tvKeywords);
tvError = itemView.findViewById(R.id.tvError);
vwRipple = itemView.findViewById(R.id.vwRipple);
grpChilds = itemView.findViewById(R.id.grpChilds);
rvChilds = itemView.findViewById(R.id.rvChilds);
LinearLayoutManager llm = new LinearLayoutManager(context);
rvChilds.setLayoutManager(llm);
rvChilds.setNestedScrollingEnabled(false);
DividerItemDecoration itemDecorator = new DividerItemDecoration(context, llm.getOrientation());
DividerItemDecoration itemDecorator = new DividerItemDecoration(context, llm.getOrientation()) {
Drawable d = context.getDrawable(R.drawable.divider);
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
for (int i = 0; i < parent.getChildCount(); i++) {
d.setBounds(0, 0, parent.getWidth(), d.getIntrinsicHeight());
canvas.save();
canvas.translate(0, parent.getChildAt(i).getTop() - d.getIntrinsicHeight());
d.draw(canvas);
canvas.restore();
}
}
@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);
outRect.set(0, outRect.bottom, 0, 0);
}
}
};
itemDecorator.setDrawable(context.getDrawable(R.drawable.divider));
rvChilds.addItemDecoration(itemDecorator);
childs = new AdapterFolder(context, owner, properties);
childs = new AdapterFolder(context, owner, show_hidden, properties);
rvChilds.setAdapter(childs);
}
@ -157,7 +181,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}
private void bindTo(final TupleFolderEx folder) {
view.setVisibility(folder.hide && !show_hidden ? View.GONE : View.VISIBLE);
view.setActivated(folder.tbc != null || folder.tbd != null);
view.setAlpha(folder.hide ? Helper.LOW_LIGHT : 1.0f);
if (textSize != 0)
tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
@ -264,29 +290,25 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvError.setText(folder.error);
tvError.setVisibility(folder.error != null ? View.VISIBLE : View.GONE);
childs.setShowHidden(show_hidden);
cowner.restart();
if (account > 0 && folder.childs > 0) {
if (folder.collapsed) {
grpChilds.setVisibility(View.GONE);
childs.set(account, folder, level + 1, new ArrayList<TupleFolderEx>());
} 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<List<TupleFolderEx>>() {
@Override
public void onChanged(List<TupleFolderEx> 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<List<TupleFolderEx>>() {
@Override
public void onChanged(List<TupleFolderEx> 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<TupleFolderEx>());
rvChilds.setVisibility(View.GONE);
childs.set(folder.account, folder, level + 1, new ArrayList<TupleFolderEx>());
}
}
@ -539,10 +561,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}
}
AdapterFolder(Context context, LifecycleOwner owner, IProperties properties) {
AdapterFolder(Context context, LifecycleOwner owner, boolean show_hidden, IProperties properties) {
this.context = context;
this.inflater = LayoutInflater.from(context);
this.owner = owner;
this.show_hidden = show_hidden;
this.properties = properties;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -642,6 +665,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
diff.dispatchUpdatesTo(this);
}
void setShowHidden(boolean show_hidden) {
if (this.show_hidden != show_hidden) {
this.show_hidden = show_hidden;
notifyDataSetChanged();
}
}
private class DiffCallback extends DiffUtil.Callback {
private List<TupleFolderEx> prev = new ArrayList<>();
private List<TupleFolderEx> next = new ArrayList<>();

@ -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<TupleFolderEx> 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);
}
}

@ -190,26 +190,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/vSeparatorChilds"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/paddingBottom" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvChilds"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorChilds" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpChilds"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorChilds,rvChilds" />
app:layout_constraintTop_toBottomOf="@id/paddingBottom" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

@ -8,4 +8,10 @@
android:title="@string/title_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|always" />
<item
android:id="@+id/menu_show_hidden"
android:checkable="true"
android:title="@string/title_show_folders"
app:showAsAction="never" />
</menu>

@ -293,7 +293,8 @@
<string name="title_folder_name">Folder name</string>
<string name="title_display_name">Display name</string>
<string name="title_hide_folder">Hide from menus</string>
<string name="title_show_folders">Show hidden folders</string>
<string name="title_hide_folder">Hide folder</string>
<string name="title_unified_folder">Show in unified inbox</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string>
<string name="title_poll_folder">Check periodically instead of continuous synchronize</string>

Loading…
Cancel
Save