mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-26 12:07:11 +08:00
feat: dyn topic
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
72
lib/pages/dynamics_topic/controller.dart
Normal file
72
lib/pages/dynamics_topic/controller.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/dynamics/dyn_topic_feed/item.dart';
|
||||
import 'package:PiliPlus/models/dynamics/dyn_topic_feed/topic_card_list.dart';
|
||||
import 'package:PiliPlus/models/dynamics/dyn_topic_feed/topic_sort_by_conf.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DynTopicController
|
||||
extends CommonListController<TopicCardList?, TopicCardItem> {
|
||||
final topicId = Get.parameters['id']!;
|
||||
final topicName = Get.parameters['name']!;
|
||||
|
||||
int sortBy = 0;
|
||||
String offset = '';
|
||||
Rx<TopicSortByConf?> topicSortByConf = Rx<TopicSortByConf?>(null);
|
||||
|
||||
// top
|
||||
// Rx<LoadingState<TopDetails?>> topState =
|
||||
// LoadingState<TopDetails?>.loading().obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// queryTop();
|
||||
queryData();
|
||||
}
|
||||
|
||||
// Future<void> queryTop() async {
|
||||
// topState.value = await DynamicsHttp.topicTop(topicId: topicId);
|
||||
// }
|
||||
|
||||
@override
|
||||
List<TopicCardItem>? getDataList(TopicCardList? response) {
|
||||
offset = response?.offset ?? '';
|
||||
topicSortByConf.value = response?.topicSortByConf;
|
||||
sortBy = response?.topicSortByConf?.showSortBy ?? 0;
|
||||
if (response?.hasMore == false) {
|
||||
isEnd = true;
|
||||
}
|
||||
return response?.items;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
offset = '';
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onReload() {
|
||||
// if (topState.value is! Success) {
|
||||
// queryTop();
|
||||
// }
|
||||
scrollController.jumpToTop();
|
||||
return super.onReload();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<TopicCardList?>> customGetData() =>
|
||||
DynamicsHttp.topicFeed(
|
||||
topicId: topicId,
|
||||
offset: offset,
|
||||
sortBy: sortBy,
|
||||
);
|
||||
|
||||
void onSort(int sortBy) {
|
||||
this.sortBy = sortBy;
|
||||
onReload();
|
||||
}
|
||||
}
|
||||
140
lib/pages/dynamics_topic/view.dart
Normal file
140
lib/pages/dynamics_topic/view.dart
Normal file
@@ -0,0 +1,140 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/dynamics/dyn_topic_feed/item.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/widgets/dynamic_panel.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_tab/view.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_topic/controller.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:waterfall_flow/waterfall_flow.dart';
|
||||
|
||||
class DynTopicPage extends StatefulWidget {
|
||||
const DynTopicPage({super.key});
|
||||
|
||||
@override
|
||||
State<DynTopicPage> createState() => _DynTopicPageState();
|
||||
}
|
||||
|
||||
class _DynTopicPageState extends State<DynTopicPage> {
|
||||
final DynTopicController _controller =
|
||||
Get.put(DynTopicController(), tag: Utils.generateRandomString(8));
|
||||
final dynamicsWaterfallFlow = GStorage.setting
|
||||
.get(SettingBoxKey.dynamicsWaterfallFlow, defaultValue: true);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_controller.topicName),
|
||||
actions: [
|
||||
Obx(() {
|
||||
if (_controller.topicSortByConf.value?.allSortBy?.isNotEmpty ==
|
||||
true) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
child: PopupMenuButton(
|
||||
initialValue: _controller.sortBy,
|
||||
itemBuilder: (context) {
|
||||
return _controller.topicSortByConf.value!.allSortBy!
|
||||
.map<PopupMenuItem>((e) {
|
||||
return PopupMenuItem(
|
||||
value: e.sortBy,
|
||||
child: Text(e.sortName!),
|
||||
onTap: () {
|
||||
_controller.onSort(e.sortBy!);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
})
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: refreshIndicator(
|
||||
onRefresh: _controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
controller: _controller.scrollController,
|
||||
slivers: [
|
||||
Obx(() => _buildBody(_controller.loadingState.value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<TopicCardItem>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => DynamicsTabPage.dynSkeleton(dynamicsWaterfallFlow),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80,
|
||||
),
|
||||
sliver: dynamicsWaterfallFlow
|
||||
? SliverWaterfallFlow.extent(
|
||||
maxCrossAxisExtent: Grid.smallCardWidth * 2,
|
||||
crossAxisSpacing: StyleString.cardSpace / 2,
|
||||
lastChildLayoutTypeBuilder: (index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
return index == loadingState.response!.length
|
||||
? LastChildLayoutType.foot
|
||||
: LastChildLayoutType.none;
|
||||
},
|
||||
children: [
|
||||
for (var item in loadingState.response!)
|
||||
if (item.dynamicCardItem != null)
|
||||
DynamicPanel(item: item.dynamicCardItem!)
|
||||
else
|
||||
Text(item.topicType ?? 'err'),
|
||||
],
|
||||
)
|
||||
: SliverCrossAxisGroup(
|
||||
slivers: [
|
||||
const SliverFillRemaining(),
|
||||
SliverConstrainedCrossAxis(
|
||||
maxExtent: Grid.smallCardWidth * 2,
|
||||
sliver: SliverList.builder(
|
||||
itemBuilder: (context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
final item = loadingState.response![index];
|
||||
if (item.topicType != null) {
|
||||
return DynamicPanel(
|
||||
item: item.dynamicCardItem!,
|
||||
);
|
||||
} else {
|
||||
return Text(item.topicType ?? 'err');
|
||||
}
|
||||
},
|
||||
itemCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
const SliverFillRemaining(),
|
||||
],
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user