mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-18 16:16:14 +08:00
merge mine & media
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -8,11 +8,15 @@ import 'package:PiliPlus/models/common/msg/msg_unread_type.dart';
|
||||
import 'package:PiliPlus/models/common/nav_bar_config.dart';
|
||||
import 'package:PiliPlus/models_new/msgfeed_unread/data.dart';
|
||||
import 'package:PiliPlus/models_new/single_unread/data.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
||||
import 'package:PiliPlus/pages/home/controller.dart';
|
||||
import 'package:PiliPlus/services/account_service.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:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -21,20 +25,27 @@ class MainController extends GetxController
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
List<NavigationBarType> navigationBars = <NavigationBarType>[];
|
||||
RxInt dynCount = 0.obs;
|
||||
|
||||
StreamController<bool>? bottomBarStream;
|
||||
late bool hideTabBar = Pref.hideTabBar;
|
||||
late dynamic controller;
|
||||
RxInt selectedIndex = 0.obs;
|
||||
|
||||
RxInt dynCount = 0.obs;
|
||||
late DynamicBadgeMode dynamicBadgeMode;
|
||||
late bool checkDynamic = Pref.checkDynamic;
|
||||
late int dynamicPeriod = Pref.dynamicPeriod;
|
||||
late int dynamicPeriod = Pref.dynamicPeriod * 60 * 1000;
|
||||
late int _lastCheckDynamicAt = 0;
|
||||
late int dynIndex = -1;
|
||||
late final DynamicsController dynamicController = Get.put(
|
||||
DynamicsController(),
|
||||
);
|
||||
|
||||
late int homeIndex = -1;
|
||||
late final HomeController? homeController = homeIndex == -1
|
||||
? null
|
||||
: Get.put(HomeController());
|
||||
|
||||
late DynamicBadgeMode msgBadgeMode = Pref.msgBadgeMode;
|
||||
late Set<MsgUnReadType> msgUnReadTypes = Pref.msgUnReadTypeV2;
|
||||
late final RxString msgUnReadCount = ''.obs;
|
||||
@@ -48,6 +59,9 @@ class MainController extends GetxController
|
||||
|
||||
late bool directExitOnBack = Pref.directExitOnBack;
|
||||
|
||||
static const _period = 5 * 60 * 1000;
|
||||
late int _lastSelectTime = 0;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -163,19 +177,19 @@ class MainController extends GetxController
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getUnreadDynamic() async {
|
||||
void getUnreadDynamic() {
|
||||
if (!accountService.isLogin.value || dynIndex == -1) {
|
||||
return;
|
||||
}
|
||||
DynGrpc.dynRed().then((res) {
|
||||
if (res != null) {
|
||||
setCount(res);
|
||||
setDynCount(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> setCount([int count = 0]) async {
|
||||
if (dynIndex == -1 || dynCount.value == count) return;
|
||||
void setDynCount([int count = 0]) {
|
||||
if (dynIndex == -1) return;
|
||||
dynCount.value = count;
|
||||
}
|
||||
|
||||
@@ -187,7 +201,7 @@ class MainController extends GetxController
|
||||
return;
|
||||
}
|
||||
int now = DateTime.now().millisecondsSinceEpoch;
|
||||
if (now - _lastCheckDynamicAt >= dynamicPeriod * 60 * 1000) {
|
||||
if (now - _lastCheckDynamicAt >= dynamicPeriod) {
|
||||
_lastCheckDynamicAt = now;
|
||||
getUnreadDynamic();
|
||||
}
|
||||
@@ -198,7 +212,7 @@ class MainController extends GetxController
|
||||
(GStorage.setting.get(SettingBoxKey.navBarSort) as List?)?.cast();
|
||||
int defaultHomePage = Pref.defaultHomePage;
|
||||
late final List<NavigationBarType> navigationBars;
|
||||
if (navBarSort == null) {
|
||||
if (navBarSort == null || navBarSort.isEmpty) {
|
||||
navigationBars = NavigationBarType.values;
|
||||
} else {
|
||||
navigationBars = navBarSort
|
||||
@@ -212,6 +226,86 @@ class MainController extends GetxController
|
||||
);
|
||||
}
|
||||
|
||||
void checkDefaultSearch([bool shouldCheck = false]) {
|
||||
if (homeController?.enableSearchWord == true) {
|
||||
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 &&
|
||||
homeIndex != -1 &&
|
||||
msgBadgeMode != DynamicBadgeMode.hidden) {
|
||||
if (shouldCheck &&
|
||||
navigationBars[selectedIndex.value] != NavigationBarType.home) {
|
||||
return;
|
||||
}
|
||||
int now = DateTime.now().millisecondsSinceEpoch;
|
||||
if (now - lastCheckUnreadAt >= _period) {
|
||||
lastCheckUnreadAt = now;
|
||||
queryUnreadMsg();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void toMinePage() {
|
||||
final index = navigationBars.indexOf(NavigationBarType.mine);
|
||||
if (index != -1) {
|
||||
setIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (currentNav == NavigationBarType.home) {
|
||||
checkDefaultSearch();
|
||||
checkUnread();
|
||||
} else if (currentNav == NavigationBarType.dynamics) {
|
||||
setDynCount();
|
||||
}
|
||||
} else {
|
||||
int now = DateTime.now().millisecondsSinceEpoch;
|
||||
if (now - _lastSelectTime < 500) {
|
||||
EasyThrottle.throttle(
|
||||
'topOrRefresh',
|
||||
const Duration(milliseconds: 500),
|
||||
() {
|
||||
if (currentNav == NavigationBarType.home) {
|
||||
homeController!.onRefresh();
|
||||
} else if (currentNav == NavigationBarType.dynamics) {
|
||||
dynamicController.onRefresh();
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
if (currentNav == NavigationBarType.home) {
|
||||
homeController!.toTopOrRefresh();
|
||||
} else if (currentNav == NavigationBarType.dynamics) {
|
||||
dynamicController.toTopOrRefresh();
|
||||
}
|
||||
}
|
||||
_lastSelectTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
bottomBarStream?.close();
|
||||
|
||||
Reference in New Issue
Block a user