一次不必要的数据清空操作
This commit is contained in:
@@ -15,19 +15,9 @@ import android.os.Looper;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.powerbell.App;
|
||||
@@ -42,6 +32,11 @@ import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
||||
import cc.winboll.studio.powerbell.utils.PermissionUtils;
|
||||
import cc.winboll.studio.powerbell.utils.UriUtil;
|
||||
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class BackgroundSettingsActivity extends WinBoLLActivity implements BackgroundPicturePreviewDialog.IOnRecivedPictureListener {
|
||||
|
||||
@@ -287,10 +282,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "【按钮点击】拍照");
|
||||
if (mfTakePhoto.exists()) {
|
||||
boolean deleteSuccess = mfTakePhoto.delete();
|
||||
LogUtils.d(TAG, "【拍照准备】清理旧文件:" + (deleteSuccess ? "成功" : "失败"));
|
||||
}
|
||||
// 移除:旧文件删除逻辑
|
||||
try {
|
||||
boolean createSuccess = mfTakePhoto.createNewFile();
|
||||
LogUtils.d(TAG, "【拍照准备】创建新文件:" + (createSuccess ? "成功" : "失败"));
|
||||
@@ -390,6 +382,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
|
||||
/**
|
||||
* 双重刷新预览,确保背景加载最新数据
|
||||
* 移除:缓存清空逻辑
|
||||
*/
|
||||
private void doubleRefreshPreview() {
|
||||
LogUtils.d(TAG, "【工具方法】doubleRefreshPreview 开始执行");
|
||||
@@ -398,15 +391,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
return;
|
||||
}
|
||||
|
||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||
if (previewBean != null && previewBean.isUseBackgroundFile()) {
|
||||
String bgPath = previewBean.isUseBackgroundScaledCompressFile()
|
||||
? previewBean.getBackgroundScaledCompressFilePath()
|
||||
: previewBean.getBackgroundFilePath();
|
||||
mBitmapCache.removeCachedBitmap(bgPath);
|
||||
LogUtils.d(TAG, "【双重刷新】已清空工具类缓存:" + bgPath);
|
||||
}
|
||||
|
||||
// 第一重刷新
|
||||
try {
|
||||
mBgSourceUtils.loadSettings();
|
||||
mBackgroundView.loadBackgroundBean(mBgSourceUtils.getPreviewBackgroundBean());
|
||||
@@ -416,6 +401,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
return;
|
||||
}
|
||||
|
||||
// 第二重刷新(延迟执行)
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -523,6 +509,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
|
||||
/**
|
||||
* 保存 Bitmap 到目标文件
|
||||
* 移除:原文件删除逻辑
|
||||
*/
|
||||
private void saveScaledBitmapToFile(Bitmap bitmap, File targetFile) {
|
||||
LogUtils.d(TAG, "【工具方法】saveScaledBitmapToFile 保存图片:" + targetFile.getAbsolutePath());
|
||||
@@ -531,11 +518,6 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetFile.exists()) {
|
||||
boolean deleteSuccess = targetFile.delete();
|
||||
LogUtils.d(TAG, "【图片保存】删除原文件:" + (deleteSuccess ? "成功" : "失败"));
|
||||
}
|
||||
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new BufferedOutputStream(new FileOutputStream(targetFile));
|
||||
@@ -777,6 +759,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
|
||||
/**
|
||||
* 处理选图结果
|
||||
* 移除:缓存清空逻辑
|
||||
*/
|
||||
private void handleSelectPictureResult(int resultCode, Intent data) {
|
||||
LogUtils.d(TAG, "【业务逻辑】handleSelectPictureResult 处理选图结果");
|
||||
@@ -802,7 +785,6 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
|
||||
if (putUriFileToPreviewSource(selectedImage)) {
|
||||
LogUtils.d(TAG, "【选图同步】路径绑定完成");
|
||||
mBitmapCache.removeCachedBitmap(mBgSourceUtils.getPreviewBackgroundBean().getBackgroundFilePath());
|
||||
ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this,
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
@@ -831,11 +813,20 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
|
||||
/**
|
||||
* 将 File 同步到预览 Bean
|
||||
* 保留:核心修复逻辑(更新预览Bean路径)
|
||||
*/
|
||||
boolean putUriFileToPreviewSource(File srcFile) {
|
||||
LogUtils.d(TAG, "【业务逻辑】putUriFileToPreviewSource 同步文件:" + srcFile.getAbsolutePath());
|
||||
LogUtils.d(TAG, String.format("putUriFileToPreviewSource(File srcFile) srcFile %s", srcFile));
|
||||
mBgSourceUtils.loadSettings();
|
||||
File dstFile = new File(mBgSourceUtils.getPreviewBackgroundBean().getBackgroundFilePath());
|
||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||
// 核心修复:将预览Bean的路径更新为选中图片的路径
|
||||
previewBean.setBackgroundFilePath(srcFile.getAbsolutePath());
|
||||
// 同步压缩图路径(避免裁剪输出路径错误)
|
||||
String compressPath = mBgSourceUtils.getBackgroundSourceDirPath() + "/cache/SelectCompress_" + srcFile.getName();
|
||||
previewBean.setBackgroundScaledCompressFilePath(compressPath);
|
||||
mBgSourceUtils.saveSettings(); // 保存修改后的Bean
|
||||
|
||||
File dstFile = new File(previewBean.getBackgroundFilePath());
|
||||
return FileUtils.copyFile(srcFile, dstFile);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user