feat: 添加后台定时自动扫描和相册最近扫描时间显示功能
## 新增功能 ### 1. 后台定时自动扫描 - 添加 ScanTaskManager 工具类,使用线程池管理扫描任务 - 添加 CacheScanReceiver 广播接收器处理定时扫描 - 在设置页面添加自动扫描间隔配置(禁用、1小时、6小时、12小时、24小时) - 使用 AlarmManager 定时触发扫描任务 - 扫描完成后自动更新相册的 lastScanTime ### 2. 相册最近扫描时间显示 - 在 Album 模型中添加 lastScanTime 字段 - 在相册卡片上显示格式化的扫描时间(刚刚、X分钟前、X小时前、X天前、具体日期) - 在相册管理页面、相册编辑页面和壁纸服务中更新扫描时间 ### 3. 性能优化 - 使用 ScanTaskManager 替代直接创建 Thread - 避免在 onBindViewHolder 中创建大量线程 - 使用固定大小的线程池(最多3个并发任务) - 在 Activity/Fragment 销毁时自动取消所有扫描任务 - 优先使用缓存,减少不必要的扫描 ## 技术实现 ### 核心类 - ScanTaskManager: 单例模式的扫描任务管理器,使用 ExecutorService 管理线程池 - CacheScanReceiver: 处理定时扫描任务的广播接收器 - AlarmScheduler: 新增 scheduleCacheScan() 和 cancelCacheScan() 方法 - MediaScanner: 新增 clearCache()、clearAllCache()、rescanFolder() 方法 - JsonHelper: 新增 clearIndex() 和 clearAllIndexes() 方法 ### UI 更新 - fragment_settings.xml: 添加自动扫描配置卡片 - item_album_card.xml: 添加最近扫描时间显示 - SettingsFragment: 添加自动扫描配置逻辑 - AlbumManagementFragment: 使用 ScanTaskManager 替代 Thread - AlbumEditorActivity: 使用 ScanTaskManager 替代 Thread ### 数据模型 - Album: 添加 lastScanTime 字段 - AppConfig: 添加 autoScanIntervalHours 字段 - WallpaperPreferences: 添加自动扫描间隔的持久化逻辑 ## 文档更新 - 更新 CLAUDE.md,添加后台定时自动扫描和性能优化的说明 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86c46f3f04
commit
e77da929bc
16 files changed
+1134
-52
No files matched your search
@@ -354,6 +354,126 @@
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<!-- 自动扫描设置卡片 -->
|
||||
<TextView
|
||||
android:id="@+id/tvAutoScanLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_lg"
|
||||
android:text="自动扫描"
|
||||
android:textSize="@dimen/text_size_xxl"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
app:layout_constraintTop_toBottomOf="@id/cardFixedWallpaper"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cardAutoScan"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_sm"
|
||||
android:layout_marginBottom="@dimen/spacing_lg"
|
||||
app:cardElevation="@dimen/card_elevation"
|
||||
app:cardCornerRadius="@dimen/corner_radius_md"
|
||||
app:cardBackgroundColor="@color/bg_card"
|
||||
app:strokeColor="@color/glass_border"
|
||||
app:strokeWidth="@dimen/glass_border_width"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAutoScanLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/card_padding">
|
||||
|
||||
<!-- 自动扫描间隔选择 -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="自动扫描间隔"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_xs"
|
||||
android:text="定期清除缓存并重新扫描相册文件夹,确保显示最新内容"
|
||||
android:textSize="@dimen/text_size_sm"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:lineSpacingExtra="4dp" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/radioGroupAutoScan"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_md"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioAutoScanDisabled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="禁用(手动刷新)"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioAutoScan1Hour"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="每 1 小时"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioAutoScan6Hours"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="每 6 小时"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioAutoScan12Hours"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="每 12 小时"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioAutoScan24Hours"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="每 24 小时(推荐)"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_md"
|
||||
android:text="注意:自动扫描会在后台定时运行,可能会消耗少量电量。建议选择较长的间隔时间。"
|
||||
android:textSize="@dimen/text_size_sm"
|
||||
android:textColor="@color/text_hint"
|
||||
android:lineSpacingExtra="4dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -129,6 +129,18 @@
|
||||
android:drawablePadding="4dp"
|
||||
android:drawableTint="@color/text_hint_modern" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLastScanTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="未扫描"
|
||||
android:textSize="@dimen/text_size_xs"
|
||||
android:textColor="@color/text_hint_modern"
|
||||
android:layout_marginStart="@dimen/spacing_md"
|
||||
android:drawableStart="@drawable/ic_refresh"
|
||||
android:drawablePadding="4dp"
|
||||
android:drawableTint="@color/text_hint_modern" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
|
||||
Reference in new issue
Block a user