|
|
|
@ -29,18 +29,33 @@ import net.micode.notes.data.Notes;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造方法
|
|
|
|
|
* @param context 上下文环境
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
@ -48,43 +63,60 @@ 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);
|
|
|
|
|
mCheckBox.setVisibility(View.VISIBLE); // 显示复选框(仅笔记项在多选模式下可见)
|
|
|
|
|
mCheckBox.setChecked(checked); // 设置选中状态
|
|
|
|
|
} else {
|
|
|
|
|
mCheckBox.setVisibility(View.GONE);
|
|
|
|
|
mCheckBox.setVisibility(View.GONE); // 隐藏复选框
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mItemData = data;
|
|
|
|
|
mItemData = data; // 保存数据项
|
|
|
|
|
|
|
|
|
|
// 根据数据类型和上下文设置不同的显示逻辑
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mCallName.setVisibility(View.GONE);
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
|
|
|
// 通话记录文件夹特殊处理
|
|
|
|
|
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);
|
|
|
|
|
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()));
|
|
|
|
|
// 通话记录文件夹内的笔记项
|
|
|
|
|
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.setImageResource(R.drawable.clock); // 闹钟图标
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mCallName.setVisibility(View.GONE);
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
|
|
|
// 普通笔记或文件夹
|
|
|
|
|
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);
|
|
|
|
|
data.getNotesCount()));
|
|
|
|
|
mAlert.setVisibility(View.GONE); // 文件夹不显示提醒图标
|
|
|
|
|
} else {
|
|
|
|
|
// 普通笔记项:显示摘要和提醒图标
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
|
|
|
if (data.hasAlert()) {
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock);
|
|
|
|
@ -94,29 +126,45 @@ public class NotesListItem extends LinearLayout {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 显示相对时间(如“5分钟前”)
|
|
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
|
|
|
|
|
// 设置列表项背景(根据笔记类型和样式)
|
|
|
|
|
setBackground(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置列表项背景资源
|
|
|
|
|
* @param data 数据项
|
|
|
|
|
*/
|
|
|
|
|
private void setBackground(NoteItemData data) {
|
|
|
|
|
int id = data.getBgColorId();
|
|
|
|
|
int id = data.getBgColorId(); // 获取背景颜色ID
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取绑定的数据项
|
|
|
|
|
* @return 笔记/文件夹数据项
|
|
|
|
|
*/
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
return mItemData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|