mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-01-11 22:40:36 +00:00
Group related functions using an extension
- new file item_type_filters.dart for the hiddenItemTypes function. - reduces code duplication in statistics_screen, categories_screen and base_library_tab_screen
This commit is contained in:
parent
7664e38cfd
commit
9efd76581f
6 changed files with 48 additions and 46 deletions
|
|
@ -178,8 +178,8 @@ class _BrowseScreenState extends ConsumerState<BrowseScreen>
|
|||
children: [
|
||||
Text(
|
||||
isExt
|
||||
? localizedExtensions(type, l10n)
|
||||
: localizedSources(type, l10n),
|
||||
? type.localizedExtensions(l10n)
|
||||
: type.localizedSources(l10n),
|
||||
),
|
||||
if (isExt) ...[
|
||||
const SizedBox(width: 8),
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import 'package:mangayomi/modules/more/settings/reader/providers/reader_state_pr
|
|||
import 'package:mangayomi/modules/more/settings/sync/providers/sync_providers.dart';
|
||||
import 'package:mangayomi/modules/widgets/progress_center.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/utils/item_type_filters.dart';
|
||||
import 'package:mangayomi/utils/item_type_localization.dart';
|
||||
import 'package:super_sliver_list/super_sliver_list.dart';
|
||||
|
||||
|
|
@ -30,11 +31,7 @@ class _CategoriesScreenState extends ConsumerState<CategoriesScreen>
|
|||
void initState() {
|
||||
super.initState();
|
||||
final hideItems = ref.read(hideItemsStateProvider);
|
||||
_visibleTabTypes = [
|
||||
if (!hideItems.contains("/MangaLibrary")) ItemType.manga,
|
||||
if (!hideItems.contains("/AnimeLibrary")) ItemType.anime,
|
||||
if (!hideItems.contains("/NovelLibrary")) ItemType.novel,
|
||||
];
|
||||
_visibleTabTypes = hiddenItemTypes(hideItems);
|
||||
_tabBarController = TabController(
|
||||
length: _visibleTabTypes.length,
|
||||
vsync: this,
|
||||
|
|
@ -72,7 +69,7 @@ class _CategoriesScreenState extends ConsumerState<CategoriesScreen>
|
|||
indicatorSize: TabBarIndicatorSize.label,
|
||||
controller: _tabBarController,
|
||||
tabs: _visibleTabTypes.map((type) {
|
||||
return Tab(text: localizedItemType(type, l10n));
|
||||
return Tab(text: type.localized(l10n));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:mangayomi/modules/more/settings/reader/providers/reader_state_pr
|
|||
import 'package:mangayomi/modules/more/statistics/statistics_provider.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/utils/extensions/build_context_extensions.dart';
|
||||
import 'package:mangayomi/utils/item_type_filters.dart';
|
||||
import 'package:mangayomi/utils/item_type_localization.dart';
|
||||
|
||||
class StatisticsScreen extends ConsumerStatefulWidget {
|
||||
|
|
@ -24,11 +25,7 @@ class _StatisticsScreenState extends ConsumerState<StatisticsScreen>
|
|||
void initState() {
|
||||
super.initState();
|
||||
hideItems = ref.read(hideItemsStateProvider);
|
||||
_visibleTabTypes = [
|
||||
if (!hideItems.contains("/MangaLibrary")) ItemType.manga,
|
||||
if (!hideItems.contains("/AnimeLibrary")) ItemType.anime,
|
||||
if (!hideItems.contains("/NovelLibrary")) ItemType.novel,
|
||||
];
|
||||
_visibleTabTypes = hiddenItemTypes(hideItems);
|
||||
_tabController = TabController(
|
||||
length: _visibleTabTypes.length,
|
||||
vsync: this,
|
||||
|
|
@ -56,7 +53,7 @@ class _StatisticsScreenState extends ConsumerState<StatisticsScreen>
|
|||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
tabs: _visibleTabTypes.map((type) {
|
||||
return Tab(text: localizedItemType(type, l10n));
|
||||
return Tab(text: type.localized(l10n));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:mangayomi/models/manga.dart';
|
|||
import 'package:mangayomi/modules/library/widgets/search_text_form_field.dart';
|
||||
import 'package:mangayomi/modules/more/settings/reader/providers/reader_state_provider.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/utils/item_type_filters.dart';
|
||||
import 'package:mangayomi/utils/item_type_localization.dart';
|
||||
|
||||
abstract class BaseLibraryTabScreenState<T extends ConsumerStatefulWidget>
|
||||
|
|
@ -34,11 +35,7 @@ abstract class BaseLibraryTabScreenState<T extends ConsumerStatefulWidget>
|
|||
super.initState();
|
||||
hideItems = ref.read(hideItemsStateProvider);
|
||||
|
||||
visibleTabTypes = [
|
||||
if (!hideItems.contains("/MangaLibrary")) ItemType.manga,
|
||||
if (!hideItems.contains("/AnimeLibrary")) ItemType.anime,
|
||||
if (!hideItems.contains("/NovelLibrary")) ItemType.novel,
|
||||
];
|
||||
visibleTabTypes = hiddenItemTypes(hideItems);
|
||||
|
||||
tabController = TabController(length: visibleTabTypes.length, vsync: this);
|
||||
|
||||
|
|
@ -94,7 +91,7 @@ abstract class BaseLibraryTabScreenState<T extends ConsumerStatefulWidget>
|
|||
controller: tabController,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
tabs: visibleTabTypes.map((type) {
|
||||
return buildTabLabel(type, localizedItemType(type, l10n));
|
||||
return buildTabLabel(type, type.localized(l10n));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
9
lib/utils/item_type_filters.dart
Normal file
9
lib/utils/item_type_filters.dart
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import 'package:mangayomi/models/manga.dart';
|
||||
|
||||
List<ItemType> hiddenItemTypes(List<String> hideItems) {
|
||||
return [
|
||||
if (!hideItems.contains("/MangaLibrary")) ItemType.manga,
|
||||
if (!hideItems.contains("/AnimeLibrary")) ItemType.anime,
|
||||
if (!hideItems.contains("/NovelLibrary")) ItemType.novel,
|
||||
];
|
||||
}
|
||||
|
|
@ -1,35 +1,37 @@
|
|||
import 'package:mangayomi/l10n/generated/app_localizations.dart';
|
||||
import 'package:mangayomi/models/manga.dart';
|
||||
|
||||
String localizedItemType(ItemType type, AppLocalizations l10n) {
|
||||
switch (type) {
|
||||
case ItemType.manga:
|
||||
return l10n.manga;
|
||||
case ItemType.anime:
|
||||
return l10n.anime;
|
||||
case ItemType.novel:
|
||||
return l10n.novel;
|
||||
extension ItemTypeLocalization on ItemType {
|
||||
String localized(AppLocalizations l10n) {
|
||||
switch (this) {
|
||||
case ItemType.manga:
|
||||
return l10n.manga;
|
||||
case ItemType.anime:
|
||||
return l10n.anime;
|
||||
case ItemType.novel:
|
||||
return l10n.novel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String localizedSources(ItemType type, AppLocalizations l10n) {
|
||||
switch (type) {
|
||||
case ItemType.manga:
|
||||
return l10n.manga_sources;
|
||||
case ItemType.anime:
|
||||
return l10n.anime_sources;
|
||||
case ItemType.novel:
|
||||
return l10n.novel_sources;
|
||||
String localizedSources(AppLocalizations l10n) {
|
||||
switch (this) {
|
||||
case ItemType.manga:
|
||||
return l10n.manga_sources;
|
||||
case ItemType.anime:
|
||||
return l10n.anime_sources;
|
||||
case ItemType.novel:
|
||||
return l10n.novel_sources;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String localizedExtensions(ItemType type, AppLocalizations l10n) {
|
||||
switch (type) {
|
||||
case ItemType.manga:
|
||||
return l10n.manga_extensions;
|
||||
case ItemType.anime:
|
||||
return l10n.anime_extensions;
|
||||
case ItemType.novel:
|
||||
return l10n.novel_extensions;
|
||||
String localizedExtensions(AppLocalizations l10n) {
|
||||
switch (this) {
|
||||
case ItemType.manga:
|
||||
return l10n.manga_extensions;
|
||||
case ItemType.anime:
|
||||
return l10n.anime_extensions;
|
||||
case ItemType.novel:
|
||||
return l10n.novel_extensions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue