This commit is contained in:
kodjomoustapha 2024-12-24 15:40:49 +01:00
parent 4adfaa4170
commit 2af2729559
5 changed files with 193 additions and 202 deletions

View file

@ -5,6 +5,7 @@ import 'package:isar/isar.dart';
import 'package:mangayomi/main.dart';
import 'package:mangayomi/models/manga.dart';
import 'package:mangayomi/models/source.dart';
import 'package:mangayomi/modules/more/settings/reader/providers/reader_state_provider.dart';
import 'package:mangayomi/providers/l10n_providers.dart';
import 'package:mangayomi/providers/storage_provider.dart';
import 'package:mangayomi/modules/browse/extension/extension_screen.dart';
@ -21,11 +22,24 @@ class BrowseScreen extends ConsumerStatefulWidget {
class _BrowseScreenState extends ConsumerState<BrowseScreen>
with TickerProviderStateMixin {
late final hideManga = ref.watch(hideMangaStateProvider);
late final hideAnime = ref.watch(hideAnimeStateProvider);
late final hideNovel = ref.watch(hideNovelStateProvider);
late TabController _tabBarController;
late final _tabList = [
if (!hideManga) 'manga',
if (!hideAnime) 'anime',
if (!hideNovel) 'novel',
if (!hideManga) 'mangaExtension',
if (!hideAnime) 'animeExtension',
if (!hideNovel) 'novelExtension',
];
@override
void initState() {
_tabBarController = TabController(length: 6, vsync: this);
void didChangeDependencies() {
super.didChangeDependencies();
_tabBarController = TabController(length: _tabList.length, vsync: this);
_tabBarController.animateTo(0);
_tabBarController.addListener(() {
_chekPermission();
@ -34,7 +48,6 @@ class _BrowseScreenState extends ConsumerState<BrowseScreen>
_isSearch = false;
});
});
super.initState();
}
_chekPermission() async {
@ -45,6 +58,15 @@ class _BrowseScreenState extends ConsumerState<BrowseScreen>
bool _isSearch = false;
@override
Widget build(BuildContext context) {
if (_tabList.isEmpty) {
return SizedBox.shrink();
}
final containsExtensionTab = [
"mangaExtension",
"animeExtension",
"novelExtension"
].any((element) => _tabList[_tabBarController.index] == element);
final l10n = l10nLocalizations(context)!;
return DefaultTabController(
animationDuration: Duration.zero,
@ -53,10 +75,8 @@ class _BrowseScreenState extends ConsumerState<BrowseScreen>
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
title: Text(
l10n.browse,
style: TextStyle(color: Theme.of(context).hintColor),
),
title: Text(l10n.browse,
style: TextStyle(color: Theme.of(context).hintColor)),
actions: [
_isSearch
? SeachFormTextField(
@ -85,136 +105,118 @@ class _BrowseScreenState extends ConsumerState<BrowseScreen>
},
icon: Icon(Icons.add_outlined,
color: Theme.of(context).hintColor)),
_tabBarController.index != 4
? IconButton(
splashRadius: 20,
onPressed: () {
if (_tabBarController.index != 0 &&
_tabBarController.index != 1 &&
_tabBarController.index != 2) {
setState(() {
_isSearch = true;
IconButton(
splashRadius: 20,
onPressed: () {
if (containsExtensionTab) {
setState(() {
_isSearch = true;
});
} else {
context.push('/globalSearch',
extra: switch (
_tabList[_tabBarController.index]) {
"manga" => ItemType.manga,
"anime" => ItemType.anime,
_ => ItemType.novel,
});
} else {
context.push('/globalSearch',
extra: _tabBarController.index == 0
? ItemType.manga
: ItemType.anime);
}
},
icon: Icon(
_tabBarController.index == 0 ||
_tabBarController.index == 1 ||
_tabBarController.index == 2
? Icons.travel_explore_rounded
: Icons.search_rounded,
color: Theme.of(context).hintColor))
: Container(),
}
},
icon: Icon(
!containsExtensionTab
? Icons.travel_explore_rounded
: Icons.search_rounded,
color: Theme.of(context).hintColor)),
],
),
IconButton(
splashRadius: 20,
onPressed: () {
if (_tabBarController.index == 0) {
context.push('/sourceFilter', extra: ItemType.manga);
} else if (_tabBarController.index == 1) {
context.push('/sourceFilter', extra: ItemType.anime);
} else if (_tabBarController.index == 2) {
context.push('/sourceFilter', extra: ItemType.anime);
} else if (_tabBarController.index == 3) {
_textEditingController.clear();
context.push('/ExtensionLang', extra: ItemType.anime);
} else if (_tabBarController.index == 4) {
_textEditingController.clear();
context.push('/ExtensionLang', extra: ItemType.anime);
} else if (_tabBarController.index == 5) {
_textEditingController.clear();
context.push('/ExtensionLang', extra: ItemType.anime);
} else {}
context.push(
containsExtensionTab ? '/ExtensionLang' : '/sourceFilter',
extra: switch (_tabList[_tabBarController.index]) {
"manga" || "mangaExtension" => ItemType.manga,
"anime" || "animeExtension" => ItemType.anime,
_ => ItemType.novel,
});
},
icon: Icon(
_tabBarController.index == 0 ||
_tabBarController.index == 1 ||
_tabBarController.index == 2
!containsExtensionTab
? Icons.filter_list_sharp
: _tabBarController.index == 3 ||
_tabBarController.index == 4 ||
_tabBarController.index == 5
? Icons.translate_rounded
: Icons.help_outline_outlined,
: Icons.translate_rounded,
color: Theme.of(context).hintColor)),
],
bottom: TabBar(
indicatorSize: TabBarIndicatorSize.label,
isScrollable: true,
controller: _tabBarController,
tabs: [
Tab(text: l10n.manga_sources),
Tab(text: l10n.anime_sources),
Tab(text: l10n.novel_sources),
Tab(
child: Row(
children: [
Text(l10n.manga_extensions),
const SizedBox(width: 8),
_extensionUpdateNumbers(ref, ItemType.manga)
],
),
),
Tab(
child: Row(
children: [
Text(l10n.anime_extensions),
const SizedBox(width: 8),
_extensionUpdateNumbers(ref, ItemType.anime)
],
),
),
Tab(
child: Row(
children: [
Text(l10n.novel_extensions),
const SizedBox(width: 8),
_extensionUpdateNumbers(ref, ItemType.novel)
],
),
),
// Tab(text: l10n.migrate),
],
),
indicatorSize: TabBarIndicatorSize.label,
isScrollable: true,
controller: _tabBarController,
tabs: [
if (!hideManga) Tab(text: l10n.manga_sources),
if (!hideAnime) Tab(text: l10n.anime_sources),
if (!hideNovel) Tab(text: l10n.novel_sources),
if (!hideManga)
Tab(
child: Row(
children: [
Text(l10n.manga_extensions),
const SizedBox(width: 8),
_extensionUpdateNumbers(ref, ItemType.manga)
],
),
),
if (!hideAnime)
Tab(
child: Row(
children: [
Text(l10n.anime_extensions),
const SizedBox(width: 8),
_extensionUpdateNumbers(ref, ItemType.anime)
],
),
),
if (!hideNovel)
Tab(
child: Row(
children: [
Text(l10n.novel_extensions),
const SizedBox(width: 8),
_extensionUpdateNumbers(ref, ItemType.novel)
],
),
),
]),
),
body: TabBarView(controller: _tabBarController, children: [
SourcesScreen(
itemType: ItemType.manga,
tabIndex: (index) {
_tabBarController.animateTo(index);
},
),
SourcesScreen(
itemType: ItemType.anime,
tabIndex: (index) {
_tabBarController.animateTo(index);
},
),
SourcesScreen(
itemType: ItemType.novel,
tabIndex: (index) {
_tabBarController.animateTo(index);
},
),
ExtensionScreen(
query: _textEditingController.text,
itemType: ItemType.manga,
),
ExtensionScreen(
query: _textEditingController.text,
itemType: ItemType.anime,
),
ExtensionScreen(
query: _textEditingController.text,
itemType: ItemType.novel,
),
// const MigrateScreen()
if (!hideManga)
SourcesScreen(
itemType: ItemType.manga,
tabIndex: (index) {
_tabBarController.animateTo(index);
},
),
if (!hideAnime)
SourcesScreen(
itemType: ItemType.anime,
tabIndex: (index) {
_tabBarController.animateTo(index);
},
),
if (!hideNovel)
SourcesScreen(
itemType: ItemType.novel,
tabIndex: (index) {
_tabBarController.animateTo(index);
},
),
if (!hideManga)
ExtensionScreen(
query: _textEditingController.text, itemType: ItemType.manga),
if (!hideAnime)
ExtensionScreen(
query: _textEditingController.text, itemType: ItemType.anime),
if (!hideNovel)
ExtensionScreen(
query: _textEditingController.text, itemType: ItemType.novel),
]),
),
);

