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