import 'package:aves/widgets/common/extensions/build_context.dart'; import 'package:aves/widgets/viewer/embedded/notifications.dart'; import 'package:aves/widgets/viewer/info/common.dart'; import 'package:aves/widgets/viewer/info/metadata/xmp_namespaces.dart'; import 'package:aves/widgets/viewer/info/metadata/xmp_structs.dart'; import 'package:collection/collection.dart'; import 'package:flutter/widgets.dart'; import 'package:tuple/tuple.dart'; abstract class XmpGoogleNamespace extends XmpNamespace { const XmpGoogleNamespace(String ns, Map rawProps) : super(ns, rawProps); List> get dataProps; @override Map linkifyValues(List props) { return Map.fromEntries(dataProps.map((t) { final dataPropPath = t.item1; final mimePropPath = t.item2; final dataProp = props.firstWhereOrNull((prop) => prop.path == dataPropPath); final mimeProp = props.firstWhereOrNull((prop) => prop.path == mimePropPath); return (dataProp != null && mimeProp != null) ? MapEntry( dataProp.displayKey, InfoLinkHandler( linkText: (context) => context.l10n.viewerInfoOpenLinkText, onTap: (context) => OpenEmbeddedDataNotification.xmp( propPath: dataProp.path, mimeType: mimeProp.value, ).dispatch(context), )) : null; }).whereNotNull()); } } class XmpGAudioNamespace extends XmpGoogleNamespace { static const ns = 'GAudio'; const XmpGAudioNamespace(Map rawProps) : super(ns, rawProps); @override List> get dataProps => const [Tuple2('$ns:Data', '$ns:Mime')]; } class XmpGDepthNamespace extends XmpGoogleNamespace { static const ns = 'GDepth'; const XmpGDepthNamespace(Map rawProps) : super(ns, rawProps); @override List> get dataProps => const [ Tuple2('$ns:Data', '$ns:Mime'), Tuple2('$ns:Confidence', '$ns:ConfidenceMime'), ]; } class XmpGImageNamespace extends XmpGoogleNamespace { static const ns = 'GImage'; const XmpGImageNamespace(Map rawProps) : super(ns, rawProps); @override List> get dataProps => const [Tuple2('$ns:Data', '$ns:Mime')]; } class XmpContainer extends XmpNamespace { static const ns = 'Container'; static final directoryPattern = RegExp('$ns:Directory\\[(\\d+)\\]/$ns:Item/(.*)'); final directories = >{}; XmpContainer(Map rawProps) : super(ns, rawProps); @override bool extractData(XmpProp prop) => extractIndexedStruct(prop, directoryPattern, directories); @override List buildFromExtractedData() => [ if (directories.isNotEmpty) XmpStructArrayCard( title: 'Directory Item', structByIndex: directories, ), ]; }