Refactoring small improvement

pull/152/head
M66B 6 years ago
parent 28fe881b46
commit e08f276996

@ -2568,7 +2568,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.name_email = prefs.getBoolean("name_email", !compact); this.name_email = prefs.getBoolean("name_email", !compact);
this.zoom = zoom; this.zoom = zoom;
this.sort = sort; this.sort = sort;
this.internet = (Helper.isMetered(context, false) != null); this.internet = Helper.isConnected(context);
this.properties = properties; this.properties = properties;
@ -2648,7 +2648,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
void checkInternet() { void checkInternet() {
boolean internet = (Helper.isMetered(context, false) != null); boolean internet = Helper.isConnected(context);
if (this.internet != internet) { if (this.internet != internet) {
this.internet = internet; this.internet = internet;
notifyDataSetChanged(); notifyDataSetChanged();

@ -695,7 +695,7 @@ public class FragmentCompose extends FragmentBase {
}; };
private void checkInternet() { private void checkInternet() {
boolean internet = (Helper.isMetered(getContext(), false) != null); boolean internet = Helper.isConnected(getContext());
Boolean content = (Boolean) tvNoInternet.getTag(); Boolean content = (Boolean) tvNoInternet.getTag();
tvNoInternet.setVisibility(!internet && content != null && !content ? View.VISIBLE : View.GONE); tvNoInternet.setVisibility(!internet && content != null && !content ? View.VISIBLE : View.GONE);

@ -696,16 +696,18 @@ public class Helper {
} }
static boolean isConnected(Context context) { static boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return (isMetered(context, false) != null);
NetworkInfo ni = cm.getActiveNetworkInfo();
return (ni != null && ni.isConnected());
} }
static Boolean isMetered(Context context, boolean log) { static Boolean isMetered(Context context, boolean log) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
NetworkInfo ani = cm.getActiveNetworkInfo();
if (ani == null || !ani.isConnected())
return null;
return cm.isActiveNetworkMetered(); return cm.isActiveNetworkMetered();
}
Network active = cm.getActiveNetwork(); Network active = cm.getActiveNetwork();
if (active == null) { if (active == null) {

Loading…
Cancel
Save