|
|
|
@ -29,18 +29,33 @@ import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 笔记列表项自定义视图类,继承自LinearLayout
|
|
|
|
|
* 用于显示笔记或文件夹在列表中的每一项
|
|
|
|
|
*/
|
|
|
|
|
public class NotesListItem extends LinearLayout {
|
|
|
|
|
// 提醒图标视图
|
|
|
|
|
private ImageView mAlert;
|
|
|
|
|
// 标题文本视图
|
|
|
|
|
private TextView mTitle;
|
|
|
|
|
// 时间文本视图
|
|
|
|
|
private TextView mTime;
|
|
|
|
|
// 通话记录名称文本视图(专用于通话记录)
|
|
|
|
|
private TextView mCallName;
|
|
|
|
|
// 当前项绑定的数据
|
|
|
|
|
private NoteItemData mItemData;
|
|
|
|
|
// 复选框(用于多选模式)
|
|
|
|
|
private CheckBox mCheckBox;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
*/
|
|
|
|
|
public NotesListItem(Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
// 从布局文件note_item.xml填充视图
|
|
|
|
|
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);
|
|
|
|
@ -48,7 +63,15 @@ public class NotesListItem extends LinearLayout {
|
|
|
|
|
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 绑定数据到列表项
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
* @param data 笔记项数据
|
|
|
|
|
* @param choiceMode 是否处于多选模式
|
|
|
|
|
* @param checked 是否被选中
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
@ -56,36 +79,44 @@ public class NotesListItem extends LinearLayout {
|
|
|
|
|
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) {
|
|
|
|
|
}
|
|
|
|
|
// 处理通话记录文件夹中的项
|
|
|
|
|
else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mCallName.setVisibility(View.VISIBLE);
|
|
|
|
|
mCallName.setText(data.getCallName());
|
|
|
|
|
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);
|
|
|
|
|
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()));
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));// 笔记类型处理
|
|
|
|
|
// 根据是否有提醒设置提醒图标
|
|
|
|
|
if (data.hasAlert()) {
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
@ -94,14 +125,21 @@ public class NotesListItem extends LinearLayout {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 设置相对时间显示(如"2分钟前")
|
|
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
|
|
|
|
|
setBackground(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据数据设置列表项背景
|
|
|
|
|
* @param 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()) {
|
|
|
|
@ -116,6 +154,10 @@ public class NotesListItem extends LinearLayout {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前项绑定的数据
|
|
|
|
|
* @return NoteItemData对象
|
|
|
|
|
*/
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
return mItemData;
|
|
|
|
|
}
|
|
|
|
|