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: case AttachmentTypeSelectorAdapter.TAKE_PHOTO:
attachmentManager.capturePhoto(this, TAKE_PHOTO); break; attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
case AttachmentTypeSelector.ADD_GIF: 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; return images.downsized.url;
} }
public String getGifMmsUrl() {
return images.fixed_height_downsampled.url;
}
public float getGifAspectRatio() { public float getGifAspectRatio() {
return (float)images.downsized.width / (float)images.downsized.height; 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(); 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 DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private GiphyGifFragment gifFragment; private GiphyGifFragment gifFragment;
private GiphyStickerFragment stickerFragment; private GiphyStickerFragment stickerFragment;
private boolean forMms;
private GiphyAdapter.GiphyViewHolder finishingImage; private GiphyAdapter.GiphyViewHolder finishingImage;
@ -74,6 +77,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
this.gifFragment = new GiphyGifFragment(); this.gifFragment = new GiphyGifFragment();
this.stickerFragment = new GiphyStickerFragment(); this.stickerFragment = new GiphyStickerFragment();
this.forMms = getIntent().getBooleanExtra(EXTRA_IS_MMS, false);
gifFragment.setClickListener(this); gifFragment.setClickListener(this);
stickerFragment.setClickListener(this); stickerFragment.setClickListener(this);
@ -105,7 +109,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
@Override @Override
protected Uri doInBackground(Void... params) { protected Uri doInBackground(Void... params) {
try { try {
return Uri.fromFile(viewHolder.getFile()); return Uri.fromFile(viewHolder.getFile(forMms));
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e); Log.w(TAG, e);
return null; return null;

View File

@ -83,7 +83,7 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
return false; return false;
} }
public File getFile() throws ExecutionException, InterruptedException { public File getFile(boolean forMms) throws ExecutionException, InterruptedException {
synchronized (this) { synchronized (this) {
while (!modelReady) { while (!modelReady) {
Util.wait(this, 0); Util.wait(this, 0);
@ -91,7 +91,7 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
} }
return Glide.with(context) return Glide.with(context)
.load(image.getGifUrl()) .load(forMms ? image.getGifMmsUrl() : image.getGifUrl())
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get(); .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 intent = new Intent(activity, GiphyActivity.class);
intent.putExtra(GiphyActivity.EXTRA_IS_MMS, isForMms);
activity.startActivityForResult(intent, requestCode); activity.startActivityForResult(intent, requestCode);
} }