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
class LoginActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
signInButton.setOnClickListener { view -> | |
if (isNetworkConnected()) { | |
authenticate() //REPLACE CALL TO startActivity() WITH THIS LINE | |
} else { |
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
class LoginActivity : AppCompatActivity() { | |
... | |
fun authenticate() { | |
val loginJob = Job() | |
val errorHandler = CoroutineExceptionHandler { _, exception -> | |
AlertDialog.Builder(this).setTitle("Error") | |
.setMessage(exception.message) |
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
<?xml version="1.0" encoding="utf-8"?> | |
<network-security-config> | |
<base-config cleartextTrafficPermitted="true"> | |
<trust-anchors> | |
<certificates src="system" /> | |
</trust-anchors> | |
</base-config> | |
</network-security-config> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.chelseatroy.canary"> | |
<application | |
//ADD THIS LINE | |
android:networkSecurityConfig="@xml/network_security_config" | |
... | |
</application> | |
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
package com.chelseatroy.canary.api | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
class MockyAPIImplementation { | |
private val service: LoginService | |
companion object { | |
const val BASE_URL = "http://www.mocky.io/" |
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
package com.chelseatroy.canary.api | |
data class CanarySession( | |
val name: String?, | |
val token: String? | |
) |
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
package com.chelseatroy.canary.api | |
import retrofit2.http.GET | |
interface LoginService { | |
@GET("/v2/5ed1d35132000070005ca001") | |
suspend fun authenticate(): CanarySession | |
} |
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
class LoginActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
signInButton.setOnClickListener { view -> | |
if (isNetworkConnected()) { | |
startActivity(Intent(this@LoginActivity, MainActivity::class.java)) | |
} else { | |
AlertDialog.Builder(this).setTitle("No Internet Connection") | |
.setMessage("Please check your internet connection and try again") |
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
class LoginActivity : AppCompatActivity() { | |
... | |
private fun isNetworkConnected(): Boolean { | |
val connectivityManager = | |
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val activeNetwork = connectivityManager.activeNetwork | |
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork) | |
return networkCapabilities != null && |
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
class LoginActivity : AppCompatActivity() { | |
... | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
signInButton.setOnClickListener { view -> | |
startActivity(Intent(this@LoginActivity, MainActivity::class.java)) | |
} | |
} |