mod: 本地缓存历史记录状态
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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<HisListItem> 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']);
|
||||
}
|
||||
|
||||
// 清空观看历史
|
||||
|
@ -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,
|
||||
|
16
lib/utils/data.dart
Normal file
16
lib/utils/data.dart
Normal file
@ -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']);
|
||||
}
|
||||
}
|
@ -59,3 +59,8 @@ class UserBoxKey {
|
||||
class SettingBoxKey {
|
||||
static const String themeMode = 'themeMode';
|
||||
}
|
||||
|
||||
class LocalCacheKey {
|
||||
// 历史记录暂停状态 默认false
|
||||
static const String historyStatus = 'historyStatus';
|
||||
}
|
||||
|
Reference in New Issue
Block a user