Skip to content

Commit

Permalink
Readd FinampLogRecord and FinampLevel adapters (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmshrv committed Apr 10, 2021
1 parent 42813bd commit 4c93b18
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Future<void> setupHive() async {
Hive.registerAdapter(ResponseProfileAdapter());
Hive.registerAdapter(SubtitleProfileAdapter());
Hive.registerAdapter(FinampSettingsAdapter());
Hive.registerAdapter(FinampLogRecordAdapter());
Hive.registerAdapter(FinampLevelAdapter());
await Future.wait([
Hive.openBox<DownloadedParent>("DownloadedParents"),
Hive.openBox<DownloadedSong>("DownloadedItems"),
Expand All @@ -107,7 +109,7 @@ Future<void> setupHive() async {
finampSettingsBox.put("FinampSettings", FinampSettings());

// Initial releases of the app used Hive to store logs. This removes the logs box from the disk if it exists.
// TODO: Remove this in a few months (added 2021-04-09)
// TODO: Remove this (and the hive adapters for FinampLogRecord and FinampLevel) in a few months (added 2021-04-09)
if (await Hive.boxExists("FinampLogs")) {
await Hive.openBox("FinampLogs");
await Hive.box("FinampLogs").deleteFromDisk();
Expand Down
8 changes: 8 additions & 0 deletions lib/models/FinampModels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FinampSettings {
/// Once audio_service 0.18.0 releases, this won't be needed anymore.
/// Serialisation is only needed so that we can pass these objects through isolates.
@JsonSerializable(explicitToJson: true)
@HiveType(typeId: 29)
class FinampLogRecord {
FinampLogRecord({
this.level,
Expand All @@ -44,13 +45,17 @@ class FinampLogRecord {
this.time,
});

@HiveField(0)
final FinampLevel level;
@HiveField(1)
final String message;

/// Logger where this record is stored.
@HiveField(2)
final String loggerName;

/// Time when this record was created.
@HiveField(3)
final DateTime time;

static FinampLogRecord fromLogRecord(LogRecord logRecord) => FinampLogRecord(
Expand All @@ -66,11 +71,14 @@ class FinampLogRecord {
}

@JsonSerializable(explicitToJson: true)
@HiveType(typeId: 30)
class FinampLevel implements Comparable<FinampLevel> {
@HiveField(0)
final String name;

/// Unique value for this level. Used to order levels, so filtering can
/// exclude messages whose level is under certain value.
@HiveField(1)
final int value;

const FinampLevel(this.name, this.value);
Expand Down
80 changes: 80 additions & 0 deletions lib/models/FinampModels.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.2.0
version: 0.2.1

environment:
sdk: ">=2.10.0 <3.0.0"
Expand Down

0 comments on commit 4c93b18

Please sign in to comment.