改进UI: 更新设置页面图标,添加关于弹窗,优化镜像更新功能
This commit is contained in:
@@ -14,6 +14,7 @@ import androidx.core.os.HandlerCompat;
|
||||
|
||||
import com.fongmi.android.tv.event.EventIndex;
|
||||
import com.fongmi.android.tv.ui.activity.CrashActivity;
|
||||
import com.fongmi.android.tv.utils.CacheCleaner;
|
||||
import com.fongmi.android.tv.utils.Notify;
|
||||
import com.fongmi.hook.Hook;
|
||||
import com.github.catvod.Init;
|
||||
@@ -41,6 +42,7 @@ public class App extends Application {
|
||||
private final Gson gson;
|
||||
private final long time;
|
||||
private Hook hook;
|
||||
private final Runnable cleanTask;
|
||||
|
||||
public App() {
|
||||
instance = this;
|
||||
@@ -48,6 +50,7 @@ public class App extends Application {
|
||||
handler = HandlerCompat.createAsync(Looper.getMainLooper());
|
||||
time = System.currentTimeMillis();
|
||||
gson = new Gson();
|
||||
cleanTask = this::checkCacheClean;
|
||||
}
|
||||
|
||||
public static App get() {
|
||||
@@ -119,6 +122,10 @@ public class App extends Application {
|
||||
OkHttp.get().setDoh(Doh.objectFrom(Setting.getDoh()));
|
||||
EventBus.builder().addIndex(new EventIndex()).installDefaultEventBus();
|
||||
CaocConfig.Builder.create().backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT).errorActivity(CrashActivity.class).apply();
|
||||
|
||||
// 初始化自动缓存清理
|
||||
initCacheCleaner();
|
||||
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||
@@ -133,6 +140,8 @@ public class App extends Application {
|
||||
@Override
|
||||
public void onActivityResumed(@NonNull Activity activity) {
|
||||
if (activity != activity()) setActivity(activity);
|
||||
// 应用回到前台时检查缓存
|
||||
checkCacheClean();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,6 +165,20 @@ public class App extends Application {
|
||||
});
|
||||
}
|
||||
|
||||
private void initCacheCleaner() {
|
||||
CacheCleaner cleaner = CacheCleaner.get();
|
||||
cleaner.setCacheThreshold(200 * 1024 * 1024); // 固定使用200MB阈值
|
||||
|
||||
// 定期检查缓存 (每30分钟)
|
||||
post(cleanTask, 30 * 60 * 1000);
|
||||
}
|
||||
|
||||
private void checkCacheClean() {
|
||||
CacheCleaner.get().checkAndClean();
|
||||
// 每30分钟定期检查缓存
|
||||
post(cleanTask, 30 * 60 * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageManager getPackageManager() {
|
||||
return hook != null ? hook : getBaseContext().getPackageManager();
|
||||
|
||||
@@ -201,6 +201,14 @@ public class Setting {
|
||||
Prefers.put("update", update);
|
||||
}
|
||||
|
||||
public static boolean getUseCnMirror() {
|
||||
return Prefers.getBoolean("use_cn_mirror", false);
|
||||
}
|
||||
|
||||
public static void putUseCnMirror(boolean useCnMirror) {
|
||||
Prefers.put("use_cn_mirror", useCnMirror);
|
||||
}
|
||||
|
||||
public static boolean isCaption() {
|
||||
return Prefers.getBoolean("caption");
|
||||
}
|
||||
|
||||
@@ -267,6 +267,19 @@ public class Config {
|
||||
Keep.delete(getId());
|
||||
}
|
||||
|
||||
public Config copy() {
|
||||
Config copy = new Config();
|
||||
copy.setType(type);
|
||||
copy.setUrl(url);
|
||||
copy.setJson(json);
|
||||
copy.setName(TextUtils.isEmpty(name) ? url + " 副本" : name + " 副本");
|
||||
copy.setLogo(logo);
|
||||
copy.setHome(home);
|
||||
copy.setParse(parse);
|
||||
copy.setTime(System.currentTimeMillis());
|
||||
return copy;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.fongmi.android.tv.utils;
|
||||
|
||||
import android.os.StatFs;
|
||||
|
||||
import com.fongmi.android.tv.App;
|
||||
import com.fongmi.android.tv.impl.Callback;
|
||||
import com.github.catvod.utils.Path;
|
||||
|
||||
/**
|
||||
* 缓存自动清理管理器
|
||||
*/
|
||||
public class CacheCleaner {
|
||||
|
||||
// 默认缓存清理阈值 200MB
|
||||
private static final long DEFAULT_CACHE_THRESHOLD = 200 * 1024 * 1024;
|
||||
// 最小保留空间 500MB
|
||||
private static final long MIN_FREE_SPACE = 500 * 1024 * 1024;
|
||||
// 单例实例
|
||||
private static CacheCleaner instance;
|
||||
// 缓存清理阈值
|
||||
private long cacheThreshold;
|
||||
|
||||
private CacheCleaner() {
|
||||
this.cacheThreshold = DEFAULT_CACHE_THRESHOLD;
|
||||
}
|
||||
|
||||
public static CacheCleaner get() {
|
||||
if (instance == null) {
|
||||
synchronized (CacheCleaner.class) {
|
||||
if (instance == null) {
|
||||
instance = new CacheCleaner();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存阈值
|
||||
* @param threshold 阈值大小(字节)
|
||||
*/
|
||||
public void setCacheThreshold(long threshold) {
|
||||
this.cacheThreshold = threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查缓存,如果超过阈值则清理
|
||||
*/
|
||||
public void checkAndClean() {
|
||||
App.execute(() -> {
|
||||
try {
|
||||
// 获取当前缓存大小
|
||||
long cacheSize = FileUtil.getDirectorySize(Path.cache());
|
||||
// 获取剩余存储空间
|
||||
long freeSpace = getAvailableStorageSpace();
|
||||
|
||||
// 如果缓存超过阈值或可用空间低于最小要求,清理缓存
|
||||
if (cacheSize > cacheThreshold || freeSpace < MIN_FREE_SPACE) {
|
||||
cleanCache();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
private void cleanCache() {
|
||||
FileUtil.clearCache(new Callback() {
|
||||
@Override
|
||||
public void success() {
|
||||
// 缓存清理成功
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备可用存储空间
|
||||
* @return 可用空间(字节)
|
||||
*/
|
||||
private long getAvailableStorageSpace() {
|
||||
try {
|
||||
StatFs stat = new StatFs(Path.cache().getPath());
|
||||
return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,8 @@
|
||||
<string name="setting_doh">DoH</string>
|
||||
<string name="setting_proxy">Proxy</string>
|
||||
<string name="setting_cache">缓存</string>
|
||||
<string name="setting_auto_clean">自动清理缓存</string>
|
||||
<string name="setting_cache_threshold">清理阈值</string>
|
||||
<string name="setting_backup">备份</string>
|
||||
<string name="setting_restore">恢复</string>
|
||||
<string name="setting_version">版本</string>
|
||||
@@ -88,6 +90,8 @@
|
||||
<string name="setting_app">应用设置</string>
|
||||
<string name="setting_network">网络设置</string>
|
||||
<string name="setting_data">数据管理</string>
|
||||
<string name="app_version">v3.0.3</string>
|
||||
<string name="about_github">在GitHub上查看</string>
|
||||
|
||||
<!-- Backup & Restore -->
|
||||
<string name="restore_select">选择备份</string>
|
||||
@@ -143,6 +147,7 @@
|
||||
<string name="error_cast_file">不支持的文件格式</string>
|
||||
<string name="error_device_limit">设备授权数已达上限</string>
|
||||
<string name="error_live_empty">该订阅无直播内容</string>
|
||||
<string name="error_no_live">当前源没有直播内容</string>
|
||||
|
||||
<!-- Update -->
|
||||
<string name="update_version">发现新版本 <xliff:g name="name">%s</xliff:g></string>
|
||||
|
||||
@@ -76,7 +76,9 @@
|
||||
<string name="setting_size">圖片尺寸</string>
|
||||
<string name="setting_doh">DoH</string>
|
||||
<string name="setting_proxy">Proxy</string>
|
||||
<string name="setting_cache">暫存</string>
|
||||
<string name="setting_cache">緩存</string>
|
||||
<string name="setting_auto_clean">自動清理緩存</string>
|
||||
<string name="setting_cache_threshold">清理閾值</string>
|
||||
<string name="setting_backup">備份</string>
|
||||
<string name="setting_restore">還原</string>
|
||||
<string name="setting_version">版本</string>
|
||||
@@ -87,6 +89,8 @@
|
||||
<string name="setting_app">應用設置</string>
|
||||
<string name="setting_network">網絡設置</string>
|
||||
<string name="setting_data">數據管理</string>
|
||||
<string name="app_version">v3.0.3</string>
|
||||
<string name="about_github">在GitHub上查看</string>
|
||||
|
||||
<!-- Backup & Restore -->
|
||||
<string name="restore_select">選擇備份</string>
|
||||
@@ -138,6 +142,10 @@
|
||||
<string name="error_play_timeout">連線逾時</string>
|
||||
<string name="error_detail">暫無播放資料</string>
|
||||
<string name="error_empty">找不到資料</string>
|
||||
<string name="error_cast_file">不支持的檔案格式</string>
|
||||
<string name="error_device_limit">設備授權數已達上限</string>
|
||||
<string name="error_live_empty">該訂閱無直播內容</string>
|
||||
<string name="error_no_live">當前源沒有直播內容</string>
|
||||
|
||||
<!-- Update -->
|
||||
<string name="update_version">發現新版本 <xliff:g name="name">%s</xliff:g></string>
|
||||
@@ -204,4 +212,8 @@
|
||||
<item>選擇字幕</item>
|
||||
</string-array>
|
||||
|
||||
<string name="config_set_current">已設為當前點播源</string>
|
||||
|
||||
<string name="source_hint">點我添加源</string>
|
||||
|
||||
</resources>
|
||||
@@ -82,13 +82,17 @@
|
||||
<string name="setting_size">Image size</string>
|
||||
<string name="setting_doh">DoH</string>
|
||||
<string name="setting_proxy">Proxy</string>
|
||||
<string name="setting_cache">Cache</string>
|
||||
<string name="setting_backup">Backup</string>
|
||||
<string name="setting_restore">Restore</string>
|
||||
<string name="setting_version">Version</string>
|
||||
<string name="setting_cache">缓存</string>
|
||||
<string name="setting_auto_clean">Auto Clean Cache</string>
|
||||
<string name="setting_cache_threshold">Cache Threshold</string>
|
||||
<string name="setting_backup">备份</string>
|
||||
<string name="setting_restore">恢复</string>
|
||||
<string name="setting_version">版本</string>
|
||||
<string name="setting_choose">Choose</string>
|
||||
<string name="setting_off">Off</string>
|
||||
<string name="setting_on">On</string>
|
||||
<string name="app_version">v3.0.3</string>
|
||||
<string name="about_github">View on GitHub</string>
|
||||
|
||||
<!-- Backup & Restore -->
|
||||
<string name="restore_select">Select backup</string>
|
||||
@@ -146,6 +150,7 @@
|
||||
<string name="error_cast_file">Unsupported file format</string>
|
||||
<string name="error_device_limit">Device authorization limit reached</string>
|
||||
<string name="error_live_empty">This subscription has no live content</string>
|
||||
<string name="error_no_live">Current source has no live content</string>
|
||||
<string name="error_empty">Not found</string>
|
||||
<string name="error_detail">No play data</string>
|
||||
<string name="error_play_flag">No flag data</string>
|
||||
@@ -224,4 +229,10 @@
|
||||
|
||||
<string name="config_set_current">已设为当前点播源</string>
|
||||
|
||||
<string name="remember_setting">Remember settings</string>
|
||||
<string name="target_size">Target size</string>
|
||||
<string name="scan_result">Scan result</string>
|
||||
|
||||
<string name="source_hint">点我添加源</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user