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,23 +352,27 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
String[] columnNames = cursor.getColumnNames(); String[] columnNames = cursor.getColumnNames();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
String key = columnNames[i]; String key = columnNames[i];
switch (cursor.getType(i)) { try {
case Cursor.FIELD_TYPE_NULL: switch (cursor.getType(i)) {
default: case Cursor.FIELD_TYPE_NULL:
metadataMap.put(key, null); default:
break; metadataMap.put(key, null);
case Cursor.FIELD_TYPE_INTEGER: break;
metadataMap.put(key, cursor.getInt(i)); case Cursor.FIELD_TYPE_INTEGER:
break; metadataMap.put(key, cursor.getLong(i));
case Cursor.FIELD_TYPE_FLOAT: break;
metadataMap.put(key, cursor.getFloat(i)); case Cursor.FIELD_TYPE_FLOAT:
break; metadataMap.put(key, cursor.getFloat(i));
case Cursor.FIELD_TYPE_STRING: break;
metadataMap.put(key, cursor.getString(i)); case Cursor.FIELD_TYPE_STRING:
break; metadataMap.put(key, cursor.getString(i));
case Cursor.FIELD_TYPE_BLOB: break;
metadataMap.put(key, cursor.getBlob(i)); case Cursor.FIELD_TYPE_BLOB:
break; metadataMap.put(key, cursor.getBlob(i));
break;
}
} catch (Exception e) {
Log.w(LOG_TAG, "failed to get value for key=" + key, e);
} }
} }
cursor.close(); cursor.close();

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() { Widget _buildContentResolverTabView() {
return ListView( return ListView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@ -153,7 +157,17 @@ class _FullscreenDebugPageState extends State<FullscreenDebugPage> {
builder: (context, AsyncSnapshot<Map> snapshot) { builder: (context, AsyncSnapshot<Map> snapshot) {
if (snapshot.hasError) return Text(snapshot.error.toString()); if (snapshot.hasError) return Text(snapshot.error.toString());
if (snapshot.connectionState != ConnectionState.done) return const SizedBox.shrink(); 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); return InfoRowGroup(data);
}, },
), ),