mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-15 05:33:59 +08:00
@@ -13,11 +13,9 @@ import 'package:PiliPlus/pages/mine/view.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/extension/get_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/update.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -35,7 +33,7 @@ class MainController extends GetxController
|
||||
late final bool hideBottomBar;
|
||||
late final barHideType = Pref.barHideType;
|
||||
bool useBottomNav = false;
|
||||
late dynamic controller;
|
||||
late PageController controller;
|
||||
final RxInt selectedIndex = 0.obs;
|
||||
|
||||
final RxInt dynCount = 0.obs;
|
||||
@@ -54,11 +52,7 @@ class MainController extends GetxController
|
||||
late final RxString msgUnReadCount = ''.obs;
|
||||
late int lastCheckUnreadAt = 0;
|
||||
|
||||
final enableMYBar = Pref.enableMYBar;
|
||||
final floatingNavBar = Pref.floatingNavBar;
|
||||
final useSideBar = Pref.useSideBar;
|
||||
final mainTabBarView = Pref.mainTabBarView;
|
||||
late final optTabletNav = Pref.optTabletNav;
|
||||
|
||||
late bool directExitOnBack = Pref.directExitOnBack;
|
||||
late bool showTrayIcon = Pref.showTrayIcon;
|
||||
@@ -72,22 +66,11 @@ class MainController extends GetxController
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (Pref.autoUpdate) {
|
||||
Update.checkUpdate();
|
||||
}
|
||||
|
||||
setNavBarConfig();
|
||||
|
||||
controller = mainTabBarView
|
||||
? TabController(
|
||||
vsync: this,
|
||||
initialIndex: selectedIndex.value,
|
||||
length: navigationBars.length,
|
||||
)
|
||||
: PageController(initialPage: selectedIndex.value);
|
||||
controller = PageController(initialPage: selectedIndex.value);
|
||||
|
||||
hideBottomBar =
|
||||
!useSideBar && navigationBars.length > 1 && Pref.hideBottomBar;
|
||||
hideBottomBar = navigationBars.length > 1 && Pref.hideBottomBar;
|
||||
if (hideBottomBar) {
|
||||
switch (barHideType) {
|
||||
case .instant:
|
||||
@@ -235,21 +218,6 @@ class MainController extends GetxController
|
||||
selectedIndex.value = Pref.defaultHomePageIndex;
|
||||
}
|
||||
|
||||
void checkDefaultSearch([bool shouldCheck = false]) {
|
||||
if (hasHome && homeController.enableSearchWord) {
|
||||
if (shouldCheck &&
|
||||
navigationBars[selectedIndex.value] != NavigationBarType.home) {
|
||||
return;
|
||||
}
|
||||
int now = DateTime.now().millisecondsSinceEpoch;
|
||||
if (now - homeController.lateCheckSearchAt >= _period) {
|
||||
homeController
|
||||
..lateCheckSearchAt = now
|
||||
..querySearchDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkUnread([bool shouldCheck = false]) {
|
||||
if (accountService.isLogin.value &&
|
||||
hasHome &&
|
||||
@@ -284,18 +252,11 @@ class MainController extends GetxController
|
||||
}
|
||||
|
||||
void setIndex(int value) {
|
||||
feedBack();
|
||||
|
||||
final currentNav = navigationBars[value];
|
||||
if (value != selectedIndex.value) {
|
||||
selectedIndex.value = value;
|
||||
if (mainTabBarView) {
|
||||
controller.animateTo(value);
|
||||
} else {
|
||||
controller.jumpToPage(value);
|
||||
}
|
||||
controller.jumpToPage(value);
|
||||
if (currentNav == NavigationBarType.home) {
|
||||
checkDefaultSearch();
|
||||
checkUnread();
|
||||
} else if (currentNav == NavigationBarType.dynamics) {
|
||||
setDynCount();
|
||||
|
||||
@@ -5,8 +5,6 @@ import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/style.dart';
|
||||
import 'package:PiliPlus/common/widgets/floating_navigation_bar.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/pop_scope.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/tabs.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/route_aware_mixin.dart';
|
||||
import 'package:PiliPlus/models/common/nav_bar_config.dart';
|
||||
import 'package:PiliPlus/pages/home/view.dart';
|
||||
@@ -73,15 +71,10 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
super.didChangeDependencies();
|
||||
_padding = MediaQuery.viewPaddingOf(context);
|
||||
theme = Theme.of(context);
|
||||
final brightness = theme.brightness;
|
||||
NetworkImgLayer.reduce =
|
||||
NetworkImgLayer.reduceLuxColor != null && brightness.isDark;
|
||||
if (PlatformUtils.isDesktop) {
|
||||
windowManager.setBrightness(brightness);
|
||||
}
|
||||
if (!_mainController.useSideBar) {
|
||||
_mainController.useBottomNav = MediaQuery.sizeOf(context).isPortrait;
|
||||
windowManager.setBrightness(theme.brightness);
|
||||
}
|
||||
_mainController.useBottomNav = MediaQuery.sizeOf(context).isPortrait;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -89,7 +82,6 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
addObserverMobile(this);
|
||||
_mainController
|
||||
..checkUnreadDynamic()
|
||||
..checkDefaultSearch(true)
|
||||
..checkUnread(_mainController.useBottomNav);
|
||||
super.didPopNext();
|
||||
}
|
||||
@@ -102,10 +94,9 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
if (state == .resumed) {
|
||||
_mainController
|
||||
..checkUnreadDynamic()
|
||||
..checkDefaultSearch(true)
|
||||
..checkUnread(_mainController.useBottomNav);
|
||||
}
|
||||
}
|
||||
@@ -291,7 +282,7 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
} else if (_mainController.enableMYBar) {
|
||||
} else {
|
||||
bottomNav = Obx(
|
||||
() => NavigationBar(
|
||||
maintainBottomViewPadding: true,
|
||||
@@ -308,26 +299,6 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
bottomNav = Obx(
|
||||
() => BottomNavigationBar(
|
||||
currentIndex: _mainController.selectedIndex.value,
|
||||
onTap: _mainController.setIndex,
|
||||
iconSize: 16,
|
||||
selectedFontSize: 12,
|
||||
unselectedFontSize: 12,
|
||||
type: .fixed,
|
||||
items: _mainController.navigationBars
|
||||
.map(
|
||||
(e) => BottomNavigationBarItem(
|
||||
label: e.label,
|
||||
icon: _buildIcon(type: e),
|
||||
activeIcon: _buildIcon(type: e, selected: true),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_mainController.hideBottomBar) {
|
||||
@@ -360,7 +331,7 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
|
||||
Widget _sideBar(ThemeData theme) {
|
||||
return _mainController.navigationBars.length > 1
|
||||
? context.isTablet && _mainController.optTabletNav
|
||||
? context.isTablet
|
||||
? Column(
|
||||
children: [
|
||||
const SizedBox(height: 25),
|
||||
@@ -427,21 +398,11 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget child;
|
||||
if (_mainController.mainTabBarView) {
|
||||
child = CustomTabBarView(
|
||||
scrollDirection: _mainController.useBottomNav ? .horizontal : .vertical,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _mainController.controller,
|
||||
children: _mainController.navigationBars.map((i) => i.page).toList(),
|
||||
);
|
||||
} else {
|
||||
child = PageView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _mainController.controller,
|
||||
children: _mainController.navigationBars.map((i) => i.page).toList(),
|
||||
);
|
||||
}
|
||||
Widget child = PageView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _mainController.controller,
|
||||
children: _mainController.navigationBars.map((i) => i.page).toList(),
|
||||
);
|
||||
|
||||
Widget? bottomNav;
|
||||
if (_mainController.useBottomNav) {
|
||||
@@ -466,7 +427,7 @@ class _MainAppState extends PopScopeState<MainApp>
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(toolbarHeight: 0),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
padding: .only(
|
||||
left: _mainController.useBottomNav ? _padding.left : 0.0,
|
||||
right: _padding.right,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user