Added color to nav menu items

pull/200/head
M66B 4 years ago
parent df7238d69a
commit 140bd2b1d6

@ -189,13 +189,14 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
final List<NavMenuItem> menus = new ArrayList<>(); final List<NavMenuItem> menus = new ArrayList<>();
int colorWarning = Helper.resolveColor(this, R.attr.colorWarning);
menus.add(new NavMenuItem(R.drawable.twotone_close_24, R.string.title_setup_close, new Runnable() { menus.add(new NavMenuItem(R.drawable.twotone_close_24, R.string.title_setup_close, new Runnable() {
@Override @Override
public void run() { public void run() {
drawerLayout.closeDrawer(drawerContainer, false); drawerLayout.closeDrawer(drawerContainer, false);
onBackPressed(); onBackPressed();
} }
}).setSeparated()); }).setColor(colorWarning).setSeparated());
menus.add(new NavMenuItem(R.drawable.twotone_archive_24, R.string.title_setup_export, new Runnable() { menus.add(new NavMenuItem(R.drawable.twotone_archive_24, R.string.title_setup_export, new Runnable() {
@Override @Override

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -46,6 +47,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
private LayoutInflater inflater; private LayoutInflater inflater;
private int colorUnread; private int colorUnread;
private int colorControlNormal;
private int textColorSecondary; private int textColorSecondary;
private List<NavMenuItem> items = new ArrayList<>(); private List<NavMenuItem> items = new ArrayList<>();
@ -84,13 +86,16 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
private void bindTo(NavMenuItem menu) { private void bindTo(NavMenuItem menu) {
ivItem.setImageResource(menu.getIcon()); ivItem.setImageResource(menu.getIcon());
Integer color = menu.getColor();
ivItem.setImageTintList(ColorStateList.valueOf(color == null ? colorControlNormal : color));
if (menu.getCount() == null) if (menu.getCount() == null)
tvItem.setText(menu.getTitle()); tvItem.setText(menu.getTitle());
else else
tvItem.setText(context.getString(R.string.title_name_count, tvItem.setText(context.getString(R.string.title_name_count,
context.getString(menu.getTitle()), NF.format(menu.getCount()))); context.getString(menu.getTitle()), NF.format(menu.getCount())));
tvItem.setTextColor(menu.getCount() == null ? textColorSecondary : colorUnread); tvItem.setTextColor(menu.getCount() == null ? (color == null ? textColorSecondary : color) : colorUnread);
tvItem.setTypeface(menu.getCount() == null ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD); tvItem.setTypeface(menu.getCount() == null ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItemExtra.setText(menu.getSubtitle()); tvItemExtra.setText(menu.getSubtitle());
@ -130,6 +135,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
boolean highlight_unread = prefs.getBoolean("highlight_unread", true); boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight)); int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread)); 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.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
setHasStableIds(true); setHasStableIds(true);
@ -200,9 +206,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
NavMenuItem m1 = prev.get(oldItemPosition); NavMenuItem m1 = prev.get(oldItemPosition);
NavMenuItem m2 = next.get(newItemPosition); NavMenuItem m2 = next.get(newItemPosition);
return m1.getIcon() == m2.getIcon() && return m1.equals(m2);
m1.getTitle() == m2.getTitle() &&
Objects.equals(m1.getCount(), m2.getCount());
} }
} }

@ -19,8 +19,11 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B) Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/ */
import java.util.Objects;
public class NavMenuItem { public class NavMenuItem {
private int icon; private int icon;
private Integer color;
private int title; private int title;
private String subtitle = null; private String subtitle = null;
private Integer count = null; private Integer count = null;
@ -43,6 +46,11 @@ public class NavMenuItem {
this.longClick = longClick; this.longClick = longClick;
} }
NavMenuItem setColor(Integer color) {
this.color = color;
return this;
}
NavMenuItem setSubtitle(String subtitle) { NavMenuItem setSubtitle(String subtitle) {
this.subtitle = subtitle; this.subtitle = subtitle;
return this; return this;
@ -72,6 +80,10 @@ public class NavMenuItem {
return this.icon; return this.icon;
} }
Integer getColor() {
return this.color;
}
int getTitle() { int getTitle() {
return this.title; return this.title;
} }
@ -114,4 +126,25 @@ public class NavMenuItem {
return false; return false;
} }
} }
@Override
public boolean equals(Object object) {
if (object instanceof NavMenuItem) {
NavMenuItem other = (NavMenuItem) object;
return (this.icon == other.icon &&
Objects.equals(this.color, other.color) &&
this.title == other.title &&
Objects.equals(this.subtitle, other.subtitle) &&
Objects.equals(this.count, other.count) &&
this.external == other.external &&
this.warning == other.warning &&
this.separated == other.separated);
} else
return false;
}
@Override
public int hashCode() {
return Objects.hash(icon, color, title, subtitle, count, external, warning, separated);
}
} }

Loading…
Cancel
Save