logo和名称替换
This commit is contained in:
Vendored
+18
-10
@@ -3,11 +3,12 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart' show DefaultCacheManager;
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart'
|
||||
show DefaultCacheManager;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:hgmj/tools_base/image/image_disk_cache.dart';
|
||||
import 'package:hgmj/tools_base/video_download/video_download_manager.dart';
|
||||
import 'package:wydj/tools_base/image/image_disk_cache.dart';
|
||||
import 'package:wydj/tools_base/video_download/video_download_manager.dart';
|
||||
|
||||
import '../../hj_utils/file_util.dart';
|
||||
import '../../hj_utils/video_cache_manager.dart';
|
||||
@@ -16,11 +17,13 @@ import 'image_cache_manager.dart';
|
||||
///加载缓存 统计缓存大小
|
||||
Future<String> loadCache() async {
|
||||
double total = 0;
|
||||
Directory videoCacheDir = Directory(await VideoCacheManager().getFilePath() ?? '');
|
||||
Directory videoCacheDir =
|
||||
Directory(await VideoCacheManager().getFilePath() ?? '');
|
||||
if (await videoCacheDir.exists()) {
|
||||
total += await _getTotalSizeOfFilesInDir(videoCacheDir);
|
||||
}
|
||||
Directory videoLoadedDir = Directory(await VideoDownloadManager.instance.cacheDir());
|
||||
Directory videoLoadedDir =
|
||||
Directory(await VideoDownloadManager.instance.cacheDir());
|
||||
if (await videoLoadedDir.exists()) {
|
||||
total += await _getTotalSizeOfFilesInDir(videoLoadedDir);
|
||||
}
|
||||
@@ -61,7 +64,8 @@ Future<double> _getTotalSizeOfFilesInDir(final FileSystemEntity file) async {
|
||||
double total = 0;
|
||||
// recursive 已一次性列出所有后代文件,只累加 File 即可;不再对子目录二次递归,
|
||||
// 避免同一文件被重复计入导致缓存大小翻倍。异步 list 替代 listSync,避免大目录阻塞 UI。
|
||||
await for (final child in file.list(recursive: true, followLinks: false)) {
|
||||
await for (final child
|
||||
in file.list(recursive: true, followLinks: false)) {
|
||||
if (child is File) {
|
||||
total += (await child.length()).toDouble();
|
||||
}
|
||||
@@ -95,10 +99,12 @@ Future clearCacheIfNeed({bool force = false, bool isHandle = false}) async {
|
||||
//await VideoDownloadManager.instance.emptyCache();
|
||||
// await ImageDiskCache.emptyCache();
|
||||
}
|
||||
debugPrint(" ------------------ VideoCacheManager ImageCacheManager clear completely");
|
||||
debugPrint(
|
||||
" ------------------ VideoCacheManager ImageCacheManager clear completely");
|
||||
} else {
|
||||
double total = 0;
|
||||
Directory videoCacheDir = Directory(await VideoCacheManager().getFilePath() ?? '');
|
||||
Directory videoCacheDir =
|
||||
Directory(await VideoCacheManager().getFilePath() ?? '');
|
||||
if (await videoCacheDir.exists()) {
|
||||
total += await _getTotalSizeOfFilesInDir(videoCacheDir);
|
||||
}
|
||||
@@ -107,7 +113,8 @@ Future clearCacheIfNeed({bool force = false, bool isHandle = false}) async {
|
||||
await VideoCacheManager().emptyCache();
|
||||
}
|
||||
total = 0;
|
||||
Directory imageCacheDir = Directory(await ImageCacheManager().getFilePath());
|
||||
Directory imageCacheDir =
|
||||
Directory(await ImageCacheManager().getFilePath());
|
||||
if (await imageCacheDir.exists()) {
|
||||
total += await _getTotalSizeOfFilesInDir(imageCacheDir);
|
||||
}
|
||||
@@ -124,7 +131,8 @@ clearAllCache(bool isHandle) async {
|
||||
PaintingBinding.instance.imageCache.clear();
|
||||
PaintingBinding.instance.imageCache.clearLiveImages();
|
||||
|
||||
debugPrint(" ----------- PaintingBinding.instance.imageCache.clearLiveImages()");
|
||||
debugPrint(
|
||||
" ----------- PaintingBinding.instance.imageCache.clearLiveImages()");
|
||||
}
|
||||
|
||||
///递归方式删除目录
|
||||
|
||||
+9
-5
@@ -2,7 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:hgmj/tools_base/debug_log.dart';
|
||||
import 'package:wydj/tools_base/debug_log.dart';
|
||||
import 'package:http/http.dart' hide Response;
|
||||
|
||||
import '../../extension/extensions.dart';
|
||||
@@ -16,7 +16,8 @@ class DioFileService extends FileService {
|
||||
final _dio = createDio();
|
||||
|
||||
@override
|
||||
Future<FileServiceResponse> get(String url, {Map<String, String>? headers = const {}}) async {
|
||||
Future<FileServiceResponse> get(String url,
|
||||
{Map<String, String>? headers = const {}}) async {
|
||||
// cancelToken 用文件名注册、下载结束后按同一 key 移除
|
||||
//(原来 createToken 用 name 而 remove 用 url,key 不一致:既移不掉导致泄漏,又会 firstWhere 抛 StateError)
|
||||
final name = FileUtil.getName(url);
|
||||
@@ -35,7 +36,8 @@ class DioFileService extends FileService {
|
||||
Response<ResponseBody>? resp;
|
||||
try {
|
||||
debugLog("DioFileService get: $url");
|
||||
resp = await _dio.get<ResponseBody>(url, cancelToken: token, options: options);
|
||||
resp = await _dio.get<ResponseBody>(url,
|
||||
cancelToken: token, options: options);
|
||||
} catch (e) {
|
||||
debugLog("DioFileService get error: $url -> $e");
|
||||
} finally {
|
||||
@@ -53,9 +55,11 @@ class DioFileService extends FileService {
|
||||
if (values.notEmpty()) respHeaders[key] = values.first;
|
||||
});
|
||||
// Content-Length 可能缺失/非数字,安全解析(原 contentLengthS[0] 在空串时会 RangeError);缺失传 null 表示长度未知
|
||||
final contentLength = int.tryParse(respHeaders[Headers.contentLengthHeader] ?? '');
|
||||
final contentLength =
|
||||
int.tryParse(respHeaders[Headers.contentLengthHeader] ?? '');
|
||||
|
||||
debugLog("DioFileService resp($statusCode): $url contentLength:$contentLength");
|
||||
debugLog(
|
||||
"DioFileService resp($statusCode): $url contentLength:$contentLength");
|
||||
|
||||
return HttpGetResponse(StreamedResponse(
|
||||
resp.data!.stream,
|
||||
|
||||
+12
-7
@@ -1,9 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hgmj/hj_model/drama/drama_models.dart';
|
||||
import 'package:hgmj/hj_model/drama_media_info.dart';
|
||||
import 'package:hgmj/tools_base/cache/history/base_history_record_store.dart';
|
||||
import 'package:hgmj/tools_base/debug_log.dart';
|
||||
import 'package:wydj/hj_model/drama/drama_models.dart';
|
||||
import 'package:wydj/hj_model/drama_media_info.dart';
|
||||
import 'package:wydj/tools_base/cache/history/base_history_record_store.dart';
|
||||
import 'package:wydj/tools_base/debug_log.dart';
|
||||
|
||||
/// 短剧观看记录:纯本地,不依赖后端。一部剧一行(看到哪一集、第几秒 + 剧信息快照),
|
||||
/// 最多留 [BaseHistoryRecordStore.maxRows] 条,超了先淘汰最久没看的那部。
|
||||
@@ -114,7 +114,8 @@ class DramaResumeStore extends BaseHistoryRecordStore {
|
||||
record(
|
||||
mediaId: mediaId,
|
||||
//空 contentId 会被 record 挡掉,那样这次刷新就白记了,退回当前这一集
|
||||
contentId: last?.contentId.isNotEmpty == true ? last!.contentId : contentId,
|
||||
contentId:
|
||||
last?.contentId.isNotEmpty == true ? last!.contentId : contentId,
|
||||
seconds: last?.progressSeconds ?? 0,
|
||||
drama: drama ?? last?.drama,
|
||||
);
|
||||
@@ -130,7 +131,10 @@ class DramaResumeStore extends BaseHistoryRecordStore {
|
||||
}) {
|
||||
//空串和 null 一样要挡:contentId 为空的记录谁都匹配不上,
|
||||
//却会把这部剧上一条好记录顶掉,还会让 _resumeIndex 白翻完整部剧的分页
|
||||
if (mediaId == null || mediaId.isEmpty || contentId == null || contentId.isEmpty) return;
|
||||
if (mediaId == null ||
|
||||
mediaId.isEmpty ||
|
||||
contentId == null ||
|
||||
contentId.isEmpty) return;
|
||||
final item = DramaResume(
|
||||
mediaId: mediaId,
|
||||
contentId: contentId,
|
||||
@@ -141,7 +145,8 @@ class DramaResumeStore extends BaseHistoryRecordStore {
|
||||
_put(mediaId, item);
|
||||
//不等落盘:主键冲突走 REPLACE,顺带把 create_time 刷成本次时间,超量时最久没看的先淘汰。
|
||||
//必须接住异常,否则 db 出错会变成没人管的 async error
|
||||
save(modelId: mediaId, modelDataJson: jsonEncode(item.toJson())).catchError((e) {
|
||||
save(modelId: mediaId, modelDataJson: jsonEncode(item.toJson()))
|
||||
.catchError((e) {
|
||||
debugLog('短剧续播记录写入失败', e.toString());
|
||||
return false;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user