viewer: minor fixes
This commit is contained in:
parent
23a20a9343
commit
b0699df136
3 changed files with 21 additions and 9 deletions
|
@ -6,6 +6,7 @@ import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
@ -13,12 +14,15 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import deckers.thibault.aves.utils.Utils;
|
||||||
import io.flutter.plugin.common.MethodCall;
|
import io.flutter.plugin.common.MethodCall;
|
||||||
import io.flutter.plugin.common.MethodChannel;
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
|
|
||||||
public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
||||||
public static final String CHANNEL = "deckers.thibault/aves/app";
|
public static final String CHANNEL = "deckers.thibault/aves/app";
|
||||||
|
|
||||||
|
private static final String LOG_TAG = Utils.createLogTag(AppAdapterHandler.class);
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public AppAdapterHandler(Context context) {
|
public AppAdapterHandler(Context context) {
|
||||||
|
@ -27,6 +31,7 @@ public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||||
|
Log.d(LOG_TAG, "onMethodCall method=" + call.method + ", arguments=" + call.arguments);
|
||||||
switch (call.method) {
|
switch (call.method) {
|
||||||
case "getAppNames": {
|
case "getAppNames": {
|
||||||
result.success(getAppNames());
|
result.success(getAppNames());
|
||||||
|
|
|
@ -40,32 +40,37 @@ public class MediaStoreImageProvider extends ImageProvider {
|
||||||
}).flatMap(Stream::of).toArray(String[]::new);
|
}).flatMap(Stream::of).toArray(String[]::new);
|
||||||
|
|
||||||
public void fetchAll(Activity activity, EventChannel.EventSink entrySink) {
|
public void fetchAll(Activity activity, EventChannel.EventSink entrySink) {
|
||||||
fetchFrom(activity, entrySink::success, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION, null, null);
|
NewEntryHandler success = entrySink::success;
|
||||||
fetchFrom(activity, entrySink::success, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, VIDEO_PROJECTION, null, null);
|
fetchFrom(activity, success, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION);
|
||||||
|
fetchFrom(activity, success, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, VIDEO_PROJECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fetchSingle(final Activity activity, final Uri uri, final String mimeType, final ImageOpCallback callback) {
|
public void fetchSingle(final Activity activity, final Uri uri, final String mimeType, final ImageOpCallback callback) {
|
||||||
long id = ContentUris.parseId(uri);
|
long id = ContentUris.parseId(uri);
|
||||||
String selection = MediaStore.MediaColumns._ID + "=?";
|
|
||||||
String[] selectionArgs = new String[]{String.valueOf(id)};
|
|
||||||
int entryCount = 0;
|
int entryCount = 0;
|
||||||
|
NewEntryHandler onSuccess = (entry) -> {
|
||||||
|
entry.put("uri", uri.toString());
|
||||||
|
callback.onSuccess(entry);
|
||||||
|
};
|
||||||
if (mimeType.startsWith(Constants.MIME_IMAGE)) {
|
if (mimeType.startsWith(Constants.MIME_IMAGE)) {
|
||||||
entryCount = fetchFrom(activity, callback::onSuccess, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION, selection, selectionArgs);
|
Uri contentUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
|
||||||
|
entryCount = fetchFrom(activity, onSuccess, contentUri, IMAGE_PROJECTION);
|
||||||
} else if (mimeType.startsWith(Constants.MIME_VIDEO)) {
|
} else if (mimeType.startsWith(Constants.MIME_VIDEO)) {
|
||||||
entryCount = fetchFrom(activity, callback::onSuccess, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, VIDEO_PROJECTION, selection, selectionArgs);
|
Uri contentUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id);
|
||||||
|
entryCount = fetchFrom(activity, onSuccess, contentUri, VIDEO_PROJECTION);
|
||||||
}
|
}
|
||||||
if (entryCount == 0) {
|
if (entryCount == 0) {
|
||||||
callback.onFailure();
|
callback.onFailure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fetchFrom(final Activity activity, NewEntryHandler newEntryHandler, final Uri contentUri, String[] projection, String selection, String[] selectionArgs) {
|
private int fetchFrom(final Activity activity, NewEntryHandler newEntryHandler, final Uri contentUri, String[] projection) {
|
||||||
String orderBy = MediaStore.MediaColumns.DATE_TAKEN + " DESC";
|
String orderBy = MediaStore.MediaColumns.DATE_TAKEN + " DESC";
|
||||||
int entryCount = 0;
|
int entryCount = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Cursor cursor = activity.getContentResolver().query(contentUri, projection, selection, selectionArgs, orderBy);
|
Cursor cursor = activity.getContentResolver().query(contentUri, projection, null, null, orderBy);
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
// image & video
|
// image & video
|
||||||
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID);
|
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID);
|
||||||
|
@ -84,6 +89,7 @@ public class MediaStoreImageProvider extends ImageProvider {
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
long contentId = cursor.getLong(idColumn);
|
long contentId = cursor.getLong(idColumn);
|
||||||
|
// this is fine if `contentUri` does not already contain the ID
|
||||||
Uri itemUri = ContentUris.withAppendedId(contentUri, contentId);
|
Uri itemUri = ContentUris.withAppendedId(contentUri, contentId);
|
||||||
int width = cursor.getInt(widthColumn);
|
int width = cursor.getInt(widthColumn);
|
||||||
// TODO TLAD sanitize mimeType
|
// TODO TLAD sanitize mimeType
|
||||||
|
|
|
@ -16,7 +16,8 @@ class BasicSection extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final date = entry.bestDate;
|
final date = entry.bestDate;
|
||||||
final dateText = date != null ? '${DateFormat.yMMMd().format(date)} at ${DateFormat.Hm().format(date)}' : '?';
|
final dateText = date != null ? '${DateFormat.yMMMd().format(date)} at ${DateFormat.Hm().format(date)}' : '?';
|
||||||
final resolutionText = '${entry.width ?? '?'} × ${entry.height ?? '?'}${(entry.isVideo || entry.isGif || entry.megaPixels == null) ? '' : ' (${entry.megaPixels} MP)'}';
|
final showMegaPixels = !entry.isVideo && !entry.isGif && entry.megaPixels != null && entry.megaPixels > 0;
|
||||||
|
final resolutionText = '${entry.width ?? '?'} × ${entry.height ?? '?'}${showMegaPixels ? ' (${entry.megaPixels} MP)' : ''}';
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
|
Loading…
Reference in a new issue