2015-03-31 15:44:41 -07:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.Context;
|
2017-04-19 21:23:57 -07:00
|
|
|
import android.graphics.Bitmap;
|
2015-03-31 15:44:41 -07:00
|
|
|
import android.net.Uri;
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2015-03-31 15:44:41 -07:00
|
|
|
|
|
|
|
import com.bumptech.glide.load.data.StreamLocalUriFetcher;
|
|
|
|
|
2017-04-19 21:23:57 -07:00
|
|
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
2015-03-31 15:44:41 -07:00
|
|
|
|
2017-04-19 21:23:57 -07:00
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
2015-03-31 15:44:41 -07:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
2017-10-11 17:12:46 -07:00
|
|
|
class DecryptableStreamLocalUriFetcher extends StreamLocalUriFetcher {
|
2015-10-12 18:25:05 -07:00
|
|
|
|
2015-03-31 15:44:41 -07:00
|
|
|
private static final String TAG = DecryptableStreamLocalUriFetcher.class.getSimpleName();
|
2015-10-12 18:25:05 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
private Context context;
|
2015-03-31 15:44:41 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
DecryptableStreamLocalUriFetcher(Context context, Uri uri) {
|
2017-10-11 17:12:46 -07:00
|
|
|
super(context.getContentResolver(), uri);
|
2015-10-12 18:25:05 -07:00
|
|
|
this.context = context;
|
2015-03-31 15:44:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected InputStream loadResource(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
|
2017-04-19 21:23:57 -07:00
|
|
|
if (MediaUtil.hasVideoThumbnail(uri)) {
|
|
|
|
Bitmap thumbnail = MediaUtil.getVideoThumbnail(context, uri);
|
|
|
|
|
|
|
|
if (thumbnail != null) {
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, baos);
|
|
|
|
return new ByteArrayInputStream(baos.toByteArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 15:44:41 -07:00
|
|
|
try {
|
2018-01-24 19:17:44 -08:00
|
|
|
return PartAuthority.getAttachmentStream(context, uri);
|
2015-03-31 15:44:41 -07:00
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.w(TAG, ioe);
|
|
|
|
throw new FileNotFoundException("PartAuthority couldn't load Uri resource.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|