~repos /only-bible-app

#kotlin#android#ios

GIT_CONFIG_PARAMETERS="'http.version=HTTP/1.1'" git clone https://git.pyrossh.dev/only-bible-app.git
Discussions: https://groups.google.com/g/rust-embed-devs

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



lib/store/app_state.dart



import "package:flutter/material.dart";
import "package:only_bible_app/gen/bible.gen.dart";
import "package:only_bible_app/theme.dart";
import "package:async_redux/async_redux.dart";
export "package:async_redux/async_redux.dart" show BuildContextExtensionForProviderAndConnector;
class AppState {
final bool engTitles;
final int fontWeight;
final bool darkMode;
final double fontSize;
final int savedBook;
final int savedChapter;
final List<Verse> selectedVerses;
final Map<String, int> highlights;
final Bible bible;
AppState({
this.engTitles = false,
this.fontWeight = 400,
this.darkMode = false,
this.fontSize = 17.0,
this.savedBook = 0,
this.savedChapter = 0,
this.selectedVerses = const [],
this.highlights = const {},
required this.bible,
});
AppState copy({
bool? engTitles,
int? fontWeight,
bool? darkMode,
double? fontSize,
int? savedBook,
int? savedChapter,
List<Verse>? selectedVerses,
Map<String, int>? highlights,
Bible? bible,
}) {
return AppState(
engTitles: engTitles ?? this.engTitles,
fontWeight: fontWeight ?? this.fontWeight,
darkMode: darkMode ?? this.darkMode,
fontSize: fontSize ?? this.fontSize,
savedBook: savedBook ?? this.savedBook,
savedChapter: savedChapter ?? this.savedChapter,
selectedVerses: selectedVerses ?? this.selectedVerses,
highlights: highlights ?? this.highlights,
bible: bible ?? this.bible,
);
}
Map<String, dynamic> toJson() => {
"bibleName": bible.name,
"engTitles": engTitles,
"fontWeight": fontWeight,
"darkMode": darkMode,
"fontSize": fontSize,
"savedBook": savedBook,
"savedChapter": savedChapter,
"highlights": highlights,
};
factory AppState.fromJson(Map<String, dynamic> json, Bible bible) => AppState(
engTitles: json["engTitles"] as bool? ?? false,
fontWeight: json["fontWeight"] as int? ?? (json["boldFont"] == true ? 500 : 400),
darkMode: json["darkMode"] as bool? ?? false,
fontSize: (json["fontSize"] as num?)?.toDouble() ?? ((json["textScale"] as num?)?.toDouble() ?? 0.0) + 16.0,
savedBook: json["savedBook"] as int? ?? 0,
savedChapter: json["savedChapter"] as int? ?? 0,
highlights: (json["highlights"] as Map<String, dynamic>?)?.map((k, v) => MapEntry(k, v as int)) ?? const {},
bible: bible,
);
Color? getHighlight(Verse v) {
final key = "${v.book}:${v.chapter}:${v.index}";
final index = highlights[key];
if (index == null) return null;
return darkMode ? darkHighlights[index] : lightHighlights[index];
}
bool isVerseSelected(Verse v) {
return selectedVerses.any(
(el) => el.book == v.book && el.chapter == v.chapter && el.index == v.index,
);
}
TextStyle getHighlightStyle(BuildContext context, Verse v) {
final isSelected = selectedVerses.any(
(el) => el.book == v.book && el.chapter == v.chapter && el.index == v.index,
);
if (isSelected) {
return TextStyle(
backgroundColor: Theme.of(context).textSelectionTheme.selectionColor,
);
}
if (darkMode) {
return TextStyle(
color: getHighlight(v) ?? Theme.of(context).colorScheme.onSurface,
);
}
return TextStyle(
backgroundColor: getHighlight(v) ?? Theme.of(context).colorScheme.surface,
);
}
}
extension AppStateExtension on BuildContext {
AppState get state => getState<AppState>();
AppState read() => getRead<AppState>();
R select<R>(R Function(AppState state) selector) => getSelect<AppState, R>(selector);
}