mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
7fdca5b58f
commit
7c2d2dbe86
|
@ -739,4 +739,32 @@ public class ConnectionHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Integer getLinkDownstreamBandwidthKbps(Context context) {
|
||||
// 2G GSM ~14.4 Kbps
|
||||
// G GPRS ~26.8 Kbps
|
||||
// E EDGE ~108.8 Kbps
|
||||
// 3G UMTS ~128 Kbps
|
||||
// H HSPA ~3.6 Mbps
|
||||
// H+ HSPA+ ~14.4 Mbps-23.0 Mbps
|
||||
// 4G LTE ~50 Mbps
|
||||
// 4G LTE-A ~500 Mbps
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
return null;
|
||||
try {
|
||||
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
|
||||
if (cm == null)
|
||||
return null;
|
||||
Network active = cm.getActiveNetwork();
|
||||
if (active == null)
|
||||
return null;
|
||||
NetworkCapabilities caps = cm.getNetworkCapabilities(active);
|
||||
if (caps == null)
|
||||
return null;
|
||||
return caps.getLinkDownstreamBandwidthKbps();
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,6 @@ import android.graphics.drawable.AnimatedImageDrawable;
|
|||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LevelListDrawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
@ -477,29 +474,8 @@ class ImageHelper {
|
|||
lld.setBounds(0, 0, px, px);
|
||||
lld.setLevel(1);
|
||||
|
||||
boolean slow = false;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
try {
|
||||
// 2G GSM ~14.4 Kbps
|
||||
// G GPRS ~26.8 Kbps
|
||||
// E EDGE ~108.8 Kbps
|
||||
// 3G UMTS ~128 Kbps
|
||||
// H HSPA ~3.6 Mbps
|
||||
// H+ HSPA+ ~14.4 Mbps-23.0 Mbps
|
||||
// 4G LTE ~50 Mbps
|
||||
// 4G LTE-A ~500 Mbps
|
||||
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
|
||||
Network active = (cm == null ? null : cm.getActiveNetwork());
|
||||
NetworkCapabilities caps = (active == null ? null : cm.getNetworkCapabilities(active));
|
||||
if (caps != null) {
|
||||
int kbps = caps.getLinkDownstreamBandwidthKbps();
|
||||
slow = (kbps < SLOW_CONNECTION);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
ExecutorService executor = (slow ? executor_1 : executor_n);
|
||||
Integer kbps = ConnectionHelper.getLinkDownstreamBandwidthKbps(context);
|
||||
ExecutorService executor = (kbps != null && kbps < SLOW_CONNECTION ? executor_1 : executor_n);
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue