mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
parent
5b8e75c068
commit
2ce9eeabed
@ -196,11 +196,10 @@ public class AttachmentManager {
|
|||||||
public void setMedia(@NonNull final MasterSecret masterSecret,
|
public void setMedia(@NonNull final MasterSecret masterSecret,
|
||||||
@NonNull final Uri uri,
|
@NonNull final Uri uri,
|
||||||
@NonNull final MediaType mediaType,
|
@NonNull final MediaType mediaType,
|
||||||
@NonNull final MediaConstraints constraints)
|
@NonNull final MediaConstraints constraints) {
|
||||||
{
|
|
||||||
inflateStub();
|
inflateStub();
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Slide>() {
|
new AsyncTask<Void, Void, Slide>() {
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
thumbnail.clear();
|
thumbnail.clear();
|
||||||
@ -210,33 +209,19 @@ public class AttachmentManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable Slide doInBackground(Void... params) {
|
protected @Nullable Slide doInBackground(Void... params) {
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
Cursor cursor = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (PartAuthority.isLocalUri(uri)) {
|
if (PartAuthority.isLocalUri(uri)) {
|
||||||
long mediaSize = MediaUtil.getMediaSize(context, masterSecret, uri);
|
return getManuallyCalculatedSlideInfo(uri);
|
||||||
Log.w(TAG, "local slide with size " + mediaSize + " took " + (System.currentTimeMillis() - start) + "ms");
|
|
||||||
return mediaType.createSlide(context, uri, null, null, mediaSize);
|
|
||||||
} else {
|
} else {
|
||||||
cursor = context.getContentResolver().query(uri, null, null, null, null);
|
Slide result = getContentResolverSlideInfo(uri);
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (result == null) return getManuallyCalculatedSlideInfo(uri);
|
||||||
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
|
else return result;
|
||||||
long fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
|
|
||||||
String mimeType = context.getContentResolver().getType(uri);
|
|
||||||
|
|
||||||
Log.w(TAG, "remote slide with size " + fileSize + " took " + (System.currentTimeMillis() - start) + "ms");
|
|
||||||
return mediaType.createSlide(context, uri, fileName, mimeType, fileSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
} finally {
|
return null;
|
||||||
if (cursor != null) cursor.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -259,7 +244,7 @@ public class AttachmentManager {
|
|||||||
audioView.setAudio(masterSecret, (AudioSlide) slide, false);
|
audioView.setAudio(masterSecret, (AudioSlide) slide, false);
|
||||||
removableMediaView.display(audioView, false);
|
removableMediaView.display(audioView, false);
|
||||||
} else if (slide.hasDocument()) {
|
} else if (slide.hasDocument()) {
|
||||||
documentView.setDocument((DocumentSlide)slide, false);
|
documentView.setDocument((DocumentSlide) slide, false);
|
||||||
removableMediaView.display(documentView, false);
|
removableMediaView.display(documentView, false);
|
||||||
} else {
|
} else {
|
||||||
thumbnail.setImageResource(masterSecret, slide, false);
|
thumbnail.setImageResource(masterSecret, slide, false);
|
||||||
@ -269,6 +254,36 @@ public class AttachmentManager {
|
|||||||
attachmentListener.onAttachmentChanged();
|
attachmentListener.onAttachmentChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @Nullable Slide getContentResolverSlideInfo(Uri uri) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
cursor = context.getContentResolver().query(uri, null, null, null, null);
|
||||||
|
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
|
||||||
|
long fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
|
||||||
|
String mimeType = context.getContentResolver().getType(uri);
|
||||||
|
|
||||||
|
Log.w(TAG, "remote slide with size " + fileSize + " took " + (System.currentTimeMillis() - start) + "ms");
|
||||||
|
return mediaType.createSlide(context, uri, fileName, mimeType, fileSize);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NonNull Slide getManuallyCalculatedSlideInfo(Uri uri) throws IOException {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
long mediaSize = MediaUtil.getMediaSize(context, masterSecret, uri);
|
||||||
|
|
||||||
|
Log.w(TAG, "local slide with size " + mediaSize + " took " + (System.currentTimeMillis() - start) + "ms");
|
||||||
|
return mediaType.createSlide(context, uri, null, null, mediaSize);
|
||||||
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user