~repos /only-bible-app
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.
94d93765
—
pyrossh 2 years ago
improve atom api
- lib/atom.dart +7 -22
- lib/navigation.dart +19 -2
- lib/state.dart +10 -24
lib/atom.dart
CHANGED
|
@@ -2,40 +2,25 @@ import "package:flutter/material.dart";
|
|
|
2
2
|
import "package:flutter/scheduler.dart";
|
|
3
3
|
import "package:get_storage/get_storage.dart";
|
|
4
4
|
|
|
5
|
-
late GetStorage localBox;
|
|
6
|
-
|
|
7
|
-
ensureAtomsInitialized(GetStorage box) async {
|
|
8
|
-
localBox = box;
|
|
9
|
-
await localBox.initStorage;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class Cubit<T> extends ValueNotifier<T> {
|
|
13
|
-
Cubit(T initialState) : super(initialState);
|
|
14
|
-
|
|
15
|
-
void emit(T state) {
|
|
16
|
-
super.value = state;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
5
|
class Atom<T> extends ValueNotifier<T> {
|
|
21
6
|
final String key;
|
|
22
|
-
final
|
|
7
|
+
final GetStorage? box;
|
|
23
8
|
Function()? set;
|
|
24
9
|
Function(T)? update;
|
|
25
10
|
|
|
26
|
-
Atom({required this.key, required T initialValue, this.
|
|
11
|
+
Atom({required this.key, required T initialValue, this.box, this.set, this.update})
|
|
27
|
-
: super(
|
|
12
|
+
: super(box != null ? box.read<T>(key) ?? initialValue : initialValue);
|
|
28
13
|
|
|
29
14
|
@override
|
|
30
15
|
set value(T newValue) {
|
|
31
16
|
super.value = newValue;
|
|
32
|
-
if (
|
|
17
|
+
if (box != null) {
|
|
33
18
|
if (newValue == null) {
|
|
34
|
-
|
|
19
|
+
box!.remove(key);
|
|
35
20
|
} else {
|
|
36
|
-
|
|
21
|
+
box!.write(key, newValue);
|
|
37
22
|
}
|
|
38
|
-
|
|
23
|
+
box!.save();
|
|
39
24
|
}
|
|
40
25
|
}
|
|
41
26
|
|
lib/navigation.dart
CHANGED
|
@@ -9,6 +9,7 @@ import "package:only_bible_app/sheets/highlight_sheet.dart";
|
|
|
9
9
|
import "package:only_bible_app/sheets/settings_sheet.dart";
|
|
10
10
|
import "package:only_bible_app/state.dart";
|
|
11
11
|
import "package:only_bible_app/utils.dart";
|
|
12
|
+
import "package:only_bible_app/widgets/note_sheet.dart";
|
|
12
13
|
import "package:only_bible_app/widgets/scaffold_markdown.dart";
|
|
13
14
|
import "package:share_plus/share_plus.dart";
|
|
14
15
|
import "package:only_bible_app/atom.dart";
|
|
@@ -16,7 +17,6 @@ import "package:only_bible_app/atom.dart";
|
|
|
16
17
|
final Atom<bool> actionsShown = Atom<bool>(
|
|
17
18
|
key: "actionsShown",
|
|
18
19
|
initialValue: false,
|
|
19
|
-
persist: false,
|
|
20
20
|
update: (bool v) {
|
|
21
21
|
actionsShown.value = v;
|
|
22
22
|
},
|
|
@@ -25,7 +25,6 @@ final Atom<bool> actionsShown = Atom<bool>(
|
|
|
25
25
|
final Atom<bool> highlightsShown = Atom<bool>(
|
|
26
26
|
key: "highlightsShown",
|
|
27
27
|
initialValue: false,
|
|
28
|
-
persist: false,
|
|
29
28
|
update: (bool v) {
|
|
30
29
|
highlightsShown.value = v;
|
|
31
30
|
},
|
|
@@ -254,3 +253,21 @@ hideHighlights(BuildContext context) {
|
|
|
254
253
|
Navigator.of(context).pop();
|
|
255
254
|
}
|
|
256
255
|
}
|
|
256
|
+
|
|
257
|
+
showNoteField(BuildContext context, Verse v) {
|
|
258
|
+
final noteText = box.read("${v.book}:${v.chapter}:${v.index}:note") ?? "";
|
|
259
|
+
noteTextController.text = noteText;
|
|
260
|
+
showModalBottomSheet(
|
|
261
|
+
context: context,
|
|
262
|
+
isDismissible: true,
|
|
263
|
+
enableDrag: true,
|
|
264
|
+
showDragHandle: true,
|
|
265
|
+
useSafeArea: true,
|
|
266
|
+
isScrollControlled: true,
|
|
267
|
+
builder: (context) => NoteSheet(verse: v),
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
hideNoteField(BuildContext context) {
|
|
272
|
+
Navigator.of(context).pop();
|
|
273
|
+
}
|
lib/state.dart
CHANGED
|
@@ -12,17 +12,17 @@ import "package:only_bible_app/models.dart";
|
|
|
12
12
|
import "package:only_bible_app/theme.dart";
|
|
13
13
|
import "package:only_bible_app/utils.dart";
|
|
14
14
|
import "package:only_bible_app/navigation.dart";
|
|
15
|
-
import "package:only_bible_app/widgets/note_sheet.dart";
|
|
16
15
|
|
|
17
16
|
final box = GetStorage("only-bible-app-prefs");
|
|
18
17
|
final player = AudioPlayer();
|
|
19
18
|
final noteTextController = TextEditingController();
|
|
20
19
|
|
|
21
20
|
initState() async {
|
|
22
|
-
await
|
|
21
|
+
await box.initStorage;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
final Atom<bool> firstOpen = Atom<bool>(
|
|
25
|
+
box: box,
|
|
26
26
|
key: "firstOpen",
|
|
27
27
|
initialValue: true,
|
|
28
28
|
set: () {
|
|
@@ -31,6 +31,7 @@ final Atom<bool> firstOpen = Atom<bool>(
|
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
final Atom<String> languageCode = Atom<String>(
|
|
34
|
+
box: box,
|
|
34
35
|
key: "languageCode",
|
|
35
36
|
initialValue: "en",
|
|
36
37
|
update: (String v) {
|
|
@@ -39,6 +40,7 @@ final Atom<String> languageCode = Atom<String>(
|
|
|
39
40
|
);
|
|
40
41
|
|
|
41
42
|
final Atom<String> bibleName = Atom<String>(
|
|
43
|
+
box: box,
|
|
42
44
|
key: "bibleName",
|
|
43
45
|
initialValue: "English",
|
|
44
46
|
update: (String v) {
|
|
@@ -48,7 +50,6 @@ final Atom<String> bibleName = Atom<String>(
|
|
|
48
50
|
|
|
49
51
|
final Atom<Bible> bible = Atom<Bible>(
|
|
50
52
|
key: "bible",
|
|
51
|
-
persist: false,
|
|
52
53
|
initialValue: Bible(name: "English"),
|
|
53
54
|
update: (Bible v) {
|
|
54
55
|
bible.value = v;
|
|
@@ -57,7 +58,6 @@ final Atom<Bible> bible = Atom<Bible>(
|
|
|
57
58
|
|
|
58
59
|
final bibleCache = Atom<Future<Bible?>?>(
|
|
59
60
|
key: "bible",
|
|
60
|
-
persist: false,
|
|
61
61
|
initialValue: null,
|
|
62
62
|
);
|
|
63
63
|
|
|
@@ -95,6 +95,7 @@ Future<Bible?> loadBible(String name) async {
|
|
|
95
95
|
// }
|
|
96
96
|
|
|
97
97
|
final Atom<bool> engTitles = Atom<bool>(
|
|
98
|
+
box: box,
|
|
98
99
|
key: "engTitles",
|
|
99
100
|
initialValue: false,
|
|
100
101
|
set: () {
|
|
@@ -103,6 +104,7 @@ final Atom<bool> engTitles = Atom<bool>(
|
|
|
103
104
|
);
|
|
104
105
|
|
|
105
106
|
final Atom<bool> darkMode = Atom<bool>(
|
|
107
|
+
box: box,
|
|
106
108
|
key: "darkMode",
|
|
107
109
|
initialValue: false,
|
|
108
110
|
set: () {
|
|
@@ -112,6 +114,7 @@ final Atom<bool> darkMode = Atom<bool>(
|
|
|
112
114
|
);
|
|
113
115
|
|
|
114
116
|
final Atom<bool> fontBold = Atom<bool>(
|
|
117
|
+
box: box,
|
|
115
118
|
key: "fontBold",
|
|
116
119
|
initialValue: false,
|
|
117
120
|
set: () {
|
|
@@ -120,6 +123,7 @@ final Atom<bool> fontBold = Atom<bool>(
|
|
|
120
123
|
);
|
|
121
124
|
|
|
122
125
|
final Atom<double> textScale = Atom<double>(
|
|
126
|
+
box: box,
|
|
123
127
|
key: "textScale",
|
|
124
128
|
initialValue: 0,
|
|
125
129
|
update: (double v) {
|
|
@@ -128,6 +132,7 @@ final Atom<double> textScale = Atom<double>(
|
|
|
128
132
|
);
|
|
129
133
|
|
|
130
134
|
final Atom<int> savedBook = Atom<int>(
|
|
135
|
+
box: box,
|
|
131
136
|
key: "savedBook",
|
|
132
137
|
initialValue: 0,
|
|
133
138
|
update: (int v) {
|
|
@@ -136,6 +141,7 @@ final Atom<int> savedBook = Atom<int>(
|
|
|
136
141
|
);
|
|
137
142
|
|
|
138
143
|
final Atom<int> savedChapter = Atom<int>(
|
|
144
|
+
box: box,
|
|
139
145
|
key: "savedChapter",
|
|
140
146
|
initialValue: 0,
|
|
141
147
|
update: (int v) {
|
|
@@ -146,7 +152,6 @@ final Atom<int> savedChapter = Atom<int>(
|
|
|
146
152
|
final Atom<bool> isPlaying = Atom<bool>(
|
|
147
153
|
key: "isPlaying",
|
|
148
154
|
initialValue: false,
|
|
149
|
-
persist: false,
|
|
150
155
|
update: (bool v) {
|
|
151
156
|
isPlaying.value = v;
|
|
152
157
|
},
|
|
@@ -155,7 +160,6 @@ final Atom<bool> isPlaying = Atom<bool>(
|
|
|
155
160
|
final Atom<List<Verse>> selectedVerses = Atom<List<Verse>>(
|
|
156
161
|
key: "selectedVerses",
|
|
157
162
|
initialValue: [],
|
|
158
|
-
persist: false,
|
|
159
163
|
update: (List<Verse> verses) {
|
|
160
164
|
selectedVerses.value = verses;
|
|
161
165
|
// selectedVerses.notifyChanged();
|
|
@@ -284,20 +288,6 @@ bool hasNote(Verse v) {
|
|
|
284
288
|
return box.hasData("${v.book}:${v.chapter}:${v.index}:note");
|
|
285
289
|
}
|
|
286
290
|
|
|
287
|
-
showNoteField(BuildContext context, Verse v) {
|
|
288
|
-
final noteText = box.read("${v.book}:${v.chapter}:${v.index}:note") ?? "";
|
|
289
|
-
noteTextController.text = noteText;
|
|
290
|
-
showModalBottomSheet(
|
|
291
|
-
context: context,
|
|
292
|
-
isDismissible: true,
|
|
293
|
-
enableDrag: true,
|
|
294
|
-
showDragHandle: true,
|
|
295
|
-
useSafeArea: true,
|
|
296
|
-
isScrollControlled: true,
|
|
297
|
-
builder: (context) => NoteSheet(verse: v),
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
291
|
saveNote(BuildContext context, Verse v) {
|
|
302
292
|
final note = noteTextController.text;
|
|
303
293
|
box.write("${v.book}:${v.chapter}:${v.index}:note", note);
|
|
@@ -313,7 +303,3 @@ deleteNote(BuildContext context, Verse v) {
|
|
|
313
303
|
// TODO: hack to re-render this page
|
|
314
304
|
selectedVerses.notifyChanged();
|
|
315
305
|
}
|
|
316
|
-
|
|
317
|
-
hideNoteField(BuildContext context) {
|
|
318
|
-
Navigator.of(context).pop();
|
|
319
|
-
}
|