check_for_slow_speed (#1293)
This commit is contained in:
@@ -28,7 +28,7 @@ public class UsersList {
|
||||
public static void getUsersList() {
|
||||
var prefs = AndroidUtils.getGlobalContext().getSharedPreferences("vt_another_data", 0);
|
||||
|
||||
if ((!NetworkUtils.isNetworkConnected() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
|
||||
if ((!NetworkUtils.isNetworkConnected() || NetworkUtils.isInternetSlow()) && prefs.contains("ids")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ public class ImageUtils {
|
||||
|
||||
// must be called asynchronously
|
||||
public static Drawable getDrawableFromUrl(String url, int placeholderRes, boolean rounded, boolean scaled) {
|
||||
|
||||
if (NetworkUtils.isNetworkConnected()) {
|
||||
if (NetworkUtils.isNetworkConnected() && !NetworkUtils.isInternetSlow()) {
|
||||
try {
|
||||
var bmp = BitmapFactory.decodeStream(new URL(url).openStream());
|
||||
|
||||
|
||||
@@ -2,7 +2,13 @@ package ru.vtosters.lite.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.telephony.TelephonyManager;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class NetworkUtils {
|
||||
public static boolean isNetworkConnected() {
|
||||
@@ -13,4 +19,28 @@ public class NetworkUtils {
|
||||
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
|
||||
}
|
||||
} // Network check
|
||||
|
||||
public static boolean isInternetSlow() {
|
||||
if (getBoolValue("isRoamingState", false)) return true;
|
||||
ConnectivityManager cm = (ConnectivityManager) AndroidUtils.getGlobalContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
NetworkCapabilities nc = cm != null ? cm.getNetworkCapabilities(cm.getActiveNetwork()) : null;
|
||||
if (nc == null) {
|
||||
return true;
|
||||
} else {
|
||||
int speed = nc.getLinkDownstreamBandwidthKbps();
|
||||
double speedMbps = speed / 1000.0;
|
||||
return speedMbps < 1.0;
|
||||
}
|
||||
} else {
|
||||
NetworkInfo ni = cm != null ? cm.getActiveNetworkInfo() : null;
|
||||
if (ni == null || !ni.isConnected()) {
|
||||
return true;
|
||||
} else {
|
||||
int type = ni.getType();
|
||||
int subtype = ni.getSubtype();
|
||||
return type == ConnectivityManager.TYPE_MOBILE && (subtype == TelephonyManager.NETWORK_TYPE_EDGE || subtype == TelephonyManager.NETWORK_TYPE_GPRS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class VTVerifications {
|
||||
public static void load(Context context) {
|
||||
var prefs = context.getSharedPreferences("vt_another_data", 0);
|
||||
|
||||
if ((!NetworkUtils.isNetworkConnected() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
|
||||
if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
|
||||
parseJson(prefs.getString("ids", "[]"));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user