mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class FavArticleController extends CommonController {
|
||||
class FavArticleController extends CommonListController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -19,7 +19,7 @@ class FavArticleController extends CommonController {
|
||||
if (res['status']) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('已取消收藏');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
|
||||
@@ -40,7 +40,7 @@ class _FavArticlePageState extends State<FavArticlePage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<dynamic>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
@@ -55,7 +55,7 @@ class _FavArticlePageState extends State<FavArticlePage>
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
@@ -69,11 +69,11 @@ class _FavArticlePageState extends State<FavArticlePage>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_favArticleController.onLoadMore();
|
||||
}
|
||||
return FavArticleItem(
|
||||
item: loadingState.response[index],
|
||||
item: loadingState.response![index],
|
||||
onDelete: () {
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
@@ -81,13 +81,13 @@ class _FavArticlePageState extends State<FavArticlePage>
|
||||
onConfirm: () {
|
||||
_favArticleController.onRemove(
|
||||
index,
|
||||
loadingState.response[index]['opus_id'],
|
||||
loadingState.response![index]['opus_id'],
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/member/article.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/controller.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/widget/item.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
@@ -132,7 +133,7 @@ class _FavNoteChildPageState extends State<FavNoteChildPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<FavArticleModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
@@ -147,7 +148,7 @@ class _FavNoteChildPageState extends State<FavNoteChildPage>
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
||||
@@ -159,18 +160,18 @@ class _FavNoteChildPageState extends State<FavNoteChildPage>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_favNoteController.onLoadMore();
|
||||
}
|
||||
return FavNoteItem(
|
||||
item: loadingState.response[index],
|
||||
item: loadingState.response![index],
|
||||
ctr: _favNoteController,
|
||||
onSelect: () {
|
||||
_favNoteController.onSelect(index);
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/member/article.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavNoteController extends MultiSelectController {
|
||||
class FavNoteController
|
||||
extends MultiSelectController<List<FavArticleModel>?, FavArticleModel> {
|
||||
FavNoteController(this.isPublish);
|
||||
|
||||
final bool isPublish;
|
||||
|
||||
late final allSelected = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -18,48 +17,36 @@ class FavNoteController extends MultiSelectController {
|
||||
}
|
||||
|
||||
@override
|
||||
onSelect(int index) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
list[index]['checked'] = !(list[index]['checked'] ?? false);
|
||||
checkedCount.value = list.where((item) => item['checked'] == true).length;
|
||||
loadingState.value = LoadingState.success(list);
|
||||
allSelected.value = checkedCount.value == list.length;
|
||||
if (checkedCount.value == 0) {
|
||||
enableMultiSelect.value = false;
|
||||
}
|
||||
onSelect(int index, [bool disableSelect = true]) {
|
||||
super.onSelect(index, false);
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSelect([bool checked = false]) {
|
||||
void handleSelect([bool checked = false, bool disableSelect = true]) {
|
||||
allSelected.value = checked;
|
||||
if (loadingState.value is Success) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
if (list.isNotEmpty) {
|
||||
loadingState.value = LoadingState.success(
|
||||
list.map((item) => item..['checked'] = checked).toList());
|
||||
checkedCount.value = checked ? list.length : 0;
|
||||
}
|
||||
}
|
||||
super.handleSelect(checked, false);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() {
|
||||
Future<LoadingState<List<FavArticleModel>?>> customGetData() {
|
||||
return isPublish
|
||||
? VideoHttp.userNoteList(page: currentPage)
|
||||
: VideoHttp.noteList(page: currentPage);
|
||||
}
|
||||
|
||||
void onRemove() async {
|
||||
List dataList = (loadingState.value as Success).response as List;
|
||||
Set removeList = dataList.where((item) => item['checked'] == true).toSet();
|
||||
List<FavArticleModel> dataList = (loadingState.value as Success).response;
|
||||
Set<FavArticleModel> removeList =
|
||||
dataList.where((item) => item.checked == true).toSet();
|
||||
final res = await VideoHttp.delNote(
|
||||
isPublish: isPublish,
|
||||
noteIds: removeList
|
||||
.map((item) => isPublish ? item['cvid'] : item['note_id'])
|
||||
.map((item) => isPublish ? item.cvid : item.noteId)
|
||||
.toList(),
|
||||
);
|
||||
if (res['status']) {
|
||||
List remainList = dataList.toSet().difference(removeList).toList();
|
||||
List<FavArticleModel> remainList =
|
||||
dataList.toSet().difference(removeList).toList();
|
||||
loadingState.value = LoadingState.success(remainList);
|
||||
enableMultiSelect.value = false;
|
||||
SmartDialog.showToast('删除成功');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/member/article.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/controller.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -12,7 +13,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
required this.onSelect,
|
||||
});
|
||||
|
||||
final dynamic item;
|
||||
final FavArticleModel item;
|
||||
final FavNoteController ctr;
|
||||
final VoidCallback onSelect;
|
||||
|
||||
@@ -26,10 +27,12 @@ class FavNoteItem extends StatelessWidget {
|
||||
onSelect();
|
||||
return;
|
||||
}
|
||||
Utils.handleWebview(
|
||||
item['web_url'],
|
||||
inApp: true,
|
||||
);
|
||||
if (item.webUrl?.isNotEmpty == true) {
|
||||
Utils.handleWebview(
|
||||
item.webUrl!,
|
||||
inApp: true,
|
||||
);
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!ctr.enableMultiSelect.value) {
|
||||
@@ -53,7 +56,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item['title'],
|
||||
item.title ?? '',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
@@ -64,14 +67,14 @@ class FavNoteItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
item['summary'],
|
||||
item.summary ?? '',
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
item['message'],
|
||||
item.message ?? '',
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
@@ -80,7 +83,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (item['arc']?['pic'] != null) ...[
|
||||
if (item.pic?.isNotEmpty == true) ...[
|
||||
const SizedBox(width: 10),
|
||||
AspectRatio(
|
||||
aspectRatio: StyleString.aspectRatio,
|
||||
@@ -91,7 +94,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
src: item['arc']?['pic'],
|
||||
src: item.pic,
|
||||
width: boxConstraints.maxWidth,
|
||||
height: boxConstraints.maxHeight,
|
||||
),
|
||||
@@ -100,7 +103,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
AnimatedOpacity(
|
||||
opacity: item['checked'] == true ? 1 : 0,
|
||||
opacity: item.checked == true ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
@@ -115,7 +118,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: item['checked'] == true ? 1 : 0,
|
||||
scale: item.checked == true ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/pages/fav/pgc/controller.dart';
|
||||
import 'package:PiliPlus/pages/fav/pgc/widget/item.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
@@ -126,7 +127,7 @@ class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
if (_favPgcController.checkedCount.value !=
|
||||
0) {
|
||||
_favPgcController
|
||||
.onUpdate(item['followStatus']);
|
||||
.onUpdateList(item['followStatus']);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
@@ -156,7 +157,7 @@ class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<BangumiListItemModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
@@ -171,7 +172,7 @@ class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
||||
@@ -183,11 +184,12 @@ class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_favPgcController.onLoadMore();
|
||||
}
|
||||
final item = loadingState.response![index];
|
||||
return FavPgcItem(
|
||||
item: loadingState.response[index],
|
||||
item: item,
|
||||
ctr: _favPgcController,
|
||||
onSelect: () {
|
||||
_favPgcController.onSelect(index);
|
||||
@@ -201,13 +203,13 @@ class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
if (followStatus == -1) {
|
||||
_favPgcController.bangumiDel(
|
||||
index,
|
||||
loadingState.response[index].seasonId,
|
||||
item.seasonId,
|
||||
);
|
||||
} else {
|
||||
_favPgcController.bangumiUpdate(
|
||||
_favPgcController.onUpdate(
|
||||
index,
|
||||
followStatus,
|
||||
loadingState.response[index].seasonId,
|
||||
item.seasonId,
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -215,7 +217,7 @@ class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -8,14 +8,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavPgcController extends MultiSelectController {
|
||||
class FavPgcController
|
||||
extends MultiSelectController<BangumiListDataModel, BangumiListItemModel> {
|
||||
final int type;
|
||||
final int followStatus;
|
||||
|
||||
FavPgcController(this.type, this.followStatus);
|
||||
|
||||
late final allSelected = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -23,34 +22,24 @@ class FavPgcController extends MultiSelectController {
|
||||
}
|
||||
|
||||
@override
|
||||
onSelect(int index) {
|
||||
List<BangumiListItemModel> list = (loadingState.value as Success).response;
|
||||
list[index].checked = !(list[index].checked ?? false);
|
||||
checkedCount.value = list.where((item) => item.checked == true).length;
|
||||
loadingState.value = LoadingState.success(list);
|
||||
allSelected.value = checkedCount.value == list.length;
|
||||
if (checkedCount.value == 0) {
|
||||
enableMultiSelect.value = false;
|
||||
}
|
||||
onSelect(int index, [bool disableSelect = true]) {
|
||||
super.onSelect(index, false);
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSelect([bool checked = false]) {
|
||||
void handleSelect([bool checked = false, bool disableSelect = true]) {
|
||||
allSelected.value = checked;
|
||||
if (loadingState.value is Success) {
|
||||
List<BangumiListItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
if (list.isNotEmpty) {
|
||||
loadingState.value = LoadingState.success(list
|
||||
.map<BangumiListItemModel>((item) => item..checked = checked)
|
||||
.toList());
|
||||
checkedCount.value = checked ? list.length : 0;
|
||||
}
|
||||
}
|
||||
super.handleSelect(checked, false);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => BangumiHttp.bangumiFollowList(
|
||||
List<BangumiListItemModel>? getDataList(BangumiListDataModel response) {
|
||||
return response.list;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<BangumiListDataModel>> customGetData() =>
|
||||
BangumiHttp.bangumiFollowList(
|
||||
mid: Accounts.main.mid,
|
||||
type: type,
|
||||
followStatus: followStatus,
|
||||
@@ -71,12 +60,12 @@ class FavPgcController extends MultiSelectController {
|
||||
List<BangumiListItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
}
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
|
||||
Future onUpdate(followStatus) async {
|
||||
Future onUpdateList(followStatus) async {
|
||||
List<BangumiListItemModel> dataList =
|
||||
(loadingState.value as Success).response as List<BangumiListItemModel>;
|
||||
Set<BangumiListItemModel> updateList =
|
||||
@@ -96,7 +85,7 @@ class FavPgcController extends MultiSelectController {
|
||||
List<BangumiListItemModel> list =
|
||||
(ctr.loadingState.value as Success).response;
|
||||
list.insertAll(0, updateList.map((item) => item..checked = null));
|
||||
ctr.loadingState.value = LoadingState.success(list);
|
||||
ctr.loadingState.refresh();
|
||||
ctr.allSelected.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -106,7 +95,7 @@ class FavPgcController extends MultiSelectController {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
|
||||
Future bangumiUpdate(index, followStatus, seasonId) async {
|
||||
Future onUpdate(index, followStatus, seasonId) async {
|
||||
var result = await VideoHttp.bangumiUpdate(
|
||||
seasonId: [seasonId],
|
||||
status: followStatus,
|
||||
@@ -115,14 +104,14 @@ class FavPgcController extends MultiSelectController {
|
||||
List<BangumiListItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
final item = list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
try {
|
||||
final ctr = Get.find<FavPgcController>(tag: '$type$followStatus');
|
||||
if (ctr.loadingState.value is Success) {
|
||||
List<BangumiListItemModel> list =
|
||||
(ctr.loadingState.value as Success).response;
|
||||
list.insert(0, item);
|
||||
ctr.loadingState.value = LoadingState.success(list);
|
||||
ctr.loadingState.refresh();
|
||||
ctr.allSelected.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/user/fav_folder.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class FavController extends CommonController {
|
||||
class FavController
|
||||
extends CommonListController<FavFolderData, FavFolderItemData> {
|
||||
late final dynamic mid = Accounts.main.mid;
|
||||
|
||||
@override
|
||||
@@ -24,22 +24,20 @@ class FavController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
if (response.response.hasMore == false ||
|
||||
(response.response.list as List?).isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
if (currentPage != 1 && loadingState.value is Success) {
|
||||
response.response.list ??= <FavFolderItemData>[];
|
||||
response.response.list!
|
||||
.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
loadingState.value = LoadingState.success(response.response.list);
|
||||
return true;
|
||||
List<FavFolderItemData>? getDataList(FavFolderData response) {
|
||||
return response.list;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => UserHttp.userfavFolder(
|
||||
bool customHandleResponse(bool isRefresh, Success<FavFolderData> response) {
|
||||
if (response.response.hasMore == false) {
|
||||
isEnd = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<FavFolderData>> customGetData() => UserHttp.userfavFolder(
|
||||
pn: currentPage,
|
||||
ps: 10,
|
||||
mid: mid,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/user/fav_folder.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -44,7 +45,7 @@ class _FavVideoPageState extends State<FavVideoPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<FavFolderItemData>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
@@ -59,7 +60,7 @@ class _FavVideoPageState extends State<FavVideoPage>
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
@@ -72,33 +73,31 @@ class _FavVideoPageState extends State<FavVideoPage>
|
||||
childAspectRatio: StyleString.aspectRatio * 2.2,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
(BuildContext context, int index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_favController.onLoadMore();
|
||||
}
|
||||
String heroTag =
|
||||
Utils.makeHeroTag(loadingState.response[index].fid);
|
||||
final item = loadingState.response![index];
|
||||
String heroTag = Utils.makeHeroTag(item.fid);
|
||||
return FavItem(
|
||||
heroTag: heroTag,
|
||||
favFolderItem: loadingState.response[index],
|
||||
favFolderItem: item,
|
||||
onTap: () async {
|
||||
dynamic res = await Get.toNamed(
|
||||
'/favDetail',
|
||||
arguments: loadingState.response[index],
|
||||
arguments: item,
|
||||
parameters: {
|
||||
'heroTag': heroTag,
|
||||
'mediaId':
|
||||
loadingState.response[index].id.toString(),
|
||||
'mediaId': item.id.toString(),
|
||||
},
|
||||
);
|
||||
if (res == true) {
|
||||
List list =
|
||||
List<FavFolderItemData> list =
|
||||
(_favController.loadingState.value as Success)
|
||||
.response;
|
||||
list.removeAt(index);
|
||||
_favController.loadingState.value =
|
||||
LoadingState.success(list);
|
||||
_favController.loadingState.refresh();
|
||||
} else {
|
||||
Future.delayed(const Duration(milliseconds: 255), () {
|
||||
_favController.onRefresh();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/user/fav_folder.dart';
|
||||
import 'package:PiliPlus/pages/fav/article/view.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/view.dart';
|
||||
import 'package:PiliPlus/pages/fav/pgc/view.dart';
|
||||
@@ -54,13 +55,13 @@ class _FavPageState extends State<FavPage> with SingleTickerProviderStateMixin {
|
||||
Get.toNamed('/createFav')?.then(
|
||||
(data) {
|
||||
if (data != null) {
|
||||
List list = _favController.loadingState.value is Success
|
||||
? (_favController.loadingState.value as Success)
|
||||
.response
|
||||
: [];
|
||||
List<FavFolderItemData> list =
|
||||
_favController.loadingState.value is Success
|
||||
? (_favController.loadingState.value as Success)
|
||||
.response
|
||||
: <FavFolderItemData>[];
|
||||
list.insert(list.isNotEmpty ? 1 : 0, data);
|
||||
_favController.loadingState.value =
|
||||
LoadingState.success(list);
|
||||
_favController.loadingState.refresh();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -81,6 +82,7 @@ class _FavPageState extends State<FavPage> with SingleTickerProviderStateMixin {
|
||||
'title': item.title,
|
||||
'count': item.mediaCount,
|
||||
'searchType': SearchType.fav,
|
||||
'isOwner': true,
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user