This file contains 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
[ | |
{ | |
"name": "Bulbasaur", | |
"id": "#001", | |
"imageurl": "https://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png", | |
"xdescription": "Bulbasaur can be seen napping in bright sunlight. There is a seed on its back. By soaking up the sun's rays, the seed grows progressively larger.", | |
"ydescription": "Bulbasaur can be seen napping in bright sunlight. There is a seed on its back. By soaking up the sun's rays, the seed grows progressively larger.", | |
"height": "2' 04\"", | |
"category": "Seed", | |
"weight": "15.2 lbs", |
This file contains 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 MovieRepository { | |
suspend fun getPopularMovies() : MutableList<Movie>? | |
} | |
class MovieRepositoryImpl(val movieApi: MovieApiInterface) : BaseRepository(), MovieRepository { | |
override suspend fun getPopularMovies(): MutableList<Movie>? { | |
val movieResponse = safeApiCall( | |
call = { movieApi.getPopularMovies(BuildConfig.API_KEY , "en-US", 1) }, |
This file contains 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 MovieRepository { | |
suspend fun getPopularMovies() : MutableList<Movie>? | |
} | |
class MovieRepositoryImpl(val movieApi: MovieApiInterface) : BaseRepository(), MovieRepository { | |
override suspend fun getPopularMovies(): MutableList<Movie>? { | |
val movieResponse = safeApiCall( | |
call = { movieApi.getPopularMovies(BuildConfig.API_KEY , "en-US", 1).await() }, |
This file contains 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
open class BaseRepository{ | |
suspend fun <T : Any> safeApiCall(call: suspend () -> Response<T>, errorMessage: String): T? { | |
val result : Result<T> = safeApiResult(call,errorMessage) | |
var data : T? = null | |
when(result) { | |
is Result.Success -> | |
data = result.data |
This file contains 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
sealed class Result<out T: Any> { | |
data class Success<out T : Any>(val data: T) : Result<T>() | |
data class Error(val exception: Exception) : Result<Nothing>() | |
} |
This file contains 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
def getApiKey() { | |
def keysProperties = new Properties() | |
keysProperties.load(project.rootProject.file("local.properties").newDataInputStream()) | |
def ApiKey = keysProperties.getProperty("api_key", "") | |
return ApiKey | |
} |
This file contains 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 RoomConverters { | |
var gson = Gson() | |
@TypeConverter | |
fun fromListIntToString( items : MutableList<Int>?) : String? { | |
if(items == null) { | |
return null | |
} | |
return gson.toJson(items) |
This file contains 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
@Dao | |
interface MovieDao { | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun insertMovie(movie: Movie) | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun insertMovies(movies: List<Movie>) | |
@Query("SELECT * FROM Movie WHERE Movie.id = :id") |
This file contains 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
@Entity(primaryKeys = ["id"]) | |
@Parcelize | |
data class Movie( | |
val id: Int, | |
val poster_path: String?, | |
val adult: Boolean, | |
val overview: String?, | |
val release_date: String?, | |
val original_title: String?, | |
val original_language: String?, |
This file contains 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
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
implementation 'androidx.appcompat:appcompat:1.0.2' | |
implementation 'androidx.core:core-ktx:1.0.2' | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'androidx.test:runner:1.2.0' | |
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | |
// Anko |
NewerOlder