From 91fbf00e1734d53d3ed6b010c255ae5ffafb63b3 Mon Sep 17 00:00:00 2001 From: MRD <1259303886@qq.com> Date: Fri, 13 Jun 2025 17:36:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NotesListItem.java | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java index 1221e80..d3d5f9c 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java @@ -1,17 +1,14 @@ /* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * 版权声明:2010-2011年,MiCode开源社区(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 + * 本代码基于Apache许可证2.0版本发布("许可证"); + * 您可以在遵守许可证的前提下使用本文件; + * 您可以从以下地址获取许可证副本: * * 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; @@ -29,15 +26,23 @@ import net.micode.notes.data.Notes; import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.ResourceParser.NoteItemBgResources; - +/** + * 便签列表项视图类 + * 继承自LinearLayout,负责渲染单个便签或文件夹项的UI界面 + * 根据便签类型和状态显示不同的布局和样式 + */ public class NotesListItem extends LinearLayout { - private ImageView mAlert; - private TextView mTitle; - private TextView mTime; - private TextView mCallName; - private NoteItemData mItemData; - private CheckBox mCheckBox; + 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); @@ -48,7 +53,12 @@ public class NotesListItem extends LinearLayout { mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); } + /** + * 绑定数据到视图 + * 根据便签类型和状态设置不同的UI显示 + */ 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); @@ -57,7 +67,10 @@ public class NotesListItem extends LinearLayout { } mItemData = data; + + // 根据便签类型和父文件夹设置不同的UI显示 if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { + // 通话记录文件夹 mCallName.setVisibility(View.GONE); mAlert.setVisibility(View.VISIBLE); mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); @@ -65,6 +78,7 @@ public class NotesListItem extends LinearLayout { + 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); @@ -80,11 +94,13 @@ public class NotesListItem extends LinearLayout { 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); @@ -94,14 +110,22 @@ public class NotesListItem extends LinearLayout { } } } + + // 设置便签修改时间,使用相对时间格式(如"2小时前") mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); + // 设置便签背景 setBackground(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()) { @@ -112,11 +136,16 @@ public class NotesListItem extends LinearLayout { setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id)); } } else { + // 文件夹使用统一的背景样式 setBackgroundResource(NoteItemBgResources.getFolderBgRes()); } } + /** + * 获取便签数据 + * @return 便签数据对象 + */ public NoteItemData getItemData() { return mItemData; } -} +} \ No newline at end of file