Skip to content

Commit

Permalink
added reader swipe toggle and hide nav bar in reader (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
DattatreyaReddy committed Jul 4, 2023
1 parent b2e18d5 commit dff5a24
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 83 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
1 change: 1 addition & 0 deletions lib/src/constants/db_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum DBKeys {
readerMagnifierSize(1.0),
readerNavigationLayout(ReaderNavigationLayout.disabled),
invertTap(false),
swipeToggle(true),
scrollAnimation(true),
showNSFW(true),
downloadedBadge(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

Expand All @@ -30,6 +31,13 @@ class ReaderScreen extends HookConsumerWidget {
final int chapterIndex;
@override
Widget build(BuildContext context, WidgetRef ref) {
useEffect(() {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
return () => SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: SystemUiOverlay.values,
);
}, []);
final mangaProvider =
useMemoized(() => mangaWithIdProvider(mangaId: mangaId), []);
final chapterProviderWithIndex = useMemoized(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import '../../../../../utils/misc/toast/toast.dart';
import '../../../../../widgets/radio_list_popup.dart';
import '../../../../settings/presentation/reader/widgets/reader_magnifier_size_slider/reader_magnifier_size_slider.dart';
import '../../../../settings/presentation/reader/widgets/reader_padding_slider/reader_padding_slider.dart';
import '../../../../settings/presentation/reader/widgets/reader_swipe_toggle_tile/reader_swipe_chapter_toggle_tile.dart';
import '../../../data/manga_book_repository.dart';
import '../../../domain/chapter/chapter_model.dart';
import '../../../domain/chapter_patch/chapter_put_model.dart';
Expand Down Expand Up @@ -73,8 +74,18 @@ class ReaderWrapper extends HookConsumerWidget {
);
final visibility = useState(true);

useEffect(() {
if (!visibility.value) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
}
return null;
}, [visibility.value]);

final double localMangaReaderPadding =
ref.watch(readerPaddingKeyProvider) ?? DBKeys.readerPadding.initial;

final bool readerSwipeChapterToggle =
ref.watch(swipeChapterToggleProvider) ?? DBKeys.swipeToggle.initial;
final mangaReaderPadding =
useState(manga.meta?.readerPadding ?? localMangaReaderPadding);

Expand Down Expand Up @@ -430,6 +441,7 @@ class ReaderWrapper extends HookConsumerWidget {
onPrevious: onPrevious,
mangaReaderNavigationLayout: mangaReaderNavigationLayout,
prevNextChapterPair: prevNextChapterPair,
readerSwipeChapterToggle: readerSwipeChapterToggle,
child: child,
),
),
Expand All @@ -448,22 +460,24 @@ class ReaderView extends HookWidget {
required this.scrollDirection,
required this.mangaReaderPadding,
required this.mangaReaderMagnifierSize,
required this.child,
required this.onNext,
required this.onPrevious,
required this.prevNextChapterPair,
required this.mangaReaderNavigationLayout,
required this.readerSwipeChapterToggle,
required this.child,
});

final VoidCallback toggleVisibility;
final Axis scrollDirection;
final double mangaReaderPadding;
final double mangaReaderMagnifierSize;
final Widget child;
final VoidCallback onNext;
final VoidCallback onPrevious;
final ({Chapter? first, Chapter? second})? prevNextChapterPair;
final ReaderNavigationLayout mangaReaderNavigationLayout;
final bool readerSwipeChapterToggle;
final Widget child;

@override
Widget build(BuildContext context) {
Expand All @@ -487,7 +501,7 @@ class ReaderView extends HookWidget {
chapterIndex: prevNextChapterPair!.second!.index!,
toPrev: true,
transVertical: scrollDirection != Axis.vertical,
)
).pushReplacement(context)
: null;
return Stack(
children: [
Expand All @@ -505,7 +519,7 @@ class ReaderView extends HookWidget {
onTap: toggleVisibility,
behavior: HitTestBehavior.translucent,
onHorizontalDragEnd: (details) {
if (scrollDirection == Axis.vertical) {
if (scrollDirection == Axis.vertical && readerSwipeChapterToggle) {
if (details.primaryVelocity == null) {
return;
} else if (details.primaryVelocity! > 8) {
Expand All @@ -516,7 +530,8 @@ class ReaderView extends HookWidget {
}
},
onVerticalDragEnd: (details) {
if (scrollDirection == Axis.horizontal) {
if (scrollDirection == Axis.horizontal &&
readerSwipeChapterToggle) {
if (details.primaryVelocity == null) {
return;
} else if (details.primaryVelocity! > 8) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ List<QuickSearchResult>? processesQuickSearch(

// Source Search
if (query.startsWith('@') ||
(context.location?.contains(Routes.browse)).ifNull()) {
(context.location.contains(Routes.browse)).ifNull()) {
String sourceQuery = query.startsWith('@') ? query.substring(1) : query;
final queryList = sourceQuery.split('/');
final sourceList =
Expand Down Expand Up @@ -121,13 +121,13 @@ List<QuickSearchResult>? processesQuickSearch(

// Manga Search
if (query.startsWith('#') ||
(context.location?.contains(Routes.library)).ifNull()) {
(context.location.contains(Routes.library)).ifNull()) {
return mangaSearch(query);
}

// Manga Description context aware Search
if ((context.location?.startsWith(Routes.mangaRoute)).ifNull()) {
final id = int.tryParse(context.location!
if ((context.location.startsWith(Routes.mangaRoute)).ifNull()) {
final id = int.tryParse(context.location
.substring(Routes.mangaRoute.length)
.split('/')
.firstOrNull
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'widgets/reader_mode_tile/reader_mode_tile.dart';
import 'widgets/reader_navigation_layout_tile/reader_navigation_layout_tile.dart';
import 'widgets/reader_padding_slider/reader_padding_slider.dart';
import 'widgets/reader_scroll_animation_tile/reader_scroll_animation_tile.dart';
import 'widgets/reader_swipe_toggle_tile/reader_swipe_chapter_toggle_tile.dart';

class ReaderSettingsScreen extends StatelessWidget {
const ReaderSettingsScreen({super.key});
Expand All @@ -26,6 +27,7 @@ class ReaderSettingsScreen extends StatelessWidget {
ReaderModeTile(),
ReaderNavigationLayoutTile(),
ReaderInvertTapTile(),
SwipeChapterToggleTile(),
ReaderScrollAnimationTile(),
ReaderPaddingSlider(),
ReaderMagnifierSizeSlider(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2022 Contributors to the Suwayomi project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../../../../../../constants/db_keys.dart';

import '../../../../../../utils/extensions/custom_extensions.dart';
import '../../../../../../utils/mixin/shared_preferences_client_mixin.dart';

part 'reader_swipe_chapter_toggle_tile.g.dart';

@riverpod
class SwipeChapterToggle extends _$SwipeChapterToggle
with SharedPreferenceClientMixin<bool> {
@override
bool? build() => initialize(
ref,
key: DBKeys.swipeToggle.name,
initial: DBKeys.swipeToggle.initial,
);
}

class SwipeChapterToggleTile extends HookConsumerWidget {
const SwipeChapterToggleTile({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return SwitchListTile(
controlAffinity: ListTileControlAffinity.trailing,
secondary: const Icon(Icons.swipe_rounded),
title: Text(context.l10n!.readerSwipeChapterToggle),
subtitle: Text(context.l10n!.readerSwipeChapterToggleDescription),
onChanged: ref.read(swipeChapterToggleProvider.notifier).update,
value: ref.watch(swipeChapterToggleProvider).ifNull(),
);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@
"@readerScrollAnimation": {
"description": "Switch title to Disable scroll animation in reader screen"
},
"@readerSwipeChapterToggle": {
"description": "Switch title to toggle `swipe to change chapter` in reader screen"
},
"@readerSwipeChapterToggleDescription": {
"description": "Switch tile description for, toggle `swipe to change chapter` in reader screen"
},
"@readerNavigationLayoutKindlish": {
"description": "Radio button text for Reader Navigation Layout - Kindle-ish"
},
Expand Down Expand Up @@ -790,6 +796,8 @@
"readerNavigationLayoutEdge": "Edge",
"readerNavigationLayoutInvert": "Invert tapping",
"readerScrollAnimation": "Scroll animation",
"readerSwipeChapterToggle": "Swipe toggle",
"readerSwipeChapterToggleDescription": "Swipe to change chapter in reader",
"readerNavigationLayoutKindlish": "Kindle-ish",
"readerNavigationLayoutLShaped": "L Shaped",
"readerNavigationLayoutRightAndLeft": "Right And Left",
Expand Down
Loading

0 comments on commit dff5a24

Please sign in to comment.