diff options
Diffstat (limited to 'lib/widgets/viewer/debug')
| -rw-r--r-- | lib/widgets/viewer/debug/db.dart | 206 | ||||
| -rw-r--r-- | lib/widgets/viewer/debug/debug_page.dart | 188 | ||||
| -rw-r--r-- | lib/widgets/viewer/debug/metadata.dart | 182 |
3 files changed, 576 insertions, 0 deletions
diff --git a/lib/widgets/viewer/debug/db.dart b/lib/widgets/viewer/debug/db.dart new file mode 100644 index 0000000..c0dfe4c --- /dev/null +++ b/lib/widgets/viewer/debug/db.dart @@ -0,0 +1,206 @@ +import 'package:aves/model/entry/entry.dart'; +import 'package:aves/model/metadata/address.dart'; +import 'package:aves/model/metadata/catalog.dart'; +import 'package:aves/model/metadata/trash.dart'; +import 'package:aves/model/source/collection_source.dart'; +import 'package:aves/model/viewer/video_playback.dart'; +import 'package:aves/services/common/services.dart'; +import 'package:aves/widgets/viewer/info/common.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class DbTab extends StatefulWidget { + final AvesEntry entry; + + const DbTab({ + super.key, + required this.entry, + }); + + @override + State<DbTab> createState() => _DbTabState(); +} + +class _DbTabState extends State<DbTab> { + late Future<int?> _dbDateLoader; + late Future<AvesEntry?> _dbEntryLoader; + late Future<CatalogMetadata?> _dbMetadataLoader; + late Future<AddressDetails?> _dbAddressLoader; + late Future<TrashDetails?> _dbTrashDetailsLoader; + late Future<VideoPlaybackRow?> _dbVideoPlaybackLoader; + + AvesEntry get entry => widget.entry; + + @override + void initState() { + super.initState(); + _loadDatabase(); + } + + void _loadDatabase() { + final id = entry.id; + _dbDateLoader = localMediaDb.loadDates().then((values) => values[id]); + _dbEntryLoader = localMediaDb.loadEntriesById({id}).then((values) => values.firstOrNull); + _dbMetadataLoader = localMediaDb.loadCatalogMetadata().then((values) => values.firstWhereOrNull((row) => row.id == id)); + _dbAddressLoader = localMediaDb.loadAddresses().then((values) => values.firstWhereOrNull((row) => row.id == id)); + _dbTrashDetailsLoader = localMediaDb.loadAllTrashDetails().then((values) => values.firstWhereOrNull((row) => row.id == id)); + _dbVideoPlaybackLoader = localMediaDb.loadVideoPlayback(id); + setState(() {}); + } + + @override + Widget build(BuildContext context) { + return ListView( + padding: const EdgeInsets.all(16), + children: [ + FutureBuilder<int?>( + future: _dbDateLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('DB date:${data == null ? ' no row' : ''}'), + if (data != null) + InfoRowGroup( + info: { + 'dateMillis': '$data', + }, + ), + ], + ); + }, + ), + const SizedBox(height: 16), + FutureBuilder<AvesEntry?>( + future: _dbEntryLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('DB entry:${data == null ? ' no row' : ''}'), + if (data != null) ...[ + ElevatedButton( + onPressed: () async { + final source = context.read<CollectionSource>(); + await source.removeEntries({entry.uri}, includeTrash: true); + }, + child: const Text('Untrack entry'), + ), + ElevatedButton( + onPressed: () async { + final duplicates = {entry.copyWith(id: localMediaDb.nextId)}; + final source = context.read<CollectionSource>(); + source.addEntries(duplicates); + await localMediaDb.insertEntries(duplicates); + }, + child: const Text('Duplicate entry'), + ), + InfoRowGroup( + info: Map.fromEntries(data.toDatabaseMap().entries.map((kv) => MapEntry(kv.key, kv.value?.toString() ?? ''))), + ), + ], + ], + ); + }, + ), + const SizedBox(height: 16), + FutureBuilder<CatalogMetadata?>( + future: _dbMetadataLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('DB metadata:${data == null ? ' no row' : ''}'), + if (data != null) + InfoRowGroup( + info: Map.fromEntries(data.toMap().entries.map((kv) => MapEntry(kv.key, kv.value?.toString() ?? ''))), + ), + ], + ); + }, + ), + const SizedBox(height: 16), + FutureBuilder<AddressDetails?>( + future: _dbAddressLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('DB address:${data == null ? ' no row' : ''}'), + if (data != null) + InfoRowGroup( + info: Map.fromEntries(data.toMap().entries.map((kv) => MapEntry(kv.key, kv.value?.toString() ?? ''))), + ), + ], + ); + }, + ), + const SizedBox(height: 16), + FutureBuilder<TrashDetails?>( + future: _dbTrashDetailsLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('DB trash details:${data == null ? ' no row' : ''}'), + if (data != null) ...[ + ElevatedButton( + onPressed: () async { + entry.trashDetails = null; + await localMediaDb.updateTrash(entry.id, entry.trashDetails); + _loadDatabase(); + }, + child: const Text('Remove details'), + ), + InfoRowGroup( + info: { + 'dateMillis': '${data.dateMillis}', + 'path': data.path, + }, + ), + ], + ], + ); + }, + ), + const SizedBox(height: 16), + FutureBuilder<VideoPlaybackRow?>( + future: _dbVideoPlaybackLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('DB video playback:${data == null ? ' no row' : ''}'), + if (data != null) + InfoRowGroup( + info: { + 'resumeTimeMillis': '${data.resumeTimeMillis}', + }, + ), + ], + ); + }, + ), + ], + ); + } +} diff --git a/lib/widgets/viewer/debug/debug_page.dart b/lib/widgets/viewer/debug/debug_page.dart new file mode 100644 index 0000000..2fca031 --- /dev/null +++ b/lib/widgets/viewer/debug/debug_page.dart @@ -0,0 +1,188 @@ +import 'package:aves/app_mode.dart'; +import 'package:aves/model/entry/entry.dart'; +import 'package:aves/model/entry/extensions/favourites.dart'; +import 'package:aves/model/entry/extensions/images.dart'; +import 'package:aves/model/entry/extensions/location.dart'; +import 'package:aves/model/entry/extensions/multipage.dart'; +import 'package:aves/model/entry/extensions/props.dart'; +import 'package:aves/theme/icons.dart'; +import 'package:aves/widgets/viewer/debug/db.dart'; +import 'package:aves/widgets/viewer/debug/metadata.dart'; +import 'package:aves/widgets/viewer/info/common.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class ViewerDebugPage extends StatelessWidget { + static const routeName = '/viewer/debug'; + + final AvesEntry entry; + + const ViewerDebugPage({ + super.key, + required this.entry, + }); + + @override + Widget build(BuildContext context) { + final tabs = <(Tab, Widget)>[ + (const Tab(text: 'Entry'), _buildEntryTabView()), + if (context.select<ValueNotifier<AppMode>, bool>((vn) => vn.value != AppMode.view)) (const Tab(text: 'DB'), DbTab(entry: entry)), + (const Tab(icon: Icon(AIcons.android)), MetadataTab(entry: entry)), + (const Tab(icon: Icon(AIcons.image)), _buildThumbnailsTabView()), + ]; + return Directionality( + textDirection: TextDirection.ltr, + child: DefaultTabController( + length: tabs.length, + child: Scaffold( + appBar: AppBar( + title: const Text('Debug'), + bottom: TabBar( + tabs: tabs.map((t) => t.$1).toList(), + ), + ), + body: SafeArea( + child: TabBarView( + children: tabs.map((t) => t.$2).toList(), + ), + ), + ), + ), + ); + } + + Widget _buildEntryTabView() { + String toDateValue(int? time, {int factor = 1}) { + var value = '$time'; + if (time != null && time > 0) { + try { + value += ' (${DateTime.fromMillisecondsSinceEpoch(time * factor)})'; + } catch (error) { + value += ' (invalid DateTime})'; + } + } + return value; + } + + return ListView( + padding: const EdgeInsets.all(16), + children: [ + InfoRowGroup( + info: { + 'hash': '#${shortHash(entry)}', + 'id': '${entry.id}', + 'origin': '${entry.origin}', + 'contentId': '${entry.contentId}', + 'uri': entry.uri, + 'path': entry.path ?? '', + 'directory': entry.directory ?? '', + 'filenameWithoutExtension': entry.filenameWithoutExtension ?? '', + 'extension': entry.extension ?? '', + 'sourceTitle': entry.sourceTitle ?? '', + 'sourceMimeType': entry.sourceMimeType, + 'mimeType': entry.mimeType, + 'isMissingAtPath': '${entry.isMissingAtPath}', + }, + ), + const Divider(), + InfoRowGroup( + info: { + 'trashed': '${entry.trashed}', + 'trashPath': '${entry.trashDetails?.path}', + 'trashDateMillis': '${entry.trashDetails?.dateMillis}', + }, + ), + const Divider(), + InfoRowGroup( + info: { + 'catalogDateMillis': toDateValue(entry.catalogDateMillis), + 'dateAddedSecs': toDateValue(entry.dateAddedSecs, factor: 1000), + 'dateModifiedMillis': toDateValue(entry.dateModifiedMillis), + 'sourceDateTakenMillis': toDateValue(entry.sourceDateTakenMillis), + 'bestDate': '${entry.bestDate}', + }, + ), + const Divider(), + InfoRowGroup( + info: { + 'width': '${entry.width}', + 'height': '${entry.height}', + 'sourceRotationDegrees': '${entry.sourceRotationDegrees}', + 'rotationDegrees': '${entry.rotationDegrees}', + 'isRotated': '${entry.isRotated}', + 'isFlipped': '${entry.isFlipped}', + 'displayAspectRatio': '${entry.displayAspectRatio}', + 'displaySize': '${entry.displaySize.width}x${entry.displaySize.height}', + }, + ), + const Divider(), + InfoRowGroup( + info: { + 'durationMillis': '${entry.durationMillis}', + 'durationText': entry.durationText, + }, + ), + const Divider(), + InfoRowGroup( + info: { + 'sizeBytes': '${entry.sizeBytes}', + 'isFavourite': '${entry.isFavourite}', + 'isSvg': '${entry.isSvg}', + 'isVideo': '${entry.isVideo}', + 'isCatalogued': '${entry.isCatalogued}', + 'is360': '${entry.is360}', + 'isAnimated': '${entry.isAnimated}', + 'isGeotiff': '${entry.isGeotiff}', + 'isHdr': '${entry.isHdr}', + 'isMultiPage': '${entry.isMultiPage}', + 'isMotionPhoto': '${entry.isMotionPhoto}', + 'canEdit': '${entry.canEdit}', + 'canEditDate': '${entry.canEditDate}', + 'canEditTags': '${entry.canEditTags}', + 'canRotate': '${entry.canRotate}', + 'canFlip': '${entry.canFlip}', + 'tags': '${entry.tags}', + }, + ), + const Divider(), + InfoRowGroup( + info: { + 'hasGps': '${entry.hasGps}', + 'hasAddress': '${entry.hasAddress}', + 'hasFineAddress': '${entry.hasFineAddress}', + 'latLng': '${entry.latLng}', + }, + ), + ], + ); + } + + Widget _buildThumbnailsTabView() { + return ListView( + padding: const EdgeInsets.all(16), + children: entry.cachedThumbnails + .expand((provider) => [ + Text('Thumb extent: ${provider.key.extent}'), + Center( + child: Image( + image: provider, + frameBuilder: (context, child, frame, wasSynchronouslyLoaded) { + return Container( + foregroundDecoration: const BoxDecoration( + border: Border.fromBorderSide(BorderSide( + color: Colors.amber, + width: .1, + )), + ), + child: child, + ); + }, + ), + ), + const SizedBox(height: 16), + ]) + .toList(), + ); + } +} diff --git a/lib/widgets/viewer/debug/metadata.dart b/lib/widgets/viewer/debug/metadata.dart new file mode 100644 index 0000000..8196324 --- /dev/null +++ b/lib/widgets/viewer/debug/metadata.dart @@ -0,0 +1,182 @@ +import 'dart:collection'; +import 'dart:typed_data'; + +import 'package:aves/model/entry/entry.dart'; +import 'package:aves/model/entry/extensions/location.dart'; +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/ref/mime_types.dart'; +import 'package:aves/services/android_debug_service.dart'; +import 'package:aves/services/geocoding_service.dart'; +import 'package:aves/widgets/common/identity/aves_expansion_tile.dart'; +import 'package:aves/widgets/viewer/info/common.dart'; +import 'package:flutter/material.dart'; + +class MetadataTab extends StatefulWidget { + final AvesEntry entry; + + const MetadataTab({ + super.key, + required this.entry, + }); + + @override + State<MetadataTab> createState() => _MetadataTabState(); +} + +class _MetadataTabState extends State<MetadataTab> { + late Future<Map> _bitmapFactoryLoader, _contentResolverMetadataLoader, _exifInterfaceMetadataLoader; + late Future<Map> _mediaMetadataLoader, _metadataExtractorLoader, _pixyMetaLoader, _tiffStructureLoader, _addressLoader; + late Future<String?> _mp4ParserDumpLoader; + + // MediaStore timestamp keys + static const secondTimestampKeys = ['date_added', 'date_modified', 'date_expires', 'isPlayed']; + static const millisecondTimestampKeys = ['datetaken', 'datetime']; + + AvesEntry get entry => widget.entry; + + @override + void initState() { + super.initState(); + _loadMetadata(); + } + + void _loadMetadata() { + _bitmapFactoryLoader = AndroidDebugService.getBitmapFactoryInfo(entry); + _contentResolverMetadataLoader = AndroidDebugService.getContentResolverMetadata(entry); + _exifInterfaceMetadataLoader = AndroidDebugService.getExifInterfaceMetadata(entry); + _mediaMetadataLoader = AndroidDebugService.getMediaMetadataRetrieverMetadata(entry); + _metadataExtractorLoader = AndroidDebugService.getMetadataExtractorSummary(entry); + _mp4ParserDumpLoader = AndroidDebugService.getMp4ParserDump(entry); + _pixyMetaLoader = AndroidDebugService.getPixyMetadata(entry); + _tiffStructureLoader = AndroidDebugService.getTiffStructure(entry); + _addressLoader = entry.hasGps + ? GeocodingService.getAddress(entry.latLng!, settings.appliedLocale).then((addresses) { + if (addresses.isNotEmpty) { + final address = addresses.first; + return { + 'addressLine': address.addressLine, + 'adminArea': address.adminArea, + 'countryCode': address.countryCode, + 'countryName': address.countryName, + 'featureName': address.featureName, + 'locality': address.locality, + 'postalCode': address.postalCode, + 'subAdminArea': address.subAdminArea, + 'subLocality': address.subLocality, + 'subThoroughfare': address.subThoroughfare, + 'thoroughfare': address.thoroughfare, + }; + } + return {}; + }) + : Future.value({}); + setState(() {}); + } + + @override + Widget build(BuildContext context) { + Widget builderFromSnapshotData(BuildContext context, Map snapshotData, String title) { + final data = SplayTreeMap.of(snapshotData.map((k, v) { + final key = k.toString(); + var value = v?.toString() ?? 'null'; + if ([...secondTimestampKeys, ...millisecondTimestampKeys].contains(key) && v is int && v != 0) { + if (secondTimestampKeys.contains(key)) { + v *= 1000; + } + try { + value += ' (${DateTime.fromMillisecondsSinceEpoch(v)})'; + } catch (error) { + value += ' (invalid DateTime})'; + } + } + if (key == 'xmp' && v != null && v is Uint8List) { + value = String.fromCharCodes(v); + } + return MapEntry(key, value); + })); + return AvesExpansionTile( + title: title, + children: [ + if (data.isNotEmpty) + Padding( + padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8), + child: InfoRowGroup(info: data), + ) + ], + ); + } + + Widget builderFromSnapshot(BuildContext context, AsyncSnapshot<Map> snapshot, String title) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + return builderFromSnapshotData(context, snapshot.data!, title); + } + + return ListView( + padding: const EdgeInsets.all(8), + children: [ + FutureBuilder<Map>( + future: _bitmapFactoryLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Bitmap Factory'), + ), + FutureBuilder<Map>( + future: _contentResolverMetadataLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Content Resolver'), + ), + FutureBuilder<Map>( + future: _exifInterfaceMetadataLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Exif Interface'), + ), + FutureBuilder<Map>( + future: _mediaMetadataLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Media Metadata Retriever'), + ), + FutureBuilder<Map>( + future: _metadataExtractorLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Metadata Extractor'), + ), + FutureBuilder<String?>( + future: _mp4ParserDumpLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final data = snapshot.data?.trim(); + return AvesExpansionTile( + title: 'MP4 Parser', + children: [ + if (data != null && data.isNotEmpty) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: SelectableText(data), + ), + ) + ], + ); + }, + ), + FutureBuilder<Map>( + future: _pixyMetaLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Pixy Meta'), + ), + if (entry.mimeType == MimeTypes.tiff) + FutureBuilder<Map>( + future: _tiffStructureLoader, + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (snapshot.connectionState != ConnectionState.done) return const SizedBox(); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: snapshot.data!.entries.map((kv) => builderFromSnapshotData(context, kv.value as Map, 'TIFF ${kv.key}')).toList(), + ); + }, + ), + FutureBuilder<Map>( + future: _addressLoader, + builder: (context, snapshot) => builderFromSnapshot(context, snapshot, 'Address'), + ), + ], + ); + } +} |
