mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: custom check unReadDynamic
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -251,6 +251,7 @@ class MyApp extends StatelessWidget {
|
||||
navigatorObservers: [
|
||||
VideoDetailPage.routeObserver,
|
||||
SearchPage.routeObserver,
|
||||
MainApp.routeObserver,
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/http/msg.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:PiliPalaX/pages/main/controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../http/dynamics.dart';
|
||||
|
||||
@@ -10,6 +12,7 @@ class DynamicsTabController extends CommonController {
|
||||
final String dynamicsType;
|
||||
String offset = '';
|
||||
int mid = -1;
|
||||
late final MainController mainController = Get.find<MainController>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -19,6 +22,11 @@ class DynamicsTabController extends CommonController {
|
||||
|
||||
@override
|
||||
Future onRefresh() async {
|
||||
if (dynamicsType == 'all') {
|
||||
if (mainController.navigationBars[1]['count'] != 0) {
|
||||
mainController.clearUnread();
|
||||
}
|
||||
}
|
||||
offset = '';
|
||||
await queryData();
|
||||
}
|
||||
|
||||
@@ -31,10 +31,15 @@ class MainController extends GetxController {
|
||||
Box userInfoCache = GStorage.userInfo;
|
||||
RxBool userLogin = false.obs;
|
||||
late DynamicBadgeMode dynamicBadgeType;
|
||||
late bool checkDynamic;
|
||||
late int dynamicPeriod;
|
||||
int? _lastCheckAt;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
checkDynamic = GStorage.checkDynamic;
|
||||
dynamicPeriod = GStorage.dynamicPeriod;
|
||||
if (setting.get(SettingBoxKey.autoUpdate, defaultValue: false)) {
|
||||
Utils.checkUpdate();
|
||||
}
|
||||
@@ -49,6 +54,9 @@ class MainController extends GetxController {
|
||||
SettingBoxKey.dynamicBadgeMode,
|
||||
defaultValue: DynamicBadgeMode.number.code)];
|
||||
if (dynamicBadgeType != DynamicBadgeMode.hidden) {
|
||||
if (checkDynamic) {
|
||||
_lastCheckAt = DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
getUnreadDynamic();
|
||||
}
|
||||
}
|
||||
@@ -78,23 +86,34 @@ class MainController extends GetxController {
|
||||
if (!userLogin.value) {
|
||||
return;
|
||||
}
|
||||
int dynamicItemIndex =
|
||||
navigationBars.indexWhere((item) => item['label'] == "动态");
|
||||
// not needed yet
|
||||
// int dynamicItemIndex =
|
||||
// navigationBars.indexWhere((item) => item['label'] == "动态");
|
||||
// if (dynamicItemIndex == -1) return;
|
||||
var res = await CommonHttp.unReadDynamic();
|
||||
var data = res['data'];
|
||||
if (dynamicItemIndex != -1) {
|
||||
navigationBars[dynamicItemIndex]['count'] =
|
||||
navigationBars[1]['count'] =
|
||||
data == null ? 0 : data.length; // 修改 count 属性为新的值
|
||||
}
|
||||
navigationBars.refresh();
|
||||
}
|
||||
|
||||
void clearUnread() async {
|
||||
int dynamicItemIndex =
|
||||
navigationBars.indexWhere((item) => item['label'] == "动态");
|
||||
if (dynamicItemIndex != -1) {
|
||||
navigationBars[dynamicItemIndex]['count'] = 0; // 修改 count 属性为新的值
|
||||
}
|
||||
// not needed yet
|
||||
// int dynamicItemIndex =
|
||||
// navigationBars.indexWhere((item) => item['label'] == "动态");
|
||||
// if (dynamicItemIndex == -1) return;
|
||||
navigationBars[1]['count'] = 0; // 修改 count 属性为新的值
|
||||
navigationBars.refresh();
|
||||
}
|
||||
|
||||
void checkUnreadDynamic() {
|
||||
if (!userLogin.value ||
|
||||
dynamicBadgeType == DynamicBadgeMode.hidden ||
|
||||
!checkDynamic) return;
|
||||
int now = DateTime.now().millisecondsSinceEpoch;
|
||||
if (now - (_lastCheckAt ?? 0) >= dynamicPeriod * 60 * 1000) {
|
||||
_lastCheckAt = now;
|
||||
getUnreadDynamic();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,13 @@ class MainApp extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<MainApp> createState() => _MainAppState();
|
||||
|
||||
static final RouteObserver<PageRoute> routeObserver =
|
||||
RouteObserver<PageRoute>();
|
||||
}
|
||||
|
||||
class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
class _MainAppState extends State<MainApp>
|
||||
with SingleTickerProviderStateMixin, RouteAware, WidgetsBindingObserver {
|
||||
final MainController _mainController = Get.put(MainController());
|
||||
final HomeController _homeController = Get.put(HomeController());
|
||||
final DynamicsController _dynamicController = Get.put(DynamicsController());
|
||||
@@ -37,6 +41,26 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
PageController(initialPage: _mainController.selectedIndex);
|
||||
enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
|
||||
useSideBar = setting.get(SettingBoxKey.useSideBar, defaultValue: false);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
MainApp.routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
|
||||
}
|
||||
|
||||
@override
|
||||
void didPopNext() {
|
||||
_mainController.checkUnreadDynamic();
|
||||
super.didPopNext();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_mainController.checkUnreadDynamic();
|
||||
}
|
||||
}
|
||||
|
||||
void setIndex(int value) async {
|
||||
@@ -92,6 +116,8 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
|
||||
@override
|
||||
void dispose() async {
|
||||
MainApp.routeObserver.unsubscribe(this);
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
await GrpcClient.instance.shutdown();
|
||||
await GStorage.close();
|
||||
EventBus().off(EventName.loginEvent);
|
||||
@@ -125,7 +151,8 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
width: context.width * 0.0387 +
|
||||
36.801 +
|
||||
MediaQuery.of(context).padding.left,
|
||||
child: NavigationRail(
|
||||
child: Obx(
|
||||
() => NavigationRail(
|
||||
groupAlignment: 1,
|
||||
minWidth: context.width * 0.0286 + 28.56,
|
||||
backgroundColor: Colors.transparent,
|
||||
@@ -135,25 +162,16 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
leading: UserAndSearchVertical(ctr: _homeController),
|
||||
destinations: _mainController.navigationBars
|
||||
.map((e) => NavigationRailDestination(
|
||||
icon: Badge(
|
||||
label: _mainController.dynamicBadgeType ==
|
||||
DynamicBadgeMode.number
|
||||
? Text(e['count'].toString())
|
||||
: null,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 4),
|
||||
isLabelVisible:
|
||||
_mainController.dynamicBadgeType !=
|
||||
DynamicBadgeMode.hidden &&
|
||||
e['count'] > 0,
|
||||
child: e['icon'],
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
textColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onInverseSurface,
|
||||
icon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['icon'],
|
||||
),
|
||||
selectedIcon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['selectIcon'],
|
||||
),
|
||||
selectedIcon: e['selectIcon'],
|
||||
label: Text(e['label']),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 0.01 * context.height),
|
||||
@@ -162,36 +180,31 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
trailing: SizedBox(height: 0.1 * context.height),
|
||||
),
|
||||
),
|
||||
),
|
||||
] else if (!isPortait)
|
||||
NavigationRail(
|
||||
Obx(
|
||||
() => NavigationRail(
|
||||
onDestinationSelected: (value) => setIndex(value),
|
||||
selectedIndex: _mainController.selectedIndex,
|
||||
destinations: _mainController.navigationBars
|
||||
.map(
|
||||
(e) => NavigationRailDestination(
|
||||
icon: Badge(
|
||||
label: _mainController.dynamicBadgeType ==
|
||||
DynamicBadgeMode.number
|
||||
? Text(e['count'].toString())
|
||||
: null,
|
||||
padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
|
||||
isLabelVisible:
|
||||
_mainController.dynamicBadgeType !=
|
||||
DynamicBadgeMode.hidden &&
|
||||
e['count'] > 0,
|
||||
child: e['icon'],
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
textColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onInverseSurface,
|
||||
icon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['icon'],
|
||||
),
|
||||
selectedIcon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['selectIcon'],
|
||||
),
|
||||
selectedIcon: e['selectIcon'],
|
||||
label: Text(e['label']),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
VerticalDivider(
|
||||
width: 1,
|
||||
indent: MediaQuery.of(context).padding.top,
|
||||
@@ -226,40 +239,33 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
duration: const Duration(milliseconds: 500),
|
||||
offset: Offset(0, snapshot.data ? 0 : 1),
|
||||
child: enableMYBar
|
||||
? NavigationBar(
|
||||
? Obx(
|
||||
() => NavigationBar(
|
||||
onDestinationSelected: (value) =>
|
||||
setIndex(value),
|
||||
selectedIndex: _mainController.selectedIndex,
|
||||
destinations: _mainController.navigationBars
|
||||
.map(
|
||||
(e) => NavigationDestination(
|
||||
icon: Badge(
|
||||
label: _mainController
|
||||
.dynamicBadgeType ==
|
||||
DynamicBadgeMode.number
|
||||
? Text(e['count'].toString())
|
||||
: null,
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
6, 0, 6, 0),
|
||||
isLabelVisible: _mainController
|
||||
.dynamicBadgeType !=
|
||||
DynamicBadgeMode.hidden &&
|
||||
e['count'] > 0,
|
||||
child: e['icon'],
|
||||
backgroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
textColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onInverseSurface,
|
||||
destinations:
|
||||
_mainController.navigationBars.map(
|
||||
(e) {
|
||||
return NavigationDestination(
|
||||
icon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['icon'],
|
||||
),
|
||||
selectedIcon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['selectIcon'],
|
||||
),
|
||||
selectedIcon: e['selectIcon'],
|
||||
label: e['label'],
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
)
|
||||
: BottomNavigationBar(
|
||||
: Obx(
|
||||
() => BottomNavigationBar(
|
||||
currentIndex: _mainController.selectedIndex,
|
||||
onTap: (value) => setIndex(value),
|
||||
iconSize: 16,
|
||||
@@ -273,32 +279,22 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
items: _mainController.navigationBars
|
||||
.map(
|
||||
(e) => BottomNavigationBarItem(
|
||||
icon: Badge(
|
||||
label: _mainController
|
||||
.dynamicBadgeType ==
|
||||
DynamicBadgeMode.number
|
||||
? Text(e['count'].toString())
|
||||
: null,
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
6, 0, 6, 0),
|
||||
isLabelVisible: _mainController
|
||||
.dynamicBadgeType !=
|
||||
DynamicBadgeMode.hidden &&
|
||||
e['count'] > 0,
|
||||
child: e['icon'],
|
||||
backgroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
textColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onInverseSurface,
|
||||
icon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['icon'],
|
||||
),
|
||||
activeIcon: _buildIcon(
|
||||
id: e['id'],
|
||||
count: e['count'],
|
||||
icon: e['selectIcon'],
|
||||
),
|
||||
activeIcon: e['selectIcon'],
|
||||
label: e['label'],
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -307,4 +303,26 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIcon({
|
||||
required int id,
|
||||
required int count,
|
||||
required Widget icon,
|
||||
}) =>
|
||||
id == 1 &&
|
||||
_mainController.dynamicBadgeType != DynamicBadgeMode.hidden &&
|
||||
count > 0
|
||||
? Badge(
|
||||
label: _mainController.dynamicBadgeType == DynamicBadgeMode.number
|
||||
? Text(count.toString())
|
||||
: null,
|
||||
padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
|
||||
// isLabelVisible:
|
||||
// _mainController.dynamicBadgeType != DynamicBadgeMode.hidden &&
|
||||
// count > 0,
|
||||
// backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
// textColor: Theme.of(context).colorScheme.onInverseSurface,
|
||||
child: icon,
|
||||
)
|
||||
: icon;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.searchFocusNode.dispose();
|
||||
SearchPage.routeObserver.unsubscribe(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/pages/main/controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
@@ -147,6 +148,58 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
defaultVal: false,
|
||||
onTap: () => Get.toNamed('/sponsorBlock'),
|
||||
),
|
||||
SetSwitchItem(
|
||||
title: '检查未读动态',
|
||||
subTitle: '点击设置检查周期(min)',
|
||||
leading: Icon(Icons.notifications_none),
|
||||
setKey: SettingBoxKey.checkDynamic,
|
||||
defaultVal: true,
|
||||
callFn: (value) {
|
||||
Get.find<MainController>().checkDynamic = value;
|
||||
},
|
||||
onTap: () {
|
||||
int dynamicPeriod = GStorage.dynamicPeriod;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('检查周期', style: TextStyle(fontSize: 18)),
|
||||
content: TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: dynamicPeriod.toString(),
|
||||
keyboardType:
|
||||
TextInputType.numberWithOptions(decimal: true),
|
||||
onChanged: (value) {
|
||||
dynamicPeriod = int.tryParse(value) ?? 5;
|
||||
},
|
||||
decoration: InputDecoration(suffixText: 'min'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Get.back,
|
||||
child: Text(
|
||||
'取消',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
GStorage.setting
|
||||
.put(SettingBoxKey.dynamicPeriod, dynamicPeriod);
|
||||
Get.find<MainController>().dynamicPeriod =
|
||||
dynamicPeriod;
|
||||
},
|
||||
child: Text('确定'),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
Obx(
|
||||
() => ListTile(
|
||||
enableFeedback: true,
|
||||
|
||||
@@ -70,6 +70,12 @@ class GStorage {
|
||||
static bool get blockTrack =>
|
||||
setting.get(SettingBoxKey.blockTrack, defaultValue: true);
|
||||
|
||||
static bool get checkDynamic =>
|
||||
setting.get(SettingBoxKey.checkDynamic, defaultValue: true);
|
||||
|
||||
static int get dynamicPeriod =>
|
||||
setting.get(SettingBoxKey.dynamicPeriod, defaultValue: 5);
|
||||
|
||||
static ThemeMode get themeMode {
|
||||
switch (setting.get(SettingBoxKey.themeMode,
|
||||
defaultValue: ThemeType.system.code)) {
|
||||
@@ -251,6 +257,8 @@ class SettingBoxKey {
|
||||
blockServer = 'blockServer',
|
||||
blockTrack = 'blockTrack',
|
||||
previewQuality = 'previewQuality',
|
||||
checkDynamic = 'checkDynamic',
|
||||
dynamicPeriod = 'dynamicPeriod',
|
||||
|
||||
// 弹幕相关设置 权重(云屏蔽) 屏蔽类型 显示区域 透明度 字体大小 弹幕时间 描边粗细 字体粗细
|
||||
danmakuWeight = 'danmakuWeight',
|
||||
|
||||
Reference in New Issue
Block a user