mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 00:28:18 +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,
|
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>))
|
?.map((e) => PgcReviewItemModel.fromJson(e as Map<String, dynamic>))
|
||||||
.toList(),
|
.toList(),
|
||||||
next: json['next'] as String?,
|
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/models/pgc/pgc_review/list.dart';
|
||||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class PgcReviewController
|
class PgcReviewController
|
||||||
extends CommonListController<PgcReviewData, PgcReviewItemModel> {
|
extends CommonListController<PgcReviewData, PgcReviewItemModel> {
|
||||||
@@ -13,8 +14,9 @@ class PgcReviewController
|
|||||||
final PgcReviewType type;
|
final PgcReviewType type;
|
||||||
final dynamic mediaId;
|
final dynamic mediaId;
|
||||||
|
|
||||||
int? count;
|
Rx<int?> count = Rx<int?>(null);
|
||||||
String? next;
|
String? next;
|
||||||
|
Rx<PgcReviewSortType> sortType = PgcReviewSortType.def.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@@ -24,22 +26,28 @@ class PgcReviewController
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onRefresh() {
|
Future<void> onRefresh() {
|
||||||
count = null;
|
count.value = null;
|
||||||
next = null;
|
next = null;
|
||||||
return super.onRefresh();
|
return super.onRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void checkIsEnd(int length) {
|
void checkIsEnd(int length) {
|
||||||
if (count != null && length >= count!) {
|
if (count.value != null && length >= count.value!) {
|
||||||
isEnd = true;
|
isEnd = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<PgcReviewItemModel>? getDataList(PgcReviewData response) {
|
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;
|
next = response.next;
|
||||||
|
|
||||||
return response.list;
|
return response.list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +56,7 @@ class PgcReviewController
|
|||||||
type: type,
|
type: type,
|
||||||
mediaId: mediaId,
|
mediaId: mediaId,
|
||||||
next: next,
|
next: next,
|
||||||
|
sort: sortType.value.sort,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> onLike(int index, bool isLike, reviewId) async {
|
Future<void> onLike(int index, bool isLike, reviewId) async {
|
||||||
@@ -104,4 +113,11 @@ class PgcReviewController
|
|||||||
SmartDialog.showToast(res['msg']);
|
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/skeleton/video_reply.dart';
|
||||||
import 'package:PiliPlus/common/widgets/custom_icon.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/dialog/dialog.dart';
|
||||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||||
@@ -58,9 +59,10 @@ class _PgcReviewChildPageState extends State<PgcReviewChildPage>
|
|||||||
controller: _controller.scrollController,
|
controller: _controller.scrollController,
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
slivers: [
|
slivers: [
|
||||||
|
_buildHeader(theme),
|
||||||
SliverPadding(
|
SliverPadding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
bottom: MediaQuery.paddingOf(context).bottom + 100),
|
||||||
sliver:
|
sliver:
|
||||||
Obx(() => _buildBody(theme, _controller.loadingState.value)),
|
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
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user