minor fixes
This commit is contained in:
parent
761a45cad9
commit
7bf464d591
2 changed files with 17 additions and 21 deletions
|
@ -10,7 +10,7 @@ import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
mixin AlbumMixin on SourceBase {
|
mixin AlbumMixin on SourceBase {
|
||||||
final Set<String?> _directories = {};
|
final Set<String> _directories = {};
|
||||||
final Set<String> _newAlbums = {};
|
final Set<String> _newAlbums = {};
|
||||||
|
|
||||||
List<String> get rawAlbums => List.unmodifiable(_directories);
|
List<String> get rawAlbums => List.unmodifiable(_directories);
|
||||||
|
@ -68,7 +68,7 @@ mixin AlbumMixin on SourceBase {
|
||||||
|
|
||||||
void addDirectories({required Set<String?> albums, bool notify = true}) {
|
void addDirectories({required Set<String?> albums, bool notify = true}) {
|
||||||
if (!_directories.containsAll(albums)) {
|
if (!_directories.containsAll(albums)) {
|
||||||
_directories.addAll(albums);
|
_directories.addAll(albums.whereNotNull());
|
||||||
_onAlbumChanged(notify: notify);
|
_onAlbumChanged(notify: notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,11 +104,12 @@ class AvesApp extends StatefulWidget {
|
||||||
|
|
||||||
class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
final ValueNotifier<AppMode> appModeNotifier = ValueNotifier(AppMode.main);
|
final ValueNotifier<AppMode> appModeNotifier = ValueNotifier(AppMode.main);
|
||||||
late Future<void> _appSetup;
|
late final Future<void> _appSetup;
|
||||||
late Future<CorePalette?> _dynamicColorPaletteLoader;
|
late final Size _screenSize;
|
||||||
final _mediaStoreSource = MediaStoreSource();
|
late final Future<CorePalette?> _dynamicColorPaletteLoader;
|
||||||
|
final CollectionSource _mediaStoreSource = MediaStoreSource();
|
||||||
final Debouncer _mediaStoreChangeDebouncer = Debouncer(delay: Durations.mediaContentChangeDebounceDelay);
|
final Debouncer _mediaStoreChangeDebouncer = Debouncer(delay: Durations.mediaContentChangeDebounceDelay);
|
||||||
final Set<String> changedUris = {};
|
final Set<String> _changedUris = {};
|
||||||
|
|
||||||
// observers are not registered when using the same list object with different items
|
// observers are not registered when using the same list object with different items
|
||||||
// the list itself needs to be reassigned
|
// the list itself needs to be reassigned
|
||||||
|
@ -125,6 +126,8 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
super.initState();
|
super.initState();
|
||||||
EquatableConfig.stringify = true;
|
EquatableConfig.stringify = true;
|
||||||
_appSetup = _setup();
|
_appSetup = _setup();
|
||||||
|
// remember screen size to use it later, when `context` and `window` are no longer reliable
|
||||||
|
_screenSize = window.physicalSize / window.devicePixelRatio;
|
||||||
_dynamicColorPaletteLoader = DynamicColorPlugin.getCorePalette();
|
_dynamicColorPaletteLoader = DynamicColorPlugin.getCorePalette();
|
||||||
_mediaStoreChangeChannel.receiveBroadcastStream().listen((event) => _onMediaStoreChange(event as String?));
|
_mediaStoreChangeChannel.receiveBroadcastStream().listen((event) => _onMediaStoreChange(event as String?));
|
||||||
_newIntentChannel.receiveBroadcastStream().listen((event) => _onNewIntent(event as Map?));
|
_newIntentChannel.receiveBroadcastStream().listen((event) => _onNewIntent(event as Map?));
|
||||||
|
@ -293,20 +296,13 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
if (!settings.initialized) return;
|
if (!settings.initialized) return;
|
||||||
|
|
||||||
final stopwatch = Stopwatch()..start();
|
final stopwatch = Stopwatch()..start();
|
||||||
final Size screenSize;
|
|
||||||
try {
|
|
||||||
screenSize = window.physicalSize / window.devicePixelRatio;
|
|
||||||
} catch (error) {
|
|
||||||
// view may no longer be usable
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var tileExtent = settings.getTileExtent(CollectionPage.routeName);
|
var tileExtent = settings.getTileExtent(CollectionPage.routeName);
|
||||||
if (tileExtent == 0) {
|
if (tileExtent == 0) {
|
||||||
tileExtent = screenSize.shortestSide / CollectionGrid.columnCountDefault;
|
tileExtent = _screenSize.shortestSide / CollectionGrid.columnCountDefault;
|
||||||
}
|
}
|
||||||
final rows = (screenSize.height / tileExtent).ceil();
|
final rows = (_screenSize.height / tileExtent).ceil();
|
||||||
final columns = (screenSize.width / tileExtent).ceil();
|
final columns = (_screenSize.width / tileExtent).ceil();
|
||||||
final count = rows * columns;
|
final count = rows * columns;
|
||||||
final collection = CollectionLens(source: _mediaStoreSource, listenToSource: false);
|
final collection = CollectionLens(source: _mediaStoreSource, listenToSource: false);
|
||||||
settings.topEntryIds = collection.sortedEntries.take(count).map((entry) => entry.id).toList();
|
settings.topEntryIds = collection.sortedEntries.take(count).map((entry) => entry.id).toList();
|
||||||
|
@ -405,14 +401,14 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onMediaStoreChange(String? uri) {
|
void _onMediaStoreChange(String? uri) {
|
||||||
if (uri != null) changedUris.add(uri);
|
if (uri != null) _changedUris.add(uri);
|
||||||
if (changedUris.isNotEmpty) {
|
if (_changedUris.isNotEmpty) {
|
||||||
_mediaStoreChangeDebouncer(() async {
|
_mediaStoreChangeDebouncer(() async {
|
||||||
final todo = changedUris.toSet();
|
final todo = _changedUris.toSet();
|
||||||
changedUris.clear();
|
_changedUris.clear();
|
||||||
final tempUris = await _mediaStoreSource.refreshUris(todo);
|
final tempUris = await _mediaStoreSource.refreshUris(todo);
|
||||||
if (tempUris.isNotEmpty) {
|
if (tempUris.isNotEmpty) {
|
||||||
changedUris.addAll(tempUris);
|
_changedUris.addAll(tempUris);
|
||||||
_onMediaStoreChange(null);
|
_onMediaStoreChange(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue