Skip to content

Instantly share code, notes, and snippets.

View matteopasotti's full-sized avatar

Matteo Pasotti matteopasotti

  • Manchester
View GitHub Profile
[
{
"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",
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) },
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() },
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
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>()
}
def getApiKey() {
def keysProperties = new Properties()
keysProperties.load(project.rootProject.file("local.properties").newDataInputStream())
def ApiKey = keysProperties.getProperty("api_key", "")
return ApiKey
}
class RoomConverters {
var gson = Gson()
@TypeConverter
fun fromListIntToString( items : MutableList<Int>?) : String? {
if(items == null) {
return null
}
return gson.toJson(items)
@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")
@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?,
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