mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
pgc review sort
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -11,3 +11,12 @@ enum PgcReviewType {
|
||||
required this.api,
|
||||
});
|
||||
}
|
||||
|
||||
enum PgcReviewSortType {
|
||||
def('默认', 0),
|
||||
latest('最新', 1);
|
||||
|
||||
final int sort;
|
||||
final String label;
|
||||
const PgcReviewSortType(this.label, this.sort);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ class PgcReviewData {
|
||||
?.map((e) => PgcReviewItemModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
next: json['next'] as String?,
|
||||
count: json['count'] as int?,
|
||||
count: json['count'] ?? json['total'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:PiliPlus/models/pgc/pgc_review/data.dart';
|
||||
import 'package:PiliPlus/models/pgc/pgc_review/list.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class PgcReviewController
|
||||
extends CommonListController<PgcReviewData, PgcReviewItemModel> {
|
||||
@@ -13,8 +14,9 @@ class PgcReviewController
|
||||
final PgcReviewType type;
|
||||
final dynamic mediaId;
|
||||
|
||||
int? count;
|
||||
Rx<int?> count = Rx<int?>(null);
|
||||
String? next;
|
||||
Rx<PgcReviewSortType> sortType = PgcReviewSortType.def.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -24,22 +26,28 @@ class PgcReviewController
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
count = null;
|
||||
count.value = null;
|
||||
next = null;
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
void checkIsEnd(int length) {
|
||||
if (count != null && length >= count!) {
|
||||
if (count.value != null && length >= count.value!) {
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<PgcReviewItemModel>? getDataList(PgcReviewData response) {
|
||||
count = response.count;
|
||||
if (type == PgcReviewType.long &&
|
||||
sortType.value == PgcReviewSortType.latest) {
|
||||
count.value = null;
|
||||
} else {
|
||||
count.value = response.count;
|
||||
}
|
||||
next = response.next;
|
||||
|
||||
return response.list;
|
||||
}
|
||||
|
||||
@@ -48,6 +56,7 @@ class PgcReviewController
|
||||
type: type,
|
||||
mediaId: mediaId,
|
||||
next: next,
|
||||
sort: sortType.value.sort,
|
||||
);
|
||||
|
||||
Future<void> onLike(int index, bool isLike, reviewId) async {
|
||||
@@ -104,4 +113,11 @@ class PgcReviewController
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
void queryBySort() {
|
||||
sortType.value = sortType.value == PgcReviewSortType.def
|
||||
? PgcReviewSortType.latest
|
||||
: PgcReviewSortType.def;
|
||||
onReload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/skeleton/video_reply.dart';
|
||||
import 'package:PiliPlus/common/widgets/custom_icon.dart';
|
||||
import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
@@ -58,9 +59,10 @@ class _PgcReviewChildPageState extends State<PgcReviewChildPage>
|
||||
controller: _controller.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
_buildHeader(theme),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 100),
|
||||
sliver:
|
||||
Obx(() => _buildBody(theme, _controller.loadingState.value)),
|
||||
),
|
||||
@@ -356,6 +358,52 @@ class _PgcReviewChildPageState extends State<PgcReviewChildPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(ThemeData theme) => SliverPersistentHeader(
|
||||
pinned: false,
|
||||
floating: true,
|
||||
delegate: CustomSliverPersistentHeaderDelegate(
|
||||
extent: 40,
|
||||
bgColor: theme.colorScheme.surface,
|
||||
child: Container(
|
||||
height: 40,
|
||||
padding: const EdgeInsets.fromLTRB(12, 0, 6, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Obx(
|
||||
() => _controller.count.value == null
|
||||
? const SizedBox.shrink()
|
||||
: Text(
|
||||
'${_controller.count.value}条点评',
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
child: TextButton.icon(
|
||||
onPressed: _controller.queryBySort,
|
||||
icon: Icon(
|
||||
Icons.sort,
|
||||
size: 16,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
label: Obx(
|
||||
() => Text(
|
||||
_controller.sortType.value.label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user