From 0b890b74e0bce2bc21cae303969c65c00f10661c Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Wed, 6 Apr 2022 10:03:37 +0300 Subject: [PATCH] fix login button display when internet connection is available --- .../safedispatch/SDMobileActivity.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java index e1f2218..6ef16a8 100644 --- a/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java @@ -10,13 +10,19 @@ import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Color; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkRequest; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.text.Editable; import android.text.InputType; +import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; @@ -114,6 +120,17 @@ public class SDMobileActivity extends Activity { super.onCreate(savedInstanceState); SM.Debug("##### onCREATE ##### with LANGUAGE " + AppParams.LANGUAGETMP); + ConnectivityManager connectivityManager = + (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + connectivityManager.registerDefaultNetworkCallback(networkCallback); + } else { + NetworkRequest request = new NetworkRequest.Builder() + .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(); + connectivityManager.registerNetworkCallback(request, networkCallback); + } + AppParams.theme = AppParams.Theme.SAFEDISPATCH; if (AppParams.theme == AppParams.Theme.SAFENET) this.setTheme(R.style.Theme_Safenet); @@ -524,6 +541,22 @@ public class SDMobileActivity extends Activity { SM.Debug("##### onRESUME #####"); } + private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { + @Override + public void onAvailable(Network network) { + // network available + Log.v("NetworkAvailability", "available"); + if (tcp != null && !tcp.isConnectionUP) + saveIPandRestartTCP(AppParams.IP, AppParams.PORT); + } + + @Override + public void onLost(Network network) { + // network unavailable + Log.v("NetworkAvailability", "unavailable"); + } + }; + private void startTabActivity(long userID) { // good login - load activity