refactor: 移除壁纸页面重复的"立即更换"按钮,只保留"下一张"
- 修改布局文件,移除 btnChangeNow - 调整 btnNext 约束和样式(改为实心按钮) - 删除 btnChangeNow 相关代码: - 字段声明 - 初始化和点击监听 - changeWallpaperNow() 方法 - showNoWallpaper() 和 showError() 中的引用 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
37aa54989e
commit
06625f24dd
2 files changed
+2
-50
No files matched your search
@@ -31,7 +31,6 @@ public class CurrentWallpaperFragment extends Fragment {
|
|||||||
private ImageView ivWallpaper;
|
private ImageView ivWallpaper;
|
||||||
private TextView tvWallpaperPath;
|
private TextView tvWallpaperPath;
|
||||||
private TextView tvWallpaperSize;
|
private TextView tvWallpaperSize;
|
||||||
private Button btnChangeNow;
|
|
||||||
private Button btnNext;
|
private Button btnNext;
|
||||||
private Button btnOpenInGallery;
|
private Button btnOpenInGallery;
|
||||||
|
|
||||||
@@ -60,11 +59,9 @@ public class CurrentWallpaperFragment extends Fragment {
|
|||||||
ivWallpaper = view.findViewById(R.id.ivWallpaper);
|
ivWallpaper = view.findViewById(R.id.ivWallpaper);
|
||||||
tvWallpaperPath = view.findViewById(R.id.tvWallpaperPath);
|
tvWallpaperPath = view.findViewById(R.id.tvWallpaperPath);
|
||||||
tvWallpaperSize = view.findViewById(R.id.tvWallpaperSize);
|
tvWallpaperSize = view.findViewById(R.id.tvWallpaperSize);
|
||||||
btnChangeNow = view.findViewById(R.id.btnChangeNow);
|
|
||||||
btnNext = view.findViewById(R.id.btnNext);
|
btnNext = view.findViewById(R.id.btnNext);
|
||||||
btnOpenInGallery = view.findViewById(R.id.btnOpenInGallery);
|
btnOpenInGallery = view.findViewById(R.id.btnOpenInGallery);
|
||||||
|
|
||||||
btnChangeNow.setOnClickListener(v -> changeWallpaperNow());
|
|
||||||
btnNext.setOnClickListener(v -> showNextWallpaper());
|
btnNext.setOnClickListener(v -> showNextWallpaper());
|
||||||
btnOpenInGallery.setOnClickListener(v -> openInGallery());
|
btnOpenInGallery.setOnClickListener(v -> openInGallery());
|
||||||
ivWallpaper.setOnClickListener(v -> openInGallery());
|
ivWallpaper.setOnClickListener(v -> openInGallery());
|
||||||
@@ -101,7 +98,6 @@ public class CurrentWallpaperFragment extends Fragment {
|
|||||||
ivWallpaper.setImageDrawable(null);
|
ivWallpaper.setImageDrawable(null);
|
||||||
tvWallpaperPath.setText("尚未设置壁纸");
|
tvWallpaperPath.setText("尚未设置壁纸");
|
||||||
tvWallpaperSize.setText("");
|
tvWallpaperSize.setText("");
|
||||||
btnChangeNow.setEnabled(false);
|
|
||||||
btnNext.setEnabled(false);
|
btnNext.setEnabled(false);
|
||||||
btnOpenInGallery.setEnabled(false);
|
btnOpenInGallery.setEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -110,43 +106,10 @@ public class CurrentWallpaperFragment extends Fragment {
|
|||||||
ivWallpaper.setImageDrawable(null);
|
ivWallpaper.setImageDrawable(null);
|
||||||
tvWallpaperPath.setText("加载壁纸失败");
|
tvWallpaperPath.setText("加载壁纸失败");
|
||||||
tvWallpaperSize.setText("");
|
tvWallpaperSize.setText("");
|
||||||
btnChangeNow.setEnabled(false);
|
|
||||||
btnNext.setEnabled(false);
|
btnNext.setEnabled(false);
|
||||||
btnOpenInGallery.setEnabled(false);
|
btnOpenInGallery.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeWallpaperNow() {
|
|
||||||
android.util.Log.i("CurrentWallpaperFragment", "changeWallpaperNow() called");
|
|
||||||
cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log("CurrentWallpaperFragment", "changeWallpaperNow() called");
|
|
||||||
|
|
||||||
cn.hugh.bz.gk2.model.AppConfig config = prefs.loadConfig();
|
|
||||||
|
|
||||||
android.util.Log.i("CurrentWallpaperFragment", "Selected folders count: " + config.getSelectedFolders().size());
|
|
||||||
cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log("CurrentWallpaperFragment", "Selected folders count: " + config.getSelectedFolders().size());
|
|
||||||
|
|
||||||
if (config.getSelectedFolders().isEmpty()) {
|
|
||||||
android.util.Log.w("CurrentWallpaperFragment", "No folders selected, showing toast");
|
|
||||||
Toast.makeText(requireContext(), "请先选择文件夹", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
android.util.Log.i("CurrentWallpaperFragment", "changeWallpaperNow: sending broadcast");
|
|
||||||
cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log("CurrentWallpaperFragment", "changeWallpaperNow: sending broadcast");
|
|
||||||
|
|
||||||
// 发送广播通知壁纸服务立即更换壁纸
|
|
||||||
Intent intent = new Intent("cn.hugh.bz.gk2.ACTION_CHANGE_WALLPAPER");
|
|
||||||
intent.putExtra("force_change", true); // 用户主动触发
|
|
||||||
intent.putExtra("scheduled", false); // 非定时触发
|
|
||||||
requireActivity().sendBroadcast(intent);
|
|
||||||
|
|
||||||
Toast.makeText(requireContext(), "壁纸已更换", Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
// 延迟刷新预览
|
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
|
||||||
loadCurrentWallpaper();
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showNextWallpaper() {
|
private void showNextWallpaper() {
|
||||||
android.util.Log.i("CurrentWallpaperFragment", "showNextWallpaper() called");
|
android.util.Log.i("CurrentWallpaperFragment", "showNextWallpaper() called");
|
||||||
cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log("CurrentWallpaperFragment", "showNextWallpaper() called");
|
cn.hugh.bz.gk2.utils.FileLogger.getInstance(requireContext()).log("CurrentWallpaperFragment", "showNextWallpaper() called");
|
||||||
|
|||||||
@@ -52,24 +52,13 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnChangeNow"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="立即更换"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvWallpaperSize"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnNext"
|
android:id="@+id/btnNext"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="下一张"
|
android:text="下一张"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="16dp"
|
||||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
app:layout_constraintTop_toBottomOf="@id/tvWallpaperSize"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btnChangeNow"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user