mirror of https://github.com/M66B/FairEmail.git
parent
77ecf31546
commit
d65f6e3225
@ -0,0 +1,47 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
|
||||
DrawerAdapter(@NonNull Context context) {
|
||||
super(context, -1);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
DrawerItem item = getItem(position);
|
||||
View row = LayoutInflater.from(getContext()).inflate(item.getLayout(), null);
|
||||
|
||||
ImageView iv = row.findViewById(R.id.ivItem);
|
||||
TextView tv = row.findViewById(R.id.tvItem);
|
||||
|
||||
if (iv != null) {
|
||||
iv.setImageResource(item.getIcon());
|
||||
if (item.getColor() != null)
|
||||
iv.setColorFilter(item.getColor());
|
||||
}
|
||||
|
||||
if (tv != null) {
|
||||
tv.setText(item.getTitle());
|
||||
|
||||
tv.setTextColor(Helper.resolveColor(getContext(),
|
||||
item.getHighlight() ? R.attr.colorUnread : android.R.attr.textColorSecondary));
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
DrawerItem item = getItem(position);
|
||||
return (item != null && item.getId() != 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class DrawerItem {
|
||||
private int layout;
|
||||
private int id;
|
||||
private int icon;
|
||||
private Integer color;
|
||||
private String title;
|
||||
private boolean highlight;
|
||||
private Object data;
|
||||
|
||||
DrawerItem(int layout) {
|
||||
this.id = 0;
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
DrawerItem(Context context, int layout, int icon, int title) {
|
||||
this.layout = layout;
|
||||
this.id = title;
|
||||
this.icon = icon;
|
||||
this.title = context.getString(title);
|
||||
}
|
||||
|
||||
DrawerItem(int layout, int id, int icon, Integer color, String title, boolean highlight, Object data) {
|
||||
this.layout = layout;
|
||||
this.id = id;
|
||||
this.icon = icon;
|
||||
this.color = color;
|
||||
this.title = title;
|
||||
this.highlight = highlight;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
int getLayout() {
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
int getIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
Integer getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
boolean getHighlight() {
|
||||
return this.highlight;
|
||||
}
|
||||
|
||||
Object getData() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue