~repos /only-bible-app

#kotlin#android#ios

git clone https://pyrossh.dev/repos/only-bible-app.git

The only bible app you will ever need. No ads. No in-app purchases. No distractions.


a6934a60 pyrossh

2 years ago
improve locale settings
lib/models.dart CHANGED
@@ -1,20 +1,17 @@
1
1
  import "package:flutter/material.dart";
2
- import "package:flutter_gen/gen_l10n/app_localizations.dart";
2
+ import "package:only_bible_app/providers/app_model.dart";
3
3
 
4
4
  class Bible {
5
- final int id;
6
5
  final String name;
7
6
  final bool hasAudio;
8
7
  List<Book> books = [];
9
8
 
10
9
  Bible({
11
- required this.id,
12
10
  required this.name,
13
11
  required this.hasAudio,
14
12
  });
15
13
 
16
14
  Bible.withBooks({
17
- required this.id,
18
15
  required this.name,
19
16
  required this.hasAudio,
20
17
  required this.books,
@@ -31,78 +28,6 @@ class Bible {
31
28
  List<Book> getNewBooks() {
32
29
  return books.where((it) => it.isNewTestament()).toList();
33
30
  }
34
-
35
- static List<String> getBookNames(BuildContext context) {
36
- final l = AppLocalizations.of(context)!;
37
- return [
38
- l.genesis,
39
- l.exodus,
40
- l.leviticus,
41
- l.numbers,
42
- l.deuteronomy,
43
- l.joshua,
44
- l.judges,
45
- l.ruth,
46
- l.firstSamuel,
47
- l.secondSamuel,
48
- l.firstKings,
49
- l.secondKings,
50
- l.firstChronicles,
51
- l.secondChronicles,
52
- l.ezra,
53
- l.nehemiah,
54
- l.esther,
55
- l.job,
56
- l.psalms,
57
- l.proverbs,
58
- l.ecclesiastes,
59
- l.song_of_solomon,
60
- l.isaiah,
61
- l.jeremiah,
62
- l.lamentations,
63
- l.ezekiel,
64
- l.daniel,
65
- l.hosea,
66
- l.joel,
67
- l.amos,
68
- l.obadiah,
69
- l.jonah,
70
- l.micah,
71
- l.nahum,
72
- l.habakkuk,
73
- l.zephaniah,
74
- l.haggai,
75
- l.zechariah,
76
- l.malachi,
77
- l.matthew,
78
- l.mark,
79
- l.luke,
80
- l.john,
81
- l.acts,
82
- l.romans,
83
- l.firstCorinthians,
84
- l.secondCorinthians,
85
- l.galatians,
86
- l.ephesians,
87
- l.philippians,
88
- l.colossians,
89
- l.firstThessalonians,
90
- l.secondThessalonians,
91
- l.firstTimothy,
92
- l.secondTimothy,
93
- l.titus,
94
- l.philemon,
95
- l.hebrews,
96
- l.james,
97
- l.firstPeter,
98
- l.secondPeter,
99
- l.firstJohn,
100
- l.secondJohn,
101
- l.thirdJohn,
102
- l.jude,
103
- l.revelation,
104
- ];
105
- }
106
31
  }
107
32
 
108
33
  class Book {
@@ -115,7 +40,7 @@ class Book {
115
40
  });
116
41
 
117
42
  String name(BuildContext context) {
118
- return Bible.getBookNames(context)[index];
43
+ return AppModel.of(context).getBookNames(context)[index];
119
44
  }
120
45
 
121
46
  bool isOldTestament() => index < 39;
@@ -146,20 +71,6 @@ class Verse {
146
71
  const Verse({required this.index, required this.text, required this.chapter, required this.book});
147
72
  }
148
73
 
149
- final bibles = [
150
- Bible(id: 1, name: "English", hasAudio: false),
151
- Bible(id: 2, name: "Kannada", hasAudio: true),
152
- Bible(id: 3, name: "Nepali", hasAudio: false),
153
- Bible(id: 4, name: "Hindi", hasAudio: false),
154
- Bible(id: 5, name: "Gujarati", hasAudio: false),
155
- Bible(id: 6, name: "Malayalam", hasAudio: false),
156
- Bible(id: 7, name: "Oriya", hasAudio: false),
157
- Bible(id: 8, name: "Punjabi", hasAudio: false),
158
- Bible(id: 9, name: "Tamil", hasAudio: false),
159
- Bible(id: 10, name: "Telugu", hasAudio: false),
160
- Bible(id: 11, name: "Bengali", hasAudio: false),
161
- ];
162
-
163
74
  List<Book> getBibleFromText(String text) {
164
75
  final List<Book> books = [];
165
76
  final lines = text.split("\n");
lib/providers/app_model.dart CHANGED
@@ -1,10 +1,10 @@
1
1
  // import "package:firebase_performance/firebase_performance.dart";
2
+ import "package:flutter_gen/gen_l10n/app_localizations.dart";
2
3
  import "package:flutter/services.dart";
3
4
  import "package:flutter/material.dart";
4
5
  import "package:only_bible_app/screens/bible_select_screen.dart";
5
6
  import "package:only_bible_app/screens/book_select_screen.dart";
6
7
  import "package:only_bible_app/models.dart";
7
- import "package:only_bible_app/screens/locale_select_screen.dart";
8
8
  import "package:only_bible_app/widgets/actions_sheet.dart";
9
9
  import "package:only_bible_app/widgets/highlight_button.dart";
10
10
  import "package:only_bible_app/widgets/scaffold_markdown.dart";
@@ -27,8 +27,9 @@ class HistoryFrame {
27
27
 
28
28
  class AppModel extends ChangeNotifier {
29
29
  late PackageInfo packageInfo;
30
- Locale locale = const Locale("en");
31
- Bible bible = bibles.first;
30
+ late Bible bible;
31
+ late Locale locale;
32
+ bool engTitles = false;
32
33
  bool darkMode = false;
33
34
  bool fontBold = false;
34
35
  double textScaleFactor = 0;
@@ -48,7 +49,7 @@ class AppModel extends ChangeNotifier {
48
49
 
49
50
  save() async {
50
51
  final prefs = await SharedPreferences.getInstance();
51
- await prefs.setInt("bibleId", bible.id);
52
+ await prefs.setString("bibleName", bible.name);
52
53
  await prefs.setBool("darkMode", darkMode);
53
54
  await prefs.setBool("fontBold", fontBold);
54
55
  await prefs.setDouble("textScaleFactor", textScaleFactor);
@@ -58,12 +59,11 @@ class AppModel extends ChangeNotifier {
58
59
  Future<(int, int)> loadData() async {
59
60
  packageInfo = await PackageInfo.fromPlatform();
60
61
  final prefs = await SharedPreferences.getInstance();
61
- final bibleId = prefs.getInt("bibleId") ?? 1;
62
62
  darkMode = prefs.getBool("darkMode") ?? false;
63
63
  fontBold = prefs.getBool("fontBold") ?? false;
64
64
  textScaleFactor = prefs.getDouble("textScaleFactor") ?? 1;
65
65
  locale = Locale(prefs.getString("languageCode") ?? "en");
66
- bible = await loadBible(bibleId);
66
+ bible = await loadBible(prefs.getString("bibleName") ?? "English");
67
67
  // await Future.delayed(Duration(seconds: 3));
68
68
  final book = prefs.getInt("book") ?? 0;
69
69
  final chapter = prefs.getInt("chapter") ?? 0;
@@ -71,31 +71,93 @@ class AppModel extends ChangeNotifier {
71
71
  return (book, chapter);
72
72
  }
73
73
 
74
- Future<Bible> loadBible(int id) async {
74
+ Future<Bible> loadBible(String name) async {
75
- final selectedBible = bibles.firstWhere((it) => it.id == id);
76
75
  // Trace customTrace;
77
76
  // if (!isDesktop()) {
78
77
  // customTrace = FirebasePerformance.instance.newTrace("loadBible");
79
78
  // await customTrace.start();
80
79
  // }
81
- final books = await getBibleFromAsset(selectedBible.name);
80
+ final books = await getBibleFromAsset(name);
82
81
  // if (!isDesktop()) {
83
82
  // await customTrace.stop();
84
83
  // }
85
84
  return Bible.withBooks(
86
- id: selectedBible.id,
87
- name: selectedBible.name,
85
+ name: name,
88
- hasAudio: selectedBible.hasAudio,
86
+ hasAudio: true,
89
87
  books: books,
90
88
  );
91
89
  }
92
90
 
93
- changeLocale(BuildContext context) {
91
+ List<String> getBookNames(BuildContext context) {
92
+ final l = engTitles ? lookupAppLocalizations(Locale("en")) : AppLocalizations.of(context)!;
93
+ return [
94
+ l.genesis,
95
+ l.exodus,
96
+ l.leviticus,
97
+ l.numbers,
98
+ l.deuteronomy,
99
+ l.joshua,
100
+ l.judges,
101
+ l.ruth,
102
+ l.firstSamuel,
103
+ l.secondSamuel,
104
+ l.firstKings,
105
+ l.secondKings,
94
- Navigator.of(context).pushReplacement(
106
+ l.firstChronicles,
95
- createNoTransitionPageRoute(
107
+ l.secondChronicles,
108
+ l.ezra,
109
+ l.nehemiah,
110
+ l.esther,
111
+ l.job,
112
+ l.psalms,
113
+ l.proverbs,
114
+ l.ecclesiastes,
115
+ l.song_of_solomon,
116
+ l.isaiah,
117
+ l.jeremiah,
118
+ l.lamentations,
119
+ l.ezekiel,
120
+ l.daniel,
121
+ l.hosea,
122
+ l.joel,
123
+ l.amos,
124
+ l.obadiah,
125
+ l.jonah,
126
+ l.micah,
127
+ l.nahum,
128
+ l.habakkuk,
129
+ l.zephaniah,
130
+ l.haggai,
131
+ l.zechariah,
132
+ l.malachi,
133
+ l.matthew,
134
+ l.mark,
135
+ l.luke,
136
+ l.john,
137
+ l.acts,
138
+ l.romans,
139
+ l.firstCorinthians,
140
+ l.secondCorinthians,
141
+ l.galatians,
142
+ l.ephesians,
143
+ l.philippians,
144
+ l.colossians,
145
+ l.firstThessalonians,
96
- const LocaleSelectScreen(),
146
+ l.secondThessalonians,
147
+ l.firstTimothy,
148
+ l.secondTimothy,
149
+ l.titus,
150
+ l.philemon,
151
+ l.hebrews,
152
+ l.james,
153
+ l.firstPeter,
154
+ l.secondPeter,
155
+ l.firstJohn,
156
+ l.secondJohn,
157
+ l.thirdJohn,
97
- ),
158
+ l.jude,
159
+ l.revelation,
98
- );
160
+ ];
99
161
  }
100
162
 
101
163
  changeBible(BuildContext context) {
@@ -114,15 +176,11 @@ class AppModel extends ChangeNotifier {
114
176
  );
115
177
  }
116
178
 
117
- updateCurrentLocale(Locale l) async {
179
+ // TODO: maybe don't pass name here
118
- locale = l;
119
- notifyListeners();
120
- save();
121
- }
122
-
123
- updateCurrentBible(BuildContext context, int id) async {
180
+ updateCurrentBible(BuildContext context, Locale l, String name) async {
124
181
  // TODO: maybe use a future as the bible needs to load
182
+ locale = l;
125
- bible = await loadBible(id);
183
+ bible = await loadBible(name);
126
184
  notifyListeners();
127
185
  save();
128
186
  }
@@ -135,13 +193,19 @@ class AppModel extends ChangeNotifier {
135
193
  );
136
194
  }
137
195
 
138
- toggleMode() async {
196
+ toggleDarkMode() {
139
197
  darkMode = !darkMode;
140
198
  updateStatusBar();
141
199
  notifyListeners();
142
200
  save();
143
201
  }
144
202
 
203
+ toggleEngBookNames() {
204
+ engTitles = !engTitles;
205
+ notifyListeners();
206
+ save();
207
+ }
208
+
145
209
  updateStatusBar() {
146
210
  if (darkMode) {
147
211
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
lib/screens/bible_select_screen.dart CHANGED
@@ -1,5 +1,5 @@
1
1
  import "package:flutter/material.dart";
2
- import "package:only_bible_app/models.dart";
2
+ import "package:flutter_gen/gen_l10n/app_localizations.dart";
3
3
  import "package:only_bible_app/providers/app_model.dart";
4
4
  import "package:only_bible_app/widgets/scaffold_menu.dart";
5
5
  import "package:only_bible_app/widgets/sliver_heading.dart";
@@ -19,13 +19,28 @@ class BibleSelectScreen extends StatelessWidget {
19
19
  SliverTileGrid(
20
20
  listType: ListType.large,
21
21
  children: List.of(
22
+ AppLocalizations.supportedLocales.map((l) {
23
+ return Localizations.override(
24
+ context: context,
25
+ locale: Locale(l.languageCode),
26
+ child: Builder(
22
- bibles.map((bible) {
27
+ builder: (context) {
28
+ final bibleName = AppLocalizations.of(context)!.languageTitle;
23
- return TextButton(
29
+ return TextButton(
24
- child: Text(bible.name),
30
+ child: Text(bibleName),
31
+ // child: Column(
32
+ // children: [
33
+ // Text(l.name),
34
+ // // Text("(${l.localName})"),
35
+ // ],
36
+ // ),
25
- onPressed: () {
37
+ onPressed: () {
26
- model.updateCurrentBible(context, bible.id);
38
+ AppModel.ofEvent(context).updateCurrentBible(context, l, bibleName);
27
- Navigator.of(context).pop();
39
+ Navigator.of(context).pop();
28
- },
40
+ },
41
+ );
42
+ },
43
+ ),
29
44
  );
30
45
  }),
31
46
  ),
lib/screens/locale_select_screen.dart DELETED
@@ -1,50 +0,0 @@
1
- import "package:flutter/material.dart";
2
- import "package:flutter_gen/gen_l10n/app_localizations.dart";
3
- import "package:only_bible_app/providers/app_model.dart";
4
- import "package:only_bible_app/widgets/scaffold_menu.dart";
5
- import "package:only_bible_app/widgets/sliver_heading.dart";
6
- import "package:only_bible_app/widgets/sliver_tile_grid.dart";
7
-
8
- class LocaleSelectScreen extends StatelessWidget {
9
- const LocaleSelectScreen({super.key});
10
-
11
- @override
12
- Widget build(BuildContext context) {
13
- return ScaffoldMenu(
14
- child: CustomScrollView(
15
- physics: const BouncingScrollPhysics(),
16
- slivers: [
17
- const SliverHeading(title: "Choose your preferred language", showClose: true),
18
- SliverTileGrid(
19
- listType: ListType.large,
20
- children: List.of(
21
- AppLocalizations.supportedLocales.map((l) {
22
- return Localizations.override(
23
- context: context,
24
- locale: Locale(l.languageCode),
25
- child: Builder(
26
- builder: (context) {
27
- return TextButton(
28
- child: Text(AppLocalizations.of(context)!.languageTitle),
29
- // child: Column(
30
- // children: [
31
- // Text(l.name),
32
- // // Text("(${l.localName})"),
33
- // ],
34
- // ),
35
- onPressed: () {
36
- AppModel.ofEvent(context).updateCurrentLocale(l);
37
- Navigator.of(context).pop();
38
- },
39
- );
40
- },
41
- ),
42
- );
43
- }),
44
- ),
45
- ),
46
- ],
47
- ),
48
- );
49
- }
50
- }
lib/widgets/settings_sheet.dart CHANGED
@@ -26,12 +26,6 @@ class SettingsSheet extends StatelessWidget {
26
26
  title: Text(localizations.settingsTitle, style: Theme.of(context).textTheme.headlineMedium),
27
27
  margin: const EdgeInsetsDirectional.symmetric(horizontal: 20),
28
28
  tiles: [
29
- SettingsTile.navigation(
30
- leading: const Icon(Icons.language, color: Colors.green),
31
- title: const Text("App Language"),
32
- value: Text(AppLocalizations.of(context)!.languageTitle),
33
- onPressed: app.changeLocale,
34
- ),
35
29
  SettingsTile.navigation(
36
30
  leading: const Icon(Icons.book_outlined, color: Colors.blueAccent),
37
31
  title: const Text("Bible"),
@@ -43,7 +37,7 @@ class SettingsSheet extends StatelessWidget {
43
37
  title: const Text("Theme"),
44
38
  trailing: ToggleButtons(
45
39
  onPressed: (int index) {
46
- app.toggleMode();
40
+ app.toggleDarkMode();
47
41
  },
48
42
  highlightColor: Colors.transparent,
49
43
  borderColor: Colors.grey,
@@ -87,6 +81,14 @@ class SettingsSheet extends StatelessWidget {
87
81
  icon: const Icon(Icons.remove_circle_outline, size: 32, color: Colors.blueAccent),
88
82
  ),
89
83
  ),
84
+ SettingsTile.switchTile(
85
+ onToggle: (value) {
86
+ app.toggleEngBookNames();
87
+ },
88
+ initialValue: app.engTitles,
89
+ leading: Icon(Icons.abc, color: iconColor),
90
+ title: const Text("English Titles"),
91
+ ),
90
92
  ],
91
93
  ),
92
94
  SettingsSection(