mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 21:34:44 +02:00
Added color to nav menu items
This commit is contained in:
@@ -21,6 +21,7 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -46,6 +47,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
||||
private LayoutInflater inflater;
|
||||
|
||||
private int colorUnread;
|
||||
private int colorControlNormal;
|
||||
private int textColorSecondary;
|
||||
|
||||
private List<NavMenuItem> items = new ArrayList<>();
|
||||
@@ -84,13 +86,16 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
||||
private void bindTo(NavMenuItem menu) {
|
||||
ivItem.setImageResource(menu.getIcon());
|
||||
|
||||
Integer color = menu.getColor();
|
||||
ivItem.setImageTintList(ColorStateList.valueOf(color == null ? colorControlNormal : color));
|
||||
|
||||
if (menu.getCount() == null)
|
||||
tvItem.setText(menu.getTitle());
|
||||
else
|
||||
tvItem.setText(context.getString(R.string.title_name_count,
|
||||
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);
|
||||
|
||||
tvItemExtra.setText(menu.getSubtitle());
|
||||
@@ -130,6 +135,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
||||
boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
|
||||
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
|
||||
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);
|
||||
|
||||
setHasStableIds(true);
|
||||
@@ -200,9 +206,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
||||
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
NavMenuItem m1 = prev.get(oldItemPosition);
|
||||
NavMenuItem m2 = next.get(newItemPosition);
|
||||
return m1.getIcon() == m2.getIcon() &&
|
||||
m1.getTitle() == m2.getTitle() &&
|
||||
Objects.equals(m1.getCount(), m2.getCount());
|
||||
return m1.equals(m2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user