Skip to content

Commit

Permalink
Merge pull request #22 from r52/dev
Browse files Browse the repository at this point in the history
Implement favorite categories
  • Loading branch information
r52 authored Sep 15, 2024
2 parents 62a408b + 2b79384 commit fde65f4
Show file tree
Hide file tree
Showing 18 changed files with 752 additions and 306 deletions.
1 change: 0 additions & 1 deletion lib/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class MainDrawer extends ConsumerWidget {
shadows: <Shadow>[
Shadow(
offset: Offset(1.5, 1.5),
blurRadius: 0.5,
color: Color.fromARGB(255, 0, 0, 0),
),
],
Expand Down
12 changes: 6 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class _AppState extends ConsumerState<App> {
path: GagakuRoute.proxyHome,
pageBuilder: (context, state) => CustomTransitionPage<void>(
key: state.pageKey,
child: WebSourceHistory(
child: WebSourceHistoryWidget(
controller: _proxycontrollers[0],
),
transitionsBuilder: Styles.fadeThroughTransitionBuilder,
Expand All @@ -309,7 +309,7 @@ class _AppState extends ConsumerState<App> {
path: GagakuRoute.proxySaved,
pageBuilder: (context, state) => CustomTransitionPage<void>(
key: state.pageKey,
child: WebSourceFavorites(
child: WebSourceFavoritesWidget(
controller: _proxycontrollers[1],
),
transitionsBuilder: Styles.fadeThroughTransitionBuilder,
Expand All @@ -324,14 +324,14 @@ class _AppState extends ConsumerState<App> {
pageBuilder: buildWebMangaViewPage,
),
GoRoute(
path: GagakuRoute.webMangaSource,
path: GagakuRoute.webMangaChapter,
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: buildWebMangaViewPage,
pageBuilder: buildWebReaderPage,
),
GoRoute(
path: GagakuRoute.webMangaFull,
path: GagakuRoute.webMangaSource,
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: buildWebReaderPage,
pageBuilder: buildWebMangaViewPage,
),
GoRoute(
path: GagakuRoute.webMangaSourceChapter,
Expand Down
228 changes: 109 additions & 119 deletions lib/mangadex/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,134 +34,124 @@ class MangaDexLibraryView extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final type = ref.watch(libraryViewTypeProvider);
final currentPage = useState(0);
bool isLoading = false;
final statuses = useMemoized(() => MangaReadingStatus.values.skip(1).toList());
final initialtype = ref.read(libraryViewTypeProvider);
final tabController = useTabController(initialLength: statuses.length, initialIndex: statuses.indexOf(initialtype));

final listProvider = ref.watch(_getLibraryListByTypeProvider(type));
useEffect(() {
void tabCallback() {
ref.read(libraryViewTypeProvider.notifier).state = statuses.elementAt(tabController.index);
}

List<Widget> children;
tabController.addListener(tabCallback);
return () => tabController.removeListener(tabCallback);
}, [tabController]);

switch (listProvider) {
case AsyncValue(value: final list?):
final titlesProvider = ref.watch(getMangaListByPageProvider(list, currentPage.value));

isLoading = titlesProvider.isLoading;

children = [
Expanded(
child: switch (titlesProvider) {
AsyncValue(:final error?, :final stackTrace?) => RefreshIndicator(
onRefresh: () async {
ref.read(userLibraryProvider.notifier).clear();
return ref.refresh(_getLibraryListByTypeProvider(type).future);
},
child: ErrorList(
error: error,
stackTrace: stackTrace,
message: "getMangaListByPageProvider(${list.toString()}, ${currentPage.value}) failed",
),
),
AsyncValue(value: final mangas) => RefreshIndicator(
onRefresh: () async {
ref.read(userLibraryProvider.notifier).clear();
final lt = ref.read(libraryViewTypeProvider);
return ref.refresh(_getLibraryListByTypeProvider(lt).future);
},
child: MangaListWidget(
title: Text(
'${list.length} Mangas',
style: const TextStyle(fontSize: 24),
),
physics: const AlwaysScrollableScrollPhysics(),
controller: controller,
children: [
if (mangas != null) MangaListViewSliver(items: mangas),
],
),
),
},
),
NumberPaginator(
numberPages: max((list.length / MangaDexEndpoints.searchLimit).ceil(), 1),
onPageChange: (int index) {
currentPage.value = index;
},
)
];
break;
case AsyncValue(:final error?, :final stackTrace?):
children = [
Expanded(
child: RefreshIndicator(
onRefresh: () async {
ref.read(userLibraryProvider.notifier).clear();
return ref.refresh(_getLibraryListByTypeProvider(type).future);
},
child: ErrorList(
error: error,
stackTrace: stackTrace,
message: "_getLibraryListByTypeProvider($type) failed",
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ScrollConfiguration(
behavior: const MouseTouchScrollBehavior(),
child: TabBar(
tabAlignment: TabAlignment.center,
isScrollable: true,
controller: tabController,
tabs: List<Tab>.generate(
statuses.length,
(int index) => Tab(
text: statuses.elementAt(index).label,
),
),
),
];
break;
case AsyncValue(:final progress):
children = [
ListSpinner(
progress: progress?.toDouble(),
)
];
break;
}
),
Expanded(
child: TabBarView(
controller: tabController,
children: [
for (final type in statuses)
HookConsumer(
builder: (context, ref, child) {
final currentPage = useState(0);
final scrollController = useScrollController();
final listProvider = ref.watch(_getLibraryListByTypeProvider(type));

switch (listProvider) {
case AsyncValue(value: final list?):
final titlesProvider = ref.watch(getMangaListByPageProvider(list, currentPage.value));

return Scaffold(
body: Center(
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: const Alignment(-0.95, 0.0),
child: DropdownMenu<MangaReadingStatus>(
initialSelection: type,
enableFilter: false,
enableSearch: false,
requestFocusOnTap: false,
inputDecorationTheme: InputDecorationTheme(
filled: true,
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
width: 2.0,
color: theme.colorScheme.inversePrimary,
),
),
),
onSelected: (MangaReadingStatus? status) async {
if (status != null) {
ref.read(libraryViewTypeProvider.notifier).state = status;
currentPage.value = 0;
}
},
dropdownMenuEntries: List<DropdownMenuEntry<MangaReadingStatus>>.generate(
MangaReadingStatus.values.skip(1).length,
(int index) => DropdownMenuEntry<MangaReadingStatus>(
value: MangaReadingStatus.values.skip(1).elementAt(index),
label: MangaReadingStatus.values.skip(1).elementAt(index).label,
),
),
),
return Column(
children: [
Expanded(
child: Stack(
children: [
switch (titlesProvider) {
AsyncValue(:final error?, :final stackTrace?) => RefreshIndicator(
onRefresh: () async {
ref.read(userLibraryProvider.notifier).clear();
return ref.refresh(_getLibraryListByTypeProvider(type).future);
},
child: ErrorList(
error: error,
stackTrace: stackTrace,
message:
"getMangaListByPageProvider(${list.toString()}, ${currentPage.value}) failed",
),
),
AsyncValue(value: final mangas) => RefreshIndicator(
onRefresh: () async {
ref.read(userLibraryProvider.notifier).clear();
return ref.refresh(_getLibraryListByTypeProvider(type).future);
},
child: MangaListWidget(
title: Text(
'${list.length} Mangas',
style: const TextStyle(fontSize: 24),
),
physics: const AlwaysScrollableScrollPhysics(),
controller: scrollController,
children: [
if (mangas != null) MangaListViewSliver(items: mangas),
],
),
),
},
if (titlesProvider.isLoading) ...Styles.loadingOverlay,
],
),
),
NumberPaginator(
numberPages: max((list.length / MangaDexEndpoints.searchLimit).ceil(), 1),
onPageChange: (int index) {
currentPage.value = index;
},
)
],
);
case AsyncValue(:final error?, :final stackTrace?):
return Expanded(
child: RefreshIndicator(
onRefresh: () async {
ref.read(userLibraryProvider.notifier).clear();
return ref.refresh(_getLibraryListByTypeProvider(type).future);
},
child: ErrorList(
error: error,
stackTrace: stackTrace,
message: "_getLibraryListByTypeProvider($type) failed",
),
),
);
case AsyncValue(:final progress):
return ListSpinner(
progress: progress?.toDouble(),
);
}
},
),
...children,
],
),
if (isLoading) ...Styles.loadingOverlay,
],
],
),
),
),
],
);
}
}
2 changes: 0 additions & 2 deletions lib/mangadex/manga_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ class MangaDexMangaViewWidget extends HookConsumerWidget {
shadows: <Shadow>[
Shadow(
offset: Offset(0.5, 0.5),
blurRadius: 1.0,
color: Color.fromARGB(255, 0, 0, 0),
),
],
Expand All @@ -250,7 +249,6 @@ class MangaDexMangaViewWidget extends HookConsumerWidget {
shadows: <Shadow>[
Shadow(
offset: Offset(1.0, 1.0),
blurRadius: 1.0,
color: Color.fromARGB(255, 0, 0, 0),
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class GagakuRoute {
static const proxySaved = '/proxy/saved';
static const web = '/read';
static const webManga = '/read/:proxy/:code';
static const webMangaFull = '/read/:proxy/:code/:chapter/:page';
static const webMangaChapter = '/read/:proxy/:code/:chapter/:page';
static const webMangaSource = '/read/:source/:url(.*)';
static const webMangaSourceChapter = '/read-chapter/:source/:url(.*)';

Expand Down
Loading

0 comments on commit fde65f4

Please sign in to comment.