diff --git a/ios/Podfile.lock b/ios/Podfile.lock index d55e74f..de7f11a 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -43,4 +43,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796 -COCOAPODS: 1.12.1 +COCOAPODS: 1.15.2 diff --git a/lib/configs/collect_ordering.dart b/lib/configs/collect_ordering.dart new file mode 100644 index 0000000..911b2b2 --- /dev/null +++ b/lib/configs/collect_ordering.dart @@ -0,0 +1,13 @@ +import 'map_config.dart'; + +final collectOrderingSetting = MapConfig( + valueName: { + "-datetime_modifier": "收藏时间倒序", + "datetime_modifier": "收藏时间正序", + "-datetime_updated": "更新时间倒序", + "datetime_updated": "更新时间正序", + }, + defaultValue: "-datetime_modifier", + propertyKey: "collect_ordering", + propertyName: "收藏排序", +); diff --git a/lib/configs/configs.dart b/lib/configs/configs.dart index 5a41738..768e811 100644 --- a/lib/configs/configs.dart +++ b/lib/configs/configs.dart @@ -7,6 +7,7 @@ import 'package:kobi/configs/reader_type.dart'; import 'package:kobi/configs/versions.dart'; import 'cache_time.dart'; +import 'collect_ordering.dart'; Future initConfigs() async { await initProxy(); @@ -17,5 +18,6 @@ Future initConfigs() async { await initReaderType(); await initLogin(); await initVersion(); + await collectOrderingSetting.initConfig(); autoCheckNewVersion(); } diff --git a/lib/configs/map_config.dart b/lib/configs/map_config.dart new file mode 100644 index 0000000..ffe4cd4 --- /dev/null +++ b/lib/configs/map_config.dart @@ -0,0 +1,65 @@ +import 'package:event/event.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:kobi/src/rust/api/api.dart'; + +import '../screens/components/commons.dart'; + +class MapConfig { + late final Map valueName; + late final Map nameValue; + final String propertyName; + final String propertyKey; + late String value; + late final Event changeEvent; + final String defaultValue; + + MapConfig({ + required Map valueName, + required this.defaultValue, + required this.propertyKey, + required this.propertyName, + }) { + this.valueName = valueName; + this.nameValue = {}; + valueName.forEach((key, value) { + nameValue[value] = key; + }); + this.changeEvent = Event(); + if (!valueName.containsKey(defaultValue)) { + throw ArgumentError("defaultValue not in valueName"); + } + } + + Future initConfig() async { + value = await loadProperty(k: propertyKey); + if (!valueName.containsKey(value)) { + value = defaultValue; + await saveProperty(k: propertyKey, v: value); + } + } + + Widget configWidget(BuildContext context) { + return StatefulBuilder( + builder: (BuildContext context, void Function(void Function()) setState) { + return ListTile( + title: Text(propertyName), + subtitle: Text(valueName[value] ?? ""), + onTap: () async { + String? result = await chooseMapDialog( + context, + title: propertyName, + values: nameValue, + ); + if (result != null) { + await saveProperty(k: propertyKey, v: result); + value = result; + setState(() {}); + changeEvent.broadcast(); + } + }, + ); + }, + ); + } +} diff --git a/lib/screens/collected_comics_account_screen.dart b/lib/screens/collected_comics_account_screen.dart index 1096bd3..12e43d1 100644 --- a/lib/screens/collected_comics_account_screen.dart +++ b/lib/screens/collected_comics_account_screen.dart @@ -1,9 +1,11 @@ +import 'dart:ffi'; + import 'package:flutter/material.dart'; import 'package:kobi/screens/components/comic_pager.dart'; +import '../configs/collect_ordering.dart'; import '../configs/login.dart'; import '../src/rust/api/api.dart' as api; -import '../src/rust/udto.dart'; import 'components/comic_card.dart'; class CollectedComicsAccountScreen extends StatefulWidget { @@ -20,11 +22,13 @@ class _CollectedComicsAccountScreenState void initState() { super.initState(); loginEvent.subscribe(_setState); + collectOrderingSetting.changeEvent.subscribe(_setState); } @override void dispose() { loginEvent.unsubscribe(_setState); + collectOrderingSetting.changeEvent.unsubscribe(_setState); super.dispose(); } @@ -52,30 +56,33 @@ class _CollectedComicsAccountScreenState if (loginState.state == 2) { return const Center(child: Text("登录失败")); } - return ComicPager(fetcher: (offset, limit) async { - final result = await api.collectFromAccount( - freeType: 1, - ordering: "-datetime_modifier", - offset: offset, - limit: limit, - ); - return CommonPage( - list: result.list - .map((e) => CommonComicInfo( - author: e.comic.author, - cover: e.comic.cover, - imgType: 1, - name: e.comic.name, - pathWord: e.comic.pathWord, - popular: e.comic.popular, - males: e.comic.males, - females: e.comic.females, - )) - .toList(), - total: result.total, - limit: result.limit, - offset: result.offset, - ); - }); + return ComicPager( + key: Key("collected_comics_account:${collectOrderingSetting.value}"), + fetcher: (offset, limit) async { + final result = await api.collectFromAccount( + freeType: 1, + ordering: "-datetime_modifier", + offset: offset, + limit: limit, + ); + return CommonPage( + list: result.list + .map((e) => CommonComicInfo( + author: e.comic.author, + cover: e.comic.cover, + imgType: 1, + name: e.comic.name, + pathWord: e.comic.pathWord, + popular: e.comic.popular, + males: e.comic.males, + females: e.comic.females, + )) + .toList(), + total: result.total, + limit: result.limit, + offset: result.offset, + ); + }, + ); } } diff --git a/lib/screens/local_collect_screen.dart b/lib/screens/local_collect_screen.dart deleted file mode 100644 index cf23444..0000000 --- a/lib/screens/local_collect_screen.dart +++ /dev/null @@ -1,17 +0,0 @@ - import 'package:flutter/material.dart'; - -class LocalCollectScreen extends StatelessWidget { - const LocalCollectScreen({super.key}); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('Local Collect'), - ), - body: Center( - child: Text('Local Collect'), - ), - ); - } - } diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index fb6a325..08d9e4d 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:kobi/configs/collect_ordering.dart'; import '../configs/cache_time.dart'; import '../configs/proxy.dart'; @@ -14,6 +15,7 @@ class SettingsScreen extends StatelessWidget { children: [ proxySetting(), cacheTimeNameSetting(), + collectOrderingSetting.configWidget(context), ], ), );