mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 01:21:09 +00:00
"All images" view for conversations
// FREEBIE
This commit is contained in:
@@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.mms;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.util.SmilUtil;
|
||||
import org.w3c.dom.smil.SMILDocument;
|
||||
import org.w3c.dom.smil.SMILMediaElement;
|
||||
@@ -34,14 +35,14 @@ import android.provider.MediaStore.Audio;
|
||||
|
||||
public class AudioSlide extends Slide {
|
||||
|
||||
public AudioSlide(Context context, PduPart part) {
|
||||
super(context, part);
|
||||
}
|
||||
|
||||
public AudioSlide(Context context, Uri uri) throws IOException, MediaTooLargeException {
|
||||
super(context, constructPartFromUri(context, uri));
|
||||
}
|
||||
|
||||
public AudioSlide(Context context, MasterSecret masterSecret, PduPart part) {
|
||||
super(context, masterSecret, part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasImage() {
|
||||
return true;
|
||||
|
||||
@@ -112,6 +112,11 @@ public class ImageSlide extends Slide {
|
||||
|
||||
@Override
|
||||
public void setThumbnailOn(ImageView imageView) {
|
||||
setThumbnailOn(imageView, imageView.getWidth(), imageView.getHeight(), new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThumbnailOn(ImageView imageView, final int width, final int height, final Drawable placeholder) {
|
||||
Drawable thumbnail = getCachedThumbnail();
|
||||
|
||||
if (thumbnail != null) {
|
||||
@@ -120,24 +125,22 @@ public class ImageSlide extends Slide {
|
||||
return;
|
||||
}
|
||||
|
||||
final ColorDrawable temporaryDrawable = new ColorDrawable(Color.TRANSPARENT);
|
||||
final WeakReference<ImageView> weakImageView = new WeakReference<ImageView>(imageView);
|
||||
final WeakReference<ImageView> weakImageView = new WeakReference<>(imageView);
|
||||
final Handler handler = new Handler();
|
||||
final int maxWidth = imageView.getWidth();
|
||||
final int maxHeight = imageView.getHeight();
|
||||
|
||||
imageView.setImageDrawable(temporaryDrawable);
|
||||
imageView.setImageDrawable(placeholder);
|
||||
|
||||
if (maxWidth == 0 || maxHeight == 0)
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
MmsDatabase.slideResolver.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Drawable bitmap = getThumbnail(maxWidth, maxHeight);
|
||||
final Drawable bitmap = getThumbnail(width, height);
|
||||
final ImageView destination = weakImageView.get();
|
||||
|
||||
if (destination != null && destination.getDrawable() == temporaryDrawable) {
|
||||
Log.w(TAG, "slide resolved, destination available? " + (destination == null));
|
||||
if (destination != null && destination.getDrawable() == placeholder) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -156,7 +159,7 @@ public class ImageSlide extends Slide {
|
||||
imageView.setImageDrawable(thumbnail);
|
||||
((AnimationDrawable)imageView.getDrawable()).start();
|
||||
} else {
|
||||
TransitionDrawable fadingResult = new TransitionDrawable(new Drawable[]{new ColorDrawable(Color.TRANSPARENT), thumbnail});
|
||||
TransitionDrawable fadingResult = new TransitionDrawable(new Drawable[]{imageView.getDrawable(), thumbnail});
|
||||
imageView.setImageDrawable(fadingResult);
|
||||
fadingResult.startTransition(300);
|
||||
}
|
||||
|
||||
@@ -10,27 +10,21 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||
import org.thoughtcrime.securesms.providers.PartProvider;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class PartAuthority {
|
||||
|
||||
private static final String PART_URI_STRING = "content://org.thoughtcrime.securesms/part";
|
||||
private static final String THUMB_URI_STRING = "content://org.thoughtcrime.securesms/thumb";
|
||||
|
||||
public static final Uri PART_CONTENT_URI = Uri.parse(PART_URI_STRING);
|
||||
public static final Uri THUMB_CONTENT_URI = Uri.parse(THUMB_URI_STRING);
|
||||
private static final String PART_URI_STRING = "content://org.thoughtcrime.securesms/part";
|
||||
public static final Uri PART_CONTENT_URI = Uri.parse(PART_URI_STRING);
|
||||
|
||||
private static final int PART_ROW = 1;
|
||||
private static final int THUMB_ROW = 2;
|
||||
|
||||
private static final UriMatcher uriMatcher;
|
||||
|
||||
static {
|
||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "part/#", PART_ROW);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "thumb/#", THUMB_ROW);
|
||||
}
|
||||
|
||||
public static InputStream getPartStream(Context context, MasterSecret masterSecret, Uri uri)
|
||||
@@ -42,7 +36,6 @@ public class PartAuthority {
|
||||
try {
|
||||
switch (match) {
|
||||
case PART_ROW: return partDatabase.getPartStream(masterSecret, ContentUris.parseId(uri));
|
||||
case THUMB_ROW: return partDatabase.getThumbnailStream(masterSecret, ContentUris.parseId(uri));
|
||||
default: return context.getContentResolver().openInputStream(uri);
|
||||
}
|
||||
} catch (SecurityException se) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class Slide {
|
||||
protected final PduPart part;
|
||||
protected final Context context;
|
||||
protected MasterSecret masterSecret;
|
||||
|
||||
|
||||
public Slide(Context context, PduPart part) {
|
||||
this.part = part;
|
||||
this.context = context;
|
||||
@@ -78,6 +78,10 @@ public abstract class Slide {
|
||||
imageView.setImageDrawable(getThumbnail(imageView.getWidth(), imageView.getHeight()));
|
||||
}
|
||||
|
||||
public void setThumbnailOn(ImageView imageView, int height, int width, Drawable placeholder) {
|
||||
imageView.setImageDrawable(getThumbnail(width, height));
|
||||
}
|
||||
|
||||
public Bitmap getGeneratedThumbnail() { return null; }
|
||||
|
||||
public boolean hasImage() {
|
||||
|
||||
@@ -20,7 +20,9 @@ import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.dom.smil.parser.SmilXmlSerializer;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.SmilUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -41,20 +43,10 @@ public class SlideDeck {
|
||||
}
|
||||
|
||||
public SlideDeck(Context context, MasterSecret masterSecret, PduBody body) {
|
||||
try {
|
||||
for (int i=0;i<body.getPartsNum();i++) {
|
||||
String contentType = new String(body.getPart(i).getContentType(), CharacterSets.MIMENAME_ISO_8859_1);
|
||||
if (ContentType.isImageType(contentType))
|
||||
slides.add(new ImageSlide(context, masterSecret, body.getPart(i)));
|
||||
else if (ContentType.isVideoType(contentType))
|
||||
slides.add(new VideoSlide(context, body.getPart(i)));
|
||||
else if (ContentType.isAudioType(contentType))
|
||||
slides.add(new AudioSlide(context, body.getPart(i)));
|
||||
else if (ContentType.isTextType(contentType))
|
||||
slides.add(new TextSlide(context, masterSecret, body.getPart(i)));
|
||||
}
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
throw new AssertionError(uee);
|
||||
for (int i=0;i<body.getPartsNum();i++) {
|
||||
String contentType = Util.toIsoString(body.getPart(i).getContentType());
|
||||
Slide slide = MediaUtil.getSlideForPart(context, masterSecret, body.getPart(i), contentType);
|
||||
if (slide != null) slides.add(slide);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.mms;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.util.SmilUtil;
|
||||
import org.w3c.dom.smil.SMILDocument;
|
||||
import org.w3c.dom.smil.SMILMediaElement;
|
||||
@@ -35,14 +36,14 @@ import android.util.Log;
|
||||
|
||||
public class VideoSlide extends Slide {
|
||||
|
||||
public VideoSlide(Context context, PduPart part) {
|
||||
super(context, part);
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, Uri uri) throws IOException, MediaTooLargeException {
|
||||
super(context, constructPartFromUri(context, uri));
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, MasterSecret masterSecret, PduPart part) {
|
||||
super(context, masterSecret, part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getThumbnail(int width, int height) {
|
||||
return context.getResources().getDrawable(R.drawable.ic_launcher_video_player);
|
||||
|
||||
Reference in New Issue
Block a user