Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
refactor(database): change overall structures
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Dec 12, 2021
1 parent 413ccda commit 42e8e67
Show file tree
Hide file tree
Showing 52 changed files with 1,046 additions and 716 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include: package:lint/analysis_options.yaml
analyzer:
exclude:
- lib/**/*.g.dart
- lib/**/*.freezed.dart

linter:
rules:
Expand Down
23 changes: 8 additions & 15 deletions lib/config/defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,22 @@ abstract class Defaults {
static const Duration _animationsFaster = Duration(milliseconds: 100);

static Duration get animationsSlower =>
AppState.settings.value.disableAnimations
? _noAnimation
: _animationsSlower;
isAnimationsDisabled ? _noAnimation : _animationsSlower;

static Duration get animationsSlow =>
AppState.settings.value.disableAnimations
? _noAnimation
: _animationsSlow;
isAnimationsDisabled ? _noAnimation : _animationsSlow;

static Duration get animationsNormal =>
AppState.settings.value.disableAnimations
? _noAnimation
: _animationsNormal;
isAnimationsDisabled ? _noAnimation : _animationsNormal;

static Duration get animationsFast =>
AppState.settings.value.disableAnimations
? _noAnimation
: _animationsFast;
isAnimationsDisabled ? _noAnimation : _animationsFast;

static Duration get animationsFaster =>
AppState.settings.value.disableAnimations
? _noAnimation
: _animationsFaster;
isAnimationsDisabled ? _noAnimation : _animationsFaster;

static bool get isAnimationsDisabled =>
AppState.settings.value.developers.disableAnimations;

static const Duration cachedAnimeInfoExpireTime = Duration(days: 1);
static const Duration cachedMangaInfoExpireTime = Duration(days: 1);
Expand Down
20 changes: 10 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class _MainAppState extends State<MainApp> {
final SettingsSchema current,
final SettingsSchema previous,
) {
final List<List<dynamic>> changables = <List<dynamic>>[
<dynamic>[
current.useSystemPreferredTheme,
previous.useSystemPreferredTheme
],
<dynamic>[current.useDarkMode, previous.useDarkMode],
];
final Map<dynamic, dynamic> changables = <dynamic, dynamic>{
current.preferences.useSystemPreferredTheme:
previous.preferences.useSystemPreferredTheme,
current.preferences.useDarkMode: previous.preferences.useDarkMode,
};

if (changables.some((final List<dynamic> x) => x.first != x.last)) {
if (changables.entries
.toList()
.some((final MapEntry<dynamic, dynamic> x) => x.key != x.value)) {
setState(() {});
}
}
Expand All @@ -91,9 +91,9 @@ class _MainAppState extends State<MainApp> {
],
theme: Palette.lightTheme,
darkTheme: Palette.darkTheme,
themeMode: AppState.settings.value.useSystemPreferredTheme
themeMode: AppState.settings.value.preferences.useSystemPreferredTheme
? ThemeMode.system
: (AppState.settings.value.useDarkMode
: (AppState.settings.value.preferences.useDarkMode
? ThemeMode.dark
: ThemeMode.light),
initialRoute: RouteNames.initialRoute,
Expand Down
8 changes: 5 additions & 3 deletions lib/modules/app/lifecycle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ abstract class AppLifecycle {
}

final TranslationSentences? settingsLocale =
AppState.settings.value.locale != null
? Translator.tryGetTranslation(AppState.settings.value.locale!)
AppState.settings.value.preferences.locale != null
? Translator.tryGetTranslation(
AppState.settings.value.preferences.locale!,
)
: null;
if (settingsLocale == null) {
AppState.settings.value.locale = null;
AppState.settings.value.preferences.locale = null;
await SettingsBox.save(AppState.settings.value);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/modules/app/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ abstract class AppState {

settings.subscribe(
(final SettingsSchema current, final SettingsSchema previous) {
if (current.ignoreBadHttpCertificate !=
previous.ignoreBadHttpCertificate) {
if (current.developers.ignoreBadHttpCertificate !=
previous.developers.ignoreBadHttpCertificate) {
HetuHttpClient.set(
HetuHttpClient(
ignoreSSLCertificate: current.ignoreBadHttpCertificate,
ignoreSSLCertificate: current.developers.ignoreBadHttpCertificate,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import '../../config/paths.dart';
import '../helpers/logger.dart';

export './schemas/cache/cache.dart';
export './schemas/cached_preferences/cached_preferences.dart';
export './schemas/credentials/credentials.dart';
export './schemas/preferences/preferences.dart';
export './schemas/settings/settings.dart';

abstract class DatabaseManager {
Expand Down
154 changes: 52 additions & 102 deletions lib/modules/database/objectbox/objectbox-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,9 @@
],
"relations": []
},
{
"id": "3:3",
"lastPropertyId": "3:5523022497379988698",
"name": "PreferencesSchema",
"properties": [
{
"id": "1:2002002972373273367",
"name": "id",
"type": 6,
"flags": 1
},
{
"id": "3:5523022497379988698",
"name": "lastSelectedSearch_",
"type": 9
}
],
"relations": []
},
{
"id": "4:1",
"lastPropertyId": "28:3896775940984922968",
"lastPropertyId": "34:7870387653348531032",
"name": "SettingsSchema",
"properties": [
{
Expand All @@ -87,111 +68,57 @@
"flags": 1
},
{
"id": "2:7259109088868208379",
"name": "useSystemPreferredTheme",
"type": 1
},
{
"id": "3:2924473886036486806",
"name": "useDarkMode",
"type": 1
},
{
"id": "4:2010270991837719628",
"name": "locale",
"type": 9
},
{
"id": "5:1562037616827922058",
"name": "introDuration",
"type": 6
},
{
"id": "6:8765360801283119193",
"name": "seekDuration",
"type": 6
},
{
"id": "7:3475745247786699814",
"name": "autoNext",
"type": 1
},
{
"id": "8:692196073396158915",
"name": "autoPlay",
"type": 1
},
{
"id": "9:1399732325084062392",
"name": "doubleClickSwitchChapter",
"type": 1
},
{
"id": "10:2555505691523001225",
"name": "animeAutoFullscreen",
"type": 1
},
{
"id": "11:8840252602874529054",
"name": "mangaAutoFullscreen",
"type": 1
},
{
"id": "12:461535158492699321",
"name": "animeTrackerWatchPercent",
"type": 6
},
{
"id": "13:450262105290459242",
"name": "animeForceLandscape",
"type": 1
},
{
"id": "14:5250915747518516456",
"name": "mangaReaderDirection_",
"id": "31:8346693753002946197",
"name": "preferences_",
"type": 9
},
{
"id": "15:4213400519418794186",
"name": "mangaReaderSwipeDirection_",
"id": "32:2945820515866688512",
"name": "anime_",
"type": 9
},
{
"id": "16:3625592503513121933",
"name": "mangaReaderMode_",
"id": "33:2004277390577324559",
"name": "manga_",
"type": 9
},
{
"id": "25:2078169098439781657",
"name": "animeShortcuts_",
"id": "34:7870387653348531032",
"name": "developers_",
"type": 9
},
{
"id": "26:8547498297673923244",
"name": "disableAnimations",
"type": 1
},
}
],
"relations": []
},
{
"id": "5:2516426530853536210",
"lastPropertyId": "2:8998961797562977595",
"name": "CachedPreferencesSchema",
"properties": [
{
"id": "27:1713392882459328993",
"name": "ignoreBadHttpCertificate",
"type": 1
"id": "1:6321108629858683715",
"name": "id",
"type": 6,
"flags": 1
},
{
"id": "28:3896775940984922968",
"name": "mangaShortcuts_",
"id": "2:8998961797562977595",
"name": "lastSelectedSearch_",
"type": 9
}
],
"relations": []
}
],
"lastEntityId": "4:1",
"lastEntityId": "5:2516426530853536210",
"lastIndexId": "0:0",
"lastRelationId": "0:0",
"lastSequenceId": "0:0",
"modelVersion": 5,
"modelVersionParserMinimum": 5,
"retiredEntityUids": [],
"retiredEntityUids": [
3
],
"retiredIndexUids": [],
"retiredPropertyUids": [
1921708900049052479,
Expand All @@ -202,7 +129,30 @@
7236699100241270147,
5432917366629577766,
3743096892862510591,
591995873535278834
591995873535278834,
7259109088868208379,
2924473886036486806,
2010270991837719628,
1562037616827922058,
8765360801283119193,
3475745247786699814,
692196073396158915,
1399732325084062392,
2555505691523001225,
8840252602874529054,
461535158492699321,
450262105290459242,
5250915747518516456,
4213400519418794186,
3625592503513121933,
2078169098439781657,
8547498297673923244,
1713392882459328993,
3896775940984922968,
5534484759579347527,
2226931077543175541,
5523022497379988698,
2002002972373273367
],
"retiredRelationUids": [],
"version": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '../../database.dart';
import '../../objectbox/objectbox.g.dart';

export './schema.dart';

abstract class CachedPreferencesBox {
static Box<CachedPreferencesSchema> get box =>
Box<CachedPreferencesSchema>(DatabaseManager.store);

static CachedPreferencesSchema get() =>
box.query().build().findUnique() ?? CachedPreferencesSchema();

static Future<void> save(final CachedPreferencesSchema value) async {
await box.putAsync(value);
}
}

0 comments on commit 42e8e67

Please sign in to comment.