mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
MMS image quality.
Fixes #8590 - Scale image larger within the dimensions. - Apply a minimum dimension of 1024.
This commit is contained in:
parent
e842f78457
commit
ce6d2d9c69
@ -8,7 +8,6 @@ import android.text.Html;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
|
|
||||||
import com.bumptech.glide.request.FutureTarget;
|
import com.bumptech.glide.request.FutureTarget;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||||
@ -132,7 +131,7 @@ public class LinkPreviewRepository {
|
|||||||
.load(new ChunkedImageUrl(imageUrl))
|
.load(new ChunkedImageUrl(imageUrl))
|
||||||
.skipMemoryCache(true)
|
.skipMemoryCache(true)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||||
.downsample(DownsampleStrategy.AT_MOST)
|
.centerInside()
|
||||||
.submit(1024, 1024);
|
.submit(1024, 1024);
|
||||||
|
|
||||||
RequestController controller = () -> bitmapFuture.cancel(false);
|
RequestController controller = () -> bitmapFuture.cancel(false);
|
||||||
|
@ -3,8 +3,7 @@ package org.thoughtcrime.securesms.mms;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.annotation.WorkerThread;
|
import android.support.annotation.WorkerThread;
|
||||||
|
|
||||||
import com.android.mms.service_alt.MmsConfig;
|
import com.android.mms.service_alt.MmsConfig;
|
||||||
@ -16,35 +15,35 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MmsConfigManager {
|
final class MmsConfigManager {
|
||||||
|
|
||||||
private static Map<Integer, MmsConfig> mmsConfigMap = new HashMap<>();
|
private static final Map<Integer, MmsConfig> mmsConfigMap = new HashMap<>();
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public synchronized static @Nullable MmsConfig getMmsConfig(Context context, int subscriptionId) {
|
synchronized static @NonNull MmsConfig getMmsConfig(Context context, int subscriptionId) {
|
||||||
if (mmsConfigMap.containsKey(subscriptionId)) {
|
MmsConfig mmsConfig = mmsConfigMap.get(subscriptionId);
|
||||||
return mmsConfigMap.get(subscriptionId);
|
if (mmsConfig != null) {
|
||||||
|
return mmsConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
MmsConfig loadedConfig = loadMmsConfig(context, subscriptionId);
|
MmsConfig loadedConfig = loadMmsConfig(context, subscriptionId);
|
||||||
|
|
||||||
if (loadedConfig != null) mmsConfigMap.put(subscriptionId, loadedConfig);
|
mmsConfigMap.put(subscriptionId, loadedConfig);
|
||||||
|
|
||||||
return loadedConfig;
|
return loadedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MmsConfig loadMmsConfig(Context context, int subscriptionId) {
|
private static @NonNull MmsConfig loadMmsConfig(Context context, int subscriptionId) {
|
||||||
if (subscriptionId != -1 && Build.VERSION.SDK_INT >= 24) {
|
Optional<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);
|
||||||
Optional<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);
|
|
||||||
|
|
||||||
if (subscriptionInfo.isPresent()) {
|
if (subscriptionInfo.isPresent()) {
|
||||||
Configuration configuration = context.getResources().getConfiguration();
|
SubscriptionInfoCompat subscriptionInfoCompat = subscriptionInfo.get();
|
||||||
configuration.mcc = subscriptionInfo.get().getMcc();
|
Configuration configuration = context.getResources().getConfiguration();
|
||||||
configuration.mnc = subscriptionInfo.get().getMnc();
|
configuration.mcc = subscriptionInfoCompat.getMcc();
|
||||||
|
configuration.mnc = subscriptionInfoCompat.getMnc();
|
||||||
|
|
||||||
Context subcontext = context.createConfigurationContext(configuration);
|
Context subContext = context.createConfigurationContext(configuration);
|
||||||
return new MmsConfig(subcontext, subscriptionId);
|
return new MmsConfig(subContext, subscriptionId);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MmsConfig(context, subscriptionId);
|
return new MmsConfig(context, subscriptionId);
|
||||||
|
@ -1,43 +1,27 @@
|
|||||||
package org.thoughtcrime.securesms.mms;
|
package org.thoughtcrime.securesms.mms;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.android.mms.service_alt.MmsConfig;
|
import com.android.mms.service_alt.MmsConfig;
|
||||||
|
|
||||||
class MmsMediaConstraints extends MediaConstraints {
|
final class MmsMediaConstraints extends MediaConstraints {
|
||||||
|
|
||||||
private static final int DEFAULT_MAX_IMAGE_DIMEN = 1024;
|
|
||||||
private static final int DEFAULT_MAX_MESSAGE_SIZE = 280 * 1024;
|
|
||||||
|
|
||||||
private final int subscriptionId;
|
private final int subscriptionId;
|
||||||
|
|
||||||
|
private static final int MIN_IMAGE_DIMEN = 1024;
|
||||||
|
|
||||||
MmsMediaConstraints(int subscriptionId) {
|
MmsMediaConstraints(int subscriptionId) {
|
||||||
this.subscriptionId = subscriptionId;
|
this.subscriptionId = subscriptionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getImageMaxWidth(Context context) {
|
public int getImageMaxWidth(Context context) {
|
||||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageWidth());
|
||||||
|
|
||||||
if (mmsConfig != null) {
|
|
||||||
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
|
||||||
return overridden.getMaxImageWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
return DEFAULT_MAX_IMAGE_DIMEN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getImageMaxHeight(Context context) {
|
public int getImageMaxHeight(Context context) {
|
||||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageHeight());
|
||||||
|
|
||||||
if (mmsConfig != null) {
|
|
||||||
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
|
||||||
return overridden.getMaxImageHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
return DEFAULT_MAX_IMAGE_DIMEN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -66,13 +50,12 @@ class MmsMediaConstraints extends MediaConstraints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getMaxMessageSize(Context context) {
|
private int getMaxMessageSize(Context context) {
|
||||||
|
return getOverriddenMmsConfig(context).getMaxMessageSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MmsConfig.Overridden getOverriddenMmsConfig(Context context) {
|
||||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||||
|
|
||||||
if (mmsConfig != null) {
|
return new MmsConfig.Overridden(mmsConfig, null);
|
||||||
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
|
|
||||||
return overridden.getMaxMessageSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
return DEFAULT_MAX_MESSAGE_SIZE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import org.thoughtcrime.securesms.logging.Log;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
||||||
@ -68,7 +67,7 @@ public class BitmapUtil {
|
|||||||
.load(model)
|
.load(model)
|
||||||
.skipMemoryCache(true)
|
.skipMemoryCache(true)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||||
.downsample(DownsampleStrategy.AT_MOST)
|
.centerInside()
|
||||||
.submit(maxImageWidth, maxImageHeight)
|
.submit(maxImageWidth, maxImageHeight)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
@ -122,7 +121,7 @@ public class BitmapUtil {
|
|||||||
return GlideApp.with(context.getApplicationContext())
|
return GlideApp.with(context.getApplicationContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(model)
|
.load(model)
|
||||||
.downsample(DownsampleStrategy.AT_MOST)
|
.centerInside()
|
||||||
.submit(maxWidth, maxHeight)
|
.submit(maxWidth, maxHeight)
|
||||||
.get();
|
.get();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user