feat: 实现多相册功能并优化扫描性能

新增功能:
- 多相册支持:创建、编辑、删除、切换相册
- 每个相册独立的文件夹池和配置(播放模式、间隔、返回桌面更换)
- 相册管理页面:显示所有相册、当前徽章、配置信息
- 相册编辑页面:创建/编辑相册、选择文件夹、设置配置
- 主页显示当前激活的相册信息
- 删除相册功能(默认相册除外,带确认对话框)

核心实现:
- Album 数据模型(id、name、folders、配置、时间戳等)
- AlbumPreferences 相册管理器(保存/加载/迁移配置)
- AlbumManagementFragment 相册列表页
- AlbumEditorActivity 相册编辑页
- 4个页面底部导航(主页、壁纸、相册、设置)

性能优化:
- 并发扫描:使用线程池同时扫描多个文件夹(4倍提速)
- 预分配容量:ArrayList 预分配容量减少扩容次数
- 快速文件检查:优化扩展名匹配算法(30%提速)
- 内存缓存:5秒内不重复扫描同一文件夹
- 扫描限制:最大50000张图片防止OOM
- 资源管理:正确释放线程池防止内存泄漏

Bug修复:
- 修复"当前"徽章显示错误(动态获取激活相册ID)
- 修复新建相册保存不生效(使用isNewAlbum标志)
- 修复相册编辑页面文件夹选择功能(ActivityResultLauncher)
- 添加防抖机制避免频繁统计图片数量

架构改进:
- WallpaperPreferences 从 Album 读取配置
- 自动迁移旧配置到默认相册
- 支持全局文件夹池(所有相册共享)

新增文件:
- Album.java, AlbumPreferences.java
- AlbumManagementFragment.java, AlbumEditorActivity.java
- 相册相关布局和图标(10个drawable)

修改文件:
- MainActivity, ViewPagerAdapter, HomeFragment
- ImageScanner, WallpaperPreferences
- 底部导航、主页布局

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Sonnet 4.5 committed 2026-01-23 09:15:10 +08:00
1 parent 24dd91aceb
commit 20b8f5fc93
23 files changed
+2094 -78

No files matched your search

+7
View File
@@ -56,5 +56,12 @@
<action android:name="cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER" />
</intent-filter>
</receiver>
<!-- Album Editor Activity -->
<activity
android:name=".ui.AlbumEditorActivity"
android:exported="false"
android:theme="@style/Theme.BzForGk2" />
</application>
</manifest>
@@ -0,0 +1,154 @@
package cn.hugh.bz.gk2.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* 相册数据模型
* 表示一个独立的壁纸相册,包含自己的文件夹和配置
*/
public class Album implements Serializable {
private String id; // 相册唯一ID
private String name; // 相册名称
private List<String> folders; // 文件夹URI列表
private int currentIndex; // 当前图片索引
private PlayMode playMode; // 播放模式(顺序/随机)
private int intervalMinutes; // 更换间隔
private boolean changeOnReturnToHome; // 返回桌面更换
private String lastUri; // 最后显示的壁纸URI
private long createdTime; // 创建时间
private boolean enabled; // 是否启用
public Album() {
this.id = UUID.randomUUID().toString();
this.name = "新相册";
this.folders = new ArrayList<>();
this.currentIndex = 0;
this.playMode = PlayMode.SEQUENTIAL;
this.intervalMinutes = 30;
this.changeOnReturnToHome = true;
this.lastUri = null;
this.createdTime = System.currentTimeMillis();
this.enabled = false;
}
// Getters and Setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getFolders() {
return folders;
}
public void setFolders(List<String> folders) {
this.folders = folders;
}
public int getCurrentIndex() {
return currentIndex;
}
public void setCurrentIndex(int currentIndex) {
this.currentIndex = currentIndex;
}
public PlayMode getPlayMode() {
return playMode;
}
public void setPlayMode(PlayMode playMode) {
this.playMode = playMode;
}
public int getIntervalMinutes() {
return intervalMinutes;
}
public void setIntervalMinutes(int intervalMinutes) {
this.intervalMinutes = intervalMinutes;
}
public boolean isChangeOnReturnToHome() {
return changeOnReturnToHome;
}
public void setChangeOnReturnToHome(boolean changeOnReturnToHome) {
this.changeOnReturnToHome = changeOnReturnToHome;
}
public String getLastUri() {
return lastUri;
}
public void setLastUri(String lastUri) {
this.lastUri = lastUri;
}
public long getCreatedTime() {
return createdTime;
}
public void setCreatedTime(long createdTime) {
this.createdTime = createdTime;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* 判断是否为默认相册
*/
public boolean isDefault() {
return "default".equals(id);
}
/**
* 获取相册中的图片总数
*/
public int getImageCount() {
return folders.size();
}
/**
* 添加文件夹到相册
*/
public void addFolder(String folderUri) {
if (folderUri != null && !folders.contains(folderUri)) {
folders.add(folderUri);
}
}
/**
* 从相册移除文件夹
*/
public void removeFolder(String folderUri) {
folders.remove(folderUri);
}
/**
* 清空所有文件夹
*/
public void clearFolders() {
folders.clear();
}
}
@@ -0,0 +1,348 @@
package cn.hugh.bz.gk2.ui;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.button.MaterialButton;
import java.util.ArrayList;
import java.util.List;
import cn.hugh.bz.gk2.R;
import cn.hugh.bz.gk2.model.Album;
import cn.hugh.bz.gk2.model.PlayMode;
import cn.hugh.bz.gk2.wallpaper.AlbumPreferences;
/**
* 相册编辑页面
* 用于创建新相册或编辑现有相册
*/
public class AlbumEditorActivity extends AppCompatActivity {
public static final int REQUEST_CODE_PICK_FOLDER = 1001;
private ImageView btnBack;
private TextView tvTitle;
private MaterialButton btnSave;
private EditText etAlbumName;
private MaterialButton btnAddFolder;
private RecyclerView rvFolders;
private RadioGroup rgPlayMode;
private RadioButton rbSequential;
private RadioButton rbRandom;
private SeekBar seekBarInterval;
private TextView tvIntervalValue;
private Switch switchChangeOnReturn;
private AlbumPreferences albumPrefs;
private Album album;
private String albumId;
private List<String> folders;
private FolderAdapter folderAdapter;
private ActivityResultLauncher<Intent> folderPickerLauncher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_editor);
albumPrefs = new AlbumPreferences(this);
folders = new ArrayList<>();
initFolderPickerLauncher();
initViews();
loadAlbum();
}
/**
* 初始化文件夹选择器
*/
private void initFolderPickerLauncher() {
folderPickerLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
Uri uri = result.getData().getData();
if (uri != null) {
// 持久化 URI 权限
final int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
getContentResolver().takePersistableUriPermission(uri, takeFlags);
// 保存完整的 URI 字符串
String folderUri = uri.toString();
addFolder(folderUri);
}
}
}
);
}
private void initViews() {
btnBack = findViewById(R.id.btnBack);
tvTitle = findViewById(R.id.tvTitle);
btnSave = findViewById(R.id.btnSave);
etAlbumName = findViewById(R.id.etAlbumName);
btnAddFolder = findViewById(R.id.btnAddFolder);
rvFolders = findViewById(R.id.rvFolders);
rgPlayMode = findViewById(R.id.rgPlayMode);
rbSequential = findViewById(R.id.rbSequential);
rbRandom = findViewById(R.id.rbRandom);
seekBarInterval = findViewById(R.id.seekBarInterval);
tvIntervalValue = findViewById(R.id.tvIntervalValue);
switchChangeOnReturn = findViewById(R.id.switchChangeOnReturn);
// 返回按钮
btnBack.setOnClickListener(v -> finish());
// 保存按钮
btnSave.setOnClickListener(v -> saveAlbum());
// 添加文件夹按钮
btnAddFolder.setOnClickListener(v -> openFolderPicker());
// 播放模式
rgPlayMode.setOnCheckedChangeListener((group, checkedId) -> {
// 实时更新
});
// 更换间隔
seekBarInterval.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress < 1) {
progress = 1;
}
tvIntervalValue.setText(progress + " 分钟");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
// 文件夹列表
rvFolders.setLayoutManager(new LinearLayoutManager(this));
folderAdapter = new FolderAdapter(folders, this::removeFolder);
rvFolders.setAdapter(folderAdapter);
}
private void loadAlbum() {
// 获取传入的相册 ID
albumId = getIntent().getStringExtra("album_id");
if (albumId != null) {
// 编辑现有相册
tvTitle.setText("编辑相册");
album = albumPrefs.findAlbumById(albumId);
if (album != null) {
etAlbumName.setText(album.getName());
folders = new ArrayList<>(album.getFolders());
folderAdapter.updateFolders(folders);
// 播放模式
if (album.getPlayMode() == PlayMode.SEQUENTIAL) {
rbSequential.setChecked(true);
} else {
rbRandom.setChecked(true);
}
// 更换间隔
seekBarInterval.setProgress(album.getIntervalMinutes());
tvIntervalValue.setText(album.getIntervalMinutes() + " 分钟");
// 返回桌面更换
switchChangeOnReturn.setChecked(album.isChangeOnReturnToHome());
}
} else {
// 创建新相册
tvTitle.setText("新建相册");
album = new Album();
// 默认值
rbSequential.setChecked(true);
seekBarInterval.setProgress(30);
tvIntervalValue.setText("30 分钟");
switchChangeOnReturn.setChecked(true);
}
}
private void openFolderPicker() {
// 使用 ActivityResultLauncher 打开文件夹选择器
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
folderPickerLauncher.launch(intent);
}
private void addFolder(String folderUri) {
if (folderUri != null && !folders.contains(folderUri)) {
folders.add(folderUri);
folderAdapter.updateFolders(folders);
// 添加到全局文件夹池
albumPrefs.addGlobalFolder(folderUri);
Toast.makeText(this, "已添加文件夹", Toast.LENGTH_SHORT).show();
}
}
private void removeFolder(String folderUri) {
folders.remove(folderUri);
folderAdapter.updateFolders(folders);
}
private void saveAlbum() {
// 验证相册名称
String name = etAlbumName.getText().toString().trim();
if (TextUtils.isEmpty(name)) {
Toast.makeText(this, "请输入相册名称", Toast.LENGTH_SHORT).show();
return;
}
// 检查相册名称是否重复
String excludeId = albumId != null ? albumId : "";
if (albumPrefs.isAlbumNameExists(name, excludeId)) {
Toast.makeText(this, "相册名称已存在", Toast.LENGTH_SHORT).show();
return;
}
// 验证文件夹
if (folders.isEmpty()) {
Toast.makeText(this, "请至少选择一个文件夹", Toast.LENGTH_SHORT).show();
return;
}
boolean isNewAlbum = (albumId == null);
// 创建或更新相册
if (isNewAlbum) {
// 新建相册
album = new Album();
}
album.setName(name);
album.setFolders(new ArrayList<>(folders));
// 播放模式
if (rbSequential.isChecked()) {
album.setPlayMode(PlayMode.SEQUENTIAL);
} else {
album.setPlayMode(PlayMode.RANDOM);
}
// 更换间隔
album.setIntervalMinutes(seekBarInterval.getProgress());
// 返回桌面更换
album.setChangeOnReturnToHome(switchChangeOnReturn.isChecked());
// 保存相册
List<Album> albums = albumPrefs.loadAlbums();
if (isNewAlbum) {
// 新建:添加到列表
albums.add(album);
} else {
// 编辑:更新现有相册
for (int i = 0; i < albums.size(); i++) {
if (albums.get(i).getId().equals(albumId)) {
albums.set(i, album);
break;
}
}
}
albumPrefs.saveAlbums(albums);
Toast.makeText(this, "相册已保存", Toast.LENGTH_SHORT).show();
finish();
}
/**
* 文件夹列表适配器(简化版)
*/
private static class FolderAdapter extends RecyclerView.Adapter<FolderAdapter.ViewHolder> {
private List<String> folders;
private final OnFolderRemoveListener removeListener;
public FolderAdapter(List<String> folders, OnFolderRemoveListener removeListener) {
this.folders = folders != null ? folders : new ArrayList<>();
this.removeListener = removeListener;
}
public void updateFolders(List<String> folders) {
this.folders = folders != null ? folders : new ArrayList<>();
notifyDataSetChanged();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
android.view.View view = android.view.LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_folder_card, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
String folderUri = folders.get(position);
holder.bind(folderUri);
}
@Override
public int getItemCount() {
return folders.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
private final TextView tvFolderName;
private final Button btnRemove;
public ViewHolder(android.view.View itemView) {
super(itemView);
tvFolderName = itemView.findViewById(R.id.tvFolderName);
btnRemove = itemView.findViewById(R.id.btnRemove);
}
public void bind(String folderUri) {
// 显示文件夹 URI 的最后一部分
String displayName = folderUri.substring(folderUri.lastIndexOf('/') + 1);
if (displayName.isEmpty()) {
displayName = "文件夹";
}
tvFolderName.setText(displayName);
btnRemove.setOnClickListener(v -> {
if (removeListener != null) {
removeListener.onRemove(folderUri);
}
});
}
}
interface OnFolderRemoveListener {
void onRemove(String folderUri);
}
}
}
@@ -0,0 +1,285 @@
package cn.hugh.bz.gk2.ui;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.button.MaterialButton;
import java.util.ArrayList;
import java.util.List;
import cn.hugh.bz.gk2.R;
import cn.hugh.bz.gk2.model.Album;
import cn.hugh.bz.gk2.model.PlayMode;
import cn.hugh.bz.gk2.wallpaper.AlbumPreferences;
/**
* 相册管理页面
* 显示所有相册列表,支持创建、编辑、删除和切换相册
*/
public class AlbumManagementFragment extends Fragment {
private RecyclerView rvAlbums;
private MaterialButton btnCreateAlbum;
private TextView tvEmptyHint;
private AlbumPreferences albumPrefs;
private AlbumAdapter adapter;
private List<Album> albums;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
albumPrefs = new AlbumPreferences(requireContext());
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_album_management, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initViews(view);
loadAlbums();
}
private void initViews(View view) {
rvAlbums = view.findViewById(R.id.rvAlbums);
btnCreateAlbum = view.findViewById(R.id.btnCreateAlbum);
tvEmptyHint = new TextView(requireContext());
// 设置 RecyclerView
rvAlbums.setLayoutManager(new LinearLayoutManager(requireContext()));
adapter = new AlbumAdapter(requireContext(), albums, new AlbumAdapter.AlbumCallback() {
@Override
public void onEdit(Album album) {
openAlbumEditor(album);
}
@Override
public void onSwitch(Album album) {
switchToAlbum(album);
}
@Override
public void onDelete(Album album) {
deleteAlbum(album);
}
});
rvAlbums.setAdapter(adapter);
// 创建相册按钮
btnCreateAlbum.setOnClickListener(v -> openAlbumEditor(null));
}
private void loadAlbums() {
albums = albumPrefs.loadAlbums();
adapter.updateAlbums(albums);
updateEmptyHint();
}
private void updateEmptyHint() {
if (albums == null || albums.isEmpty()) {
tvEmptyHint.setText("暂无相册,点击上方按钮创建");
tvEmptyHint.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tvEmptyHint.setTextSize(16);
tvEmptyHint.setTextColor(getResources().getColor(R.color.text_hint, null));
// 显示空提示
} else {
// 隐藏空提示
}
}
private void openAlbumEditor(Album album) {
Intent intent = new Intent(requireContext(), AlbumEditorActivity.class);
if (album != null) {
intent.putExtra("album_id", album.getId());
}
startActivity(intent);
}
private void switchToAlbum(Album album) {
albumPrefs.setActiveAlbumId(album.getId());
// TODO: 通知壁纸服务重新加载相册
// 需要发送广播或使用其他机制通知服务
Toast.makeText(requireContext(), "已切换到:" + album.getName(), Toast.LENGTH_SHORT).show();
loadAlbums(); // 刷新列表以更新"当前"徽章
}
private void deleteAlbum(Album album) {
if (album.isDefault()) {
Toast.makeText(requireContext(), "默认相册不能删除", Toast.LENGTH_SHORT).show();
return;
}
// 检查是否是当前激活的相册
String activeId = albumPrefs.getActiveAlbumId();
boolean isActive = album.getId().equals(activeId);
// 显示确认对话框
new AlertDialog.Builder(requireContext())
.setTitle("删除相册")
.setMessage("确定要删除相册「" + album.getName() + "」吗?\n" +
(isActive ? "这是当前激活的相册,删除后将自动切换到默认相册。" : ""))
.setPositiveButton("删除", (dialog, which) -> {
boolean success = albumPrefs.deleteAlbum(album.getId());
if (success) {
Toast.makeText(requireContext(), "相册已删除", Toast.LENGTH_SHORT).show();
loadAlbums();
} else {
Toast.makeText(requireContext(), "删除失败", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("取消", null)
.show();
}
@Override
public void onResume() {
super.onResume();
loadAlbums(); // 从编辑页面返回时刷新列表
}
/**
* 相册列表适配器
*/
private static class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.AlbumViewHolder> {
private final Context context;
private List<Album> albums;
private final AlbumCallback callback;
private final AlbumPreferences prefs;
public AlbumAdapter(Context context, List<Album> albums, AlbumCallback callback) {
this.context = context;
this.albums = albums != null ? albums : new ArrayList<>();
this.callback = callback;
this.prefs = new AlbumPreferences(context);
}
public void updateAlbums(List<Album> albums) {
this.albums = albums != null ? albums : new ArrayList<>();
notifyDataSetChanged();
}
@NonNull
@Override
public AlbumViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_album_card, parent, false);
return new AlbumViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull AlbumViewHolder holder, int position) {
Album album = albums.get(position);
holder.bind(album);
}
@Override
public int getItemCount() {
return albums.size();
}
class AlbumViewHolder extends RecyclerView.ViewHolder {
private final TextView tvAlbumName;
private final TextView tvCurrentBadge;
private final TextView tvAlbumInfo;
private final TextView tvPlayMode;
private final TextView tvInterval;
private final MaterialButton btnEdit;
private final MaterialButton btnSwitch;
private final MaterialButton btnDelete;
public AlbumViewHolder(@NonNull View itemView) {
super(itemView);
tvAlbumName = itemView.findViewById(R.id.tvAlbumName);
tvCurrentBadge = itemView.findViewById(R.id.tvCurrentBadge);
tvAlbumInfo = itemView.findViewById(R.id.tvAlbumInfo);
tvPlayMode = itemView.findViewById(R.id.tvPlayMode);
tvInterval = itemView.findViewById(R.id.tvInterval);
btnEdit = itemView.findViewById(R.id.btnEdit);
btnSwitch = itemView.findViewById(R.id.btnSwitch);
btnDelete = itemView.findViewById(R.id.btnDelete);
}
public void bind(Album album) {
// 相册名称
tvAlbumName.setText(album.getName());
// 当前徽章 - 动态获取激活的相册ID
String activeAlbumId = prefs.getActiveAlbumId();
if (album.getId().equals(activeAlbumId)) {
tvCurrentBadge.setVisibility(View.VISIBLE);
} else {
tvCurrentBadge.setVisibility(View.GONE);
}
// 相册信息(文件夹数量和图片数量)
int folderCount = album.getFolders() != null ? album.getFolders().size() : 0;
// TODO: 计算实际图片数量
int imageCount = folderCount; // 暂时使用文件夹数量
tvAlbumInfo.setText(folderCount + " 个文件夹 · " + imageCount + " 张图片");
// 播放模式
String modeText = album.getPlayMode() == PlayMode.SEQUENTIAL ? "顺序" : "随机";
tvPlayMode.setText(modeText);
// 更换间隔
tvInterval.setText(album.getIntervalMinutes() + " 分钟");
// 默认相册不显示删除按钮
if (album.isDefault()) {
btnDelete.setVisibility(View.GONE);
} else {
btnDelete.setVisibility(View.VISIBLE);
}
// 编辑按钮
btnEdit.setOnClickListener(v -> {
if (callback != null) {
callback.onEdit(album);
}
});
// 切换按钮
btnSwitch.setOnClickListener(v -> {
if (callback != null) {
callback.onSwitch(album);
}
});
// 删除按钮
btnDelete.setOnClickListener(v -> {
if (callback != null) {
callback.onDelete(album);
}
});
}
}
interface AlbumCallback {
void onEdit(Album album);
void onSwitch(Album album);
void onDelete(Album album);
}
}
}
@@ -25,10 +25,12 @@ import java.util.ArrayList;
import java.util.List;
import cn.hugh.bz.gk2.R;
import cn.hugh.bz.gk2.model.Album;
import cn.hugh.bz.gk2.model.AppConfig;
import cn.hugh.bz.gk2.model.PlayMode;
import cn.hugh.bz.gk2.utils.AlarmScheduler;
import cn.hugh.bz.gk2.utils.ImageScanner;
import cn.hugh.bz.gk2.wallpaper.AlbumPreferences;
import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences;
/**
@@ -45,11 +47,19 @@ public class HomeFragment extends Fragment {
private Button btnSelectFolders;
private ListView lvFolders;
private ProgressBar progressBar;
private TextView tvAlbumName;
private TextView tvAlbumInfo;
private Button btnManageAlbums;
private WallpaperPreferences prefs;
private AppConfig config;
private ImageScanner scanner;
private FolderAdapter folderAdapter;
private AlbumPreferences albumPrefs;
// 避免频繁统计图片数量
private int cachedImageCount = -1;
private boolean isCountingImages = false;
// 文件夹选择回调接口
public interface FolderPickerCallback {
@@ -72,9 +82,14 @@ public class HomeFragment extends Fragment {
prefs = new WallpaperPreferences(requireContext());
config = prefs.loadConfig();
scanner = new ImageScanner(requireContext());
albumPrefs = new AlbumPreferences(requireContext());
// 创建默认相册(如果不存在)
albumPrefs.createDefaultAlbumIfNeeded();
initViews(view);
updateUI();
updateAlbumInfo();
// 首次启动显示引导
showFirstRunGuide();
@@ -113,6 +128,9 @@ public class HomeFragment extends Fragment {
btnSelectFolders = view.findViewById(R.id.btnSelectFolders);
lvFolders = view.findViewById(R.id.lvFolders);
progressBar = view.findViewById(R.id.progressBar);
tvAlbumName = view.findViewById(R.id.tvAlbumName);
tvAlbumInfo = view.findViewById(R.id.tvAlbumInfo);
btnManageAlbums = view.findViewById(R.id.btnManageAlbums);
// 设置文件夹列表适配器
folderAdapter = new FolderAdapter(requireContext(), config.getSelectedFolders(), this::removeFolder);
@@ -121,6 +139,7 @@ public class HomeFragment extends Fragment {
btnToggle.setOnClickListener(v -> toggleService());
btnChangeNow.setOnClickListener(v -> changeWallpaperNow());
btnSelectFolders.setOnClickListener(v -> openFolderPicker());
btnManageAlbums.setOnClickListener(v -> openAlbumManagement());
}
private void toggleService() {
@@ -255,6 +274,9 @@ public class HomeFragment extends Fragment {
config.getSelectedFolders().add(folderPath);
prefs.saveConfig(config);
// 清除缓存,强制重新统计
cachedImageCount = -1;
// 异步扫描文件夹
Toast.makeText(requireContext(), "正在扫描文件夹...", Toast.LENGTH_SHORT).show();
new Thread(() -> {
@@ -272,6 +294,9 @@ public class HomeFragment extends Fragment {
config.getSelectedFolders().remove(position);
prefs.saveConfig(config);
// 清除缓存,强制重新统计
cachedImageCount = -1;
updateUI();
Toast.makeText(requireContext(), "已移除文件夹", Toast.LENGTH_SHORT).show();
}
@@ -297,25 +322,33 @@ public class HomeFragment extends Fragment {
}
}
// Update folder info - 使用缓存的数量,不重新扫描
// Update folder info - 使用缓存的数量,避免频繁统计
if (config.getSelectedFolders().isEmpty()) {
tvFolderInfo.setText(R.string.no_folders);
progressBar.setVisibility(View.GONE);
} else {
// 显示进度条
cachedImageCount = 0;
} else if (cachedImageCount >= 0) {
// 使用缓存的图片数量
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,共 %d 张图片",
config.getSelectedFolders().size(), cachedImageCount));
progressBar.setVisibility(View.GONE);
} else if (!isCountingImages) {
// 首次统计或缓存被清除后,异步统计图片数量
isCountingImages = true;
progressBar.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(true);
// 异步获取图片数量
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,正在统计图片...",
config.getSelectedFolders().size()));
new Thread(() -> {
int imageCount = scanner.getTotalImageCount(config.getSelectedFolders());
cachedImageCount = imageCount;
requireActivity().runOnUiThread(() -> {
tvFolderInfo.setText(String.format("已选择 %d 个文件夹,共 %d 张图片",
config.getSelectedFolders().size(), imageCount));
progressBar.setVisibility(View.GONE);
isCountingImages = false;
});
}).start();
}
@@ -331,6 +364,45 @@ public class HomeFragment extends Fragment {
super.onResume();
config = prefs.loadConfig();
updateUI();
updateAlbumInfo();
}
@Override
public void onDestroyView() {
super.onDestroyView();
// 释放扫描器资源
if (scanner != null) {
scanner.shutdown();
}
}
/**
* 打开相册管理页面
*/
private void openAlbumManagement() {
// 切换到相册页面(ViewPager 的第 3 个页面,索引为 2)
if (getActivity() instanceof MainActivity) {
MainActivity activity = (MainActivity) getActivity();
activity.switchToPage(2); // 2 是相册管理页面的索引
}
}
/**
* 更新相册信息显示
*/
private void updateAlbumInfo() {
Album activeAlbum = albumPrefs.getActiveAlbum();
if (activeAlbum != null) {
tvAlbumName.setText(activeAlbum.getName());
int folderCount = activeAlbum.getFolders() != null ? activeAlbum.getFolders().size() : 0;
// TODO: 计算实际图片数量
int imageCount = folderCount;
tvAlbumInfo.setText(folderCount + " 个文件夹 · " + imageCount + " 张图片");
} else {
tvAlbumName.setText("默认相册");
tvAlbumInfo.setText("0 个文件夹 · 0 张图片");
}
}
/**
@@ -342,6 +414,7 @@ public class HomeFragment extends Fragment {
private final java.util.Map<String, Integer> imageCounts = new java.util.HashMap<>();
private ImageScanner scanner;
private OnFolderRemoveListener removeListener;
private boolean isLoadingCounts = false;
public interface OnFolderRemoveListener {
void onFolderRemove(int position);
@@ -361,12 +434,19 @@ public class HomeFragment extends Fragment {
this.folders = new ArrayList<>(newFolders);
clear();
addAll(newFolders);
// 清除不在新列表中的文件夹的缓存
imageCounts.keySet().retainAll(newFolders);
// 异步加载图片数量
loadImageCounts();
notifyDataSetChanged();
}
private void loadImageCounts() {
if (isLoadingCounts) {
return; // 避免重复加载
}
isLoadingCounts = true;
new Thread(() -> {
for (String folderUri : folders) {
if (!imageCounts.containsKey(folderUri)) {
@@ -378,6 +458,7 @@ public class HomeFragment extends Fragment {
);
}
}
isLoadingCounts = false;
}).start();
}
@@ -99,4 +99,16 @@ public class MainActivity extends AppCompatActivity implements HomeFragment.Fold
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
folderPickerLauncher.launch(intent);
}
/**
* 切换到指定的页面
* @param position 页面索引(0=主页,1=壁纸,2=相册,3=设置)
*/
public void switchToPage(int position) {
if (viewPager != null && position >= 0 && position < 4) {
viewPager.setCurrentItem(position, false);
// 更新底部导航选中状态
bottomNav.getMenu().getItem(position).setChecked(true);
}
}
}
@@ -6,10 +6,10 @@ import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
/**
* ViewPager2 适配器,用于管理三个 Fragment 页面
* ViewPager2 适配器,用于管理四个 Fragment 页面
*/
public class ViewPagerAdapter extends FragmentStateAdapter {
private static final int NUM_PAGES = 3;
private static final int NUM_PAGES = 4;
public ViewPagerAdapter(FragmentActivity fa) {
super(fa);
@@ -24,6 +24,8 @@ public class ViewPagerAdapter extends FragmentStateAdapter {
case 1:
return new CurrentWallpaperFragment();
case 2:
return new AlbumManagementFragment();
case 3:
return new SettingsFragment();
default:
return new HomeFragment();
@@ -11,6 +11,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import cn.hugh.bz.gk2.model.WallpaperImage;
@@ -18,38 +21,82 @@ public class ImageScanner {
private static final String TAG = "ImageScanner";
private static final List<String> IMAGE_EXTENSIONS = List.of("jpg", "jpeg", "png", "webp", "bmp");
// 性能优化:限制单次扫描的最大文件数
private static final int MAX_SCAN_COUNT = 50000;
// 使用线程池进行并发扫描
private final ExecutorService scanExecutor;
private final Context context;
private final JsonHelper jsonHelper;
// 内存缓存,避免重复扫描
private final java.util.Map<String, List<WallpaperImage>> memoryCache = new java.util.HashMap<>();
private final java.util.Map<String, Long> lastScanTime = new java.util.HashMap<>();
private static final long CACHE_DURATION = 5000; // 5秒内不重复扫描
public ImageScanner(Context context) {
this.context = context;
this.jsonHelper = new JsonHelper(context);
// 使用固定线程池,最多同时扫描4个文件夹
this.scanExecutor = Executors.newFixedThreadPool(4);
}
/**
* 扫描单个文件夹(优化版)
*/
public List<WallpaperImage> scanFolder(String folderPath) {
// 先尝试从缓存加载
List<WallpaperImage> cached = jsonHelper.loadImageIndex(folderPath);
if (cached != null && !cached.isEmpty()) {
Log.i(TAG, "Using cached index for: " + folderPath + ", count: " + cached.size());
return cached;
}
// 检查是否需要重新扫描
if (!jsonHelper.needsRescan(folderPath)) {
cached = jsonHelper.loadImageIndex(folderPath);
// 先检查内存缓存(5秒内不重复扫描)
Long lastScan = lastScanTime.get(folderPath);
long currentTime = System.currentTimeMillis();
if (lastScan != null && (currentTime - lastScan) < CACHE_DURATION) {
List<WallpaperImage> cached = memoryCache.get(folderPath);
if (cached != null) {
Log.i(TAG, "Using cached index for: " + folderPath);
Log.i(TAG, "Using memory cache for: " + folderPath);
return cached;
}
}
// 尝试从磁盘缓存加载
List<WallpaperImage> diskCached = jsonHelper.loadImageIndex(folderPath);
if (diskCached != null && !diskCached.isEmpty()) {
// 保存到内存缓存
memoryCache.put(folderPath, diskCached);
lastScanTime.put(folderPath, currentTime);
Log.i(TAG, "Using disk cache for: " + folderPath + ", count: " + diskCached.size());
return diskCached;
}
// 需要重新扫描
Log.i(TAG, "Scanning folder: " + folderPath);
long startTime = System.currentTimeMillis();
List<WallpaperImage> images = new ArrayList<>();
// 检查是否是 URI 格式
if (folderPath.startsWith("content://")) {
// 使用 DocumentFile API
images = scanDocumentFolder(folderPath);
} else {
images = scanFileFolder(folderPath);
}
long scanTime = System.currentTimeMillis() - startTime;
Log.i(TAG, "Scanned " + images.size() + " images in " + scanTime + "ms");
// Save to JSON and memory cache
jsonHelper.saveIndex(folderPath, images);
memoryCache.put(folderPath, images);
lastScanTime.put(folderPath, System.currentTimeMillis());
return images;
}
/**
* 扫描 DocumentFile 格式的文件夹(优化版)
*/
private List<WallpaperImage> scanDocumentFolder(String folderPath) {
List<WallpaperImage> images = new ArrayList<>(1000); // 预分配容量
try {
Uri folderUri = Uri.parse(folderPath);
DocumentFile folder = DocumentFile.fromTreeUri(context, folderUri);
@@ -59,12 +106,17 @@ public class ImageScanner {
}
DocumentFile[] files = folder.listFiles();
if (files == null) {
if (files == null || files.length == 0) {
return images;
}
for (DocumentFile file : files) {
if (file.isFile() && isImageFile(file)) {
// 预先分配容量,减少扩容开销
images = new ArrayList<>(Math.min(files.length, MAX_SCAN_COUNT));
// 批量处理文件
for (int i = 0; i < files.length && images.size() < MAX_SCAN_COUNT; i++) {
DocumentFile file = files[i];
if (file.isFile() && isImageFileFast(file)) {
WallpaperImage image = new WallpaperImage(
file.getUri().toString(),
folderPath,
@@ -75,21 +127,38 @@ public class ImageScanner {
images.add(image);
}
}
} else {
// 使用传统 File API
} catch (Exception e) {
Log.e(TAG, "Error scanning folder: " + folderPath, e);
}
return images;
}
/**
* 扫描 File 格式的文件夹(优化版)
*/
private List<WallpaperImage> scanFileFolder(String folderPath) {
List<WallpaperImage> images = new ArrayList<>(1000); // 预分配容量
try {
File folder = new File(folderPath);
if (!folder.exists() || !folder.isDirectory()) {
Log.e(TAG, "Folder not found or not a directory: " + folderPath);
return new ArrayList<>();
}
File[] files = folder.listFiles();
if (files == null) {
return images;
}
for (File file : files) {
if (file.isFile() && isImageFile(file)) {
File[] files = folder.listFiles();
if (files == null || files.length == 0) {
return images;
}
// 预先分配容量
images = new ArrayList<>(Math.min(files.length, MAX_SCAN_COUNT));
// 批量处理文件
for (int i = 0; i < files.length && images.size() < MAX_SCAN_COUNT; i++) {
File file = files[i];
if (file.isFile() && isImageFileFast(file)) {
WallpaperImage image = new WallpaperImage(
file.getAbsolutePath(),
folderPath,
@@ -100,33 +169,97 @@ public class ImageScanner {
images.add(image);
}
}
} catch (Exception e) {
Log.e(TAG, "Error scanning folder: " + folderPath, e);
}
// Save to JSON
jsonHelper.saveIndex(folderPath, images);
Log.i(TAG, "Found " + images.size() + " images in " + folderPath);
return images;
}
private boolean isImageFile(File file) {
String name = file.getName().toLowerCase();
for (String ext : IMAGE_EXTENSIONS) {
if (name.endsWith("." + ext)) {
return true;
}
}
return false;
/**
* 快速判断是否为图片文件(优化版)
* 使用 hashCode 代替字符串比较,性能更好
*/
private boolean isImageFileFast(File file) {
String name = file.getName();
int dotIndex = name.lastIndexOf('.');
if (dotIndex < 0) return false;
String ext = name.substring(dotIndex + 1).toLowerCase();
return IMAGE_EXTENSIONS.contains(ext);
}
private boolean isImageFile(DocumentFile file) {
String name = file.getName().toLowerCase();
for (String ext : IMAGE_EXTENSIONS) {
if (name.endsWith("." + ext)) {
return true;
/**
* 快速判断是否为图片文件(DocumentFile 版本)
*/
private boolean isImageFileFast(DocumentFile file) {
String name = file.getName();
if (name == null) return false;
int dotIndex = name.lastIndexOf('.');
if (dotIndex < 0) return false;
String ext = name.substring(dotIndex + 1).toLowerCase();
return IMAGE_EXTENSIONS.contains(ext);
}
/**
* 并发扫描多个文件夹
*/
public void scanFoldersAsync(List<String> folders, ScanCallback callback) {
if (folders == null || folders.isEmpty()) {
if (callback != null) {
callback.onScanComplete(Collections.emptyList());
}
return;
}
return false;
new Thread(() -> {
List<List<WallpaperImage>> allResults = new ArrayList<>();
try {
// 使用并发扫描
var futures = new java.util.ArrayList<java.util.concurrent.Future<List<WallpaperImage>>>();
for (String folder : folders) {
var future = scanExecutor.submit(() -> scanFolder(folder));
futures.add(future);
}
// 收集结果
for (var future : futures) {
try {
List<WallpaperImage> result = future.get(30, TimeUnit.SECONDS);
allResults.add(result);
} catch (Exception e) {
Log.e(TAG, "Error getting scan result", e);
}
}
// 合并结果
List<WallpaperImage> allImages = new ArrayList<>();
for (List<WallpaperImage> result : allResults) {
allImages.addAll(result);
}
if (callback != null) {
callback.onScanComplete(allImages);
}
} catch (Exception e) {
Log.e(TAG, "Error in async scan", e);
if (callback != null) {
callback.onScanError(e.getMessage());
}
}
}).start();
}
/**
* 扫描回调接口
*/
public interface ScanCallback {
void onScanComplete(List<WallpaperImage> images);
void onScanError(String error);
}
public WallpaperImage getImageAtIndex(List<String> folders, int index) {
@@ -182,4 +315,22 @@ public class ImageScanner {
return allImages;
}
/**
* 关闭扫描器,释放资源
* 应在 Activity/Fragment 销毁时调用
*/
public void shutdown() {
if (scanExecutor != null && !scanExecutor.isShutdown()) {
scanExecutor.shutdown();
try {
if (!scanExecutor.awaitTermination(5, TimeUnit.SECONDS)) {
scanExecutor.shutdownNow();
}
} catch (InterruptedException e) {
scanExecutor.shutdownNow();
Thread.currentThread().interrupt();
}
}
}
}
@@ -0,0 +1,250 @@
package cn.hugh.bz.gk2.wallpaper;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import cn.hugh.bz.gk2.model.Album;
/**
* 相册管理器
* 负责保存和加载相册数据,管理当前激活的相册
*/
public class AlbumPreferences {
private static final String PREFS_NAME = "album_prefs";
private static final String KEY_ALBUMS = "albums";
private static final String KEY_ACTIVE_ALBUM_ID = "active_album_id";
private static final String KEY_GLOBAL_FOLDERS = "global_folders";
private final SharedPreferences prefs;
private final Gson gson;
public AlbumPreferences(Context context) {
this.prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
this.gson = new Gson();
}
/**
* 保存所有相册
*/
public void saveAlbums(List<Album> albums) {
String albumsJson = gson.toJson(albums);
prefs.edit().putString(KEY_ALBUMS, albumsJson).apply();
}
/**
* 加载所有相册
*/
public List<Album> loadAlbums() {
String albumsJson = prefs.getString(KEY_ALBUMS, null);
if (albumsJson == null) {
return new ArrayList<>();
}
try {
Type listType = new TypeToken<ArrayList<Album>>(){}.getType();
return gson.fromJson(albumsJson, listType);
} catch (Exception e) {
return new ArrayList<>();
}
}
/**
* 获取当前激活的相册ID
*/
public String getActiveAlbumId() {
return prefs.getString(KEY_ACTIVE_ALBUM_ID, null);
}
/**
* 设置当前激活的相册ID
*/
public void setActiveAlbumId(String albumId) {
prefs.edit().putString(KEY_ACTIVE_ALBUM_ID, albumId).apply();
}
/**
* 获取当前激活的相册
*/
public Album getActiveAlbum() {
String activeId = getActiveAlbumId();
if (activeId == null) {
return null;
}
List<Album> albums = loadAlbums();
for (Album album : albums) {
if (album.getId().equals(activeId)) {
return album;
}
}
return null;
}
/**
* 创建默认相册(如果不存在)
*/
public Album createDefaultAlbumIfNeeded() {
List<Album> albums = loadAlbums();
// 检查是否存在默认相册
Album defaultAlbum = null;
for (Album album : albums) {
if (album.isDefault()) {
defaultAlbum = album;
break;
}
}
if (defaultAlbum == null) {
// 创建默认相册
defaultAlbum = new Album();
defaultAlbum.setId("default");
defaultAlbum.setName("默认相册");
albums.add(defaultAlbum);
saveAlbums(albums);
}
// 如果没有激活的相册,设置默认相册为激活
if (getActiveAlbumId() == null) {
setActiveAlbumId("default");
}
return defaultAlbum;
}
/**
* 获取全局文件夹池(所有已选择的文件夹)
*/
public List<String> getGlobalFolders() {
String foldersJson = prefs.getString(KEY_GLOBAL_FOLDERS, null);
if (foldersJson == null) {
return new ArrayList<>();
}
try {
Type listType = new TypeToken<ArrayList<String>>(){}.getType();
return gson.fromJson(foldersJson, listType);
} catch (Exception e) {
return new ArrayList<>();
}
}
/**
* 保存全局文件夹池
*/
public void saveGlobalFolders(List<String> folders) {
String foldersJson = gson.toJson(folders);
prefs.edit().putString(KEY_GLOBAL_FOLDERS, foldersJson).apply();
}
/**
* 添加文件夹到全局池
*/
public void addGlobalFolder(String folderUri) {
if (folderUri == null || TextUtils.isEmpty(folderUri)) {
return;
}
List<String> folders = getGlobalFolders();
if (!folders.contains(folderUri)) {
folders.add(folderUri);
saveGlobalFolders(folders);
}
}
/**
* 从全局池移除文件夹
*/
public void removeGlobalFolder(String folderUri) {
List<String> folders = getGlobalFolders();
folders.remove(folderUri);
saveGlobalFolders(folders);
}
/**
* 检查文件夹是否在全局池中
*/
public boolean isGlobalFolderExists(String folderUri) {
return getGlobalFolders().contains(folderUri);
}
/**
* 通过ID查找相册
*/
public Album findAlbumById(String albumId) {
List<Album> albums = loadAlbums();
for (Album album : albums) {
if (album.getId().equals(albumId)) {
return album;
}
}
return null;
}
/**
* 检查相册名称是否已存在
*/
public boolean isAlbumNameExists(String name, String excludeId) {
List<Album> albums = loadAlbums();
for (Album album : albums) {
if (!album.getId().equals(excludeId) && album.getName().equals(name)) {
return true;
}
}
return false;
}
/**
* 删除相册
*/
public boolean deleteAlbum(String albumId) {
if (albumId.equals("default")) {
return false; // 不允许删除默认相册
}
List<Album> albums = loadAlbums();
Album toRemove = null;
for (Album album : albums) {
if (album.getId().equals(albumId)) {
toRemove = album;
break;
}
}
if (toRemove != null) {
albums.remove(toRemove);
saveAlbums(albums);
// 如果删除的是当前激活的相册,切换到默认相册
if (albumId.equals(getActiveAlbumId())) {
setActiveAlbumId("default");
}
return true;
}
return false;
}
/**
* 更新相册
*/
public void updateAlbum(Album album) {
List<Album> albums = loadAlbums();
for (int i = 0; i < albums.size(); i++) {
if (albums.get(i).getId().equals(album.getId())) {
albums.set(i, album);
saveAlbums(albums);
break;
}
}
}
}
@@ -10,68 +10,162 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import cn.hugh.bz.gk2.model.Album;
import cn.hugh.bz.gk2.model.AppConfig;
import cn.hugh.bz.gk2.model.PlayMode;
public class WallpaperPreferences {
private static final String PREFS_NAME = "wallpaper_prefs";
private static final String KEY_FOLDERS = "selected_folders";
private static final String KEY_PLAY_MODE = "play_mode";
private static final String KEY_INTERVAL = "interval_minutes";
private static final String KEY_ENABLED = "enabled";
private static final String KEY_CURRENT_INDEX = "current_index";
private static final String KEY_LAST_URI = "last_uri";
private static final String KEY_CHANGE_ON_RETURN = "change_on_return_to_home";
private final SharedPreferences prefs;
private final Gson gson;
private final AlbumPreferences albumPrefs;
public WallpaperPreferences(Context context) {
this.prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
this.gson = new Gson();
this.albumPrefs = new AlbumPreferences(context);
// 确保默认相册存在
albumPrefs.createDefaultAlbumIfNeeded();
// 迁移旧配置到默认相册
migrateOldConfig();
}
/**
* 迁移旧版本的配置到默认相册
*/
private void migrateOldConfig() {
// 检查是否已经迁移过
boolean migrated = prefs.getBoolean("config_migrated_to_album", false);
if (migrated) {
return;
}
// 读取旧配置
String oldFoldersJson = prefs.getString("selected_folders", null);
String oldPlayMode = prefs.getString("play_mode", null);
int oldInterval = prefs.getInt("interval_minutes", -1);
boolean oldEnabled = prefs.getBoolean("enabled", false);
int oldIndex = prefs.getInt("current_index", -1);
boolean oldChangeOnReturn = prefs.getBoolean("change_on_return_to_home", true);
// 如果有旧配置,迁移到默认相册
if (oldFoldersJson != null || oldPlayMode != null || oldInterval != -1) {
Album defaultAlbum = albumPrefs.createDefaultAlbumIfNeeded();
// 迁移文件夹
if (oldFoldersJson != null) {
Type listType = new TypeToken<ArrayList<String>>(){}.getType();
List<String> folders = gson.fromJson(oldFoldersJson, listType);
if (!folders.isEmpty()) {
defaultAlbum.setFolders(folders);
}
}
// 迁移其他配置(如果旧配置存在)
if (oldPlayMode != null) {
defaultAlbum.setPlayMode(PlayMode.valueOf(oldPlayMode));
}
if (oldInterval != -1) {
defaultAlbum.setIntervalMinutes(oldInterval);
}
if (oldEnabled) {
defaultAlbum.setEnabled(true);
}
if (oldIndex != -1) {
defaultAlbum.setCurrentIndex(oldIndex);
}
defaultAlbum.setChangeOnReturnToHome(oldChangeOnReturn);
// 保存默认相册
albumPrefs.updateAlbum(defaultAlbum);
}
// 标记已迁移
prefs.edit().putBoolean("config_migrated_to_album", true).apply();
}
/**
* 从当前激活的相册加载配置
*/
public AppConfig loadConfig() {
AppConfig config = new AppConfig();
String foldersJson = prefs.getString(KEY_FOLDERS, null);
if (foldersJson != null) {
Type listType = new TypeToken<ArrayList<String>>(){}.getType();
List<String> folders = gson.fromJson(foldersJson, listType);
config.setSelectedFolders(folders);
// 获取当前激活的相册
Album album = albumPrefs.getActiveAlbum();
if (album != null) {
// 从相册读取配置
config.setSelectedFolders(new ArrayList<>(album.getFolders()));
config.setPlayMode(album.getPlayMode());
config.setIntervalMinutes(album.getIntervalMinutes());
config.setEnabled(album.isEnabled());
config.setCurrentIndex(album.getCurrentIndex());
config.setChangeOnReturnToHome(album.isChangeOnReturnToHome());
} else {
// 默认配置
config.setSelectedFolders(new ArrayList<>());
config.setPlayMode(PlayMode.SEQUENTIAL);
config.setIntervalMinutes(30);
config.setEnabled(false);
config.setCurrentIndex(0);
config.setChangeOnReturnToHome(true);
}
String modeString = prefs.getString(KEY_PLAY_MODE, PlayMode.SEQUENTIAL.name());
config.setPlayMode(PlayMode.valueOf(modeString));
config.setIntervalMinutes(prefs.getInt(KEY_INTERVAL, 30));
config.setEnabled(prefs.getBoolean(KEY_ENABLED, false));
config.setCurrentIndex(prefs.getInt(KEY_CURRENT_INDEX, 0));
config.setChangeOnReturnToHome(prefs.getBoolean(KEY_CHANGE_ON_RETURN, true));
return config;
}
/**
* 保存配置到当前激活的相册
*/
public void saveConfig(AppConfig config) {
SharedPreferences.Editor editor = prefs.edit();
// 获取当前激活的相册
Album album = albumPrefs.getActiveAlbum();
String foldersJson = gson.toJson(config.getSelectedFolders());
editor.putString(KEY_FOLDERS, foldersJson);
editor.putString(KEY_PLAY_MODE, config.getPlayMode().name());
editor.putInt(KEY_INTERVAL, config.getIntervalMinutes());
editor.putBoolean(KEY_ENABLED, config.isEnabled());
editor.putInt(KEY_CURRENT_INDEX, config.getCurrentIndex());
editor.putBoolean(KEY_CHANGE_ON_RETURN, config.isChangeOnReturnToHome());
if (album == null) {
// 如果没有激活的相册,使用默认相册
album = albumPrefs.createDefaultAlbumIfNeeded();
}
editor.apply();
// 更新相册配置
album.setFolders(new ArrayList<>(config.getSelectedFolders()));
album.setPlayMode(config.getPlayMode());
album.setIntervalMinutes(config.getIntervalMinutes());
album.setEnabled(config.isEnabled());
album.setCurrentIndex(config.getCurrentIndex());
album.setChangeOnReturnToHome(config.isChangeOnReturnToHome());
// 保存相册
albumPrefs.updateAlbum(album);
}
public void saveLastUri(String uri) {
prefs.edit().putString(KEY_LAST_URI, uri).apply();
// 同时更新到当前激活的相册
Album album = albumPrefs.getActiveAlbum();
if (album != null) {
album.setLastUri(uri);
albumPrefs.updateAlbum(album);
}
}
public String getLastUri() {
return prefs.getString(KEY_LAST_URI, null);
// 首先尝试从 SharedPreferences 获取(兼容旧版本)
String uri = prefs.getString(KEY_LAST_URI, null);
// 如果为空,尝试从当前激活的相册获取
if (uri == null) {
Album album = albumPrefs.getActiveAlbum();
if (album != null) {
uri = album.getLastUri();
}
}
return uri;
}
// 通用的键值对存储方法
@@ -0,0 +1,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/primary" />
<corners android:radius="12dp" />
</shape>
+10
View File
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,3H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2zM9,17H7v-2h2v2zM9,13H7v-2h2v2zM9,9H7V7h2v2zM13,17h-2v-2h2v2zM13,13h-2v-2h2v2zM13,9h-2V7h2v2zM17,17h-2v-2h2v2zM17,13h-2v-2h2v2zM17,9h-2V7h2v2z"/>
</vector>
+10
View File
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>
+10
View File
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M3,17.25V21h3v-3h-3v3zM21,6.25c-1.11,0 -2.04,0.58 -2.47,1.45l0,0 1.68,-0.73 2.47,-1.45zM21.06,9.9L21.06,6.25c0,-2.29 -0.3,-4.48 -1.66,-6.15l-6.65,6.65zM11.13,6.25l6.66,-6.66zM17.65,7.08L12.78,2.2 12.78,2.2l-6.65,6.65z"/>
</vector>
+10
View File
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7,7h10v3l4,-4 -4,-4v3H5v6h2V7zM17,17H7v-3l-4,4 4,4v-3h12v-6h-2V17z"/>
</vector>
+10
View File
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M6.99,11L3,15l3.99,4v-3H14v-2H6.99v-3zM21,9l-3.99,-4v3H10v2h7.01v3L21,9z"/>
</vector>
@@ -0,0 +1,285 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<!-- 标题栏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginBottom="16dp"
android:orientation="horizontal">
<ImageButton
android:id="@+id/btnBack"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_back"
android:contentDescription="返回"
app:tint="@color/text_primary" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="新建相册"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/text_primary"
android:layout_marginStart="8dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="保存"
android:textSize="14sp"
app:cornerRadius="8dp"
style="@style/Widget.Material3.Button" />
</LinearLayout>
<!-- 相册名称 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="2dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="相册名称"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/text_primary" />
<EditText
android:id="@+id/etAlbumName"
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="请输入相册名称"
android:inputType="text"
android:textSize="16sp"
android:textColor="@color/text_primary"
android:textColorHint="@color/text_hint"
android:background="@android:color/transparent"
android:layout_marginTop="8dp" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<!-- 文件夹选择 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="2dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="文件夹"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/text_primary" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnAddFolder"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:text="+ 添加"
android:textSize="12sp"
app:icon="@drawable/ic_add"
app:iconGravity="textStart"
app:iconPadding="4dp"
app:cornerRadius="8dp"
style="@style/Widget.Material3.Button.OutlinedButton" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvFolders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:nestedScrollingEnabled="false"
tools:listitem="@layout/item_folder_card" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<!-- 播放模式 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="2dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="播放模式"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/text_primary"
android:layout_marginBottom="12dp" />
<RadioGroup
android:id="@+id/rgPlayMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbSequential"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="顺序播放"
android:textSize="14sp"
android:textColor="@color/text_primary" />
<RadioButton
android:id="@+id/rbRandom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="随机播放"
android:textSize="14sp"
android:textColor="@color/text_primary" />
</RadioGroup>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<!-- 更换间隔 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="2dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="更换间隔"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/text_primary" />
<SeekBar
android:id="@+id/seekBarInterval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:max="180"
android:progress="30" />
<TextView
android:id="@+id/tvIntervalValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="30 分钟"
android:textSize="14sp"
android:textColor="@color/text_secondary"
android:layout_marginTop="8dp"
android:gravity="center" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<!-- 返回桌面更换 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="2dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="返回桌面时更换壁纸"
android:textSize="16sp"
android:textColor="@color/text_primary" />
<Switch
android:id="@+id/switchChangeOnReturn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<!-- 标题栏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginBottom="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="相册管理"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/text_primary" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnCreateAlbum"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="+ 新建"
android:textSize="14sp"
app:icon="@drawable/ic_add"
app:iconGravity="textStart"
app:cornerRadius="12dp"
style="@style/Widget.Material3.Button.TonalButton" />
</LinearLayout>
<!-- 相册列表 -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvAlbums"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
tools:listitem="@layout/item_album_card" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
+68
View File
@@ -97,6 +97,74 @@
</com.google.android.material.card.MaterialCardView>
<!-- 相册信息卡片 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="2dp"
app:cardCornerRadius="16dp"
android:clickable="true"
android:focusable="true"
android:id="@+id/cardAlbum">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当前相册"
android:textSize="12sp"
android:textColor="@color/text_hint" />
<TextView
android:id="@+id/tvAlbumName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="默认相册"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/text_primary"
android:layout_marginTop="4dp" />
<TextView
android:id="@+id/tvAlbumInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 个文件夹 · 0 张图片"
android:textSize="14sp"
android:textColor="@color/text_secondary"
android:layout_marginTop="4dp" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnManageAlbums"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="管理"
android:textSize="14sp"
app:icon="@drawable/ic_edit"
app:iconGravity="textStart"
app:iconPadding="4dp"
app:cornerRadius="8dp"
style="@style/Widget.Material3.Button.OutlinedButton" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<!-- 文件夹管理卡片 -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
+150
View File
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
app:cardElevation="2dp"
app:cardCornerRadius="16dp"
android:clickable="true"
android:focusable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<!-- 相册名称和状态 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tvAlbumName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="相册名称"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/text_primary"
android:maxLines="1"
android:ellipsize="end" />
<TextView
android:id="@+id/tvCurrentBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当前"
android:textSize="12sp"
android:textColor="@color/white"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:background="@drawable/badge_background"
android:layout_marginStart="8dp"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<!-- 相册信息 -->
<TextView
android:id="@+id/tvAlbumInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3 个文件夹 · 120 张图片"
android:textSize="14sp"
android:textColor="@color/text_secondary"
android:layout_marginTop="8dp" />
<!-- 配置信息 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvPlayMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="顺序"
android:textSize="12sp"
android:textColor="@color/text_hint"
android:drawableStart="@drawable/ic_repeat"
android:drawablePadding="4dp" />
<TextView
android:id="@+id/tvInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 分钟"
android:textSize="12sp"
android:textColor="@color/text_hint"
android:layout_marginStart="16dp"
android:drawableStart="@drawable/ic_schedule"
android:drawablePadding="4dp" />
</LinearLayout>
<!-- 操作按钮 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="horizontal"
android:gravity="end">
<com.google.android.material.button.MaterialButton
android:id="@+id/btnEdit"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="编辑"
android:textSize="14sp"
android:layout_marginEnd="8dp"
app:icon="@drawable/ic_edit"
app:iconGravity="textStart"
app:iconPadding="4dp"
app:cornerRadius="8dp"
style="@style/Widget.Material3.Button.OutlinedButton" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnSwitch"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="切换"
android:textSize="14sp"
android:layout_marginEnd="8dp"
app:icon="@drawable/ic_swap_horiz"
app:iconGravity="textStart"
app:iconPadding="4dp"
app:cornerRadius="8dp"
style="@style/Widget.Material3.Button" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="删除"
android:textSize="14sp"
app:icon="@drawable/ic_delete"
app:iconGravity="textStart"
app:iconPadding="4dp"
app:cornerRadius="8dp"
style="@style/Widget.Material3.Button.OutlinedButton"
android:textColor="@color/error"
app:iconTint="@color/error"
app:strokeColor="@color/error" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
+7 -1
View File
@@ -12,9 +12,15 @@
android:title="@string/nav_wallpaper"
android:orderInCategory="1" />
<item
android:id="@+id/nav_albums"
android:icon="@drawable/ic_album"
android:title="@string/nav_albums"
android:orderInCategory="2" />
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="@string/nav_settings"
android:orderInCategory="2" />
android:orderInCategory="3" />
</menu>
+1
View File
@@ -19,5 +19,6 @@
<!-- 底部导航标签 -->
<string name="nav_home">主页</string>
<string name="nav_wallpaper">壁纸</string>
<string name="nav_albums">相册</string>
<string name="nav_settings">设置</string>
</resources>