minor fixes

This commit is contained in:
Thibault Deckers 2022-09-26 21:22:56 +02:00
parent 12420ded61
commit acf475c4b1
3 changed files with 20 additions and 12 deletions

View file

@ -277,6 +277,8 @@ class AvesEntry {
bool get isMediaStoreContent => uri.startsWith('content://media/'); bool get isMediaStoreContent => uri.startsWith('content://media/');
bool get isMediaStoreMediaContent => isMediaStoreContent && {'/external/images/', '/external/video/'}.any(uri.contains);
bool get canEdit => path != null && !trashed && isMediaStoreContent; bool get canEdit => path != null && !trashed && isMediaStoreContent;
bool get canEditDate => canEdit && (canEditExif || canEditXmp); bool get canEditDate => canEdit && (canEditExif || canEditXmp);

View file

@ -105,11 +105,11 @@ 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 final Future<void> _appSetup; late final Future<void> _appSetup;
late final Size _screenSize;
late final Future<CorePalette?> _dynamicColorPaletteLoader; late final Future<CorePalette?> _dynamicColorPaletteLoader;
final CollectionSource _mediaStoreSource = MediaStoreSource(); 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 = {};
Size? _screenSize;
// 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
@ -119,15 +119,13 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
final EventChannel _analysisCompletionChannel = const OptionalEventChannel('deckers.thibault/aves/analysis_events'); final EventChannel _analysisCompletionChannel = const OptionalEventChannel('deckers.thibault/aves/analysis_events');
final EventChannel _errorChannel = const OptionalEventChannel('deckers.thibault/aves/error'); final EventChannel _errorChannel = const OptionalEventChannel('deckers.thibault/aves/error');
Widget getFirstPage({Map? intentData}) => settings.hasAcceptedTerms ? HomePage(intentData: intentData) : const WelcomePage();
@override @override
void initState() { void initState() {
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 // remember screen size to use it later, when `context` and `window` are no longer reliable
_screenSize = window.physicalSize / window.devicePixelRatio; _screenSize = _getScreenSize();
_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?));
@ -159,7 +157,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
AvesApp.showSystemUI(); AvesApp.showSystemUI();
} }
final home = initialized final home = initialized
? getFirstPage() ? _getFirstPage()
: Scaffold( : Scaffold(
body: snapshot.hasError ? _buildError(snapshot.error!) : const SizedBox(), body: snapshot.hasError ? _buildError(snapshot.error!) : const SizedBox(),
); );
@ -291,23 +289,31 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
} }
} }
Widget _getFirstPage({Map? intentData}) => settings.hasAcceptedTerms ? HomePage(intentData: intentData) : const WelcomePage();
Size? _getScreenSize() {
final physicalSize = window.physicalSize;
final ratio = window.devicePixelRatio;
return physicalSize > Size.zero && ratio > 0 ? physicalSize / ratio : null;
}
// save IDs of entries visible at the top of the collection page with current layout settings // save IDs of entries visible at the top of the collection page with current layout settings
void _saveTopEntries() { void _saveTopEntries() {
if (!settings.initialized) return; if (!settings.initialized) return;
final stopwatch = Stopwatch()..start(); final screenSize = _screenSize ?? _getScreenSize();
if (screenSize == null) 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();
collection.dispose(); collection.dispose();
debugPrint('Saved $count top entries in ${stopwatch.elapsed.inMilliseconds}ms');
} }
// setup before the first page is displayed. keep it short // setup before the first page is displayed. keep it short
@ -389,7 +395,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
reportService.log('New intent'); reportService.log('New intent');
AvesApp.navigatorKey.currentState!.pushReplacement(DirectMaterialPageRoute( AvesApp.navigatorKey.currentState!.pushReplacement(DirectMaterialPageRoute(
settings: const RouteSettings(name: HomePage.routeName), settings: const RouteSettings(name: HomePage.routeName),
builder: (_) => getFirstPage(intentData: intentData), builder: (_) => _getFirstPage(intentData: intentData),
)); ));
} }

View file

@ -189,7 +189,7 @@ class _BasicInfoState extends State<_BasicInfo> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (!entry.trashed && entry.isMediaStoreContent) { if (!entry.trashed && entry.isMediaStoreMediaContent) {
_ownerPackageLoader = metadataFetchService.hasContentResolverProp(ownerPackageNamePropKey).then((exists) { _ownerPackageLoader = metadataFetchService.hasContentResolverProp(ownerPackageNamePropKey).then((exists) {
return exists ? metadataFetchService.getContentResolverProp(entry, ownerPackageNamePropKey) : SynchronousFuture(null); return exists ? metadataFetchService.getContentResolverProp(entry, ownerPackageNamePropKey) : SynchronousFuture(null);
}); });