Added icon nav menu

This commit is contained in:
M66B 2021-08-11 09:31:00 +02:00
parent b4bec5ae45
commit 6747aba112
9 changed files with 125 additions and 31 deletions

View File

@ -294,7 +294,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
}
}).setSubtitle(BuildConfig.VERSION_NAME));
adapter.set(menus);
adapter.set(menus, true);
getSupportFragmentManager().addOnBackStackChangedListener(this);

View File

@ -97,6 +97,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private DrawerLayoutEx drawerLayout;
private ActionBarDrawerToggle drawerToggle;
private NestedScrollView drawerContainer;
private ImageButton ibExpanderNav;
private ImageButton ibExpanderAccount;
private RecyclerView rvAccount;
private ImageButton ibExpanderUnified;
@ -108,6 +109,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private ImageButton ibExpanderExtra;
private RecyclerView rvMenuExtra;
private boolean expanded;
private AdapterNavAccount adapterNavAccount;
private AdapterNavUnified adapterNavUnified;
private AdapterNavFolder adapterNavFolder;
@ -261,12 +263,15 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
drawerContainer = findViewById(R.id.drawer_container);
int drawerWidth;
final boolean nav_fixed;
DisplayMetrics dm = getResources().getDisplayMetrics();
if (viewId == R.layout.activity_view_landscape_split && landscape3)
if (viewId == R.layout.activity_view_landscape_split && landscape3) {
drawerWidth = Helper.dp2pixels(this, 300);
else if (viewId != R.layout.activity_view_landscape_split && portrait3)
nav_fixed = true;
} else if (viewId != R.layout.activity_view_landscape_split && portrait3) {
drawerWidth = Math.min(Helper.dp2pixels(this, 300), dm.widthPixels / 2);
else {
nav_fixed = true;
} else {
int actionBarHeight;
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
@ -277,12 +282,42 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
int screenWidth = Math.min(dm.widthPixels, dm.heightPixels);
int dp320 = Helper.dp2pixels(this, 320);
drawerWidth = Math.min(screenWidth - actionBarHeight, dp320);
nav_fixed = false;
}
int dp48 = Helper.dp2pixels(this, 48);
expanded = (!nav_fixed || prefs.getBoolean("nav_expanded", true));
ViewGroup.LayoutParams lparam = drawerContainer.getLayoutParams();
lparam.width = drawerWidth;
lparam.width = (expanded ? drawerWidth : dp48);
drawerContainer.setLayoutParams(lparam);
// Navigation expander
ibExpanderNav = drawerContainer.findViewById(R.id.ibExpanderNav);
ibExpanderNav.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expanded = !expanded;
prefs.edit().putBoolean("nav_expanded", expanded).apply();
lparam.width = (expanded ? drawerWidth : dp48);
drawerContainer.setLayoutParams(lparam);
if (nav_fixed)
childContent.setPaddingRelative(childDrawer.getLayoutParams().width, 0, 0, 0);
ibExpanderNav.setImageLevel(expanded ? 0 : 1);
adapterNavAccount.setExpanded(expanded);
adapterNavUnified.setExpanded(expanded);
adapterNavFolder.setExpanded(expanded);
adapterNavMenu.setExpanded(expanded);
adapterNavMenuExtra.setExpanded(expanded);
}
});
ibExpanderNav.setImageLevel(expanded ? 0 : 1);
ibExpanderNav.setVisibility(nav_fixed ? View.VISIBLE : View.GONE);
// Accounts
ibExpanderAccount = drawerContainer.findViewById(R.id.ibExpanderAccount);
@ -526,7 +561,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
}));
adapterNavMenu.set(menus);
adapterNavMenu.set(menus, expanded);
// Collapsible menus
@ -629,7 +664,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
}).setExternal(true));
adapterNavMenuExtra.set(extra);
adapterNavMenuExtra.set(extra, expanded);
// Live data
@ -640,7 +675,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
public void onChanged(@Nullable List<TupleAccountEx> accounts) {
if (accounts == null)
accounts = new ArrayList<>();
adapterNavAccount.set(accounts);
adapterNavAccount.set(accounts, expanded);
}
});
@ -649,7 +684,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
public void onChanged(List<TupleFolderUnified> folders) {
if (folders == null)
folders = new ArrayList<>();
adapterNavUnified.set(folders);
adapterNavUnified.set(folders, expanded);
}
});
@ -658,7 +693,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
public void onChanged(List<TupleFolderNav> folders) {
if (folders == null)
folders = new ArrayList<>();
adapterNavFolder.set(folders);
adapterNavFolder.set(folders, expanded);
}
});

View File

@ -22,6 +22,7 @@ package eu.faircode.email;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -54,7 +55,9 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
private int colorUnread;
private int textColorSecondary;
private int colorWarning;
private boolean expanded = true;
private List<TupleAccountEx> items = new ArrayList<>();
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -116,8 +119,10 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
tvItem.setTextColor(account.unseen == 0 ? textColorSecondary : colorUnread);
tvItem.setTypeface(account.unseen == 0 ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItem.setVisibility(expanded ? View.VISIBLE : View.GONE);
tvItemExtra.setText(account.last_connected == null ? null : TF.format(account.last_connected));
tvItemExtra.setVisibility(account.last_connected != null && expanded ? View.VISIBLE : View.GONE);
ivExtra.setVisibility(View.GONE);
@ -126,13 +131,17 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
if (account.error != null) {
ivWarning.setEnabled(false);
ivWarning.setImageResource(R.drawable.twotone_warning_24);
ivWarning.setVisibility(View.VISIBLE);
ivWarning.setVisibility(expanded ? View.VISIBLE : View.GONE);
view.setBackgroundColor(expanded ? Color.TRANSPARENT : colorWarning);
} else if (percent != null && percent > QUOTA_WARNING) {
ivWarning.setEnabled(true);
ivWarning.setImageResource(R.drawable.twotone_disc_full_24);
ivWarning.setVisibility(View.VISIBLE);
} else
ivWarning.setVisibility(expanded ? View.VISIBLE : View.GONE);
view.setBackgroundColor(expanded ? Color.TRANSPARENT : colorWarning);
} else {
ivWarning.setVisibility(View.GONE);
view.setBackgroundColor(Color.TRANSPARENT);
}
}
@Override
@ -211,13 +220,14 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
this.colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
this.TF = Helper.getTimeInstance(context, SimpleDateFormat.SHORT);
setHasStableIds(true);
}
public void set(@NonNull List<TupleAccountEx> accounts) {
public void set(@NonNull List<TupleAccountEx> accounts, boolean expanded) {
Log.i("Set nav accounts=" + accounts.size());
if (accounts.size() > 0)
@ -225,7 +235,8 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, accounts), false);
items = accounts;
this.expanded = expanded;
this.items = accounts;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
@ -251,6 +262,11 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
diff.dispatchUpdatesTo(this);
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
notifyDataSetChanged();
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleAccountEx> prev = new ArrayList<>();
private List<TupleAccountEx> next = new ArrayList<>();

View File

@ -22,6 +22,7 @@ package eu.faircode.email;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
@ -52,7 +53,9 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
private boolean nav_count;
private int colorUnread;
private int textColorSecondary;
private int colorWarning;
private boolean expanded = true;
private List<TupleFolderNav> items = new ArrayList<>();
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -126,12 +129,14 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
tvItem.setTextColor(count == 0 ? textColorSecondary : colorUnread);
tvItem.setTypeface(count == 0 ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItem.setVisibility(expanded ? View.VISIBLE : View.GONE);
tvItemExtra.setText(NF.format(folder.messages));
tvItemExtra.setVisibility(nav_count ? View.VISIBLE : View.GONE);
tvItemExtra.setVisibility(nav_count && expanded ? View.VISIBLE : View.GONE);
ivExtra.setVisibility(View.GONE);
ivWarning.setVisibility(folder.error == null ? View.GONE : View.VISIBLE);
ivWarning.setVisibility(folder.error != null && expanded ? View.VISIBLE : View.GONE);
view.setBackgroundColor(folder.error != null && !expanded ? colorWarning : Color.TRANSPARENT);
}
@Override
@ -170,15 +175,16 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
setHasStableIds(true);
}
public void set(@NonNull List<TupleFolderNav> folders) {
Log.i("Set nav folders=" + folders.size());
public void set(@NonNull List<TupleFolderNav> folders, boolean expanded) {
Log.i("Set nav folders=" + folders.size() + " expanded=" + expanded);
if (folders.size() > 0)
Collections.sort(folders, folders.get(0).getComparator(context));
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, folders), false);
items = folders;
this.expanded = expanded;
this.items = folders;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
@ -204,6 +210,11 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
diff.dispatchUpdatesTo(this);
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
notifyDataSetChanged();
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleFolderNav> prev = new ArrayList<>();
private List<TupleFolderNav> next = new ArrayList<>();

