Files
lunasea/lib/core/database/luna_database.dart
Jagandeep Brar dec1845764 [Release] (chore): Dirty v5.0.0+50000013 (#382) (#383)
* [iOS/Build] Add GoogleUtilities pod to prevent archive errors

* (chore) version bump

* [Git] Initialize blackbox

* [Git] Initialize blackbox

* [Git/Blackbox] Add me@jagandeepbrar.io as admin

* registered in blackbox: ios/ExportOptions.plist

* registered in blackbox: ios/GoogleService-Info.plist

* registered in blackbox: android/key.properties

* registered in blackbox: android/app/google-services.json

* Re-encrypted keys

* registered in blackbox: android/key.jks

* Updated key.properties, re-encrypted

* [Android/Keystore] Update same key.properties

* [Tautulli/Activity] Incorrectly localized "Transcodes" string

* [Radarr, UI] Implemented quick manual import, Implemented new design of ExpandableTile across UI (#378)

* Use local path for radarr package

* [Radarr/Manual Import] Browse filesystem, trigger quick import

* [UI/Buttons] Normalize the height of all buttons

* Update packages

* [ListView] Exposed itemExtent property

* [Lidarr/Releases] Move from LSExpandable to LunaExpandableListTile implementation

* [Tautulli/Logs] Use the new expandable table card styling

* [SABnzbd/History] Use the newer expandable table card styling

* [NZBGet/History] Use the newer expandable table card styling

* [UI/Button] Reduce size of the loader and icon to closer match text size

* [Sonarr/Releases] Use the newer expandable table card styling

* [Sonarr/Episodes] Use the newer expandable table card styling

* [UI/Table] Safe-guard title and body text, show emdash when receiving null data

* [Radarr/Details] Show monitor status and properly update the overview table on edit or monitor status changes

* Updated changelog

* [Sonarr/Queue & Episodes] Cleaned up implementation of expandable tile

* Translated using Weblate (Norwegian Bokmål)

Currently translated at 100.0% (14 of 14 strings)

Translation: LunaSea/LunaSea
Translate-URL: https://hosted.weblate.org/projects/lunasea/lunasea/nb_NO/

* Translated using Weblate (Swedish)

Currently translated at 100.0% (14 of 14 strings)

Translation: LunaSea/LunaSea
Translate-URL: https://hosted.weblate.org/projects/lunasea/lunasea/sv/

* Translated using Weblate (German)

Currently translated at 100.0% (68 of 68 strings)

Translation: LunaSea/Tautulli
Translate-URL: https://hosted.weblate.org/projects/lunasea/tautulli/de/

* Translated using Weblate (Norwegian Bokmål)

Currently translated at 80.8% (55 of 68 strings)

Translation: LunaSea/Tautulli
Translate-URL: https://hosted.weblate.org/projects/lunasea/tautulli/nb_NO/

* Translated using Weblate (Swedish)

Currently translated at 100.0% (68 of 68 strings)

Translation: LunaSea/Tautulli
Translate-URL: https://hosted.weblate.org/projects/lunasea/tautulli/sv/

* Translated using Weblate (Russian)

Currently translated at 57.3% (39 of 68 strings)

Translation: LunaSea/Tautulli
Translate-URL: https://hosted.weblate.org/projects/lunasea/tautulli/ru/

* (chore) Build localizations

* [Tautulli/Webhooks] Implement webhook data handlers for all Tautulli webhooks (#380)

* [Tautulli/Webhooks] Handle transcode decision change and watched event types
* [Radarr/Sonarr] Safe-guard webhooks by pushing the home route on invalid received data blocks
* [Tautulli/Webhooks] Implemented all webhooks

* Translated using Weblate (French)

Currently translated at 100.0% (78 of 78 strings)

Translation: LunaSea/Radarr
Translate-URL: https://hosted.weblate.org/projects/lunasea/radarr/fr/

* Translated using Weblate (German)

Currently translated at 100.0% (78 of 78 strings)

Translation: LunaSea/Radarr
Translate-URL: https://hosted.weblate.org/projects/lunasea/radarr/de/

* Translated using Weblate (Russian)

Currently translated at 92.8% (13 of 14 strings)

Translation: LunaSea/LunaSea
Translate-URL: https://hosted.weblate.org/projects/lunasea/lunasea/ru/

* [Release] (chore): Dirty v5.0.0+50000013 (#382)

* [Radarr/Manual Import] Add search bar for host system path, add stub manual import page

* [Radarr/Manual Import] Change path bar text to "File Browser..."

* [Radarr/Manual Import] Pass "/" if textController text is null

* [Radarr/Import] Stub details state

* [Database] Correctly register LunaIndexerIcon hive adapter

* [Radarr/Import] Filter directories when typing path, Fetch manual import results with stub cards

* [UI/Bottom Bar] Abstract bottom action bar, use on add movie page

* [UI/Navigation Bar] Add option to attach stickied top actions to navigation bar

* [Radarr/Edit] Use stickied bottom action bar for buttons

* [Radarr/Details] use sticky navigation actions for interactive and automatic search

* [Dialogs] CheckboxTiles were padded too aggressively in the X-axis

* [Sentry] Remove remaining references to Sentry

* (chore) Build localizations

* (chore) Update changelog

* Preparing to shift GitHub repository structure

Co-authored-by: Allan Nordhøy <epost@anotheragency.no>
Co-authored-by: Patrik Hauguth <patrik.hauguth@gmail.com>
Co-authored-by: cpt-kuesel <jln.sltr@pm.me>
Co-authored-by: Artem <KovalevArtem.ru@gmail.com>
Co-authored-by: Antoine C <contact+weblate@antoinecardon.fr>
2021-03-24 08:12:41 -05:00

186 lines
11 KiB
Dart

import 'package:flutter/material.dart';
import 'package:lunasea/core.dart';
class LunaDatabase extends LunaModuleDatabase {
@override
void registerAdapters() {
Hive.registerAdapter(IndexerHiveObjectAdapter());
Hive.registerAdapter(ProfileHiveObjectAdapter());
Hive.registerAdapter(LunaLogHiveObjectAdapter());
Hive.registerAdapter(LunaLogTypeAdapter());
Hive.registerAdapter(LunaBrowserAdapter());
Hive.registerAdapter(LunaIndexerIconAdapter());
}
@override
Map<String, dynamic> export() {
Map<String, dynamic> data = {};
for(LunaDatabaseValue value in LunaDatabaseValue.values) {
switch(value) {
// Non-primitive values
case LunaDatabaseValue.SELECTED_BROWSER: data[value.key] = (LunaDatabaseValue.SELECTED_BROWSER.data as LunaBrowser).key; break;
// Primitive values
case LunaDatabaseValue.ENABLED_PROFILE:
case LunaDatabaseValue.ENABLE_FIREBASE_ANALYTICS:
case LunaDatabaseValue.ENABLE_FIREBASE_CRASHLYTICS:
case LunaDatabaseValue.THEME_AMOLED:
case LunaDatabaseValue.THEME_AMOLED_BORDER:
case LunaDatabaseValue.THEME_IMAGE_BACKGROUND_OPACITY:
case LunaDatabaseValue.QUICK_ACTIONS_LIDARR:
case LunaDatabaseValue.QUICK_ACTIONS_RADARR:
case LunaDatabaseValue.QUICK_ACTIONS_SONARR:
case LunaDatabaseValue.QUICK_ACTIONS_NZBGET:
case LunaDatabaseValue.QUICK_ACTIONS_SABNZBD:
case LunaDatabaseValue.QUICK_ACTIONS_OMBI:
case LunaDatabaseValue.QUICK_ACTIONS_TAUTULLI:
case LunaDatabaseValue.QUICK_ACTIONS_SEARCH:
case LunaDatabaseValue.USE_24_HOUR_TIME: data[value.key] = value.data; break;
}
}
return data;
}
@override
void import(Map<String, dynamic> config) {
for(String key in config.keys) {
LunaDatabaseValue value = valueFromKey(key);
if(value != null) switch(value) {
// Non-primitive values
case LunaDatabaseValue.SELECTED_BROWSER: value.put(LunaBrowser.APPLE_SAFARI.fromKey(config[key])); break;
// Primitive values
case LunaDatabaseValue.ENABLED_PROFILE:
case LunaDatabaseValue.ENABLE_FIREBASE_ANALYTICS:
case LunaDatabaseValue.ENABLE_FIREBASE_CRASHLYTICS:
case LunaDatabaseValue.THEME_AMOLED:
case LunaDatabaseValue.THEME_AMOLED_BORDER:
case LunaDatabaseValue.THEME_IMAGE_BACKGROUND_OPACITY:
case LunaDatabaseValue.QUICK_ACTIONS_LIDARR:
case LunaDatabaseValue.QUICK_ACTIONS_RADARR:
case LunaDatabaseValue.QUICK_ACTIONS_SONARR:
case LunaDatabaseValue.QUICK_ACTIONS_NZBGET:
case LunaDatabaseValue.QUICK_ACTIONS_SABNZBD:
case LunaDatabaseValue.QUICK_ACTIONS_TAUTULLI:
case LunaDatabaseValue.QUICK_ACTIONS_OMBI:
case LunaDatabaseValue.QUICK_ACTIONS_SEARCH:
case LunaDatabaseValue.USE_24_HOUR_TIME: value.put(config[key]); break;
}
}
}
LunaDatabaseValue valueFromKey(String key) {
switch(key) {
case 'profile': return LunaDatabaseValue.ENABLED_PROFILE;
case 'LUNASEA_ENABLE_FIREBASE_ANALYTICS': return LunaDatabaseValue.ENABLE_FIREBASE_ANALYTICS;
case 'LUNASEA_ENABLE_FIREBASE_CRASHLYTICS': return LunaDatabaseValue.ENABLE_FIREBASE_CRASHLYTICS;
case 'LUNASEA_THEME_AMOLED': return LunaDatabaseValue.THEME_AMOLED;
case 'LUNASEA_THEME_AMOLED_BORDER': return LunaDatabaseValue.THEME_AMOLED_BORDER;
case 'LUNASEA_THEME_IMAGE_BACKGROUND_OPACITY': return LunaDatabaseValue.THEME_IMAGE_BACKGROUND_OPACITY;
case 'LUNASEA_SELECTED_BROWSER': return LunaDatabaseValue.SELECTED_BROWSER;
case 'LUNASEA_QUICK_ACTIONS_LIDARR': return LunaDatabaseValue.QUICK_ACTIONS_LIDARR;
case 'LUNASEA_QUICK_ACTIONS_RADARR': return LunaDatabaseValue.QUICK_ACTIONS_RADARR;
case 'LUNASEA_QUICK_ACTIONS_SONARR': return LunaDatabaseValue.QUICK_ACTIONS_SONARR;
case 'LUNASEA_QUICK_ACTIONS_NZBGET': return LunaDatabaseValue.QUICK_ACTIONS_NZBGET;
case 'LUNASEA_QUICK_ACTIONS_SABNZBD': return LunaDatabaseValue.QUICK_ACTIONS_SABNZBD;
case 'LUNASEA_QUICK_ACTIONS_OMBI': return LunaDatabaseValue.QUICK_ACTIONS_OMBI;
case 'LUNASEA_QUICK_ACTIONS_TAUTULLI': return LunaDatabaseValue.QUICK_ACTIONS_TAUTULLI;
case 'LUNASEA_QUICK_ACTIONS_SEARCH': return LunaDatabaseValue.QUICK_ACTIONS_SEARCH;
case 'LUNASEA_USE_24_HOUR_TIME': return LunaDatabaseValue.USE_24_HOUR_TIME;
default: return null;
}
}
}
enum LunaDatabaseValue {
ENABLED_PROFILE,
ENABLE_FIREBASE_ANALYTICS,
ENABLE_FIREBASE_CRASHLYTICS,
THEME_AMOLED,
THEME_AMOLED_BORDER,
THEME_IMAGE_BACKGROUND_OPACITY,
SELECTED_BROWSER,
QUICK_ACTIONS_LIDARR,
QUICK_ACTIONS_RADARR,
QUICK_ACTIONS_SONARR,
QUICK_ACTIONS_NZBGET,
QUICK_ACTIONS_SABNZBD,
QUICK_ACTIONS_OMBI,
QUICK_ACTIONS_TAUTULLI,
QUICK_ACTIONS_SEARCH,
USE_24_HOUR_TIME,
}
extension LunaDatabaseValueExtension on LunaDatabaseValue {
String get key {
switch(this) {
case LunaDatabaseValue.ENABLED_PROFILE: return 'profile';
case LunaDatabaseValue.ENABLE_FIREBASE_ANALYTICS: return 'LUNASEA_ENABLE_FIREBASE_ANALYTICS';
case LunaDatabaseValue.ENABLE_FIREBASE_CRASHLYTICS: return 'LUNASEA_ENABLE_FIREBASE_CRASHLYTICS';
case LunaDatabaseValue.THEME_AMOLED: return 'LUNASEA_THEME_AMOLED';
case LunaDatabaseValue.THEME_AMOLED_BORDER: return 'LUNASEA_THEME_AMOLED_BORDER';
case LunaDatabaseValue.THEME_IMAGE_BACKGROUND_OPACITY: return 'LUNASEA_THEME_IMAGE_BACKGROUND_OPACITY';
case LunaDatabaseValue.SELECTED_BROWSER: return 'LUNASEA_SELECTED_BROWSER';
case LunaDatabaseValue.QUICK_ACTIONS_LIDARR: return 'LUNASEA_QUICK_ACTIONS_LIDARR';
case LunaDatabaseValue.QUICK_ACTIONS_RADARR: return 'LUNASEA_QUICK_ACTIONS_RADARR';
case LunaDatabaseValue.QUICK_ACTIONS_SONARR: return 'LUNASEA_QUICK_ACTIONS_SONARR';
case LunaDatabaseValue.QUICK_ACTIONS_NZBGET: return 'LUNASEA_QUICK_ACTIONS_NZBGET';
case LunaDatabaseValue.QUICK_ACTIONS_SABNZBD: return 'LUNASEA_QUICK_ACTIONS_SABNZBD';
case LunaDatabaseValue.QUICK_ACTIONS_TAUTULLI: return 'LUNASEA_QUICK_ACTIONS_TAUTULLI';
case LunaDatabaseValue.QUICK_ACTIONS_OMBI: return 'LUNASEA_QUICK_ACTIONS_OMBI';
case LunaDatabaseValue.QUICK_ACTIONS_SEARCH: return 'LUNASEA_QUICK_ACTIONS_SEARCH';
case LunaDatabaseValue.USE_24_HOUR_TIME: return 'LUNASEA_USE_24_HOUR_TIME';
}
throw Exception('key not found');
}
dynamic get data {
final box = Database.lunaSeaBox;
switch(this) {
case LunaDatabaseValue.ENABLED_PROFILE: return box.get(this.key, defaultValue: 'default');
case LunaDatabaseValue.SELECTED_BROWSER: return box.get(this.key, defaultValue: LunaBrowser.APPLE_SAFARI);
case LunaDatabaseValue.THEME_AMOLED: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.THEME_AMOLED_BORDER: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.THEME_IMAGE_BACKGROUND_OPACITY: return box.get(this.key, defaultValue: 10);
case LunaDatabaseValue.ENABLE_FIREBASE_ANALYTICS: return box.get(this.key, defaultValue: true);
case LunaDatabaseValue.ENABLE_FIREBASE_CRASHLYTICS: return box.get(this.key, defaultValue: true);
case LunaDatabaseValue.QUICK_ACTIONS_LIDARR: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_RADARR: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_SONARR: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_NZBGET: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_SABNZBD: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_TAUTULLI: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_OMBI: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.QUICK_ACTIONS_SEARCH: return box.get(this.key, defaultValue: false);
case LunaDatabaseValue.USE_24_HOUR_TIME: return box.get(this.key, defaultValue: false);
}
throw Exception('data not found');
}
void put(dynamic value) {
final box = Database.lunaSeaBox;
switch(this) {
case LunaDatabaseValue.ENABLED_PROFILE: if(value.runtimeType == String) box.put(this.key, value); return;
case LunaDatabaseValue.ENABLE_FIREBASE_ANALYTICS: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.ENABLE_FIREBASE_CRASHLYTICS: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.THEME_AMOLED: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.THEME_AMOLED_BORDER: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.THEME_IMAGE_BACKGROUND_OPACITY: if(value.runtimeType == int) box.put(this.key, value); return;
case LunaDatabaseValue.SELECTED_BROWSER: if(value.runtimeType == LunaBrowser) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_LIDARR: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_RADARR: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_SONARR: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_NZBGET: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_SABNZBD: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_OMBI: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_TAUTULLI: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.QUICK_ACTIONS_SEARCH: if(value.runtimeType == bool) box.put(this.key, value); return;
case LunaDatabaseValue.USE_24_HOUR_TIME: if(value.runtimeType == bool) box.put(this.key, value); return;
}
LunaLogger().warning('LunaDatabaseValueExtension', 'put', 'Attempted to enter data for invalid LunaDatabaseValue: ${this?.toString() ?? 'null'}');
}
ValueListenableBuilder listen({ @required Widget Function(BuildContext, dynamic, Widget) builder }) => ValueListenableBuilder(
valueListenable: Database.lunaSeaBox.listenable(keys: [this.key]),
builder: builder,
);
}