mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
opt: save reply (#1860)
* opt: save reply * opt: reply save switch * remove unneeded sort * clear sub replies [skip ci] --------- Co-authored-by: dom <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
4ad422c3ea
commit
f825f87dc1
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:PiliPlus/models/model_owner.dart';
|
||||
import 'package:PiliPlus/models/user/danmaku_rule_adapter.dart';
|
||||
@@ -9,6 +10,7 @@ import 'package:PiliPlus/utils/accounts/account_type_adapter.dart';
|
||||
import 'package:PiliPlus/utils/accounts/cookie_jar_adapter.dart';
|
||||
import 'package:PiliPlus/utils/path_utils.dart';
|
||||
import 'package:PiliPlus/utils/set_int_adapter.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -20,7 +22,7 @@ abstract final class GStorage {
|
||||
static late final Box<dynamic> setting;
|
||||
static late final Box<dynamic> video;
|
||||
static late final Box<int> watchProgress;
|
||||
static late final Box<Map> reply;
|
||||
static late final Box<Uint8List>? reply;
|
||||
|
||||
static Future<void> init() async {
|
||||
await Hive.initFlutter(path.join(appSupportDirPath, 'hive'));
|
||||
@@ -55,17 +57,24 @@ abstract final class GStorage {
|
||||
Accounts.init(),
|
||||
Hive.openBox<int>(
|
||||
'watchProgress',
|
||||
keyComparator: _intStrKeyComparator,
|
||||
compactionStrategy: (entries, deletedEntries) {
|
||||
return deletedEntries > 4;
|
||||
},
|
||||
).then((res) => watchProgress = res),
|
||||
Hive.openBox<Map>(
|
||||
]);
|
||||
|
||||
if (Pref.saveReply) {
|
||||
reply = await Hive.openBox<Uint8List>(
|
||||
'reply',
|
||||
keyComparator: _intStrKeyComparator,
|
||||
compactionStrategy: (entries, deletedEntries) {
|
||||
return deletedEntries > 10;
|
||||
},
|
||||
).then((res) => reply = res),
|
||||
]);
|
||||
);
|
||||
} else {
|
||||
reply = null;
|
||||
}
|
||||
}
|
||||
|
||||
static String exportAllSettings() {
|
||||
@@ -107,7 +116,7 @@ abstract final class GStorage {
|
||||
video.compact(),
|
||||
Accounts.account.compact(),
|
||||
watchProgress.compact(),
|
||||
reply.compact(),
|
||||
?reply?.compact(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -120,7 +129,26 @@ abstract final class GStorage {
|
||||
video.close(),
|
||||
Accounts.account.close(),
|
||||
watchProgress.close(),
|
||||
reply.close(),
|
||||
?reply?.close(),
|
||||
]);
|
||||
}
|
||||
|
||||
static int _intStrKeyComparator(dynamic k1, dynamic k2) {
|
||||
if (k1 is int) {
|
||||
if (k2 is int) {
|
||||
return k2.compareTo(k1);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (k2 is String) {
|
||||
final lenCompare = k2.length.compareTo((k1 as String).length);
|
||||
if (lenCompare == 0) {
|
||||
return k2.compareTo(k1);
|
||||
} else {
|
||||
return lenCompare;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user