import "package:async_redux/async_redux.dart";
import "package:flutter/material.dart";
import "package:flutter_soloud/flutter_soloud.dart";
import "package:go_router/go_router.dart";
import "package:only_bible_app/gen/bible.gen.dart";
import "package:only_bible_app/store/app_state.dart";
import "package:only_bible_app/utils.dart";
import "package:only_bible_app/widgets/book_select_sheet.dart";
import "package:only_bible_app/widgets/settings_sheet.dart";
import "package:share_plus/share_plus.dart";
class ShowSettingsAction extends ReduxAction<AppState> {
final BuildContext buildContext;
ShowSettingsAction(this.buildContext, this.bible);
final surface = Theme.of(context).colorScheme.surface;
data: Theme.of(context).copyWith(
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: surface,
dragHandleColor: Theme.of(context).colorScheme.onSurfaceVariant,
child: SettingsSheet(bible: bible),
class ShowBookSelectAction extends ReduxAction<AppState> {
final BuildContext buildContext;
ShowBookSelectAction(this.buildContext, this.router, this.bible);
parentContext: buildContext,
onChapterSelected: (int bookIndex, int chapterIndex) {
Navigator.of(buildContext).pop();
dispatch(GoToChapterAction(router, bookIndex, chapterIndex));
class ShowChapterSelectAction extends ReduxAction<AppState> {
final BuildContext buildContext;
ShowChapterSelectAction(this.buildContext, this.router, this.bible, this.book);
parentContext: buildContext,
onChapterSelected: (int bookIndex, int chapterIndex) {
Navigator.of(buildContext).pop();
dispatch(GoToChapterAction(router, bookIndex, chapterIndex));
class GoToChapterAction extends ReduxAction<AppState> {
GoToChapterAction(this.router, this.book, this.chapter, {this.verse});
SoLoud.instance.disposeAllSources();
final navId = DateTime.now().millisecondsSinceEpoch;
if (book > state.savedBook || (book == state.savedBook && chapter > state.savedChapter)) {
router.push("/chapter/$book/$chapter", extra: (slideDir: TextDirection.ltr, scrollToVerse: verse, navId: navId));
} else if (book < state.savedBook || (book == state.savedBook && chapter < state.savedChapter)) {
router.push("/chapter/$book/$chapter", extra: (slideDir: TextDirection.rtl, scrollToVerse: verse, navId: navId));
router.push("/chapter/$book/$chapter",
extra: (slideDir: null as TextDirection?, scrollToVerse: verse, navId: navId));
class NextChapterAction extends ReduxAction<AppState> {
NextChapterAction(this.router, this.bible, this.book, this.chapter);
final selectedBook = bible.books![book];
if (selectedBook.chapters!.length > chapter + 1) {
newBook = selectedBook.index;
newChapter = chapter + 1;
} else if (selectedBook.index + 1 < bible.books!.length) {
final nextBook = bible.books![selectedBook.index + 1];
newBook = nextBook.index;
if (newBook == null) return null;
SoLoud.instance.disposeAllSources();
"/chapter/$newBook/$newChapter",
extra: (slideDir: TextDirection.ltr, scrollToVerse: null as int?, navId: DateTime.now().millisecondsSinceEpoch),
savedChapter: newChapter,
class PreviousChapterAction extends ReduxAction<AppState> {
PreviousChapterAction(this.router, this.bible, this.book, this.chapter);
final selectedBook = bible.books![book];
newBook = selectedBook.index;
newChapter = chapter - 1;
} else if (selectedBook.index - 1 >= 0) {
final prevBook = bible.books![selectedBook.index - 1];
newBook = prevBook.index;
newChapter = prevBook.chapters!.length - 1;
if (newBook == null) return null;
SoLoud.instance.disposeAllSources();
"/chapter/$newBook/$newChapter",
extra: (slideDir: TextDirection.rtl, scrollToVerse: null as int?, navId: DateTime.now().millisecondsSinceEpoch),
savedChapter: newChapter,
class UpdateCurrentBibleAction extends ReduxAction<AppState> {
UpdateCurrentBibleAction(this.name, this.book, this.chapter);
Future<AppState> reduce() async {
final bible = await loadBible(name);
class ShareVersesAction extends ReduxAction<AppState> {
final List<Verse> verses;
ShareVersesAction(this.verses, this.bookName);
Future<AppState?> reduce() async {
final chapter = verses.first.chapter + 1;
final items = verses.sortedBy((e) => e.index).map((e) => e.index + 1);
final versesThrough = items.length >= 3 ? "${items.first}-${items.last}" : items.join(",");
final version = state.bible.languageCode == "en" ? "KJV" : "";
final title = "$bookName $chapter:$versesThrough $version";
final text = verses.map((e) => e.text ?? "").join("\n");
await SharePlus.instance.share(
ShareParams(title: title, subject: title, text: "$title\n$text"),
return state.copy(selectedVerses: []);