mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
improve explore page loading
This commit is contained in:
@@ -832,6 +832,7 @@ class ComicList extends StatefulWidget {
|
|||||||
this.errorLeading,
|
this.errorLeading,
|
||||||
this.menuBuilder,
|
this.menuBuilder,
|
||||||
this.controller,
|
this.controller,
|
||||||
|
this.refreshHandlerCallback,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Future<Res<List<Comic>>> Function(int page)? loadPage;
|
final Future<Res<List<Comic>>> Function(int page)? loadPage;
|
||||||
@@ -848,6 +849,8 @@ class ComicList extends StatefulWidget {
|
|||||||
|
|
||||||
final ScrollController? controller;
|
final ScrollController? controller;
|
||||||
|
|
||||||
|
final void Function(VoidCallback c)? refreshHandlerCallback;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ComicList> createState() => ComicListState();
|
State<ComicList> createState() => ComicListState();
|
||||||
}
|
}
|
||||||
@@ -892,10 +895,22 @@ class ComicListState extends State<ComicList> {
|
|||||||
PageStorage.of(context).writeState(context, state);
|
PageStorage.of(context).writeState(context, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
_data.clear();
|
||||||
|
_page = 1;
|
||||||
|
_maxPage = null;
|
||||||
|
_error = null;
|
||||||
|
_nextUrl = null;
|
||||||
|
_loading.clear();
|
||||||
|
storeState();
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
restoreState(PageStorage.of(context).readState(context));
|
restoreState(PageStorage.of(context).readState(context));
|
||||||
|
widget.refreshHandlerCallback?.call(refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(Comic c) {
|
void remove(Comic c) {
|
||||||
|
@@ -242,12 +242,12 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
|
|||||||
|
|
||||||
late final String comicSourceKey;
|
late final String comicSourceKey;
|
||||||
|
|
||||||
int key = 0;
|
|
||||||
|
|
||||||
bool _wantKeepAlive = true;
|
bool _wantKeepAlive = true;
|
||||||
|
|
||||||
var scrollController = ScrollController();
|
var scrollController = ScrollController();
|
||||||
|
|
||||||
|
VoidCallback? refreshHandler;
|
||||||
|
|
||||||
void onSettingsChanged() {
|
void onSettingsChanged() {
|
||||||
var explorePages = appdata.settings["explore_pages"];
|
var explorePages = appdata.settings["explore_pages"];
|
||||||
if (!explorePages.contains(widget.title)) {
|
if (!explorePages.contains(widget.title)) {
|
||||||
@@ -283,24 +283,33 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
|
|||||||
super.build(context);
|
super.build(context);
|
||||||
if (data.loadMultiPart != null) {
|
if (data.loadMultiPart != null) {
|
||||||
return _MultiPartExplorePage(
|
return _MultiPartExplorePage(
|
||||||
key: PageStorageKey(key),
|
key: const PageStorageKey("comic_list"),
|
||||||
data: data,
|
data: data,
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
comicSourceKey: comicSourceKey,
|
comicSourceKey: comicSourceKey,
|
||||||
|
refreshHandlerCallback: (c) {
|
||||||
|
refreshHandler = c;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} else if (data.loadPage != null || data.loadNext != null) {
|
} else if (data.loadPage != null || data.loadNext != null) {
|
||||||
return ComicList(
|
return ComicList(
|
||||||
loadPage: data.loadPage,
|
loadPage: data.loadPage,
|
||||||
loadNext: data.loadNext,
|
loadNext: data.loadNext,
|
||||||
key: PageStorageKey(key),
|
key: const PageStorageKey("comic_list"),
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
|
refreshHandlerCallback: (c) {
|
||||||
|
refreshHandler = c;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} else if (data.loadMixed != null) {
|
} else if (data.loadMixed != null) {
|
||||||
return _MixedExplorePage(
|
return _MixedExplorePage(
|
||||||
data,
|
data,
|
||||||
comicSourceKey,
|
comicSourceKey,
|
||||||
key: ValueKey(key),
|
key: const PageStorageKey("comic_list"),
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
|
refreshHandlerCallback: (c) {
|
||||||
|
refreshHandler = c;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return const Center(
|
return const Center(
|
||||||
@@ -314,9 +323,7 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void refresh() {
|
void refresh() {
|
||||||
setState(() {
|
refreshHandler?.call();
|
||||||
key++;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -338,7 +345,7 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
|
|||||||
|
|
||||||
class _MixedExplorePage extends StatefulWidget {
|
class _MixedExplorePage extends StatefulWidget {
|
||||||
const _MixedExplorePage(this.data, this.sourceKey,
|
const _MixedExplorePage(this.data, this.sourceKey,
|
||||||
{super.key, this.controller});
|
{super.key, this.controller, required this.refreshHandlerCallback});
|
||||||
|
|
||||||
final ExplorePageData data;
|
final ExplorePageData data;
|
||||||
|
|
||||||
@@ -346,12 +353,24 @@ class _MixedExplorePage extends StatefulWidget {
|
|||||||
|
|
||||||
final ScrollController? controller;
|
final ScrollController? controller;
|
||||||
|
|
||||||
|
final void Function(VoidCallback c) refreshHandlerCallback;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_MixedExplorePage> createState() => _MixedExplorePageState();
|
State<_MixedExplorePage> createState() => _MixedExplorePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MixedExplorePageState
|
class _MixedExplorePageState
|
||||||
extends MultiPageLoadingState<_MixedExplorePage, Object> {
|
extends MultiPageLoadingState<_MixedExplorePage, Object> {
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
widget.refreshHandlerCallback(refresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
Iterable<Widget> buildSlivers(BuildContext context, List<Object> data) sync* {
|
Iterable<Widget> buildSlivers(BuildContext context, List<Object> data) sync* {
|
||||||
List<Comic> cache = [];
|
List<Comic> cache = [];
|
||||||
for (var part in data) {
|
for (var part in data) {
|
||||||
@@ -470,6 +489,7 @@ class _MultiPartExplorePage extends StatefulWidget {
|
|||||||
required this.data,
|
required this.data,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required this.comicSourceKey,
|
required this.comicSourceKey,
|
||||||
|
required this.refreshHandlerCallback,
|
||||||
});
|
});
|
||||||
|
|
||||||
final ExplorePageData data;
|
final ExplorePageData data;
|
||||||
@@ -478,6 +498,8 @@ class _MultiPartExplorePage extends StatefulWidget {
|
|||||||
|
|
||||||
final String comicSourceKey;
|
final String comicSourceKey;
|
||||||
|
|
||||||
|
final void Function(VoidCallback c) refreshHandlerCallback;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_MultiPartExplorePage> createState() => _MultiPartExplorePageState();
|
State<_MultiPartExplorePage> createState() => _MultiPartExplorePageState();
|
||||||
}
|
}
|
||||||
@@ -508,6 +530,15 @@ class _MultiPartExplorePageState extends State<_MultiPartExplorePage> {
|
|||||||
PageStorage.of(context).writeState(context, state);
|
PageStorage.of(context).writeState(context, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
setState(() {
|
||||||
|
loading = true;
|
||||||
|
message = null;
|
||||||
|
parts = null;
|
||||||
|
});
|
||||||
|
storeState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -518,6 +549,7 @@ class _MultiPartExplorePageState extends State<_MultiPartExplorePage> {
|
|||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
restoreState(PageStorage.of(context).readState(context));
|
restoreState(PageStorage.of(context).readState(context));
|
||||||
|
widget.refreshHandlerCallback(refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load() async {
|
void load() async {
|
||||||
|
Reference in New Issue
Block a user