Use downsampled GIFs for MMS messages

Fixes #5958
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2016-12-14 11:58:47 -08:00
parent 71276161fc
commit 791cc4b4f8
5 changed files with 14 additions and 5 deletions

View File

@ -1143,7 +1143,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
case AttachmentTypeSelectorAdapter.TAKE_PHOTO:
attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
case AttachmentTypeSelector.ADD_GIF:
AttachmentManager.selectGif(this, PICK_GIF); break;
AttachmentManager.selectGif(this, PICK_GIF, !isSecureText); break;
}
}

View File

@ -12,6 +12,10 @@ public class GiphyImage {
return images.downsized.url;
}
public String getGifMmsUrl() {
return images.fixed_height_downsampled.url;
}
public float getGifAspectRatio() {
return (float)images.downsized.width / (float)images.downsized.height;
}

View File

@ -35,11 +35,14 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
private static final String TAG = GiphyActivity.class.getSimpleName();
public static final String EXTRA_IS_MMS = "extra_is_mms";
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private GiphyGifFragment gifFragment;
private GiphyStickerFragment stickerFragment;
private boolean forMms;
private GiphyAdapter.GiphyViewHolder finishingImage;
@ -74,6 +77,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
this.gifFragment = new GiphyGifFragment();
this.stickerFragment = new GiphyStickerFragment();
this.forMms = getIntent().getBooleanExtra(EXTRA_IS_MMS, false);
gifFragment.setClickListener(this);
stickerFragment.setClickListener(this);
@ -105,7 +109,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
@Override
protected Uri doInBackground(Void... params) {
try {
return Uri.fromFile(viewHolder.getFile());
return Uri.fromFile(viewHolder.getFile(forMms));
} catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e);
return null;

View File

@ -83,7 +83,7 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
return false;
}
public File getFile() throws ExecutionException, InterruptedException {
public File getFile(boolean forMms) throws ExecutionException, InterruptedException {
synchronized (this) {
while (!modelReady) {
Util.wait(this, 0);
@ -91,7 +91,7 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
}
return Glide.with(context)
.load(image.getGifUrl())
.load(forMms ? image.getGifMmsUrl() : image.getGifUrl())
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get();
}

View File

@ -264,8 +264,9 @@ public class AttachmentManager {
}
}
public static void selectGif(Activity activity, int requestCode) {
public static void selectGif(Activity activity, int requestCode, boolean isForMms) {
Intent intent = new Intent(activity, GiphyActivity.class);
intent.putExtra(GiphyActivity.EXTRA_IS_MMS, isForMms);
activity.startActivityForResult(intent, requestCode);
}