|
|
/*
|
|
|
* 版权所有 (c) 2010-2011,The MiCode 开源社区 (www.micode.net)
|
|
|
*
|
|
|
* 本软件根据 Apache 许可证 2.0 版("许可证")发布;
|
|
|
* 除非符合许可证,否则不得使用此文件。
|
|
|
* 您可以在以下网址获取许可证副本:
|
|
|
*
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* 除非法律要求或书面同意,软件
|
|
|
* 根据许可证分发的内容按"原样"提供,
|
|
|
* 不附带任何明示或暗示的保证或条件。
|
|
|
* 请参阅许可证,了解有关权限和限制的具体语言。
|
|
|
*/
|
|
|
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
* 笔记列表项视图组件(继承自LinearLayout)
|
|
|
* 功能:展示单个笔记/文件夹/通话记录项的UI界面,支持不同类型数据的差异化展示
|
|
|
* 包含元素:
|
|
|
* - 提醒图标(mAlert)
|
|
|
* - 标题(mTitle)
|
|
|
* - 时间(mTime)
|
|
|
* - 通话联系人(mCallName,仅通话记录项显示)
|
|
|
* - 多选框(mCheckBox,仅笔记项在多选模式下显示)
|
|
|
*/
|
|
|
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);
|
|
|
// 加载列表项布局(R.layout.note_item)并添加到当前视图
|
|
|
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 数据对象(NoteItemData)
|
|
|
* @param choiceMode 是否为多选模式(控制多选框显示)
|
|
|
* @param checked 多选框选中状态(仅在choiceMode为true时有效)
|
|
|
*/
|
|
|
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.style.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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 设置最后修改时间(相对时间格式,如"5分钟前")
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
|
// 设置背景样式(根据笔记类型和排列位置)
|
|
|
setBackground(data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置列表项背景样式
|
|
|
* @param data 数据对象
|
|
|
*/
|
|
|
private void setBackground(NoteItemData data) {
|
|
|
int bgColorId = data.getBgColorId(); // 获取背景颜色ID
|
|
|
|
|
|
if (data.getType() == Notes.TYPE_NOTE) {
|
|
|
// 笔记类型,根据排列位置设置不同背景
|
|
|
if (data.isSingle() || data.isOneFollowingFolder()) {
|
|
|
// 单独项或后续仅有一个文件夹(单背景)
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(bgColorId));
|
|
|
} else if (data.isLast()) {
|
|
|
// 最后一项(底部圆角背景)
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(bgColorId));
|
|
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
|
|
// 第一项或后续有多个文件夹(顶部圆角背景)
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(bgColorId));
|
|
|
} else {
|
|
|
// 中间项(普通背景)
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(bgColorId));
|
|
|
}
|
|
|
} else {
|
|
|
// 文件夹类型,使用统一背景
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取绑定的数据对象
|
|
|
* @return NoteItemData 数据对象
|
|
|
*/
|
|
|
public NoteItemData getItemData() {
|
|
|
return mItemData;
|
|
|
}
|
|
|
} |