info: fixed owner for current entry

This commit is contained in:
Thibault Deckers 2021-01-30 13:00:32 +09:00
parent f133ebf624
commit 09de6bb76b
3 changed files with 71 additions and 15 deletions

View file

@ -20,12 +20,14 @@ import 'package:intl/intl.dart';
class BasicSection extends StatelessWidget { class BasicSection extends StatelessWidget {
final AvesEntry entry; final AvesEntry entry;
final CollectionLens collection; final CollectionLens collection;
final ValueNotifier<bool> visibleNotifier;
final FilterCallback onFilter; final FilterCallback onFilter;
const BasicSection({ const BasicSection({
Key key, Key key,
@required this.entry, @required this.entry,
this.collection, this.collection,
@required this.visibleNotifier,
@required this.onFilter, @required this.onFilter,
}) : super(key: key); }) : super(key: key);
@ -58,7 +60,10 @@ class BasicSection extends StatelessWidget {
'URI': uri, 'URI': uri,
if (path != null) 'Path': path, if (path != null) 'Path': path,
}), }),
OwnerProp(entry: entry), OwnerProp(
entry: entry,
visibleNotifier: visibleNotifier,
),
_buildChips(), _buildChips(),
], ],
); );
@ -109,9 +114,11 @@ class BasicSection extends StatelessWidget {
class OwnerProp extends StatefulWidget { class OwnerProp extends StatefulWidget {
final AvesEntry entry; final AvesEntry entry;
final ValueNotifier<bool> visibleNotifier;
const OwnerProp({ const OwnerProp({
@required this.entry, @required this.entry,
@required this.visibleNotifier,
}); });
@override @override
@ -119,24 +126,53 @@ class OwnerProp extends StatefulWidget {
} }
class _OwnerPropState extends State<OwnerProp> { class _OwnerPropState extends State<OwnerProp> {
Future<String> _loader; final ValueNotifier<String> _loadedUri = ValueNotifier(null);
String _ownerPackage;
AvesEntry get entry => widget.entry;
bool get isVisible => widget.visibleNotifier.value;
static const iconSize = 20.0; static const iconSize = 20.0;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loader = MetadataService.getContentResolverProp(widget.entry, 'owner_package_name'); _registerWidget(widget);
_getOwner();
}
@override
void didUpdateWidget(covariant OwnerProp oldWidget) {
super.didUpdateWidget(oldWidget);
_unregisterWidget(oldWidget);
_registerWidget(widget);
_getOwner();
}
@override
void dispose() {
_unregisterWidget(widget);
super.dispose();
}
void _registerWidget(OwnerProp widget) {
widget.visibleNotifier.addListener(_getOwner);
}
void _unregisterWidget(OwnerProp widget) {
widget.visibleNotifier.removeListener(_getOwner);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<String>( return ValueListenableBuilder<String>(
future: _loader, valueListenable: _loadedUri,
builder: (context, snapshot) { builder: (context, uri, child) {
final packageName = snapshot.data; if (_ownerPackage == null) return SizedBox();
if (packageName == null) return SizedBox(); final appName = androidFileUtils.getCurrentAppName(_ownerPackage) ?? _ownerPackage;
final appName = androidFileUtils.getCurrentAppName(packageName) ?? packageName; // as of Flutter v1.22.6, `SelectableText` cannot contain `WidgetSpan`
// so be use a basic `Text` instead
return Text.rich( return Text.rich(
TextSpan( TextSpan(
children: [ children: [
@ -150,7 +186,7 @@ class _OwnerPropState extends State<OwnerProp> {
padding: EdgeInsets.symmetric(horizontal: 4), padding: EdgeInsets.symmetric(horizontal: 4),
child: Image( child: Image(
image: AppIconImage( image: AppIconImage(
packageName: packageName, packageName: _ownerPackage,
size: iconSize, size: iconSize,
), ),
width: iconSize, width: iconSize,
@ -168,4 +204,16 @@ class _OwnerPropState extends State<OwnerProp> {
}, },
); );
} }
Future<void> _getOwner() async {
if (entry == null) return;
if (_loadedUri.value == entry.uri) return;
if (isVisible) {
_ownerPackage = await MetadataService.getContentResolverProp(widget.entry, 'owner_package_name');
_loadedUri.value = entry.uri;
} else {
_ownerPackage = null;
_loadedUri.value = null;
}
}
} }

View file

@ -116,7 +116,7 @@ class _InfoRowGroupState extends State<InfoRowGroup> {
value = '$value\n'; value = '$value\n';
} }
// as of Flutter v1.22.4, `SelectableText` cannot contain `WidgetSpan` // as of Flutter v1.22.6, `SelectableText` cannot contain `WidgetSpan`
// so we add padding using multiple hair spaces instead // so we add padding using multiple hair spaces instead
final thisSpaceSize = max(0.0, (baseValueX - keySizes[key])) + InfoRowGroup.keyValuePadding; final thisSpaceSize = max(0.0, (baseValueX - keySizes[key])) + InfoRowGroup.keyValuePadding;
final spaceCount = (100 * thisSpaceSize / baseSpaceWidth).round(); final spaceCount = (100 * thisSpaceSize / baseSpaceWidth).round();

View file

@ -156,14 +156,22 @@ class _InfoPageContentState extends State<_InfoPageContent> {
AvesEntry get entry => widget.entry; AvesEntry get entry => widget.entry;
ValueNotifier<bool> get visibleNotifier => widget.visibleNotifier;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final basicSection = BasicSection(
entry: entry,
collection: collection,
visibleNotifier: visibleNotifier,
onFilter: _goToCollection,
);
final locationAtTop = widget.split && entry.hasGps; final locationAtTop = widget.split && entry.hasGps;
final locationSection = LocationSection( final locationSection = LocationSection(
collection: collection, collection: collection,
entry: entry, entry: entry,
showTitle: !locationAtTop, showTitle: !locationAtTop,
visibleNotifier: widget.visibleNotifier, visibleNotifier: visibleNotifier,
onFilter: _goToCollection, onFilter: _goToCollection,
); );
final basicAndLocationSliver = locationAtTop final basicAndLocationSliver = locationAtTop
@ -171,7 +179,7 @@ class _InfoPageContentState extends State<_InfoPageContent> {
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded(child: BasicSection(entry: entry, collection: collection, onFilter: _goToCollection)), Expanded(child: basicSection),
SizedBox(width: 8), SizedBox(width: 8),
Expanded(child: locationSection), Expanded(child: locationSection),
], ],
@ -180,7 +188,7 @@ class _InfoPageContentState extends State<_InfoPageContent> {
: SliverList( : SliverList(
delegate: SliverChildListDelegate.fixed( delegate: SliverChildListDelegate.fixed(
[ [
BasicSection(entry: entry, collection: collection, onFilter: _goToCollection), basicSection,
locationSection, locationSection,
], ],
), ),
@ -188,7 +196,7 @@ class _InfoPageContentState extends State<_InfoPageContent> {
final metadataSliver = MetadataSectionSliver( final metadataSliver = MetadataSectionSliver(
entry: entry, entry: entry,
metadataNotifier: _metadataNotifier, metadataNotifier: _metadataNotifier,
visibleNotifier: widget.visibleNotifier, visibleNotifier: visibleNotifier,
); );
return CustomScrollView( return CustomScrollView(