local history

This commit is contained in:
wgh19
2024-06-12 15:43:06 +08:00
parent 759d6959b5
commit d247455c19
7 changed files with 383 additions and 28 deletions

View File

@@ -14,6 +14,7 @@ import 'package:pixes/components/page_route.dart';
import 'package:pixes/components/title_bar.dart';
import 'package:pixes/components/user_preview.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/history.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/network/download.dart';
import 'package:pixes/network/network.dart';
@@ -44,6 +45,8 @@ class IllustGalleryPage extends StatefulWidget {
final String? nextUrl;
static var cachedHistoryIds = <int>{};
@override
State<IllustGalleryPage> createState() => _IllustGalleryPageState();
}
@@ -68,6 +71,16 @@ class _IllustGalleryPageState extends State<IllustGalleryPage> {
super.initState();
}
@override
void dispose() {
if(IllustGalleryPage.cachedHistoryIds.length > 5) {
Network().sendHistory(
IllustGalleryPage.cachedHistoryIds.toList().reversed.toList());
IllustGalleryPage.cachedHistoryIds.clear();
}
super.dispose();
}
void nextPage() {
var length = illusts.length;
if (controller.page == length - 1) return;
@@ -169,6 +182,10 @@ class _IllustPageState extends State<IllustPage> {
widget.illust.author.isFollowed = v;
});
};
HistoryManager().addHistory(widget.illust);
if(appdata.account!.user.isPremium) {
IllustGalleryPage.cachedHistoryIds.add(widget.illust.id);
}
super.initState();
}