Skip to content

Commit

Permalink
Merge pull request #242 from DattatreyaReddy:volume-tap
Browse files Browse the repository at this point in the history
Added reader page change with volume keys
  • Loading branch information
DattatreyaReddy authored Oct 21, 2023
2 parents 1e2224c + 7a4c919 commit 859f1cc
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ package com.suwayomi.tachidesk_sorayomi

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
import dev.darttools.flutter_android_volume_keydown.FlutterAndroidVolumeKeydownActivity;

class MainActivity: FlutterAndroidVolumeKeydownActivity() {
}
2 changes: 2 additions & 0 deletions lib/src/constants/db_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum DBKeys {
sourceDisplayMode(DisplayMode.grid),
gridMangaCoverWidth(192.0),
readerOverlay(true),
volumeTap(false),
volumeTapInvert(false),
;

const DBKeys(this.initial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ class MangaDetailsScreen extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// Providers as Class for this screen
final mangaProvider =
useMemoized(() => mangaWithIdProvider(mangaId: mangaId), []);
final chapterListProvider =
useMemoized(() => mangaChapterListProvider(mangaId: mangaId), []);
final chapterListFilteredProvider = useMemoized(
() => mangaChapterListWithFilterProvider(mangaId: mangaId), []);
final mangaProvider = mangaWithIdProvider(mangaId: mangaId);
final chapterListProvider = mangaChapterListProvider(mangaId: mangaId);
final chapterListFilteredProvider =
mangaChapterListWithFilterProvider(mangaId: mangaId);

final manga = ref.watch(mangaProvider);
final filteredChapterList = ref.watch(chapterListFilteredProvider);
Expand Down
23 changes: 11 additions & 12 deletions lib/src/features/manga_book/presentation/reader/reader_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,9 @@ class ReaderScreen extends HookConsumerWidget {
final bool showReaderLayoutAnimation;
@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(
() => chapterProvider(mangaId: mangaId, chapterIndex: chapterIndex),
[]);
final mangaProvider = mangaWithIdProvider(mangaId: mangaId);
final chapterProviderWithIndex =
chapterProvider(mangaId: mangaId, chapterIndex: chapterIndex);

final manga = ref.watch(mangaProvider);
final chapter = ref.watch(chapterProviderWithIndex);
Expand Down Expand Up @@ -97,6 +88,14 @@ class ReaderScreen extends HookConsumerWidget {
[chapter],
);

useEffect(() {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
return () => SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: SystemUiOverlay.values,
);
}, []);

return WillPopScope(
onWillPop: () async {
ref.invalidate(chapterProviderWithIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ContinuousReaderMode extends HookConsumerWidget {
final bool showReaderLayoutAnimation;
@override
Widget build(BuildContext context, WidgetRef ref) {
final touchPoints = useState(0);
final scrollController = useMemoized(() => ItemScrollController());
final positionsListener = useMemoized(() => ItemPositionsListener.create());
final currentIndex = useState(
Expand Down Expand Up @@ -82,119 +83,126 @@ class ContinuousReaderMode extends HookConsumerWidget {
final isAnimationEnabled =
ref.read(readerScrollAnimationProvider).ifNull(true);
return ReaderWrapper(
scrollDirection: scrollDirection,
chapter: chapter,
manga: manga,
showReaderLayoutAnimation: showReaderLayoutAnimation,
currentIndex: currentIndex.value,
onChanged: (index) => scrollController.jumpTo(index: index),
onPrevious: () {
final ItemPosition itemPosition =
positionsListener.itemPositions.value.toList().first;
isAnimationEnabled
? scrollController.scrollTo(
index: itemPosition.index,
duration: kDuration,
curve: kCurve,
alignment: itemPosition.itemLeadingEdge + .8,
)
: scrollController.jumpTo(
index: itemPosition.index,
alignment: itemPosition.itemLeadingEdge + .8,
);
},
onNext: () {
ItemPosition itemPosition =
positionsListener.itemPositions.value.first;
final int index;
final double alignment;
if (itemPosition.itemTrailingEdge > 1) {
index = itemPosition.index;
alignment = itemPosition.itemLeadingEdge - .8;
} else {
index = itemPosition.index + 1;
alignment = 0;
}
isAnimationEnabled
? scrollController.scrollTo(
index: index,
duration: kDuration,
curve: kCurve,
alignment: alignment,
)
: scrollController.jumpTo(
index: index,
alignment: alignment,
);
},
child: AppUtils.wrapIf(
!kIsWeb && (Platform.isAndroid || Platform.isIOS)
? (child) => InteractiveViewer(maxScale: 5, child: child)
touchPoints: touchPoints,
scrollDirection: scrollDirection,
chapter: chapter,
manga: manga,
showReaderLayoutAnimation: showReaderLayoutAnimation,
currentIndex: currentIndex.value,
onChanged: (index) => scrollController.jumpTo(index: index),
onPrevious: () {
final ItemPosition itemPosition =
positionsListener.itemPositions.value.toList().first;
isAnimationEnabled
? scrollController.scrollTo(
index: itemPosition.index,
duration: kDuration,
curve: kCurve,
alignment: itemPosition.itemLeadingEdge + .8,
)
: scrollController.jumpTo(
index: itemPosition.index,
alignment: itemPosition.itemLeadingEdge + .8,
);
},
onNext: () {
ItemPosition itemPosition = positionsListener.itemPositions.value.first;
final int index;
final double alignment;
if (itemPosition.itemTrailingEdge > 1) {
index = itemPosition.index;
alignment = itemPosition.itemLeadingEdge - .8;
} else {
index = itemPosition.index + 1;
alignment = 0;
}
isAnimationEnabled
? scrollController.scrollTo(
index: index,
duration: kDuration,
curve: kCurve,
alignment: alignment,
)
: scrollController.jumpTo(
index: index,
alignment: alignment,
);
},
child: AppUtils.wrapIf(
!kIsWeb && (Platform.isAndroid || Platform.isIOS)
? (child) => InteractiveViewer(maxScale: 5, child: child)
: null,
ScrollablePositionedList.separated(
physics: touchPoints.value >= 2
? const NeverScrollableScrollPhysics()
: null,
ScrollablePositionedList.separated(
itemScrollController: scrollController,
itemPositionsListener: positionsListener,
initialScrollIndex: chapter.read.ifNull()
? 0
: chapter.lastPageRead.getValueOnNullOrNegative(),
scrollDirection: scrollDirection,
reverse: reverse,
itemCount: chapter.pageCount ?? 0,
separatorBuilder: (BuildContext context, int index) =>
showSeparator ? KSizedBox.h16.size : const SizedBox.shrink(),
itemBuilder: (BuildContext context, int index) {
final image = ServerImage(
showReloadButton: true,
fit: scrollDirection == Axis.vertical
? BoxFit.fitWidth
: BoxFit.fitHeight,
appendApiToUrl: true,
imageUrl: MangaUrl.chapterPageWithIndex(
chapterIndex: chapter.index!,
mangaId: manga.id!,
pageIndex: index,
itemScrollController: scrollController,
itemPositionsListener: positionsListener,
initialScrollIndex: chapter.read.ifNull()
? 0
: chapter.lastPageRead.getValueOnNullOrNegative(),
scrollDirection: scrollDirection,
reverse: reverse,
itemCount: chapter.pageCount ?? 0,
minCacheExtent: scrollDirection == Axis.vertical
? context.height * 2
: context.width * 2,
separatorBuilder: (BuildContext context, int index) =>
showSeparator ? KSizedBox.h16.size : const SizedBox.shrink(),
itemBuilder: (BuildContext context, int index) {
final image = ServerImage(
showReloadButton: true,
fit: scrollDirection == Axis.vertical
? BoxFit.fitWidth
: BoxFit.fitHeight,
appendApiToUrl: true,
imageUrl: MangaUrl.chapterPageWithIndex(
chapterIndex: chapter.index!,
mangaId: manga.id!,
pageIndex: index,
),
progressIndicatorBuilder: (_, __, downloadProgress) => Center(
child: CircularProgressIndicator(
value: downloadProgress.progress,
),
progressIndicatorBuilder: (_, __, downloadProgress) => Center(
child: CircularProgressIndicator(
value: downloadProgress.progress,
),
),
wrapper: (child) => SizedBox(
height: scrollDirection == Axis.vertical
? context.height * .7
: null,
width: scrollDirection != Axis.vertical
? context.width * .7
: null,
child: child,
),
wrapper: (child) => SizedBox(
height: scrollDirection == Axis.vertical
? context.height * .7
: null,
width: scrollDirection != Axis.vertical
? context.width * .7
: null,
child: child,
),
);
if (index == 0 || index == (chapter.pageCount ?? 1) - 1) {
final bool reverseDirection =
scrollDirection == Axis.horizontal && reverse;
final separator = SizedBox(
width: scrollDirection != Axis.vertical
? context.width * .5
: null,
child: ChapterSeparator(
manga: manga,
chapter: chapter,
isPreviousChapterSeparator: (index == 0),
),
);
if (index == 0 || index == (chapter.pageCount ?? 1) - 1) {
final bool reverseDirection =
scrollDirection == Axis.horizontal && reverse;
final separator = SizedBox(
width: scrollDirection != Axis.vertical
? context.width * .5
: null,
child: ChapterSeparator(
manga: manga,
chapter: chapter,
isPreviousChapterSeparator: (index == 0),
),
);
return Flex(
direction: scrollDirection,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: ((index == 0) != reverseDirection)
? [separator, image]
: [image, separator],
);
} else {
return image;
}
},
),
));
return Flex(
direction: scrollDirection,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: ((index == 0) != reverseDirection)
? [separator, image]
: [image, separator],
);
} else {
return image;
}
},
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SinglePageReaderMode extends HookConsumerWidget {
final bool showReaderLayoutAnimation;
@override
Widget build(BuildContext context, WidgetRef ref) {
final touchPoints = useState(0);
final cacheManager = useMemoized(() => DefaultCacheManager());
final scrollController = usePageController(
initialPage: chapter.read.ifNull()
Expand Down Expand Up @@ -100,6 +101,7 @@ class SinglePageReaderMode extends HookConsumerWidget {
final isAnimationEnabled =
ref.read(readerScrollAnimationProvider).ifNull(true);
return ReaderWrapper(
touchPoints: touchPoints,
scrollDirection: scrollDirection,
chapter: chapter,
manga: manga,
Expand All @@ -115,6 +117,9 @@ class SinglePageReaderMode extends HookConsumerWidget {
curve: kCurve,
),
child: PageView.builder(
physics: touchPoints.value >= 2
? const NeverScrollableScrollPhysics()
: null,
scrollDirection: scrollDirection,
reverse: reverse,
controller: scrollController,
Expand Down
Loading

0 comments on commit 859f1cc

Please sign in to comment.