mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: home: cinema
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/models/common/tab_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -8,6 +9,9 @@ import 'package:PiliPlus/http/bangumi.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class BangumiController extends CommonController {
|
||||
BangumiController({required this.tabType});
|
||||
final TabType tabType;
|
||||
|
||||
bool isLoadingMore = true;
|
||||
RxBool isLogin = false.obs;
|
||||
int? mid;
|
||||
@@ -33,6 +37,7 @@ class BangumiController extends CommonController {
|
||||
followPage = 1;
|
||||
followEnd = false;
|
||||
}
|
||||
queryBangumiFollow();
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@@ -51,7 +56,7 @@ class BangumiController extends CommonController {
|
||||
followLoading = true;
|
||||
dynamic res = await BangumiHttp.bangumiFollow(
|
||||
mid: mid,
|
||||
type: 1,
|
||||
type: tabType == TabType.bangumi ? 1 : 2,
|
||||
pn: followPage,
|
||||
);
|
||||
if (res is Success) {
|
||||
@@ -75,6 +80,7 @@ class BangumiController extends CommonController {
|
||||
@override
|
||||
Future<LoadingState> customGetData() => BangumiHttp.bangumiList(
|
||||
page: currentPage,
|
||||
indexType: tabType == TabType.cinema ? 102 : null, // TODO: sort
|
||||
);
|
||||
|
||||
@override
|
||||
|
||||
@@ -34,6 +34,8 @@ class BangumiIntroController extends CommonController {
|
||||
? int.tryParse(Get.parameters['epId']!)
|
||||
: null;
|
||||
|
||||
late dynamic type = Get.parameters['type'] == '1' ? '追番' : '追剧';
|
||||
|
||||
// 是否预渲染 骨架屏
|
||||
bool preRender = false;
|
||||
|
||||
|
||||
@@ -343,8 +343,8 @@ class _BangumiInfoState extends State<BangumiInfo>
|
||||
child: Text(
|
||||
bangumiIntroController
|
||||
.isFollowed.value
|
||||
? '已追番'
|
||||
: '追番',
|
||||
? '已${bangumiIntroController.type}'
|
||||
: '${bangumiIntroController.type}',
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -632,10 +632,10 @@ class _BangumiInfoState extends State<BangumiInfo>
|
||||
_followDialogItem(1, '想看'),
|
||||
ListTile(
|
||||
dense: true,
|
||||
title: const Padding(
|
||||
title: Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
'取消追番',
|
||||
'取消${bangumiIntroController.type}',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/tab_type.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -16,7 +17,12 @@ import 'controller.dart';
|
||||
import 'widgets/bangumi_card_v.dart';
|
||||
|
||||
class BangumiPage extends StatefulWidget {
|
||||
const BangumiPage({super.key});
|
||||
const BangumiPage({
|
||||
super.key,
|
||||
required this.tabType,
|
||||
});
|
||||
|
||||
final TabType tabType;
|
||||
|
||||
@override
|
||||
State<BangumiPage> createState() => _BangumiPageState();
|
||||
@@ -24,7 +30,10 @@ class BangumiPage extends StatefulWidget {
|
||||
|
||||
class _BangumiPageState extends State<BangumiPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
final BangumiController _bangumiController = Get.put(BangumiController());
|
||||
late final BangumiController _bangumiController = Get.put(
|
||||
BangumiController(tabType: widget.tabType),
|
||||
tag: widget.tabType.name,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
@@ -84,7 +93,7 @@ class _BangumiPageState extends State<BangumiPage>
|
||||
children: [
|
||||
Obx(
|
||||
() => Text(
|
||||
'最近追番${_bangumiController.followCount.value == -1 ? '' : ' ${_bangumiController.followCount.value}'}',
|
||||
'最近${widget.tabType == TabType.bangumi ? '追番' : '追剧'}${_bangumiController.followCount.value == -1 ? '' : ' ${_bangumiController.followCount.value}'}',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
@@ -210,7 +219,9 @@ class _BangumiPageState extends State<BangumiPage>
|
||||
Loading() => loadingWidget,
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
? _buildFollowList(loadingState)
|
||||
: const Center(child: Text('还没有追番')),
|
||||
: Center(
|
||||
child: Text(
|
||||
'还没有${widget.tabType == TabType.bangumi ? '追番' : '追剧'}')),
|
||||
Error() => Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
alignment: Alignment.center,
|
||||
|
||||
@@ -52,7 +52,13 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||
try {
|
||||
int index = tabController.index;
|
||||
var ctr = tabsCtrList[index];
|
||||
ctr().onRefresh();
|
||||
ctr(
|
||||
tag: tabs[index]['type'] == TabType.bangumi
|
||||
? TabType.bangumi.name
|
||||
: tabs[index]['type'] == TabType.cinema
|
||||
? TabType.cinema.name
|
||||
: null)
|
||||
.onRefresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -60,7 +66,13 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||
try {
|
||||
int index = tabController.index;
|
||||
var ctr = tabsCtrList[index];
|
||||
ctr().animateToTop();
|
||||
ctr(
|
||||
tag: tabs[index]['type'] == TabType.bangumi
|
||||
? TabType.bangumi.name
|
||||
: tabs[index]['type'] == TabType.cinema
|
||||
? TabType.cinema.name
|
||||
: null)
|
||||
.animateToTop();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -68,14 +80,14 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||
defaultTabs = [...tabsConfig];
|
||||
tabbarSort = GStorage.setting
|
||||
.get(SettingBoxKey.tabbarSort,
|
||||
defaultValue: ['live', 'rcmd', 'hot', 'rank', 'bangumi'])
|
||||
defaultValue: TabType.values.map((item) => item.name).toList())
|
||||
.map<String>((i) => i.toString())
|
||||
.toList();
|
||||
defaultTabs.retainWhere(
|
||||
(item) => tabbarSort.contains((item['type'] as TabType).id));
|
||||
(item) => tabbarSort.contains((item['type'] as TabType).name));
|
||||
defaultTabs.sort((a, b) => tabbarSort
|
||||
.indexOf((a['type'] as TabType).id)
|
||||
.compareTo(tabbarSort.indexOf((b['type'] as TabType).id)));
|
||||
.indexOf((a['type'] as TabType).name)
|
||||
.compareTo(tabbarSort.indexOf((b['type'] as TabType).name)));
|
||||
|
||||
tabs.value = defaultTabs;
|
||||
|
||||
@@ -83,7 +95,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||
tabsPageList = tabs.map<Widget>((e) => e['page']).toList();
|
||||
|
||||
tabController = TabController(
|
||||
initialIndex: max(0, tabbarSort.indexOf(TabType.rcmd.id)),
|
||||
initialIndex: max(0, tabbarSort.indexOf(TabType.rcmd.name)),
|
||||
length: tabs.length,
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
@@ -25,8 +25,8 @@ class _TabbarSetPageState extends State<TabbarSetPage> {
|
||||
.toList();
|
||||
// 对 tabData 进行排序
|
||||
defaultTabs.sort((a, b) {
|
||||
int indexA = tabbarSort.indexOf((a['type'] as TabType).id);
|
||||
int indexB = tabbarSort.indexOf((b['type'] as TabType).id);
|
||||
int indexA = tabbarSort.indexOf((a['type'] as TabType).name);
|
||||
int indexB = tabbarSort.indexOf((b['type'] as TabType).name);
|
||||
|
||||
// 如果类型在 sortOrder 中不存在,则放在末尾
|
||||
if (indexA == -1) indexA = tabbarSort.length;
|
||||
@@ -38,8 +38,8 @@ class _TabbarSetPageState extends State<TabbarSetPage> {
|
||||
|
||||
void saveEdit() {
|
||||
List<String> sortedTabbar = defaultTabs
|
||||
.where((i) => tabbarSort.contains((i['type'] as TabType).id))
|
||||
.map<String>((i) => (i['type'] as TabType).id)
|
||||
.where((i) => tabbarSort.contains((i['type'] as TabType).name))
|
||||
.map<String>((i) => (i['type'] as TabType).name)
|
||||
.toList();
|
||||
GStorage.setting.put(SettingBoxKey.tabbarSort, sortedTabbar);
|
||||
SmartDialog.showToast('保存成功,下次启动时生效');
|
||||
@@ -61,9 +61,9 @@ class _TabbarSetPageState extends State<TabbarSetPage> {
|
||||
for (int i = 0; i < defaultTabs.length; i++) ...[
|
||||
CheckboxListTile(
|
||||
key: Key(defaultTabs[i]['label']),
|
||||
value: tabbarSort.contains((defaultTabs[i]['type'] as TabType).id),
|
||||
value: tabbarSort.contains((defaultTabs[i]['type'] as TabType).name),
|
||||
onChanged: (bool? newValue) {
|
||||
String tabTypeId = (defaultTabs[i]['type'] as TabType).id;
|
||||
String tabTypeId = (defaultTabs[i]['type'] as TabType).name;
|
||||
if (!newValue!) {
|
||||
tabbarSort.remove(tabTypeId);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user