diff --git a/lib/models.dart b/lib/models.dart index 2405da15..27a119bc 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -1,20 +1,17 @@ import "package:flutter/material.dart"; -import "package:flutter_gen/gen_l10n/app_localizations.dart"; +import "package:only_bible_app/providers/app_model.dart"; class Bible { - final int id; final String name; final bool hasAudio; List books = []; Bible({ - required this.id, required this.name, required this.hasAudio, }); Bible.withBooks({ - required this.id, required this.name, required this.hasAudio, required this.books, @@ -31,78 +28,6 @@ class Bible { List getNewBooks() { return books.where((it) => it.isNewTestament()).toList(); } - - static List getBookNames(BuildContext context) { - final l = AppLocalizations.of(context)!; - return [ - l.genesis, - l.exodus, - l.leviticus, - l.numbers, - l.deuteronomy, - l.joshua, - l.judges, - l.ruth, - l.firstSamuel, - l.secondSamuel, - l.firstKings, - l.secondKings, - l.firstChronicles, - l.secondChronicles, - l.ezra, - l.nehemiah, - l.esther, - l.job, - l.psalms, - l.proverbs, - l.ecclesiastes, - l.song_of_solomon, - l.isaiah, - l.jeremiah, - l.lamentations, - l.ezekiel, - l.daniel, - l.hosea, - l.joel, - l.amos, - l.obadiah, - l.jonah, - l.micah, - l.nahum, - l.habakkuk, - l.zephaniah, - l.haggai, - l.zechariah, - l.malachi, - l.matthew, - l.mark, - l.luke, - l.john, - l.acts, - l.romans, - l.firstCorinthians, - l.secondCorinthians, - l.galatians, - l.ephesians, - l.philippians, - l.colossians, - l.firstThessalonians, - l.secondThessalonians, - l.firstTimothy, - l.secondTimothy, - l.titus, - l.philemon, - l.hebrews, - l.james, - l.firstPeter, - l.secondPeter, - l.firstJohn, - l.secondJohn, - l.thirdJohn, - l.jude, - l.revelation, - ]; - } } class Book { @@ -115,7 +40,7 @@ class Book { }); String name(BuildContext context) { - return Bible.getBookNames(context)[index]; + return AppModel.of(context).getBookNames(context)[index]; } bool isOldTestament() => index < 39; @@ -146,20 +71,6 @@ class Verse { const Verse({required this.index, required this.text, required this.chapter, required this.book}); } -final bibles = [ - Bible(id: 1, name: "English", hasAudio: false), - Bible(id: 2, name: "Kannada", hasAudio: true), - Bible(id: 3, name: "Nepali", hasAudio: false), - Bible(id: 4, name: "Hindi", hasAudio: false), - Bible(id: 5, name: "Gujarati", hasAudio: false), - Bible(id: 6, name: "Malayalam", hasAudio: false), - Bible(id: 7, name: "Oriya", hasAudio: false), - Bible(id: 8, name: "Punjabi", hasAudio: false), - Bible(id: 9, name: "Tamil", hasAudio: false), - Bible(id: 10, name: "Telugu", hasAudio: false), - Bible(id: 11, name: "Bengali", hasAudio: false), -]; - List getBibleFromText(String text) { final List books = []; final lines = text.split("\n"); diff --git a/lib/providers/app_model.dart b/lib/providers/app_model.dart index e53dc085..7b615371 100644 --- a/lib/providers/app_model.dart +++ b/lib/providers/app_model.dart @@ -1,10 +1,10 @@ // import "package:firebase_performance/firebase_performance.dart"; +import "package:flutter_gen/gen_l10n/app_localizations.dart"; import "package:flutter/services.dart"; import "package:flutter/material.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/models.dart"; -import "package:only_bible_app/screens/locale_select_screen.dart"; import "package:only_bible_app/widgets/actions_sheet.dart"; import "package:only_bible_app/widgets/highlight_button.dart"; import "package:only_bible_app/widgets/scaffold_markdown.dart"; @@ -27,8 +27,9 @@ class HistoryFrame { class AppModel extends ChangeNotifier { late PackageInfo packageInfo; - Locale locale = const Locale("en"); - Bible bible = bibles.first; + late Bible bible; + late Locale locale; + bool engTitles = false; bool darkMode = false; bool fontBold = false; double textScaleFactor = 0; @@ -48,7 +49,7 @@ class AppModel extends ChangeNotifier { save() async { final prefs = await SharedPreferences.getInstance(); - await prefs.setInt("bibleId", bible.id); + await prefs.setString("bibleName", bible.name); await prefs.setBool("darkMode", darkMode); await prefs.setBool("fontBold", fontBold); await prefs.setDouble("textScaleFactor", textScaleFactor); @@ -58,12 +59,11 @@ class AppModel extends ChangeNotifier { Future<(int, int)> loadData() async { packageInfo = await PackageInfo.fromPlatform(); final prefs = await SharedPreferences.getInstance(); - final bibleId = prefs.getInt("bibleId") ?? 1; darkMode = prefs.getBool("darkMode") ?? false; fontBold = prefs.getBool("fontBold") ?? false; textScaleFactor = prefs.getDouble("textScaleFactor") ?? 1; locale = Locale(prefs.getString("languageCode") ?? "en"); - bible = await loadBible(bibleId); + bible = await loadBible(prefs.getString("bibleName") ?? "English"); // await Future.delayed(Duration(seconds: 3)); final book = prefs.getInt("book") ?? 0; final chapter = prefs.getInt("chapter") ?? 0; @@ -71,31 +71,93 @@ class AppModel extends ChangeNotifier { return (book, chapter); } - Future loadBible(int id) async { - final selectedBible = bibles.firstWhere((it) => it.id == id); + Future loadBible(String name) async { // Trace customTrace; // if (!isDesktop()) { // customTrace = FirebasePerformance.instance.newTrace("loadBible"); // await customTrace.start(); // } - final books = await getBibleFromAsset(selectedBible.name); + final books = await getBibleFromAsset(name); // if (!isDesktop()) { // await customTrace.stop(); // } return Bible.withBooks( - id: selectedBible.id, - name: selectedBible.name, - hasAudio: selectedBible.hasAudio, + name: name, + hasAudio: true, books: books, ); } - changeLocale(BuildContext context) { - Navigator.of(context).pushReplacement( - createNoTransitionPageRoute( - const LocaleSelectScreen(), - ), - ); + List getBookNames(BuildContext context) { + final l = engTitles ? lookupAppLocalizations(Locale("en")) : AppLocalizations.of(context)!; + return [ + l.genesis, + l.exodus, + l.leviticus, + l.numbers, + l.deuteronomy, + l.joshua, + l.judges, + l.ruth, + l.firstSamuel, + l.secondSamuel, + l.firstKings, + l.secondKings, + l.firstChronicles, + l.secondChronicles, + l.ezra, + l.nehemiah, + l.esther, + l.job, + l.psalms, + l.proverbs, + l.ecclesiastes, + l.song_of_solomon, + l.isaiah, + l.jeremiah, + l.lamentations, + l.ezekiel, + l.daniel, + l.hosea, + l.joel, + l.amos, + l.obadiah, + l.jonah, + l.micah, + l.nahum, + l.habakkuk, + l.zephaniah, + l.haggai, + l.zechariah, + l.malachi, + l.matthew, + l.mark, + l.luke, + l.john, + l.acts, + l.romans, + l.firstCorinthians, + l.secondCorinthians, + l.galatians, + l.ephesians, + l.philippians, + l.colossians, + l.firstThessalonians, + l.secondThessalonians, + l.firstTimothy, + l.secondTimothy, + l.titus, + l.philemon, + l.hebrews, + l.james, + l.firstPeter, + l.secondPeter, + l.firstJohn, + l.secondJohn, + l.thirdJohn, + l.jude, + l.revelation, + ]; } changeBible(BuildContext context) { @@ -114,15 +176,11 @@ class AppModel extends ChangeNotifier { ); } - updateCurrentLocale(Locale l) async { - locale = l; - notifyListeners(); - save(); - } - - updateCurrentBible(BuildContext context, int id) async { + // TODO: maybe don't pass name here + updateCurrentBible(BuildContext context, Locale l, String name) async { // TODO: maybe use a future as the bible needs to load - bible = await loadBible(id); + locale = l; + bible = await loadBible(name); notifyListeners(); save(); } @@ -135,13 +193,19 @@ class AppModel extends ChangeNotifier { ); } - toggleMode() async { + toggleDarkMode() { darkMode = !darkMode; updateStatusBar(); notifyListeners(); save(); } + toggleEngBookNames() { + engTitles = !engTitles; + notifyListeners(); + save(); + } + updateStatusBar() { if (darkMode) { SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( diff --git a/lib/screens/bible_select_screen.dart b/lib/screens/bible_select_screen.dart index d7f54538..8d040f5e 100644 --- a/lib/screens/bible_select_screen.dart +++ b/lib/screens/bible_select_screen.dart @@ -1,5 +1,5 @@ import "package:flutter/material.dart"; -import "package:only_bible_app/models.dart"; +import "package:flutter_gen/gen_l10n/app_localizations.dart"; import "package:only_bible_app/providers/app_model.dart"; import "package:only_bible_app/widgets/scaffold_menu.dart"; import "package:only_bible_app/widgets/sliver_heading.dart"; @@ -19,13 +19,28 @@ class BibleSelectScreen extends StatelessWidget { SliverTileGrid( listType: ListType.large, children: List.of( - bibles.map((bible) { - return TextButton( - child: Text(bible.name), - onPressed: () { - model.updateCurrentBible(context, bible.id); - Navigator.of(context).pop(); - }, + AppLocalizations.supportedLocales.map((l) { + return Localizations.override( + context: context, + locale: Locale(l.languageCode), + child: Builder( + builder: (context) { + final bibleName = AppLocalizations.of(context)!.languageTitle; + return TextButton( + child: Text(bibleName), + // child: Column( + // children: [ + // Text(l.name), + // // Text("(${l.localName})"), + // ], + // ), + onPressed: () { + AppModel.ofEvent(context).updateCurrentBible(context, l, bibleName); + Navigator.of(context).pop(); + }, + ); + }, + ), ); }), ), diff --git a/lib/screens/locale_select_screen.dart b/lib/screens/locale_select_screen.dart deleted file mode 100644 index 3306fcc3..00000000 --- a/lib/screens/locale_select_screen.dart +++ /dev/null @@ -1,50 +0,0 @@ -import "package:flutter/material.dart"; -import "package:flutter_gen/gen_l10n/app_localizations.dart"; -import "package:only_bible_app/providers/app_model.dart"; -import "package:only_bible_app/widgets/scaffold_menu.dart"; -import "package:only_bible_app/widgets/sliver_heading.dart"; -import "package:only_bible_app/widgets/sliver_tile_grid.dart"; - -class LocaleSelectScreen extends StatelessWidget { - const LocaleSelectScreen({super.key}); - - @override - Widget build(BuildContext context) { - return ScaffoldMenu( - child: CustomScrollView( - physics: const BouncingScrollPhysics(), - slivers: [ - const SliverHeading(title: "Choose your preferred language", showClose: true), - SliverTileGrid( - listType: ListType.large, - children: List.of( - AppLocalizations.supportedLocales.map((l) { - return Localizations.override( - context: context, - locale: Locale(l.languageCode), - child: Builder( - builder: (context) { - return TextButton( - child: Text(AppLocalizations.of(context)!.languageTitle), - // child: Column( - // children: [ - // Text(l.name), - // // Text("(${l.localName})"), - // ], - // ), - onPressed: () { - AppModel.ofEvent(context).updateCurrentLocale(l); - Navigator.of(context).pop(); - }, - ); - }, - ), - ); - }), - ), - ), - ], - ), - ); - } -} diff --git a/lib/widgets/settings_sheet.dart b/lib/widgets/settings_sheet.dart index cf45d494..5cf52638 100644 --- a/lib/widgets/settings_sheet.dart +++ b/lib/widgets/settings_sheet.dart @@ -26,12 +26,6 @@ class SettingsSheet extends StatelessWidget { title: Text(localizations.settingsTitle, style: Theme.of(context).textTheme.headlineMedium), margin: const EdgeInsetsDirectional.symmetric(horizontal: 20), tiles: [ - SettingsTile.navigation( - leading: const Icon(Icons.language, color: Colors.green), - title: const Text("App Language"), - value: Text(AppLocalizations.of(context)!.languageTitle), - onPressed: app.changeLocale, - ), SettingsTile.navigation( leading: const Icon(Icons.book_outlined, color: Colors.blueAccent), title: const Text("Bible"), @@ -43,7 +37,7 @@ class SettingsSheet extends StatelessWidget { title: const Text("Theme"), trailing: ToggleButtons( onPressed: (int index) { - app.toggleMode(); + app.toggleDarkMode(); }, highlightColor: Colors.transparent, borderColor: Colors.grey, @@ -87,6 +81,14 @@ class SettingsSheet extends StatelessWidget { icon: const Icon(Icons.remove_circle_outline, size: 32, color: Colors.blueAccent), ), ), + SettingsTile.switchTile( + onToggle: (value) { + app.toggleEngBookNames(); + }, + initialValue: app.engTitles, + leading: Icon(Icons.abc, color: iconColor), + title: const Text("English Titles"), + ), ], ), SettingsSection(