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"?> | |
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".ui.main.view.MainActivity"> | |
| <androidx.recyclerview.widget.RecyclerView | |
| android:id="@+id/superhero_recycler" |
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
| enum class Status { | |
| SUCCESS, | |
| ERROR, | |
| LOADING | |
| } |
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
| data class Resource<out T>(val status: Status, val data: T?, val message: String?) { | |
| companion object { | |
| fun <T> success(data: T): Resource<T> = Resource(status = Status.SUCCESS, data = data, message = null) | |
| fun <T> error(data: T?, message: String): Resource<T> = | |
| Resource(status = Status.ERROR, data = data, message = message) | |
| fun <T> loading(data: T?): Resource<T> = Resource(status = Status.LOADING, data = data, message = 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 MainRepository(private val apiHelper: ApiHelper) { | |
| suspend fun getSuperHeroes() = apiHelper.getSuperHeroes() | |
| } |
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
| object RetrofitBuilder { | |
| private const val BASE_URL = "https://akabab.github.io/superhero-api/api/" | |
| private fun getRetrofit(): Retrofit{ | |
| return Retrofit.Builder() | |
| .baseUrl(BASE_URL) | |
| .addConverterFactory(GsonConverterFactory.create()) | |
| .build() | |
| } |
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 ApiHelper(private val apiService: ApiService) { | |
| suspend fun getSuperHeroes() = apiService.getSuperHeroes() | |
| } |
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
| interface ApiService { | |
| @GET("all.json") | |
| suspend fun getSuperHeroes(): List<Hero> | |
| } |
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
| import com.google.gson.annotations.SerializedName | |
| data class Hero( | |
| @SerializedName("id") | |
| val id: Long, | |
| @SerializedName("name") | |
| val name: String, | |
| @SerializedName("slug") |
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
| <uses-permission android:name="android.permission.INTERNET" /> |
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
| implementation 'androidx.gridlayout:gridlayout:1.0.0' | |
| implementation 'com.google.android.material:material:1.2.0' | |
| implementation 'androidx.cardview:cardview:1.0.0' | |
| implementation 'androidx.recyclerview:recyclerview:1.1.0' | |
| implementation 'com.github.bumptech.glide:glide:4.11.0' | |
| //LifeCycle | |
| implementation 'androidx.lifecycle:lifecycle-common:2.2.0' | |
| implementation 'androidx.lifecycle:lifecycle-runtime:2.2.0' | |
| implementation 'android.arch.lifecycle:extensions:2.2.0' |