feat: 评论默认排序
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/http/reply.dart';
|
import 'package:pilipala/http/reply.dart';
|
||||||
import 'package:pilipala/models/common/reply_sort_type.dart';
|
import 'package:pilipala/models/common/reply_sort_type.dart';
|
||||||
import 'package:pilipala/models/video/reply/item.dart';
|
import 'package:pilipala/models/video/reply/item.dart';
|
||||||
import 'package:pilipala/utils/feed_back.dart';
|
import 'package:pilipala/utils/feed_back.dart';
|
||||||
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class DynamicDetailController extends GetxController {
|
class DynamicDetailController extends GetxController {
|
||||||
DynamicDetailController(this.oid, this.type);
|
DynamicDetailController(this.oid, this.type);
|
||||||
@ -16,9 +18,10 @@ class DynamicDetailController extends GetxController {
|
|||||||
RxList<ReplyItemModel> replyList = [ReplyItemModel()].obs;
|
RxList<ReplyItemModel> replyList = [ReplyItemModel()].obs;
|
||||||
RxInt acount = 0.obs;
|
RxInt acount = 0.obs;
|
||||||
|
|
||||||
ReplySortType sortType = ReplySortType.time;
|
ReplySortType _sortType = ReplySortType.time;
|
||||||
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
||||||
RxString sortTypeLabel = ReplySortType.time.labels.obs;
|
RxString sortTypeLabel = ReplySortType.time.labels.obs;
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -29,6 +32,11 @@ class DynamicDetailController extends GetxController {
|
|||||||
acount.value =
|
acount.value =
|
||||||
int.parse(item!.modules!.moduleStat!.comment!.count ?? '0');
|
int.parse(item!.modules!.moduleStat!.comment!.count ?? '0');
|
||||||
}
|
}
|
||||||
|
int deaultReplySortIndex =
|
||||||
|
setting.get(SettingBoxKey.replySortType, defaultValue: 0);
|
||||||
|
_sortType = ReplySortType.values[deaultReplySortIndex];
|
||||||
|
sortTypeTitle.value = _sortType.titles;
|
||||||
|
sortTypeLabel.value = _sortType.labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryReplyList({reqType = 'init'}) async {
|
Future queryReplyList({reqType = 'init'}) async {
|
||||||
@ -39,7 +47,7 @@ class DynamicDetailController extends GetxController {
|
|||||||
oid: oid!,
|
oid: oid!,
|
||||||
pageNum: currentPage + 1,
|
pageNum: currentPage + 1,
|
||||||
type: type!,
|
type: type!,
|
||||||
sort: sortType.index,
|
sort: _sortType.index,
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
List<ReplyItemModel> replies = res['data'].replies;
|
List<ReplyItemModel> replies = res['data'].replies;
|
||||||
@ -76,20 +84,20 @@ class DynamicDetailController extends GetxController {
|
|||||||
// 排序搜索评论
|
// 排序搜索评论
|
||||||
queryBySort() {
|
queryBySort() {
|
||||||
feedBack();
|
feedBack();
|
||||||
switch (sortType) {
|
switch (_sortType) {
|
||||||
case ReplySortType.time:
|
case ReplySortType.time:
|
||||||
sortType = ReplySortType.like;
|
_sortType = ReplySortType.like;
|
||||||
break;
|
break;
|
||||||
case ReplySortType.like:
|
case ReplySortType.like:
|
||||||
sortType = ReplySortType.reply;
|
_sortType = ReplySortType.reply;
|
||||||
break;
|
break;
|
||||||
case ReplySortType.reply:
|
case ReplySortType.reply:
|
||||||
sortType = ReplySortType.time;
|
_sortType = ReplySortType.time;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
sortTypeTitle.value = sortType.titles;
|
sortTypeTitle.value = _sortType.titles;
|
||||||
sortTypeLabel.value = sortType.labels;
|
sortTypeLabel.value = _sortType.labels;
|
||||||
replyList.clear();
|
replyList.clear();
|
||||||
queryReplyList(reqType: 'init');
|
queryReplyList(reqType: 'init');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:pilipala/models/common/reply_sort_type.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
import 'widgets/switch_item.dart';
|
import 'widgets/switch_item.dart';
|
||||||
@ -11,8 +13,24 @@ class ExtraSetting extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ExtraSettingState extends State<ExtraSetting> {
|
class _ExtraSettingState extends State<ExtraSetting> {
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
|
late dynamic defaultReplySort;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
// 默认优先显示最新评论
|
||||||
|
defaultReplySort =
|
||||||
|
setting.get(SettingBoxKey.replySortType, defaultValue: 0);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
|
||||||
|
TextStyle subTitleStyle = Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.labelMedium!
|
||||||
|
.copyWith(color: Theme.of(context).colorScheme.outline);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
@ -23,8 +41,33 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: const [
|
children: [
|
||||||
SetSwitchItem(
|
ListTile(
|
||||||
|
dense: false,
|
||||||
|
title: Text('评论展示', style: titleStyle),
|
||||||
|
subtitle: Text(
|
||||||
|
'当前优先展示「${ReplySortType.values[defaultReplySort].titles}」',
|
||||||
|
style: subTitleStyle,
|
||||||
|
),
|
||||||
|
trailing: PopupMenuButton(
|
||||||
|
initialValue: defaultReplySort,
|
||||||
|
icon: const Icon(Icons.more_vert_outlined, size: 22),
|
||||||
|
onSelected: (item) {
|
||||||
|
defaultReplySort = item;
|
||||||
|
setting.put(SettingBoxKey.replySortType, item);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
|
||||||
|
for (var i in ReplySortType.values) ...[
|
||||||
|
PopupMenuItem(
|
||||||
|
value: i.index,
|
||||||
|
child: Text(i.titles),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SetSwitchItem(
|
||||||
title: '检查更新',
|
title: '检查更新',
|
||||||
subTitle: '每次启动时检查是否需要更新',
|
subTitle: '每次启动时检查是否需要更新',
|
||||||
setKey: SettingBoxKey.autoUpdate,
|
setKey: SettingBoxKey.autoUpdate,
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/http/reply.dart';
|
import 'package:pilipala/http/reply.dart';
|
||||||
import 'package:pilipala/models/common/reply_sort_type.dart';
|
import 'package:pilipala/models/common/reply_sort_type.dart';
|
||||||
import 'package:pilipala/models/common/reply_type.dart';
|
import 'package:pilipala/models/common/reply_type.dart';
|
||||||
import 'package:pilipala/models/video/reply/item.dart';
|
import 'package:pilipala/models/video/reply/item.dart';
|
||||||
import 'package:pilipala/utils/feed_back.dart';
|
import 'package:pilipala/utils/feed_back.dart';
|
||||||
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class VideoReplyController extends GetxController {
|
class VideoReplyController extends GetxController {
|
||||||
VideoReplyController(
|
VideoReplyController(
|
||||||
@ -29,10 +31,22 @@ class VideoReplyController extends GetxController {
|
|||||||
// 当前回复的回复
|
// 当前回复的回复
|
||||||
ReplyItemModel? currentReplyItem;
|
ReplyItemModel? currentReplyItem;
|
||||||
|
|
||||||
ReplySortType sortType = ReplySortType.time;
|
ReplySortType _sortType = ReplySortType.time;
|
||||||
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
||||||
RxString sortTypeLabel = ReplySortType.time.labels.obs;
|
RxString sortTypeLabel = ReplySortType.time.labels.obs;
|
||||||
|
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
int deaultReplySortIndex =
|
||||||
|
setting.get(SettingBoxKey.replySortType, defaultValue: 0);
|
||||||
|
_sortType = ReplySortType.values[deaultReplySortIndex];
|
||||||
|
sortTypeTitle.value = _sortType.titles;
|
||||||
|
sortTypeLabel.value = _sortType.labels;
|
||||||
|
}
|
||||||
|
|
||||||
Future queryReplyList({type = 'init'}) async {
|
Future queryReplyList({type = 'init'}) async {
|
||||||
isLoadingMore = true;
|
isLoadingMore = true;
|
||||||
if (type == 'init') {
|
if (type == 'init') {
|
||||||
@ -46,7 +60,7 @@ class VideoReplyController extends GetxController {
|
|||||||
pageNum: currentPage + 1,
|
pageNum: currentPage + 1,
|
||||||
ps: ps,
|
ps: ps,
|
||||||
type: ReplyType.video.index,
|
type: ReplyType.video.index,
|
||||||
sort: sortType.index,
|
sort: _sortType.index,
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
List<ReplyItemModel> replies = res['data'].replies;
|
List<ReplyItemModel> replies = res['data'].replies;
|
||||||
@ -95,20 +109,20 @@ class VideoReplyController extends GetxController {
|
|||||||
queryBySort() {
|
queryBySort() {
|
||||||
EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () {
|
EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () {
|
||||||
feedBack();
|
feedBack();
|
||||||
switch (sortType) {
|
switch (_sortType) {
|
||||||
case ReplySortType.time:
|
case ReplySortType.time:
|
||||||
sortType = ReplySortType.like;
|
_sortType = ReplySortType.like;
|
||||||
break;
|
break;
|
||||||
case ReplySortType.like:
|
case ReplySortType.like:
|
||||||
sortType = ReplySortType.reply;
|
_sortType = ReplySortType.reply;
|
||||||
break;
|
break;
|
||||||
case ReplySortType.reply:
|
case ReplySortType.reply:
|
||||||
sortType = ReplySortType.time;
|
_sortType = ReplySortType.time;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
sortTypeTitle.value = sortType.titles;
|
sortTypeTitle.value = _sortType.titles;
|
||||||
sortTypeLabel.value = sortType.labels;
|
sortTypeLabel.value = _sortType.labels;
|
||||||
currentPage = 0;
|
currentPage = 0;
|
||||||
noMore.value = '';
|
noMore.value = '';
|
||||||
replyList.clear();
|
replyList.clear();
|
||||||
|
|||||||
@ -82,6 +82,7 @@ class GStrorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SettingBoxKey {
|
class SettingBoxKey {
|
||||||
|
/// 播放器
|
||||||
static const String btmProgressBehavior = 'btmProgressBehavior';
|
static const String btmProgressBehavior = 'btmProgressBehavior';
|
||||||
static const String defaultVideoSpeed = 'defaultVideoSpeed';
|
static const String defaultVideoSpeed = 'defaultVideoSpeed';
|
||||||
static const String autoUpgradeEnable = 'autoUpgradeEnable';
|
static const String autoUpgradeEnable = 'autoUpgradeEnable';
|
||||||
@ -96,10 +97,14 @@ class SettingBoxKey {
|
|||||||
static const String enableHA = 'enableHA';
|
static const String enableHA = 'enableHA';
|
||||||
static const String enableOnlineTotal = 'enableOnlineTotal';
|
static const String enableOnlineTotal = 'enableOnlineTotal';
|
||||||
|
|
||||||
|
/// 隐私
|
||||||
static const String blackMidsList = 'blackMidsList';
|
static const String blackMidsList = 'blackMidsList';
|
||||||
|
|
||||||
|
/// 其他
|
||||||
static const String autoUpdate = 'autoUpdate';
|
static const String autoUpdate = 'autoUpdate';
|
||||||
|
static const String replySortType = 'replySortType';
|
||||||
|
|
||||||
|
/// 外观
|
||||||
static const String themeMode = 'themeMode';
|
static const String themeMode = 'themeMode';
|
||||||
static const String defaultTextScale = 'textScale';
|
static const String defaultTextScale = 'textScale';
|
||||||
static const String dynamicColor = 'dynamicColor'; // bool
|
static const String dynamicColor = 'dynamicColor'; // bool
|
||||||
|
|||||||
Reference in New Issue
Block a user