viewer: get title & size for entries from generic content providers
This commit is contained in:
parent
24f9bc1b81
commit
fa738b6a55
4 changed files with 33 additions and 25 deletions
|
@ -1,18 +1,44 @@
|
|||
package deckers.thibault.aves.model.provider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import deckers.thibault.aves.model.SourceImageEntry;
|
||||
|
||||
class ContentImageProvider extends ImageProvider {
|
||||
@Override
|
||||
public void fetchSingle(@NonNull final Context context, @NonNull final Uri uri, @NonNull final String mimeType, @NonNull final ImageOpCallback callback) {
|
||||
SourceImageEntry entry = new SourceImageEntry(uri, mimeType).fillPreCatalogMetadata(context);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("uri", uri.toString());
|
||||
map.put("sourceMimeType", mimeType);
|
||||
|
||||
if (entry.getHasSize() || entry.isSvg()) {
|
||||
String[] projection = {
|
||||
MediaStore.MediaColumns.SIZE,
|
||||
MediaStore.MediaColumns.DISPLAY_NAME,
|
||||
};
|
||||
try {
|
||||
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToNext()) {
|
||||
map.put("sizeBytes", cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE)));
|
||||
map.put("title", cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME)));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
callback.onFailure(e);
|
||||
return;
|
||||
}
|
||||
|
||||
SourceImageEntry entry = new SourceImageEntry(map).fillPreCatalogMetadata(context);
|
||||
if (entry.isSized() || entry.isSvg()) {
|
||||
callback.onSuccess(entry.toMap());
|
||||
} else {
|
||||
callback.onFailure(new Exception("entry has no size"));
|
||||
|
|
|
@ -27,7 +27,7 @@ class FileImageProvider extends ImageProvider {
|
|||
}
|
||||
entry.fillPreCatalogMetadata(context);
|
||||
|
||||
if (entry.getHasSize() || entry.isSvg()) {
|
||||
if (entry.isSized() || entry.isSvg()) {
|
||||
callback.onSuccess(entry.toMap());
|
||||
} else {
|
||||
callback.onFailure(new Exception("entry has no size"));
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package deckers.thibault.aves.model
|
||||
|
||||
import android.net.Uri
|
||||
import deckers.thibault.aves.utils.MimeTypes
|
||||
|
||||
class AvesImageEntry(map: Map<String?, Any?>) {
|
||||
@JvmField
|
||||
|
@ -21,18 +20,4 @@ class AvesImageEntry(map: Map<String?, Any?>) {
|
|||
|
||||
@JvmField
|
||||
val rotationDegrees = map["rotationDegrees"] as Int
|
||||
|
||||
@JvmField
|
||||
val dateModifiedSecs = toLong(map["dateModifiedSecs"])
|
||||
|
||||
val isVideo: Boolean
|
||||
get() = MimeTypes.isVideo(mimeType)
|
||||
|
||||
companion object {
|
||||
// convenience method
|
||||
private fun toLong(o: Any?): Long? = when (o) {
|
||||
is Int -> o.toLong()
|
||||
else -> o as? Long
|
||||
}
|
||||
}
|
||||
}
|
|
@ -101,15 +101,12 @@ class SourceImageEntry {
|
|||
return null
|
||||
}
|
||||
|
||||
val hasSize: Boolean
|
||||
val isSized: Boolean
|
||||
get() = width ?: 0 > 0 && height ?: 0 > 0
|
||||
|
||||
private val hasDuration: Boolean
|
||||
get() = durationMillis ?: 0 > 0
|
||||
|
||||
private val isImage: Boolean
|
||||
get() = MimeTypes.isImage(sourceMimeType)
|
||||
|
||||
private val isVideo: Boolean
|
||||
get() = MimeTypes.isVideo(sourceMimeType)
|
||||
|
||||
|
@ -123,15 +120,15 @@ class SourceImageEntry {
|
|||
if (isSvg) return this
|
||||
if (isVideo) {
|
||||
fillVideoByMediaMetadataRetriever(context)
|
||||
if (hasSize && hasDuration) return this
|
||||
if (isSized && hasDuration) return this
|
||||
}
|
||||
if (MimeTypes.isSupportedByMetadataExtractor(sourceMimeType)) {
|
||||
fillByMetadataExtractor(context)
|
||||
if (hasSize && foundExif) return this
|
||||
if (isSized && foundExif) return this
|
||||
}
|
||||
if (ExifInterface.isSupportedMimeType(sourceMimeType)) {
|
||||
fillByExifInterface(context)
|
||||
if (hasSize) return this
|
||||
if (isSized) return this
|
||||
}
|
||||
fillByBitmapDecode(context)
|
||||
return this
|
||||
|
|
Loading…
Reference in a new issue