|
|
|
@ -30,93 +30,152 @@ import net.micode.notes.tool.DataUtils;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NotesListItem extends LinearLayout {
|
|
|
|
|
private ImageView mAlert;
|
|
|
|
|
private TextView mTitle;
|
|
|
|
|
private TextView mTime;
|
|
|
|
|
private TextView mCallName;
|
|
|
|
|
private NoteItemData mItemData;
|
|
|
|
|
private CheckBox mCheckBox;
|
|
|
|
|
|
|
|
|
|
public NotesListItem(Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
inflate(context, R.layout.note_item, this);
|
|
|
|
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
|
mTitle = (TextView) findViewById(R.id.tv_title);
|
|
|
|
|
mTime = (TextView) findViewById(R.id.tv_time);
|
|
|
|
|
mCallName = (TextView) findViewById(R.id.tv_name);
|
|
|
|
|
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
|
|
|
|
|
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
mCheckBox.setVisibility(View.VISIBLE);
|
|
|
|
|
mCheckBox.setChecked(checked);
|
|
|
|
|
} else {
|
|
|
|
|
mCheckBox.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mItemData = data;
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mCallName.setVisibility(View.GONE);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
|
|
|
mTitle.setText(context.getString(R.string.call_record_folder_name)
|
|
|
|
|
+ context.getString(R.string.format_folder_files_count, data.getNotesCount()));
|
|
|
|
|
mAlert.setImageResource(R.drawable.call_record);
|
|
|
|
|
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mCallName.setVisibility(View.VISIBLE);
|
|
|
|
|
mCallName.setText(data.getCallName());
|
|
|
|
|
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
|
|
|
if (data.hasAlert()) {
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mCallName.setVisibility(View.GONE);
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
|
|
|
|
|
|
|
|
if (data.getType() == Notes.TYPE_FOLDER) {
|
|
|
|
|
mTitle.setText(data.getSnippet()
|
|
|
|
|
+ context.getString(R.string.format_folder_files_count,
|
|
|
|
|
data.getNotesCount()));
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
|
|
|
if (data.hasAlert()) {
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
|
|
|
|
|
setBackground(data);
|
|
|
|
|
}
|
|
|
|
|
//定义一个名为NotesListItem的类,它继承自LinearLayout
|
|
|
|
|
public class NotesListItem extends LinearLayout {
|
|
|
|
|
|
|
|
|
|
// 定义一个私有的ImageView对象,用于显示警报图标
|
|
|
|
|
private ImageView mAlert;
|
|
|
|
|
|
|
|
|
|
// 定义一个私有的TextView对象,用于显示标题
|
|
|
|
|
private TextView mTitle;
|
|
|
|
|
|
|
|
|
|
// 定义一个私有的TextView对象,用于显示时间
|
|
|
|
|
private TextView mTime;
|
|
|
|
|
|
|
|
|
|
// 定义一个私有的TextView对象,用于显示电话的名字
|
|
|
|
|
private TextView mCallName;
|
|
|
|
|
|
|
|
|
|
// 定义一个私有的NoteItemData对象,用于存储与笔记相关的数据
|
|
|
|
|
private NoteItemData mItemData;
|
|
|
|
|
|
|
|
|
|
// 定义一个私有的CheckBox对象,用于表示笔记是否被选中
|
|
|
|
|
private CheckBox mCheckBox;
|
|
|
|
|
|
|
|
|
|
// 定义一个公共的构造函数,接收一个Context参数
|
|
|
|
|
public NotesListItem(Context context) {
|
|
|
|
|
// 调用父类的构造函数,传入context参数
|
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
|
|
// 使用inflate方法从指定的XML布局文件中创建视图,并将视图添加到当前实例中
|
|
|
|
|
inflate(context, R.layout.note_item, this);
|
|
|
|
|
|
|
|
|
|
// 通过ID查找布局中的控件,并赋值给相应的变量
|
|
|
|
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
|
mTitle = (TextView) findViewById(R.id.tv_title);
|
|
|
|
|
mTime = (TextView) findViewById(R.id.tv_time);
|
|
|
|
|
mCallName = (TextView) findViewById(R.id.tv_name);
|
|
|
|
|
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
|
|
|
|
|
// 如果处于选择模式,并且数据类型是笔记
|
|
|
|
|
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
// 显示复选框,并设置其选中状态
|
|
|
|
|
mCheckBox.setVisibility(View.VISIBLE);
|
|
|
|
|
mCheckBox.setChecked(checked);
|
|
|
|
|
} else {
|
|
|
|
|
// 隐藏复选框
|
|
|
|
|
mCheckBox.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存传入的数据
|
|
|
|
|
mItemData = data;
|
|
|
|
|
}
|
|
|
|
|
//如果data的id等于Notes.ID_CALL_RECORD_FOLDER
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
// 隐藏电话名称的显示
|
|
|
|
|
mCallName.setVisibility(View.GONE);
|
|
|
|
|
// 显示警报图标
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
// 设置标题的文本样式为默认样式
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
|
|
|
// 设置标题的文本为“通话记录文件夹名”加上data中的笔记数量
|
|
|
|
|
mTitle.setText(context.getString(R.string.call_record_folder_name)
|
|
|
|
|
+ context.getString(R.string.format_folder_files_count, data.getNotesCount()));
|
|
|
|
|
// 设置警报图标的资源为通话记录图标
|
|
|
|
|
mAlert.setImageResource(R.drawable.call_record);
|
|
|
|
|
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
// 显示电话名称的显示
|
|
|
|
|
mCallName.setVisibility(View.VISIBLE);
|
|
|
|
|
// 设置电话名称的文本为data中的callName
|
|
|
|
|
mCallName.setText(data.getCallName());
|
|
|
|
|
// 设置标题的文本样式为二级样式
|
|
|
|
|
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
|
|
|
|
|
// 设置标题的文本为DataUtils格式化后的摘要
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
|
|
|
// 如果data有警报
|
|
|
|
|
if (data.hasAlert()) {
|
|
|
|
|
// 设置警报图标的资源为时钟图标,并显示警报图标
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
// 否则隐藏警报图标
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 隐藏电话名称的显示
|
|
|
|
|
mCallName.setVisibility(View.GONE);
|
|
|
|
|
// 设置标题的文本样式为默认样式
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
|
|
|
// 如果data的类型是文件夹
|
|
|
|
|
if (data.getType() == Notes.TYPE_FOLDER) {
|
|
|
|
|
// 设置标题的文本为摘要加上data中的笔记数量
|
|
|
|
|
mTitle.setText(data.getSnippet()
|
|
|
|
|
+ context.getString(R.string.format_folder_files_count,
|
|
|
|
|
data.getNotesCount()));
|
|
|
|
|
// 隐藏警报图标
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
// 设置标题的文本为DataUtils格式化后的摘要
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
|
|
|
// 如果data有警报
|
|
|
|
|
if (data.hasAlert()) {
|
|
|
|
|
// 设置警报图标的资源为时钟图标,并显示警报图标
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
// 否则隐藏警报图标
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//设置时间文本为相对时间格式(例如:1小时前,2分钟前等)
|
|
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
//根据data设置背景色或背景图片等背景样式
|
|
|
|
|
setBackground(data);
|
|
|
|
|
|
|
|
|
|
private void setBackground(NoteItemData data) {
|
|
|
|
|
int id = data.getBgColorId();
|
|
|
|
|
if (data.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
if (data.isSingle() || data.isOneFollowingFolder()) {
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
|
|
|
|
|
} else if (data.isLast()) {
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
|
|
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
|
|
|
|
} else {
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//设置背景的方法
|
|
|
|
|
private void setBackground(NoteItemData data) {
|
|
|
|
|
// 获取data的背景颜色id
|
|
|
|
|
int id = data.getBgColorId();
|
|
|
|
|
|
|
|
|
|
// 如果data的类型是笔记
|
|
|
|
|
if (data.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
// 如果data是单条笔记或者是某个文件夹下的第一条笔记
|
|
|
|
|
if (data.isSingle() || data.isOneFollowingFolder()) {
|
|
|
|
|
// 设置背景资源为单条笔记的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
|
|
|
|
|
// 如果data是最后一条笔记
|
|
|
|
|
} else if (data.isLast()) {
|
|
|
|
|
// 设置背景资源为最后一条笔记的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
|
|
|
// 如果data是第一条笔记或者是某个文件夹下的第一条多条笔记
|
|
|
|
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
|
|
|
|
// 设置背景资源为第一条笔记的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
|
|
|
|
// 其他情况,默认为普通情况
|
|
|
|
|
} else {
|
|
|
|
|
// 设置背景资源为普通笔记的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
|
|
|
|
|
}
|
|
|
|
|
// 如果data的类型是文件夹
|
|
|
|
|
} else {
|
|
|
|
|
// 设置背景资源为文件夹的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
return mItemData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//获取itemData的方法,返回mItemData对象
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
return mItemData;
|
|
|
|
|
}
|