diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 1e99890..a8e41ff 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -27,7 +27,8 @@ "mcp__plugin_serena_serena__replace_content", "Bash(git reset:*)", "mcp__plugin_serena_serena__create_text_file", - "Bash(powershell:*)" + "Bash(powershell:*)", + "Bash(find:*)" ] } } diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/CurrentWallpaperFragment.java b/app/src/main/java/cn/hugh/bz/gk2/ui/CurrentWallpaperFragment.java deleted file mode 100644 index ad08d57..0000000 --- a/app/src/main/java/cn/hugh/bz/gk2/ui/CurrentWallpaperFragment.java +++ /dev/null @@ -1,255 +0,0 @@ -package cn.hugh.bz.gk2.ui; - -import android.content.Intent; -import android.graphics.Bitmap; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.provider.OpenableColumns; -import android.database.Cursor; -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.fragment.app.Fragment; - -import com.google.android.material.button.MaterialButton; -import android.widget.ImageView; - -import cn.hugh.bz.gk2.R; -import cn.hugh.bz.gk2.utils.BackgroundHelper; -import cn.hugh.bz.gk2.utils.ImageLoader; -import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences; - -/** - * 当前壁纸 Fragment - * 显示当前壁纸大图预览、壁纸信息和操作按钮 - */ -public class CurrentWallpaperFragment extends Fragment { - - private ImageView ivWallpaper; - private View touchOverlay; - private TextView tvWallpaperName; - private TextView tvResolution; - private TextView tvFileSize; - private TextView tvPath; - private MaterialButton btnNext; - private MaterialButton btnOpenGallery; - - private WallpaperPreferences prefs; - private ImageLoader imageLoader; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_current_wallpaper, container, false); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - prefs = new WallpaperPreferences(requireContext()); - imageLoader = new ImageLoader(requireContext()); - - initViews(view); - loadCurrentWallpaper(); - - // 应用背景图片 - BackgroundHelper.applyBackground(requireContext(), view); - } - - private void initViews(View view) { - ivWallpaper = view.findViewById(R.id.ivWallpaper); - touchOverlay = view.findViewById(R.id.touchOverlay); - tvWallpaperName = view.findViewById(R.id.tvWallpaperName); - tvResolution = view.findViewById(R.id.tvResolution); - tvFileSize = view.findViewById(R.id.tvFileSize); - tvPath = view.findViewById(R.id.tvPath); - btnNext = view.findViewById(R.id.btnNext); - btnOpenGallery = view.findViewById(R.id.btnOpenGallery); - - btnNext.setOnClickListener(v -> showNextWallpaper()); - btnOpenGallery.setOnClickListener(v -> openInGallery()); - touchOverlay.setOnClickListener(v -> openInGallery()); - } - - private void loadCurrentWallpaper() { - String currentUri = prefs.getLastUri(); - - if (currentUri == null || currentUri.isEmpty()) { - showNoWallpaper(); - return; - } - - // 显示加载状态 - tvWallpaperName.setText("加载中..."); - tvResolution.setText("-- x --"); - tvFileSize.setText("-- MB"); - tvPath.setText(currentUri); - btnNext.setEnabled(false); - - // 获取文件大小和名称 - new Thread(() -> { - String fileSizeStr = getFileSize(Uri.parse(currentUri)); - String displayName = getDisplayName(currentUri); - - requireActivity().runOnUiThread(() -> { - tvFileSize.setText(fileSizeStr); - tvWallpaperName.setText(displayName); - }); - - // 加载图片 - Bitmap bitmap = imageLoader.loadImage(currentUri, 1080, 1920); - - requireActivity().runOnUiThread(() -> { - if (bitmap != null) { - ivWallpaper.setImageBitmap(bitmap); - tvResolution.setText(bitmap.getWidth() + " x " + bitmap.getHeight()); - btnNext.setEnabled(true); - } else { - showError(); - } - }); - }).start(); - } - - private String getFileSize(Uri uri) { - try (Cursor cursor = requireContext().getContentResolver().query(uri, null, null, null, null)) { - if (cursor != null && cursor.moveToFirst()) { - int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); - if (sizeIndex != -1) { - long size = cursor.getLong(sizeIndex); - return formatFileSize(size); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return "未知大小"; - } - - private String formatFileSize(long size) { - if (size <= 0) return "0 B"; - final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"}; - int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); - return String.format("%.1f %s", size / Math.pow(1024, digitGroups), units[digitGroups]); - } - - private void showNoWallpaper() { - ivWallpaper.setImageDrawable(null); - tvWallpaperName.setText("未设置壁纸"); - tvResolution.setText("--"); - tvFileSize.setText("--"); - tvPath.setText(""); - btnNext.setEnabled(false); - btnOpenGallery.setEnabled(false); - } - - private void showError() { - ivWallpaper.setImageDrawable(null); - tvWallpaperName.setText("加载失败"); - btnNext.setEnabled(true); // 允许尝试下一张 - } - - private void showNextWallpaper() { - android.util.Log.i("CurrentWallpaperFragment", "showNextWallpaper() called"); - - cn.hugh.bz.gk2.model.AppConfig config = prefs.loadConfig(); - - if (config.getSelectedFolders().isEmpty() && - (config.getImageUris() == null || config.getImageUris().isEmpty())) { - Toast.makeText(requireContext(), "请先在相册页面添加图片", Toast.LENGTH_SHORT).show(); - return; - } - - // 禁用按钮防止重复点击 - btnNext.setEnabled(false); - btnNext.setText("切换中..."); - - // 发送广播 - cn.hugh.bz.gk2.receiver.WallpaperChangeReceiver receiver = new cn.hugh.bz.gk2.receiver.WallpaperChangeReceiver(); - Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER"); - intent.putExtra("force_change", true); - intent.putExtra("scheduled", false); - receiver.onReceive(requireContext(), intent); - - Toast.makeText(requireContext(), "已切换", Toast.LENGTH_SHORT).show(); - - // 延迟刷新 - new Handler(Looper.getMainLooper()).postDelayed(() -> { - loadCurrentWallpaper(); - btnNext.setText("切换下一张"); - btnNext.setEnabled(true); - }, 800); - } - - private void openInGallery() { - String currentUri = prefs.getLastUri(); - if (currentUri != null) { - try { - Uri uri = Uri.parse(currentUri); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - startActivity(intent); - } catch (Exception e) { - Toast.makeText(requireContext(), "无法打开图片", Toast.LENGTH_SHORT).show(); - } - } - } - - private String getDisplayName(String uriString) { - if (uriString == null || uriString.isEmpty()) { - return "未知图片"; - } - - try { - Uri uri = Uri.parse(uriString); - - // 尝试从 ContentResolver 获取文件名 - try (Cursor cursor = requireContext().getContentResolver().query(uri, null, null, null, null)) { - if (cursor != null && cursor.moveToFirst()) { - int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); - if (nameIndex != -1) { - return cursor.getString(nameIndex); - } - } - } - - // 如果失败,回退到路径解析 - String path = uri.getLastPathSegment(); - if (path != null) { - if (path.contains(":")) { - String[] parts = path.split(":"); - if (parts.length > 1) { - path = parts[1]; - } - } - if (path.contains("/")) { - String[] segments = path.split("/"); - path = segments[segments.length - 1]; - } - return path; - } - } catch (Exception e) { - // Ignore - } - - return "未命名图片"; - } - - @Override - public void onResume() { - super.onResume(); - loadCurrentWallpaper(); - - View rootView = getView(); - if (rootView != null) { - BackgroundHelper.applyBackground(requireContext(), rootView); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/HomeFragment.java b/app/src/main/java/cn/hugh/bz/gk2/ui/HomeFragment.java index 3df99f9..3e70830 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/ui/HomeFragment.java +++ b/app/src/main/java/cn/hugh/bz/gk2/ui/HomeFragment.java @@ -2,12 +2,17 @@ package cn.hugh.bz.gk2.ui; import android.app.WallpaperManager; import android.content.Intent; +import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.provider.OpenableColumns; +import android.database.Cursor; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -15,7 +20,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import com.airbnb.lottie.LottieAnimationView; +import com.google.android.material.button.MaterialButton; import java.util.List; @@ -23,30 +28,41 @@ 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.utils.BackgroundHelper; +import cn.hugh.bz.gk2.utils.ImageLoader; import cn.hugh.bz.gk2.utils.WallpaperServiceHelper; import cn.hugh.bz.gk2.wallpaper.AlbumPreferences; import cn.hugh.bz.gk2.wallpaper.WallpaperPreferences; /** - * 主页 Fragment - * 负责显示服务状态和启用/禁用服务 + * 主页 Fragment (Dashboard) + * 负责显示当前壁纸、服务状态和快速操作 */ public class HomeFragment extends Fragment { private static final String TAG = "HomeFragment"; + // 状态相关 private TextView tvStatus; - private LottieAnimationView statusAnimation; - private TextView tvFolderInfo; - private TextView tvSingleImageInfo; - private Button btnToggle; - private Button btnChangeNow; + private View viewStatusDot; + private MaterialButton btnToggle; + + // 壁纸预览相关 + private ImageView ivBlurBackground; + private ImageView ivCurrentWallpaper; + private View touchOverlay; + private MaterialButton btnChangeNow; + private MaterialButton btnOpenGallery; + + // 信息相关 + private TextView tvWallpaperName; + private TextView tvResolution; + private TextView tvFileSize; private TextView tvAlbumName; - private TextView tvAlbumInfo; - private Button btnManageAlbums; + private MaterialButton btnManageAlbums; private WallpaperPreferences prefs; private AppConfig config; private AlbumPreferences albumPrefs; + private ImageLoader imageLoader; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -60,226 +76,205 @@ public class HomeFragment extends Fragment { prefs = new WallpaperPreferences(requireContext()); config = prefs.loadConfig(); albumPrefs = new AlbumPreferences(requireContext()); + imageLoader = new ImageLoader(requireContext()); - // 创建默认相册(如果不存在) albumPrefs.createDefaultAlbumIfNeeded(); initViews(view); updateUI(); - updateAlbumInfo(); + loadCurrentWallpaper(); - // 应用背景图片 + // 应用自定义背景(如果有) BackgroundHelper.applyBackground(requireContext(), view); } private void initViews(View view) { + // 状态 tvStatus = view.findViewById(R.id.tvStatus); - statusAnimation = view.findViewById(R.id.statusAnimation); - tvFolderInfo = view.findViewById(R.id.tvFolderInfo); - tvSingleImageInfo = view.findViewById(R.id.tvSingleImageInfo); + viewStatusDot = view.findViewById(R.id.viewStatusDot); btnToggle = view.findViewById(R.id.btnToggle); + + // 预览 + ivBlurBackground = view.findViewById(R.id.ivBlurBackground); + ivCurrentWallpaper = view.findViewById(R.id.ivCurrentWallpaper); + touchOverlay = view.findViewById(R.id.touchOverlay); btnChangeNow = view.findViewById(R.id.btnChangeNow); + btnOpenGallery = view.findViewById(R.id.btnOpenGallery); + + // 信息 + tvWallpaperName = view.findViewById(R.id.tvWallpaperName); + tvResolution = view.findViewById(R.id.tvResolution); + tvFileSize = view.findViewById(R.id.tvFileSize); tvAlbumName = view.findViewById(R.id.tvAlbumName); - tvAlbumInfo = view.findViewById(R.id.tvAlbumInfo); btnManageAlbums = view.findViewById(R.id.btnManageAlbums); btnToggle.setOnClickListener(v -> toggleService()); btnChangeNow.setOnClickListener(v -> changeWallpaperNow()); + btnOpenGallery.setOnClickListener(v -> openInGallery()); + touchOverlay.setOnClickListener(v -> openInGallery()); btnManageAlbums.setOnClickListener(v -> openAlbumManagement()); } private void toggleService() { if (!config.hasMedia()) { - Toast.makeText(requireContext(), "请先在相册页面添加文件夹或图片", Toast.LENGTH_SHORT).show(); + Toast.makeText(requireContext(), "请先在相册页面添加图片", Toast.LENGTH_SHORT).show(); return; } boolean newState = !config.isEnabled(); - if (newState) { - // 每次启用都弹出壁纸设置引导 showSetWallpaperDialog(); } else { - config.setEnabled(newState); + config.setEnabled(false); prefs.saveConfig(config); - - cn.hugh.bz.gk2.utils.AlarmScheduler scheduler = new cn.hugh.bz.gk2.utils.AlarmScheduler(requireContext()); - scheduler.cancelSchedule(); + new cn.hugh.bz.gk2.utils.AlarmScheduler(requireContext()).cancelSchedule(); Toast.makeText(requireContext(), "已禁用", Toast.LENGTH_SHORT).show(); } - updateUI(); } - /** - * 显示引导设置壁纸的对话框 - */ private void showSetWallpaperDialog() { new androidx.appcompat.app.AlertDialog.Builder(requireContext()) - .setTitle("设置动态壁纸") - .setMessage("点击「确定」后将打开壁纸选择界面,请选择「BzForGk2」作为动态壁纸。\n\n设置完成后返回应用即可自动启用。") + .setTitle("启用壁纸服务") + .setMessage("点击确定后请选择「BzForGk2」作为动态壁纸。") .setPositiveButton("确定", (dialog, which) -> { - cn.hugh.bz.gk2.utils.FileLogger fileLogger = cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()); - String msg = "User confirmed wallpaper service enable"; - android.util.Log.i(TAG, msg); - fileLogger.log(TAG, msg); - openWallpaperSelector(); - // 启用服务 config.setEnabled(true); prefs.saveConfig(config); - - String scheduleMsg = "Scheduling alarm with interval: " + config.getIntervalMinutes() + " minutes"; - android.util.Log.i(TAG, scheduleMsg); - fileLogger.log(TAG, scheduleMsg); - - cn.hugh.bz.gk2.utils.AlarmScheduler scheduler = new cn.hugh.bz.gk2.utils.AlarmScheduler(requireContext()); - scheduler.scheduleWallpaperChange(config.getIntervalMinutes()); - - Toast.makeText(requireContext(), "已启用,请选择壁纸", Toast.LENGTH_LONG).show(); + new cn.hugh.bz.gk2.utils.AlarmScheduler(requireContext()).scheduleWallpaperChange(config.getIntervalMinutes()); updateUI(); }) .setNegativeButton("取消", null) .show(); } - /** - * 打开系统壁纸选择界面 - */ private void openWallpaperSelector() { try { Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); - intent.putExtra( - WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, - new android.content.ComponentName(requireContext(), cn.hugh.bz.gk2.wallpaper.AutoWallpaperService.class) - ); + intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, + new android.content.ComponentName(requireContext(), cn.hugh.bz.gk2.wallpaper.AutoWallpaperService.class)); startActivity(intent); } catch (Exception e) { - // 如果上述方法失败,尝试打开壁纸选择器 try { - Intent intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER); - startActivity(intent); - Toast.makeText(requireContext(), "请选择 BzForGk2 动态壁纸", Toast.LENGTH_LONG).show(); + startActivity(new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)); } catch (Exception ex) { - // 最后的备用方案:打开壁纸设置页面 - try { - Intent intent = new Intent("android.settings.WALLPAPER_SETTINGS"); - startActivity(intent); - Toast.makeText(requireContext(), "请选择 动态壁纸 → BzForGk2", Toast.LENGTH_LONG).show(); - } catch (Exception exc) { - Toast.makeText(requireContext(), "无法打开壁纸设置,请手动去系统设置中选择", Toast.LENGTH_LONG).show(); - } + Toast.makeText(requireContext(), "无法打开壁纸设置", Toast.LENGTH_SHORT).show(); } } } private void changeWallpaperNow() { - android.util.Log.i(TAG, "changeWallpaperNow() called"); - cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log(TAG, "changeWallpaperNow() called"); - - android.util.Log.i(TAG, "Selected folders count: " + config.getSelectedFolders().size()); - cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log(TAG, "Selected folders count: " + config.getSelectedFolders().size()); - - List imageUris = config.getImageUris(); - int imageCount = (imageUris != null) ? imageUris.size() : 0; - android.util.Log.i(TAG, "Image URIs count: " + imageCount); - cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log(TAG, "Image URIs count: " + imageCount); - if (!config.hasMedia()) { - android.util.Log.w(TAG, "No media available, showing toast"); - Toast.makeText(requireContext(), "请先在相册页面添加文件夹或图片", Toast.LENGTH_SHORT).show(); + Toast.makeText(requireContext(), "请先添加图片", Toast.LENGTH_SHORT).show(); return; } - android.util.Log.i(TAG, "changeWallpaperNow: sending broadcast"); - cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log(TAG, "changeWallpaperNow: sending broadcast"); - - // 直接实例化 BroadcastReceiver 并调用 onReceive(避免隐式广播限制) + btnChangeNow.setEnabled(false); + cn.hugh.bz.gk2.receiver.WallpaperChangeReceiver receiver = new cn.hugh.bz.gk2.receiver.WallpaperChangeReceiver(); Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER"); - intent.putExtra("force_change", true); // 用户主动触发 - intent.putExtra("scheduled", false); // 非定时触发 + intent.putExtra("force_change", true); receiver.onReceive(requireContext(), intent); - Toast.makeText(requireContext(), "壁纸已更换", Toast.LENGTH_SHORT).show(); + Toast.makeText(requireContext(), "正在更换...", Toast.LENGTH_SHORT).show(); + + new Handler(Looper.getMainLooper()).postDelayed(() -> { + loadCurrentWallpaper(); + btnChangeNow.setEnabled(true); + }, 1000); + } + + private void loadCurrentWallpaper() { + String currentUri = prefs.getLastUri(); + if (currentUri == null || currentUri.isEmpty()) { + tvWallpaperName.setText("未设置壁纸"); + ivCurrentWallpaper.setImageResource(R.drawable.ic_image); + ivBlurBackground.setImageDrawable(null); + return; + } + + new Thread(() -> { + String fileName = getDisplayName(currentUri); + String size = getFileSize(Uri.parse(currentUri)); + Bitmap bitmap = imageLoader.loadImage(currentUri, 500, 800); // 预览图不需要太大 + + if (isAdded()) { + requireActivity().runOnUiThread(() -> { + tvWallpaperName.setText(fileName); + tvFileSize.setText(size); + if (bitmap != null) { + ivCurrentWallpaper.setImageBitmap(bitmap); + ivBlurBackground.setImageBitmap(bitmap); // 布局中 alpha 已经设为 0.4 + tvResolution.setText(bitmap.getWidth() + " x " + bitmap.getHeight()); + } + }); + } + }).start(); + } + + private String getDisplayName(String uriString) { + try { + Uri uri = Uri.parse(uriString); + try (Cursor cursor = requireContext().getContentResolver().query(uri, null, null, null, null)) { + if (cursor != null && cursor.moveToFirst()) { + int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); + if (nameIndex != -1) return cursor.getString(nameIndex); + } + } + return uri.getLastPathSegment(); + } catch (Exception e) { return "未知文件"; } + } + + private String getFileSize(Uri uri) { + try (Cursor cursor = requireContext().getContentResolver().query(uri, null, null, null, null)) { + if (cursor != null && cursor.moveToFirst()) { + int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); + if (sizeIndex != -1) { + long size = cursor.getLong(sizeIndex); + if (size <= 0) return "0 B"; + final String[] units = new String[]{"B", "KB", "MB", "GB"}; + int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); + return String.format("%.1f %s", size / Math.pow(1024, digitGroups), units[digitGroups]); + } + } + } catch (Exception e) {} + return "未知大小"; + } + + private void openInGallery() { + String uriStr = prefs.getLastUri(); + if (uriStr != null) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriStr)); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivity(intent); + } catch (Exception e) { + Toast.makeText(requireContext(), "无法打开图片", Toast.LENGTH_SHORT).show(); + } + } } private void openAlbumManagement() { - // 切换到相册页面(ViewPager 的第 3 个页面,索引为 2) if (getActivity() instanceof MainActivity) { - MainActivity activity = (MainActivity) getActivity(); - activity.switchToPage(2); // 2 是相册管理页面的索引 + ((MainActivity) getActivity()).switchToPage(1); // 调整后的相册页索引为 1 } } private void updateUI() { - // 检测壁纸服务是否真实在运行 - boolean isServiceActuallyRunning = WallpaperServiceHelper.isServiceRunning(requireContext()); - boolean isConfigEnabled = config.isEnabled(); - - // Update status - 优先使用实际运行状态 - if (isServiceActuallyRunning && isConfigEnabled) { - // 服务真正在运行 - tvStatus.setText(R.string.status_enabled); - btnToggle.setText(R.string.disable); - btnChangeNow.setEnabled(true); - // 启动 Lottie 动画 - if (statusAnimation != null) { - statusAnimation.setAnimation(R.raw.status_active); - statusAnimation.playAnimation(); - } - } else if (isConfigEnabled && !isServiceActuallyRunning) { - // 配置已启用但服务未运行(用户可能还没选择壁纸) - tvStatus.setText("等待设置壁纸"); - btnToggle.setText(R.string.disable); - btnChangeNow.setEnabled(false); - // 停止 Lottie 动画 - if (statusAnimation != null) { - statusAnimation.cancelAnimation(); - statusAnimation.setProgress(0f); - } + boolean isRunning = WallpaperServiceHelper.isServiceRunning(requireContext()) && config.isEnabled(); + + if (isRunning) { + tvStatus.setText("服务已开启"); + viewStatusDot.setBackgroundResource(R.drawable.status_indicator_enabled); + btnToggle.setText("禁用"); } else { - // 服务已禁用 - tvStatus.setText(R.string.status_disabled); - btnToggle.setText(R.string.enable); - btnChangeNow.setEnabled(false); - // 停止 Lottie 动画 - if (statusAnimation != null) { - statusAnimation.cancelAnimation(); - statusAnimation.setProgress(0f); - } + tvStatus.setText("服务已禁用"); + viewStatusDot.setBackgroundResource(R.drawable.status_indicator_disabled); + btnToggle.setText("启用"); } - // Update folder info - int folderCount = config.getSelectedFolders().size(); - if (folderCount == 0) { - tvFolderInfo.setText("未选择文件夹"); - } else { - tvFolderInfo.setText("已选择 " + folderCount + " 个文件夹"); - } - - // Update single image info - List imageUris = config.getImageUris(); - if (imageUris != null && !imageUris.isEmpty()) { - tvSingleImageInfo.setText("已选择 " + imageUris.size() + " 张图片"); - tvSingleImageInfo.setVisibility(View.VISIBLE); - } else { - tvSingleImageInfo.setVisibility(View.GONE); - } - } - - /** - * 更新相册信息显示 - */ - private void updateAlbumInfo() { Album activeAlbum = albumPrefs.getActiveAlbum(); - if (activeAlbum != null) { - tvAlbumName.setText(activeAlbum.getName()); - tvAlbumInfo.setText(activeAlbum.getMediaSummary()); - } else { - tvAlbumName.setText("默认相册"); - tvAlbumInfo.setText("无媒体内容"); - } + tvAlbumName.setText(activeAlbum != null ? activeAlbum.getName() : "默认相册"); } @Override @@ -287,12 +282,6 @@ public class HomeFragment extends Fragment { super.onResume(); config = prefs.loadConfig(); updateUI(); - updateAlbumInfo(); - - // 重新应用背景图片(从设置页面返回时可能需要更新) - View rootView = getView(); - if (rootView != null) { - BackgroundHelper.applyBackground(requireContext(), rootView); - } + loadCurrentWallpaper(); } -} +} \ No newline at end of file diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/MainActivity.java b/app/src/main/java/cn/hugh/bz/gk2/ui/MainActivity.java index a86cd76..5065ca4 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/ui/MainActivity.java +++ b/app/src/main/java/cn/hugh/bz/gk2/ui/MainActivity.java @@ -170,7 +170,6 @@ public class MainActivity extends AppCompatActivity { // 导航容器 ID(LinearLayout,用于点击事件) int[] navContainerIds = { R.id.navHome, - R.id.navWallpaper, R.id.navAlbum, R.id.navHistory, R.id.navSettings @@ -179,7 +178,6 @@ public class MainActivity extends AppCompatActivity { // 导航文本 ID(TextView,用于更新选中状态) int[] navTextIds = { R.id.tvNavHome, - R.id.tvNavWallpaper, R.id.tvNavAlbum, R.id.tvNavHistory, R.id.tvNavSettings @@ -188,18 +186,17 @@ public class MainActivity extends AppCompatActivity { // 图标 ID int[] navIconIds = { R.id.ivNavHome, - R.id.ivNavWallpaper, R.id.ivNavAlbum, R.id.ivNavHistory, R.id.ivNavSettings }; // 初始化导航项和图标数组 - navContainers = new LinearLayout[5]; - navItems = new TextView[5]; - navIcons = new ImageView[5]; + navContainers = new LinearLayout[4]; + navItems = new TextView[4]; + navIcons = new ImageView[4]; - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 4; i++) { navContainers[i] = findViewById(navContainerIds[i]); navItems[i] = findViewById(navTextIds[i]); navIcons[i] = findViewById(navIconIds[i]); @@ -254,10 +251,10 @@ public class MainActivity extends AppCompatActivity { /** * 切换到指定的页面 - * @param position 页面索引(0=主页,1=壁纸,2=相册,3=历史,4=设置) + * @param position 页面索引(0=主页,1=相册,2=历史,3=设置) */ public void switchToPage(int position) { - if (viewPager != null && position >= 0 && position < 5) { + if (viewPager != null && position >= 0 && position < 4) { viewPager.setCurrentItem(position, false); // 更新底部导航选中状态 updateNavSelection(position); diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/ViewPagerAdapter.java b/app/src/main/java/cn/hugh/bz/gk2/ui/ViewPagerAdapter.java index 98c58e1..694b2ce 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/ui/ViewPagerAdapter.java +++ b/app/src/main/java/cn/hugh/bz/gk2/ui/ViewPagerAdapter.java @@ -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 = 5; + private static final int NUM_PAGES = 4; public ViewPagerAdapter(FragmentActivity fa) { super(fa); @@ -22,12 +22,10 @@ public class ViewPagerAdapter extends FragmentStateAdapter { case 0: return new HomeFragment(); case 1: - return new CurrentWallpaperFragment(); - case 2: return new AlbumManagementFragment(); - case 3: + case 2: return new WallpaperHistoryFragment(); - case 4: + case 3: return new SettingsFragment(); default: return new HomeFragment(); @@ -38,4 +36,4 @@ public class ViewPagerAdapter extends FragmentStateAdapter { public int getItemCount() { return NUM_PAGES; } -} +} \ No newline at end of file diff --git a/app/src/main/java/cn/hugh/bz/gk2/ui/WallpaperHistoryFragment.java b/app/src/main/java/cn/hugh/bz/gk2/ui/WallpaperHistoryFragment.java index 6b5618f..6b6d537 100644 --- a/app/src/main/java/cn/hugh/bz/gk2/ui/WallpaperHistoryFragment.java +++ b/app/src/main/java/cn/hugh/bz/gk2/ui/WallpaperHistoryFragment.java @@ -5,10 +5,10 @@ import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import android.provider.DocumentsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -81,6 +81,12 @@ public class WallpaperHistoryFragment extends Fragment { public void onItemClick(WallpaperHistory history) { openAlbumForHistory(history); } + + @Override + public void onReuseClick(WallpaperHistory history) { + // 跳转到相册管理页面并定位到该相册 + jumpToAlbum(history.getAlbumId()); + } @Override public void onDelete(WallpaperHistory history) { @@ -93,6 +99,18 @@ public class WallpaperHistoryFragment extends Fragment { btnClearHistory.setOnClickListener(v -> confirmClearHistory()); } + private void jumpToAlbum(String albumId) { + if (albumId == null) return; + + // 设置目标相册ID(需要在 AlbumManagementFragment 中处理) + AlbumManagementFragment.targetAlbumId = albumId; + + // 切换到相册页面 (Index 1) + if (getActivity() instanceof MainActivity) { + ((MainActivity) getActivity()).switchToPage(1); + } + } + private void loadHistory() { historyList = historyManager.loadHistory(); adapter.updateHistory(historyList); @@ -211,16 +229,18 @@ public class WallpaperHistoryFragment extends Fragment { } class HistoryViewHolder extends RecyclerView.ViewHolder { - private final android.widget.ImageView ivThumbnail; + private final ImageView ivThumbnail; private final TextView tvAlbumName; private final TextView tvTimestamp; - private final MaterialButton btnDelete; + private final TextView btnReuse; // Changed to TextView for click area + private final ImageView btnDelete; // Changed to ImageView public HistoryViewHolder(@NonNull View itemView) { super(itemView); ivThumbnail = itemView.findViewById(R.id.ivThumbnail); tvAlbumName = itemView.findViewById(R.id.tvAlbumName); tvTimestamp = itemView.findViewById(R.id.tvTimestamp); + btnReuse = itemView.findViewById(R.id.btnReuse); btnDelete = itemView.findViewById(R.id.btnDelete); } @@ -238,16 +258,23 @@ public class WallpaperHistoryFragment extends Fragment { tvAlbumName.setText(history.getAlbumName()); // 时间戳格式化 - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm", Locale.getDefault()); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault()); String timestamp = sdf.format(new Date(history.getTimestamp())); tvTimestamp.setText(timestamp); - // 卡片点击事件 + // 卡片点击事件 (预览大图) itemView.setOnClickListener(v -> { if (callback != null) { callback.onItemClick(history); } }); + + // 跳转相册按钮 + btnReuse.setOnClickListener(v -> { + if (callback != null) { + callback.onReuseClick(history); + } + }); // 删除按钮 btnDelete.setOnClickListener(v -> { @@ -260,7 +287,8 @@ public class WallpaperHistoryFragment extends Fragment { interface HistoryCallback { void onItemClick(WallpaperHistory history); + void onReuseClick(WallpaperHistory history); void onDelete(WallpaperHistory history); } } -} +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d972bdc..f77e80a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -41,7 +41,7 @@ android:paddingEnd="8dp" android:gravity="center_vertical"> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 792c4bc..707c8bb 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -1,221 +1,288 @@ - + android:background="@color/bg_primary"> - + android:layout_height="match_parent"> - - - - - + android:orientation="vertical" + android:paddingBottom="80dp"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:padding="16dp"> - - + + - - + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="16dp"> - + - + + + + + + + + + + + + - - + android:layout_marginTop="12dp" + app:cardCornerRadius="16dp" + app:cardElevation="0dp" + app:strokeWidth="1dp" + app:strokeColor="#E0E0E0" + app:cardBackgroundColor="@color/white"> + + + + + + + + + + + + + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_wallpaper_history.xml b/app/src/main/res/layout/fragment_wallpaper_history.xml index 3aa873d..27de7dc 100644 --- a/app/src/main/res/layout/fragment_wallpaper_history.xml +++ b/app/src/main/res/layout/fragment_wallpaper_history.xml @@ -1,68 +1,107 @@ - + android:background="@color/bg_primary"> - - + android:background="@android:color/transparent" + app:elevation="0dp"> + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="暂无历史记录 +使用后的壁纸会出现在这里" + android:textSize="16sp" + android:textColor="@color/text_hint" + android:gravity="center" + android:lineSpacingExtra="4dp" + android:visibility="gone" /> - + - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/item_history_card.xml b/app/src/main/res/layout/item_history_card.xml index bc5498a..e957cfa 100644 --- a/app/src/main/res/layout/item_history_card.xml +++ b/app/src/main/res/layout/item_history_card.xml @@ -5,76 +5,105 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="6dp" - app:cardElevation="2dp" - app:cardCornerRadius="12dp" + app:cardElevation="0dp" + app:cardCornerRadius="16dp" + app:cardBackgroundColor="@color/white" + app:strokeWidth="0dp" android:clickable="true" - android:focusable="true"> + android:focusable="true" + android:foreground="?attr/selectableItemBackground"> - - + + android:layout_height="180dp"> - + + + + + + + + + + + - + android:ellipsize="end" /> - - - - - + android:gravity="center_vertical"> + + + + + + + - + \ No newline at end of file diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml index debad96..8a97e02 100644 --- a/app/src/main/res/menu/bottom_nav_menu.xml +++ b/app/src/main/res/menu/bottom_nav_menu.xml @@ -3,30 +3,17 @@ - - - + android:title="首页" /> - + android:title="相册" /> - + android:title="历史" /> - + android:title="设置" /> + \ No newline at end of file