|
|
@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NotesListItem extends 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;
|
|
|
|
|
|
|
|
// 根据数据项ID调整视图显示
|
|
|
|
|
|
|
|
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 笔记项的数据对象,包含笔记项的类型、颜色ID等信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void setBackground(NoteItemData data) {
|
|
|
|
|
|
|
|
// 获取笔记项的背景颜色ID
|
|
|
|
|
|
|
|
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 返回一个NoteItemData对象,该对象包含了笔记项的详细数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
|
|
|
return mItemData;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|