View File

@ -22,6 +22,7 @@ package eu.faircode.email;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
@ -48,7 +49,9 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
private int colorUnread;
private int colorControlNormal;
private int textColorSecondary;
private int colorWarning;
private boolean expanded = true;
private List<NavMenuItem> items = new ArrayList<>();
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -96,13 +99,15 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
tvItem.setTextColor(menu.getCount() == null ? (color == null ? textColorSecondary : color) : colorUnread);
tvItem.setTypeface(menu.getCount() == null ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItem.setVisibility(expanded ? View.VISIBLE : View.GONE);
tvItemExtra.setText(menu.getSubtitle());
tvItemExtra.setVisibility(menu.getSubtitle() == null ? View.GONE : View.VISIBLE);
tvItemExtra.setVisibility(menu.getSubtitle() != null && expanded ? View.VISIBLE : View.GONE);
ivExtra.setImageResource(menu.getExtraIcon());
ivExtra.setVisibility(menu.getExtraIcon() == 0 ? View.GONE : View.VISIBLE);
ivWarning.setVisibility(menu.hasWarning() ? View.VISIBLE : View.GONE);
ivExtra.setVisibility(menu.getExtraIcon() != 0 && expanded ? View.VISIBLE : View.GONE);
ivWarning.setVisibility(menu.hasWarning() && expanded ? View.VISIBLE : View.GONE);
view.setBackgroundColor(menu.hasWarning() && !expanded ? colorWarning : Color.TRANSPARENT);
}
@Override
@ -137,16 +142,18 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));
this.colorControlNormal = Helper.resolveColor(context, R.attr.colorControlNormal);
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
this.colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
setHasStableIds(true);
}
public void set(@NonNull List<NavMenuItem> menus) {
Log.i("Set nav menus=" + menus.size());
public void set(@NonNull List<NavMenuItem> menus, boolean expanded) {
Log.i("Set nav menus=" + menus.size() + " expanded=" + expanded);
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, menus), false);
items = menus;
this.expanded = expanded;
this.items = menus;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
@ -172,6 +179,11 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
diff.dispatchUpdatesTo(this);
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
notifyDataSetChanged();
}
NavMenuItem get(int pos) {
return items.get(pos);
}

View File

@ -52,6 +52,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
private int colorUnread;
private int textColorSecondary;
private boolean expanded = true;
private List<TupleFolderUnified> items = new ArrayList<>();
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -103,9 +104,10 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
tvItem.setTextColor(count == 0 ? textColorSecondary : colorUnread);
tvItem.setTypeface(count == 0 ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItem.setVisibility(expanded ? View.VISIBLE : View.GONE);
tvItemExtra.setText(NF.format(folder.messages));
tvItemExtra.setVisibility(nav_count ? View.VISIBLE : View.GONE);
tvItemExtra.setVisibility(nav_count && expanded ? View.VISIBLE : View.GONE);
ivExtra.setVisibility(View.GONE);
ivWarning.setVisibility(View.GONE);
@ -141,7 +143,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
}
public void set(@NonNull List<TupleFolderUnified> types) {
public void set(@NonNull List<TupleFolderUnified> types, boolean expanded) {
Log.i("Set nav unified=" + types.size());
Collections.sort(types, new Comparator<TupleFolderUnified>() {
@ -155,7 +157,8 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, types), false);
items = types;
this.expanded = expanded;
this.items = types;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
@ -181,6 +184,11 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
diff.dispatchUpdatesTo(this);
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
notifyDataSetChanged();
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleFolderUnified> prev = new ArrayList<>();
private List<TupleFolderUnified> next = new ArrayList<>();

View File

@ -72,8 +72,9 @@ public class NavMenuItem {
return this;
}
void setWarning(boolean warning) {
NavMenuItem setWarning(boolean warning) {
this.warning = warning;
return this;
}
NavMenuItem setSeparated() {

View File

@ -5,6 +5,16 @@
android:layout_height="wrap_content"
android:animateLayoutChanges="false">
<ImageButton
android:id="@+id/ibExpanderNav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/title_legend_expander"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/expander_hor" />
<ImageButton
android:id="@+id/ibExpanderAccount"
android:layout_width="0dp"
@ -13,7 +23,7 @@
android:contentDescription="@string/title_legend_expander"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibExpanderNav"
app:srcCompat="@drawable/expander" />
<androidx.recyclerview.widget.RecyclerView

View File

@ -16,6 +16,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:gravity="center_vertical"
android:minHeight="42dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"