|
|
/*
|
|
|
* 版权信息:由MiCode开源社区(www.micode.net)贡献
|
|
|
* Apache 2.0许可证协议
|
|
|
* 本文件为NotesListItem类实现,用于Android平台的笔记列表项视图组件
|
|
|
*/
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.text.format.DateUtils;
|
|
|
import android.view.View;
|
|
|
import android.widget.CheckBox;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
import net.micode.notes.data.Notes;
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
|
|
|
|
|
|
/**
|
|
|
* 笔记列表项视图组件
|
|
|
* 用于在笔记列表中显示单个笔记或文件夹的UI元素
|
|
|
*/
|
|
|
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);
|
|
|
// 加载布局文件并附加到当前LinearLayout
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 绑定数据到视图
|
|
|
* @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);
|
|
|
} 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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据数据设置背景样式
|
|
|
* @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()) {
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
|
|
} else {
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
|
|
|
}
|
|
|
} else {
|
|
|
// 文件夹项的背景设置
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取当前绑定的笔记数据
|
|
|
* @return NoteItemData对象
|
|
|
*/
|
|
|
public NoteItemData getItemData() {
|
|
|
return mItemData;
|
|
|
}
|
|
|
} |