Last active
November 20, 2020 09:57
-
-
Save adityaladwa/04a3246b5a6b33c5e271492a91d0c4ca to your computer and use it in GitHub Desktop.
Revisions
-
adityaladwa revised this gist
Nov 19, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ class NetworkInterceptor(context: Context) : Interceptor { private val mApplicationContext: Context = context.applicationContext private val isConnected: Boolean -
adityaladwa revised this gist
Nov 19, 2017 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,16 +7,15 @@ class LiveNetworkInterceptor(context: Context) : Interceptor { val activeNetwork = cm.activeNetworkInfo return activeNetwork != null && activeNetwork.isConnectedOrConnecting } @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { val originalRequest = chain.request() if (!isConnected) { throw NoNetworkException() } return chain.proceed(originalRequest) } class NoNetworkException internal constructor() : RuntimeException("Please check Network Connection") } -
adityaladwa created this gist
Nov 19, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ class LiveNetworkInterceptor(context: Context) : Interceptor { private val mApplicationContext: Context = context.applicationContext private val isConnected: Boolean get() { val cm = mApplicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetwork = cm.activeNetworkInfo return activeNetwork != null && activeNetwork.isConnectedOrConnecting } @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { val connected = isConnected val originalRequest = chain.request() if (!connected) { throw NoNetworkException() } return chain.proceed(originalRequest) } class NoNetworkException internal constructor() : RuntimeException("Please check Network Connection") }