Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrossh committed May 31, 2024
1 parent e7e5687 commit 07fd041
Show file tree
Hide file tree
Showing 24 changed files with 31,492 additions and 31,629 deletions.
62,204 changes: 31,102 additions & 31,102 deletions assets/bibles/English.txt

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions integration_test/home_screen_test.dart

This file was deleted.

50 changes: 24 additions & 26 deletions lib/models.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import "package:flutter/material.dart";
import "package:only_bible_app/utils.dart";

class Bible {
final String name;
final List<Book> books;
Expand Down Expand Up @@ -32,16 +29,11 @@ class Book {
required this.chapters,
});

String name(BuildContext context) {
return context.bookNames[index];
}

bool isOldTestament() => index < 39;

bool isNewTestament() => index >= 39;

String shortName(BuildContext context) {
final name = this.name(context);
String shortName(String name) {
if (name[0] == "1" || name[0] == "2" || name[0] == "3") {
return "${name[0]}${name[2].toUpperCase()}${name.substring(3, 4).toLowerCase()}";
}
Expand All @@ -54,22 +46,25 @@ class Chapter {
final int book;
final List<Verse> verses;

const Chapter({required this.index, required this.verses, required this.book});
const Chapter(
{required this.index, required this.verses, required this.book});
}

class Verse {
final int index;
final String bibleName;
final int book;
final int chapter;
String heading;
final String text;

const Verse({
Verse({
required this.index,
required this.text,
required this.bibleName,
required this.chapter,
required this.book,
required this.heading,
});
}

Expand All @@ -81,34 +76,37 @@ List<Book> getBibleFromText(String bibleName, String text) {
if (lines.length - 1 == index) {
continue;
}
var book = int.parse(line.substring(0, 2));
var chapter = int.parse(line.substring(3, 6));
var verseNo = int.parse(line.substring(7, 10));
var verseText = line.substring(11);
if (books.length < book) {
final arr = line.split("|");
final book = int.parse(arr[0]);
final chapter = int.parse(arr[1]);
final verseNo = int.parse(arr[2]);
final heading = arr[3];
final verseText = arr[4];
if (books.length < book + 1) {
books.add(
Book(
index: book - 1,
index: book,
chapters: [],
),
);
}
if (books[book - 1].chapters.length < chapter) {
books[book - 1].chapters.add(
if (books[book].chapters.length < chapter + 1) {
books[book].chapters.add(
Chapter(
index: chapter - 1,
book: book - 1,
index: chapter,
book: book,
verses: [],
),
);
}
books[book - 1].chapters[chapter - 1].verses.add(
books[book].chapters[chapter].verses.add(
Verse(
index: verseNo - 1,
text: verseText,
index: verseNo,
bibleName: bibleName,
chapter: chapter - 1,
book: book - 1,
chapter: chapter,
book: book,
text: verseText,
heading: heading,
),
);
}
Expand Down
59 changes: 37 additions & 22 deletions lib/navigation.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import "package:atoms_state/atoms_state.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:app_review/app_review.dart";
import "package:only_bible_app/models.dart";
import "package:only_bible_app/screens/bible_select_screen.dart";
import "package:only_bible_app/screens/book_select_screen.dart";
import "package:only_bible_app/screens/chapter_select_screen.dart";
import "package:only_bible_app/screens/chapter_view_screen.dart";
import "package:only_bible_app/sheets/actions_sheet.dart";
import "package:only_bible_app/sheets/highlight_sheet.dart";
Expand Down Expand Up @@ -45,11 +47,12 @@ createNoTransitionPageRoute(Widget page) {
);
}

createSlideRoute(
{required BuildContext context,
TextDirection? slideDir,
required Widget page}) {
if (context.isWide || slideDir == null) {
createSlideRoute({
required BuildContext context,
TextDirection? slideDir,
required Widget page,
}) {
if (slideDir == null) {
return PageRouteBuilder(
pageBuilder: (context, _, __) {
return page;
Expand Down Expand Up @@ -105,13 +108,20 @@ pushBookChapter(BuildContext context, String bibleName, int book, int chapter,
}

replaceBookChapter(
BuildContext context, String bibleName, int book, int chapter) {
BuildContext context,
String bibleName,
int book,
int chapter,
) {
dispatch(UpdateChapter(book, chapter));
clearEvents(context);
Navigator.of(context).pushReplacement(
createNoTransitionPageRoute(
ChapterViewScreen(
bibleName: bibleName, bookIndex: book, chapterIndex: chapter),
bibleName: bibleName,
bookIndex: book,
chapterIndex: chapter,
),
),
);
}
Expand Down Expand Up @@ -202,6 +212,14 @@ changeBook(BuildContext context, Bible bible) {
);
}

changeChapter(BuildContext context, Bible bible, Book book, int index) {
Navigator.of(context).push(
createNoTransitionPageRoute(
ChapterSelectScreen(bible: bible, book: book, selectedBookIndex: index),
),
);
}

updateCurrentBible(BuildContext context, String name, String code, int book,
int chapter) async {
hideActions(context);
Expand All @@ -223,24 +241,21 @@ shareAppLink(BuildContext context) {
}
}

rateApp(BuildContext context) {
if (isAndroid()) {
context.openUrl(
"https://play.google.com/store/apps/details?id=sh.pyros.only_bible_app",
);
} else {
context.openUrl(
"https://apps.apple.com/us/app/only-bible-app/id6467606465",
);
}
rateApp(BuildContext context) async {
await AppReview.requestReview;
}

shareVerses(BuildContext context, Bible bible, List<Verse> verses) {
final name = bible.books[verses.first.book].name(context);
shareVerses(BuildContext context, Bible bible, List<Verse> verses) async {
final name = context.bookNames[verses.first.book];
final chapter = verses.first.chapter + 1;
final title = "$name $chapter:${verses.map((e) => e.index + 1).join(", ")}";
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 = context.currentLang.languageCode == "en" ? "KJV" : "";
final title = "$name $chapter:$versesThrough $version";
final text = verses.map((e) => e.text).join("\n");
Share.share("$title\n$text", subject: title);
await Share.share("$title\n$text", subject: title);
hideActions(context);
}

showSettings(BuildContext context, Bible bible) {
Expand Down Expand Up @@ -287,4 +302,4 @@ hideHighlights(BuildContext context) {
dispatch(const SetHighlightsShown(false));
Navigator.of(context).pop();
}
}
}
11 changes: 8 additions & 3 deletions lib/screens/book_select_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "package:flutter/material.dart";
import "package:only_bible_app/navigation.dart";
import "package:only_bible_app/utils.dart";
import "package:only_bible_app/widgets/scaffold_menu.dart";
import "package:only_bible_app/screens/chapter_select_screen.dart";
Expand All @@ -12,14 +13,18 @@ class BookSelectScreen extends StatelessWidget {
const BookSelectScreen({super.key, required this.bible});

onBookSelected(BuildContext context, int index) {
final book = bible.books[index];
if (book.chapters.length == 1) {
return replaceBookChapter(context, bible.name, index, 0);
}
Navigator.of(context).pushReplacement(
PageRouteBuilder(
opaque: false,
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
pageBuilder: (context, _, __) => ChapterSelectScreen(
bible: bible,
book: bible.books[index],
book: book,
selectedBookIndex: index,
),
),
Expand All @@ -37,7 +42,7 @@ class BookSelectScreen extends StatelessWidget {
children: List.of(
bible.getOldBooks().map((book) {
return TextButton(
child: Text(book.shortName(context)),
child: Text(book.shortName(context.bookNames[book.index])),
onPressed: () => onBookSelected(context, book.index),
);
}),
Expand All @@ -48,7 +53,7 @@ class BookSelectScreen extends StatelessWidget {
children: List.of(
bible.getNewBooks().map((book) {
return TextButton(
child: Text(book.shortName(context)),
child: Text(book.shortName(context.bookNames[book.index])),
onPressed: () => onBookSelected(context, book.index),
);
}),
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/chapter_select_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "package:flutter/material.dart";
import "package:only_bible_app/models.dart";
import "package:only_bible_app/navigation.dart";
import "package:only_bible_app/utils.dart";
import "package:only_bible_app/widgets/scaffold_menu.dart";
import "package:only_bible_app/widgets/sliver_tile_grid.dart";
import "package:only_bible_app/widgets/sliver_heading.dart";
Expand All @@ -18,7 +19,7 @@ class ChapterSelectScreen extends StatelessWidget {
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
SliverHeading(title: book.name(context), showClose: true),
SliverHeading(title: context.bookNames[book.index], showClose: true),
SliverTileGrid(
children: List.generate(book.chapters.length, (index) {
return TextButton(
Expand Down
Loading

0 comments on commit 07fd041

Please sign in to comment.