debug: improved display for mediastore timestamps

This commit is contained in:
Thibault Deckers 2020-06-12 11:04:15 +09:00
parent 25e394dbba
commit 9c98920639
2 changed files with 36 additions and 18 deletions

View file

@ -352,13 +352,14 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
String[] columnNames = cursor.getColumnNames();
for (int i = 0; i < columnCount; i++) {
String key = columnNames[i];
try {
switch (cursor.getType(i)) {
case Cursor.FIELD_TYPE_NULL:
default:
metadataMap.put(key, null);
break;
case Cursor.FIELD_TYPE_INTEGER:
metadataMap.put(key, cursor.getInt(i));
metadataMap.put(key, cursor.getLong(i));
break;
case Cursor.FIELD_TYPE_FLOAT:
metadataMap.put(key, cursor.getFloat(i));
@ -370,6 +371,9 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
metadataMap.put(key, cursor.getBlob(i));
break;
}
} catch (Exception e) {
Log.w(LOG_TAG, "failed to get value for key=" + key, e);
}
}
cursor.close();
result.success(metadataMap);

View file

@ -144,6 +144,10 @@ class _FullscreenDebugPageState extends State<FullscreenDebugPage> {
);
}
// MediaStore timestamp keys
static const secondTimestampKeys = ['date_added', 'date_modified', 'date_expires', 'isPlayed'];
static const millisecondTimestampKeys = ['datetaken', 'datetime'];
Widget _buildContentResolverTabView() {
return ListView(
padding: const EdgeInsets.all(16),
@ -153,7 +157,17 @@ class _FullscreenDebugPageState extends State<FullscreenDebugPage> {
builder: (context, AsyncSnapshot<Map> snapshot) {
if (snapshot.hasError) return Text(snapshot.error.toString());
if (snapshot.connectionState != ConnectionState.done) return const SizedBox.shrink();
final data = SplayTreeMap.of(snapshot.data.map((k, v) => MapEntry(k.toString(), v?.toString() ?? 'null')));
final data = SplayTreeMap.of(snapshot.data.map((k, v) {
final key = k.toString();
var value = v?.toString() ?? 'null';
if ([...secondTimestampKeys, ...millisecondTimestampKeys].contains(key) && v is num && v != 0) {
if (secondTimestampKeys.contains(key)) {
v *= 1000;
}
value += ' (${DateTime.fromMillisecondsSinceEpoch(v)})';
}
return MapEntry(key, value);
}));
return InfoRowGroup(data);
},
),