-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use UpdateNotifications service
- Loading branch information
Showing
19 changed files
with
149 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:lotti/database/database.dart'; | ||
import 'package:lotti/get_it.dart'; | ||
import 'dart:async'; | ||
|
||
class DatabaseUpdateNotifications { | ||
DatabaseUpdateNotifications() { | ||
listen(); | ||
} | ||
enum DatabaseType { | ||
journal, | ||
setting, | ||
sync, | ||
logging, | ||
} | ||
|
||
class UpdateNotifications { | ||
UpdateNotifications(); | ||
|
||
final _updateStreamController = StreamController<DatabaseType>.broadcast(); | ||
|
||
final JournalDb _journalDb = getIt<JournalDb>(); | ||
Stream<DatabaseType> get updateStream => _updateStreamController.stream; | ||
|
||
void listen() { | ||
_journalDb.countJournalEntries().watch().listen((event) async { | ||
final start = DateTime.now(); | ||
final count = await _journalDb.countJournalEntries().getSingle(); | ||
final end = DateTime.now(); | ||
final duration = end.difference(start).inMicroseconds / 1000; | ||
debugPrint('DatabaseUpdateNotifications $count - $duration ms'); | ||
}); | ||
void notifyUpdate(DatabaseType databaseType) { | ||
_updateStreamController.add(databaseType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.