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