View file

@ -57,9 +57,13 @@ class _HistoryScreenState extends ConsumerState<HistoryScreen>
final hideManga = ref.watch(hideMangaStateProvider);
final hideAnime = ref.watch(hideAnimeStateProvider);
final hideNovel = ref.watch(hideNovelStateProvider);
if (!hideManga) newTabs++;
if (!hideAnime) newTabs++;
if (!hideNovel) newTabs++;
if (newTabs == 0) {
return SizedBox.shrink();
}
if (tabs != newTabs) {
_tabBarController.removeListener(tabListener);
_tabBarController.dispose();

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -22,11 +23,16 @@ import 'package:mangayomi/utils/extensions/build_context_extensions.dart';
import 'package:mangayomi/modules/library/providers/library_state_provider.dart';
import 'package:mangayomi/modules/more/providers/incognito_mode_state_provider.dart';
class MainScreen extends ConsumerWidget {
class MainScreen extends ConsumerStatefulWidget {
const MainScreen({super.key, required this.child});
final Widget child;
@override
ConsumerState<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends ConsumerState<MainScreen> {
String getHyphenatedUpdatesLabel(String languageCode, String defaultLabel) {
switch (languageCode) {
case 'de':
@ -43,23 +49,45 @@ class MainScreen extends ConsumerWidget {
}
}
late bool hideManga = ref.watch(hideMangaStateProvider);
late bool hideAnime = ref.watch(hideAnimeStateProvider);
late bool hideNovel = ref.watch(hideNovelStateProvider);
late String? location =
ref.watch(routerCurrentLocationStateProvider(context));
late String defaultLocation = hideManga
? hideAnime
? hideNovel
? '/more'
: '/NovelLibrary'
: '/AnimeLibrary'
: '/MangaLibrary';
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = l10nLocalizations(context)!;
initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.go(defaultLocation);
Timer.periodic(Duration(minutes: 5), (timer) {
ref.read(checkAndBackupProvider);
});
ref.watch(checkForUpdateProvider(context: context));
ref.watch(fetchMangaSourcesListProvider(id: null, reFresh: false));
ref.watch(fetchAnimeSourcesListProvider(id: null, reFresh: false));
ref.watch(fetchNovelSourcesListProvider(id: null, reFresh: false));
});
super.initState();
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final route = GoRouter.of(context);
ref.read(checkAndBackupProvider);
ref.watch(checkForUpdateProvider(context: context));
ref.watch(fetchMangaSourcesListProvider(id: null, reFresh: false));
ref.watch(fetchAnimeSourcesListProvider(id: null, reFresh: false));
ref.watch(fetchNovelSourcesListProvider(id: null, reFresh: false));
location = ref.watch(routerCurrentLocationStateProvider(context));
return ref.watch(migrationProvider).when(data: (_) {
return Consumer(builder: (context, ref, chuld) {
final location = ref.watch(
routerCurrentLocationStateProvider(context),
);
final hideManga = ref.watch(hideMangaStateProvider);
final hideAnime = ref.watch(hideAnimeStateProvider);
final hideNovel = ref.watch(hideNovelStateProvider);
hideManga = ref.watch(hideMangaStateProvider);
hideAnime = ref.watch(hideAnimeStateProvider);
hideNovel = ref.watch(hideNovelStateProvider);
bool isReadingScreen = location == '/mangaReaderView' ||
location == '/animePlayerView' ||
location == '/novelReaderView';
@ -81,7 +109,7 @@ class MainScreen extends ConsumerWidget {
if (hideNovel) {
dest.removeWhere((d) => d == "/NovelLibrary");
}
int currentIndex = location == null ? 0 : dest.indexOf(location);
int currentIndex = dest.indexOf(location ?? defaultLocation);
if (currentIndex == -1) {
currentIndex = dest.length - 1;
}
@ -195,23 +223,19 @@ class MainScreen extends ConsumerWidget {
Icon(Icons
.new_releases_outlined)),
label: Padding(
padding: const EdgeInsets.only(
top: 5),
child: Stack(
children: [
Text(
getHyphenatedUpdatesLabel(
ref
.watch(
l10nLocaleStateProvider)
.languageCode,
l10n.updates,
),
textAlign:
TextAlign.center,
),
],
))),
padding:
const EdgeInsets.only(top: 5),
child: Text(
getHyphenatedUpdatesLabel(
ref
.watch(
l10nLocaleStateProvider)
.languageCode,
l10n.updates,
),
textAlign: TextAlign.center,
),
)),
NavigationRailDestination(
selectedIcon:
const Icon(Icons.history),
@ -244,30 +268,7 @@ class MainScreen extends ConsumerWidget {
],
selectedIndex: currentIndex,
onDestinationSelected: (newIndex) {
final dest = [
'/MangaLibrary',
'/AnimeLibrary',
'/NovelLibrary',
'/updates',
'/history',
'/browse',
'/more'
];
if (hideManga) {
dest.removeWhere(
(d) => d == "/MangaLibrary");
}
if (hideAnime) {
dest.removeWhere(
(d) => d == "/AnimeLibrary");
}
if (hideNovel) {
dest.removeWhere(
(d) => d == "/NovelLibrary");
}
route.go(dest[newIndex >= dest.length
? dest.length - 1
: newIndex]);
route.go(dest[newIndex]);
},
);
}),
@ -275,10 +276,10 @@ class MainScreen extends ConsumerWidget {
],
),
),
Expanded(child: child)
Expanded(child: widget.child)
],
)
: child,
: widget.child,
bottomNavigationBar: context.isTablet
? null
: AnimatedContainer(
@ -352,27 +353,7 @@ class MainScreen extends ConsumerWidget {
label: l10n.more),
],
onDestinationSelected: (newIndex) {
final dest = [
'/MangaLibrary',
'/AnimeLibrary',
'/NovelLibrary',
'/updates',
'/history',
'/browse',
'/more'
];
if (hideManga) {
dest.removeWhere((d) => d == "/MangaLibrary");
}
if (hideAnime) {
dest.removeWhere((d) => d == "/AnimeLibrary");
}
if (hideNovel) {
dest.removeWhere((d) => d == "/NovelLibrary");
}
route.go(dest[newIndex >= dest.length
? dest.length - 1
: newIndex]);
route.go(dest[newIndex]);
},
),
),

View file

@ -99,6 +99,9 @@ class _UpdatesScreenState extends ConsumerState<UpdatesScreen>
if (!hideManga) newTabs++;
if (!hideAnime) newTabs++;
if (!hideNovel) newTabs++;
if (newTabs == 0) {
return SizedBox.shrink();
}
if (tabs != newTabs) {
_tabBarController.removeListener(tabListener);
_tabBarController.dispose();

View file

@ -80,6 +80,7 @@ class RouterCurrentLocationState extends _$RouterCurrentLocationState {
}
class RouterNotifier extends ChangeNotifier {
List<RouteBase> get _routes => [
ShellRoute(
builder: (context, state, child) => MainScreen(child: child),