Created
May 5, 2020 18:25
-
-
Save hissain/d9c4651be3ca2b60358f6de97859047c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun loadWebView(){ | |
| val loader = Thread { | |
| when { | |
| MyReachability.hasServerConnected(this) -> runOnUiThread { | |
| hideLoadingDialog() | |
| Log.d(classTag, "Loading ${Constants.LANDING_SERVER}") | |
| mWebView.loadUrl(Constants.LANDING_SERVER) | |
| } | |
| MyReachability.hasInternetConnected(this) -> runOnUiThread { | |
| //showServerConnectionLost() | |
| } | |
| else -> runOnUiThread { | |
| showInternetConnectionLost() | |
| } | |
| } | |
| } | |
| loader.start() | |
| } | |
| fun showInternetConnectionLost(){ | |
| try { | |
| val dialog = AlertDialog.Builder(this, android.R.style.Theme_Material_Light_Dialog_Alert).create() | |
| dialog.setTitle("No Internet Connection") | |
| dialog.setMessage("Please make sure your Wi-Fi or mobile data is turned on, then try again.") | |
| dialog.setCancelable(false) | |
| dialog.setButton(DialogInterface.BUTTON_POSITIVE,"OK", DialogInterface.OnClickListener { _, _ -> finish() }) | |
| dialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Retry", DialogInterface.OnClickListener { _, _ -> | |
| val hThread = HandlerThread("connectivity") | |
| hThread.start() | |
| Handler(hThread.looper).post { | |
| if (MyReachability.hasInternetConnected(this)){ | |
| Handler(Looper.getMainLooper()).post{ | |
| dialog.dismiss() | |
| webView?.reload() | |
| } | |
| }else{ | |
| Handler(Looper.getMainLooper()).postDelayed({showInternetConnectionLost()}, 500) | |
| } | |
| } | |
| }) | |
| dialog.show() | |
| } catch (e: Exception) { | |
| Log.e(classTag, e) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment