diff --git a/lib/pages/dynamics/controller.dart b/lib/pages/dynamics/controller.dart index d8417d506..3ff3ace2b 100644 --- a/lib/pages/dynamics/controller.dart +++ b/lib/pages/dynamics/controller.dart @@ -50,17 +50,21 @@ class DynamicsController extends GetxController { }, ]; bool flag = false; - RxInt initialValue = 1.obs; + RxInt initialValue = 0.obs; Box userInfoCache = GStrorage.userInfo; RxBool userLogin = false.obs; var userInfo; RxBool isLoadingDynamic = false.obs; + Box setting = GStrorage.setting; @override void onInit() { userInfo = userInfoCache.get('userInfoCache'); userLogin.value = userInfo != null; super.onInit(); + initialValue.value = + setting.get(SettingBoxKey.defaultDynamicType, defaultValue: 0); + dynamicsType = DynamicsType.values[initialValue.value].obs; } Future queryFollowDynamic({type = 'init'}) async { @@ -99,7 +103,7 @@ class DynamicsController extends GetxController { } onSelectType(value) async { - dynamicsType.value = filterTypeList[value - 1]['value']; + dynamicsType.value = filterTypeList[value]['value']; dynamicsList.value = [DynamicItemModel()]; page = 1; initialValue.value = value; @@ -247,7 +251,7 @@ class DynamicsController extends GetxController { void resetSearch() { mid.value = -1; dynamicsType.value = DynamicsType.values[0]; - initialValue.value = 1; + initialValue.value = 0; SmartDialog.showToast('还原默认加载'); dynamicsList.value = [DynamicItemModel()]; queryFollowDynamic(); diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index a29e1f915..20a14e6a7 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -132,7 +132,7 @@ class _DynamicsPageState extends State initialValue: _dynamicsController.initialValue.value, children: { - 1: Text( + 0: Text( '全部', style: TextStyle( fontSize: Theme.of(context) @@ -140,19 +140,19 @@ class _DynamicsPageState extends State .labelMedium! .fontSize), ), - 2: Text('投稿', + 1: Text('投稿', style: TextStyle( fontSize: Theme.of(context) .textTheme .labelMedium! .fontSize)), - 3: Text('番剧', + 2: Text('番剧', style: TextStyle( fontSize: Theme.of(context) .textTheme .labelMedium! .fontSize)), - 4: Text('专栏', + 3: Text('专栏', style: TextStyle( fontSize: Theme.of(context) .textTheme diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index 44646bb5f..29ad5aac2 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; +import 'package:pilipala/models/common/dynamics_type.dart'; import 'package:pilipala/models/common/reply_sort_type.dart'; import 'package:pilipala/utils/storage.dart'; @@ -15,6 +16,7 @@ class ExtraSetting extends StatefulWidget { class _ExtraSettingState extends State { Box setting = GStrorage.setting; late dynamic defaultReplySort; + late dynamic defaultDynamicType; @override void initState() { @@ -22,6 +24,9 @@ class _ExtraSettingState extends State { // 默认优先显示最新评论 defaultReplySort = setting.get(SettingBoxKey.replySortType, defaultValue: 0); + // 优先展示全部动态 all + defaultDynamicType = + setting.get(SettingBoxKey.defaultDynamicType, defaultValue: 0); } @override @@ -67,6 +72,31 @@ class _ExtraSettingState extends State { ], ), ), + ListTile( + dense: false, + title: Text('动态展示', style: titleStyle), + subtitle: Text( + '当前优先展示「${DynamicsType.values[defaultDynamicType].labels}」', + style: subTitleStyle, + ), + trailing: PopupMenuButton( + initialValue: defaultDynamicType, + icon: const Icon(Icons.more_vert_outlined, size: 22), + onSelected: (item) { + defaultDynamicType = item; + setting.put(SettingBoxKey.defaultDynamicType, item); + setState(() {}); + }, + itemBuilder: (BuildContext context) => [ + for (var i in DynamicsType.values) ...[ + PopupMenuItem( + value: i.index, + child: Text(i.labels), + ), + ] + ], + ), + ), const SetSwitchItem( title: '检查更新', subTitle: '每次启动时检查是否需要更新', diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 6f8d66eaf..6d5ef4eb6 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -103,6 +103,7 @@ class SettingBoxKey { /// 其他 static const String autoUpdate = 'autoUpdate'; static const String replySortType = 'replySortType'; + static const String defaultDynamicType = 'defaultDynamicType'; /// 外观 static const String themeMode = 'themeMode';