diff --git a/lib/main.dart b/lib/main.dart index e6ab6110..9b12d72d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,6 +9,7 @@ import 'package:pilipala/pages/search/index.dart'; import 'package:pilipala/pages/video/detail/index.dart'; import 'package:pilipala/router/app_pages.dart'; import 'package:pilipala/pages/main/view.dart'; +import 'package:pilipala/utils/data.dart'; import 'package:pilipala/utils/storage.dart'; void main() async { @@ -16,6 +17,7 @@ void main() async { MediaKit.ensureInitialized(); await GStrorage.init(); await Request.setCookie(); + await Data.init(); runApp(const MyApp()); } diff --git a/lib/pages/history/controller.dart b/lib/pages/history/controller.dart index 0b248a08..2d47726b 100644 --- a/lib/pages/history/controller.dart +++ b/lib/pages/history/controller.dart @@ -1,14 +1,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; +import 'package:hive/hive.dart'; import 'package:pilipala/http/user.dart'; import 'package:pilipala/models/user/history.dart'; +import 'package:pilipala/utils/storage.dart'; class HistoryController extends GetxController { final ScrollController scrollController = ScrollController(); RxList historyList = [HisListItem()].obs; bool isLoadingMore = false; RxBool pauseStatus = false.obs; + Box localCache = GStrorage.localCache; @override void onInit() { @@ -78,10 +81,11 @@ class HistoryController extends GetxController { ); } -// 观看历史暂停状态 + // 观看历史暂停状态 Future historyStatus() async { var res = await UserHttp.historyStatus(); pauseStatus.value = res.data['data']; + localCache.put(LocalCacheKey.historyStatus, res.data['data']); } // 清空观看历史 diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index 8158a984..4c4c3085 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -54,6 +54,7 @@ class VideoDetailController extends GetxController RxString bgCover = ''.obs; Box user = GStrorage.user; + Box localCache = GStrorage.localCache; @override void onInit() { @@ -149,6 +150,9 @@ class VideoDetailController extends GetxController if (user.get(UserBoxKey.userMid) == null) { return; } + if (localCache.get(LocalCacheKey.historyStatus) == true) { + return; + } Duration progress = meeduPlayerController.position.value; await VideoHttp.heartBeat( bvid: bvid, diff --git a/lib/utils/data.dart b/lib/utils/data.dart new file mode 100644 index 00000000..e6ab2ae3 --- /dev/null +++ b/lib/utils/data.dart @@ -0,0 +1,16 @@ +import 'package:hive/hive.dart'; +import 'package:pilipala/http/user.dart'; + +import 'storage.dart'; + +class Data { + static Future init() async { + await historyStatus(); + } + + static Future historyStatus() async { + Box localCache = GStrorage.localCache; + var res = await UserHttp.historyStatus(); + localCache.put(LocalCacheKey.historyStatus, res.data['data']); + } +} diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index df3c92b8..899ba485 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -59,3 +59,8 @@ class UserBoxKey { class SettingBoxKey { static const String themeMode = 'themeMode'; } + +class LocalCacheKey { + // 历史记录暂停状态 默认false + static const String historyStatus = 'historyStatus'; +}