Skip to content

Commit

Permalink
***2022/09/24***
Browse files Browse the repository at this point in the history
* self update files clear
  • Loading branch information
Jack251970 committed Sep 24, 2022
1 parent 02a6b8b commit 54bfbc1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/updateLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

***2022/09/24***
* 整合并优化了布局文件
* 加入了更新文件自动清理的功能

***2022/09/23***
* 优化了所有主布局加载速度
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/jack/bookshelf/constant/AppConstant.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.jack.bookshelf.constant;

import android.content.Context;
import android.provider.Settings;

import com.google.gson.reflect.TypeToken;
import com.jack.bookshelf.BuildConfig;
import com.jack.bookshelf.help.FileHelp;
Expand All @@ -15,8 +12,6 @@
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import okhttp3.MediaType;

public class AppConstant {
public static final String ActionStartService = "startService";
public static final String ActionDoneService = "doneService";
Expand All @@ -40,10 +35,4 @@ public class AppConstant {
public static final Pattern EXP_PATTERN = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}");

public static final ScriptEngine SCRIPT_ENGINE = new ScriptEngineManager().getEngineByName("rhino");

public static final MediaType jsonMediaType = MediaType.parse("Content-Type, application/json");

static public String androidId(Context context) {
return Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void forPositiveButton() {
startUpdate(context, updateInfo);
}
}).show(mainView);
clearApkClear();
} else {
callBack.showDialog(/*UpdateDownloadTask.getLastProgress()*/0);
}
Expand Down Expand Up @@ -210,6 +211,23 @@ private String getApkPath(String fileName) {
return Environment.getExternalStoragePublicDirectory(DOWNLOAD_SERVICE).getPath() + File.separator + fileName + ".apk";
}

public void clearApkClear() {
String thisVersion = MApplication.getVersionName().split("\\s")[0];
File[] files = Environment.getExternalStoragePublicDirectory(DOWNLOAD_SERVICE).listFiles();
if(files == null) return;
for (File file : files) {
if (file.isFile()) {
String fileName = file.getName();
if (fileName.endsWith(".apk") && fileName.startsWith(StringUtils.getString(R.string.app_name))) {
String otherVersion = fileName.substring(2, fileName.length()-4);
if (!StringUtils.compareVersion(otherVersion, thisVersion)) {
file.delete();
}
}
}
}
}

public interface CallBack {
void setProgress(int progress);

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/jack/bookshelf/utils/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ object FileUtils {
@JvmOverloads
fun delete(path: String, deleteRootDir: Boolean = false): Boolean {
val file = File(path)

return if (file.exists()) {
delete(file, deleteRootDir)
} else false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jack.bookshelf.help.permission.Permissions;
import com.jack.bookshelf.help.permission.PermissionsCompat;
import com.jack.bookshelf.help.storage.BackupRestoreUi;
import com.jack.bookshelf.help.update.UpdateManager;
import com.jack.bookshelf.model.UpLastChapterModel;
import com.jack.bookshelf.presenter.MainPresenter;
import com.jack.bookshelf.presenter.contract.MainContract;
Expand Down Expand Up @@ -116,7 +117,10 @@ public void delete(String value) {}
}

@Override
protected void initData() {}
protected void initData() {
// 清除下载缓存
UpdateManager.getInstance(this).clearApkClear();
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) { return super.dispatchTouchEvent(ev); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private void initData() {
if (!preferences.getBoolean("importDefaultBookSource", false)) {
String json = null;
try {
InputStream inputStream = MApplication.getInstance().getAssets()
.open("default/bookSource.json");
InputStream inputStream = MApplication.getInstance().getAssets().open("default/bookSource.json");
json = IOUtils.toString(inputStream);
inputStream.close();
} catch (IOException e) {
Expand All @@ -102,9 +101,7 @@ private void initData() {
if (ruleDefaultList != null) {
DbHelper.getDaoSession().getTxtChapterRuleBeanDao().insertOrReplaceInTx(ruleDefaultList);
}
preferences.edit()
.putBoolean("importDefaultTxtRule", ruleDefaultList != null)
.apply();
preferences.edit().putBoolean("importDefaultTxtRule", ruleDefaultList != null).apply();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.jack.bookshelf.R;
import com.jack.bookshelf.databinding.FragmentGeneralSettingBinding;
import com.jack.bookshelf.help.BookshelfHelp;
import com.jack.bookshelf.help.update.UpdateManager;
import com.jack.bookshelf.service.WebService;
import com.jack.bookshelf.view.activity.SettingActivity;
import com.jack.bookshelf.widget.dialog.NumberPickerDialog;
Expand Down Expand Up @@ -92,11 +93,13 @@ private void bindView() {
@Override
public void forNegativeButton() {
BookshelfHelp.clearCaches(false);
UpdateManager.getInstance(settingActivity).clearApkClear();
}

@Override
public void forPositiveButton() {
BookshelfHelp.clearCaches(true);
UpdateManager.getInstance(settingActivity).clearApkClear();
}})
.show(settingActivity.getRoot()));
binding.tvAboutRead.setOnClickListener(v -> openAboutFragment());
Expand Down

0 comments on commit 54bfbc1

Please sign in to comment.