Files
lunasea/lib/core/database/database.dart
Jagandeep Brar 4340853b8c [Release] v5.0.0 (50000001) (#312)
NEW
- [Radarr] Completely rewritten from the ground-up
- [Radarr] View system status, disk usage, and manage tags
- [Radarr] Catalogue, upcoming, missing, tags, and quality profiles are now held in-state between module switches
- [Radarr/Add] Long-pressing a search result tile will open the movie's TMDB entry
- [Radarr/History] Now an infinite scrolling list
- [Radarr/Movie] Cast information, movie-specific history, more detailed file information, more detailed overview page
- [Radarr/Filtering] Improved sorting and filtering speed, performance, and consistency
- [Radarr/Filtering] Ability to set sorting and filtering defaults in settings
- [Radarr/Filtering] Many additional filtering options
- [Haptics] Added haptic feedback to all buttons, toggles, and dropdowns
- [Quick Actions] Default "Settings" quick action added to end of the list (if there is room)
- [UI/UX] (Radarr Only For Now) Ability to tap the AppBar to scroll to top
- [UI/UX] (Radarr Only For Now) If the list is in a tabbed PageView, tapping the active tab will scroll the list to the top
- [UI/UX] (Radarr Only For Now) If the keyboard is open, scrolling the list, swiping between pages, or opening the drawer will dismiss the keyboard
- [Webhooks] Notification webhooks will now show as an in-app heads up if LunaSea is open at the time of receiving the notification

TWEAKS
- [Radarr] Now only supports v3.0.0 and higher of Radarr
- [Radarr] Many visual changes, too many to list
- [Radarr] The tab "History" has been replaced with "More"
- [Radarr/Edit] Monitor toggle has been moved to the edit prompt
- [Sonarr/Filtering] Updated button to use standard filtering icon
- [Tautulli/Activity] Show session type and bandwidth type breakdown on activity page
- [Tautulli/Activity] Cleanup player information to more closely resemble web GUI
- [Tautulli/Activity] Show subtitle stream decision
- [UI/UX] Reduced the weight of bold text across the application
- [UI/UX] Added padding to bottom of lists for devices that require a safe area
- [UI/UX] Active tab in navigation bar now has a border with the AMOLED theme

FIXES
- [Changelog] Properly align/pad "Full Changelog" button at the end of the changelog
- [Flutter] Update packages
- [Flutter] Now using the beta channel
- [Quick Actions] Improve internal implementation of quick actions to be more stable and reliable
- [Settings/Modules] Newly set headers would sometimes not be passed to the connection test
- [Sonarr/Edit] Series path prompt would show an incorrect title
- [Sonarr/Description] Show "No summary is available" when there is no summary instead of an empty string
- [Sonarr/Releases] Default sorting direction was using catalogue default value
- [Tautulli/Graphs] Description of some graphs were not correct (Thanks @ZuluWhiskey!)
- [Tautulli/IPs] Fix location showing as null for local addresses
- [UI/UX] Border radius for the splash highlight wouldn't clip correctly on slim buttons
- [UI/UX] Margin/size of sort/filter buttons were off by a few pixels
- [UI/UX] InkWell splash now clips correctly to the rounded borders of popup menu buttons
2021-02-16 22:51:43 -06:00

97 lines
3.7 KiB
Dart

// Imports
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:lunasea/core.dart';
import 'package:lunasea/modules/home/core.dart' show HomeDatabase;
import 'package:lunasea/modules/search/core.dart' show SearchDatabase;
import 'package:lunasea/modules/settings/core.dart' show SettingsDatabase;
import 'package:lunasea/modules/lidarr/core.dart' show LidarrDatabase;
import 'package:lunasea/modules/radarr/core.dart' show RadarrDatabase;
import 'package:lunasea/modules/sonarr/core.dart' show SonarrDatabase;
import 'package:lunasea/modules/nzbget/core.dart' show NZBGetDatabase;
import 'package:lunasea/modules/sabnzbd/core.dart' show SABnzbdDatabase;
import 'package:lunasea/modules/tautulli/core.dart' show TautulliDatabase;
// Exports
export 'package:hive/hive.dart';
export 'package:hive_flutter/hive_flutter.dart';
class Database {
static const String _DATABASE_PATH = 'database';
/// Initialize the database.
///
/// - Initializes Hive database path
/// - Register all adapters
/// - Open all boxes
/// - Set default database state of necessary
Future<void> initialize() async {
await Hive.initFlutter(_DATABASE_PATH);
_registerAdapters();
await _openBoxes();
if(profilesBox.keys.length == 0) setDefaults(clearAlerts: true);
}
/// Deinitialize the database by closing all open hive boxes.
Future<void> deinitialize() async => await Hive.close();
/// Registers all necessary object adapters for Hive.
void _registerAdapters() {
//Core
Hive.registerAdapter(IndexerHiveObjectAdapter());
Hive.registerAdapter(ProfileHiveObjectAdapter());
//General
LunaDatabase().registerAdapters();
HomeDatabase().registerAdapters();
SearchDatabase().registerAdapters();
SettingsDatabase().registerAdapters();
//Automation
LidarrDatabase().registerAdapters();
RadarrDatabase().registerAdapters();
SonarrDatabase().registerAdapters();
//Clients
NZBGetDatabase().registerAdapters();
SABnzbdDatabase().registerAdapters();
//Monitoring
TautulliDatabase().registerAdapters();
}
/// Open all Hive boxes for reading.
Future<void> _openBoxes() async {
await Hive.openBox('lunasea');
await Hive.openBox('alerts');
await Hive.openBox<IndexerHiveObject>('indexers');
await Hive.openBox<ProfileHiveObject>('profiles');
}
/// Set the default state for all hive boxes.
void setDefaults({ bool clearAlerts = false }) {
//Clear all the boxes
clearAllBoxes(clearAlerts: clearAlerts);
//Set default profile & enabled profile
profilesBox.put('default', ProfileHiveObject.empty());
lunaSeaBox.put(LunaDatabaseValue.ENABLED_PROFILE.key, 'default');
}
//Get boxes
static Box get lunaSeaBox => Hive.box('lunasea');
static Box get alertsBox => Hive.box('alerts');
static Box get profilesBox => Hive.box<ProfileHiveObject>('profiles');
static Box get indexersBox => Hive.box<IndexerHiveObject>('indexers');
//Clear boxes
void clearLunaSeaBox() => lunaSeaBox.deleteAll(lunaSeaBox.keys);
void clearProfilesBox() => profilesBox.deleteAll(profilesBox.keys);
void clearIndexersBox() => indexersBox.deleteAll(indexersBox.keys);
void clearAlertsBox() => alertsBox.deleteAll(alertsBox.keys);
void clearAllBoxes({ bool clearAlerts = false }) {
clearLunaSeaBox();
clearProfilesBox();
clearIndexersBox();
if(clearAlerts) clearAlertsBox();
}
//Profile values
static String get currentProfile => lunaSeaBox.get('profile');
static ProfileHiveObject get currentProfileObject => profilesBox.get(currentProfile);
}