|
|
/*
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
* You may obtain a copy of the License at
|
|
|
*
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui; // 定义包名
|
|
|
|
|
|
import android.content.Context; // 导入Context类,用于获取上下文
|
|
|
import android.text.format.DateUtils; // 导入DateUtils类,用于日期格式化
|
|
|
import android.view.View; // 导入View类,用于视图操作
|
|
|
import android.widget.CheckBox; // 导入CheckBox类,用于复选框
|
|
|
import android.widget.ImageView; // 导入ImageView类,用于图像显示
|
|
|
import android.widget.LinearLayout; // 导入LinearLayout类,用于线性布局
|
|
|
import android.widget.TextView; // 导入TextView类,用于文本显示
|
|
|
|
|
|
import net.micode.notes.R; // 导入R类,用于资源引用
|
|
|
import net.micode.notes.data.Notes; // 导入Notes类,用于笔记数据操作
|
|
|
import net.micode.notes.tool.DataUtils; // 导入DataUtils类,用于数据处理
|
|
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources; // 导入NoteItemBgResources类,用于背景资源解析
|
|
|
|
|
|
/*
|
|
|
* 该类表示一个笔记列表项,继承自LinearLayout,并包含了显示笔记各种信息的组件。
|
|
|
* 它用于在UI中展示一个笔记或文件夹的条目。
|
|
|
*/
|
|
|
|
|
|
public class NotesListItem extends LinearLayout { // 定义NotesListItem类,继承自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); // 初始化复选框
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 绑定数据到视图,根据数据设置视图状态。
|
|
|
*
|
|
|
* @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); // 设置背景
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 根据笔记数据设置列表项的背景资源。
|
|
|
*/
|
|
|
private void setBackground(NoteItemData data) { // 设置背景方法
|
|
|
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 绑定的NoteItemData对象
|
|
|
*/
|
|
|
public NoteItemData getItemData() { // 获取笔记数据方法
|
|
|
return mItemData; // 返回笔记数据
|
|
|
}
|
|
|
}
|