Skip to content

Commit

Permalink
Processing lack of internet(API 16+). Processing back button press (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalitosh authored and omralcrt committed Dec 11, 2019
1 parent 2fb6910 commit bc74a2b
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,19 @@ class LinkedinSignInActivity: Activity() {
return super.shouldOverrideUrlLoading(view, request)
}

@RequiresApi(Build.VERSION_CODES.M)
override fun onReceivedError( view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
super.onReceivedError(view, request, error)
finish()
Linkedin.linkedinLoginViewResponseListener?.linkedinLoginDidFail(PAGE_CANT_LOADING_MESSAGE)
}

override fun onReceivedError(view: WebView?, errorCode: Int, description: String?, failingUrl: String?) {
super.onReceivedError(view, errorCode, description, failingUrl)
finish()
Linkedin.linkedinLoginViewResponseListener?.linkedinLoginDidFail(PAGE_CANT_LOADING_MESSAGE)
}

}

webView.loadUrl(url)
Expand Down Expand Up @@ -226,6 +233,15 @@ class LinkedinSignInActivity: Activity() {
return result.toString()
}

override fun onBackPressed() {
super.onBackPressed()
if (isNotLoggedIn) {
runOnUiThread {
Linkedin.linkedinLoginViewResponseListener?.linkedinLoginDidFail(SIGNIN_CANCELED_MESSAGE)
}
}
}

companion object {
private const val AUTHORIZATION_URL = "https://www.linkedin.com/oauth/v2/authorization"
private const val ACCESS_TOKEN_URL = "https://www.linkedin.com/oauth/v2/accessToken"
Expand All @@ -242,5 +258,6 @@ class LinkedinSignInActivity: Activity() {
private const val CLIENT_SECRET = "client_secret"

private const val PAGE_CANT_LOADING_MESSAGE = "LinkedIn cannot be loaded"
private const val SIGNIN_CANCELED_MESSAGE = "LinkedIn sign in has been canceled"
}
}

0 comments on commit bc74a2b

Please sign in to comment.