Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache home #121

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ dependencies {

// Lottie Animation
implementation("com.airbnb.android:lottie:6.0.0")

// Room components
val room_version = "2.5.1"
implementation ("androidx.room:room-runtime:$room_version")
annotationProcessor ("androidx.room:room-compiler:$room_version")
kapt ("androidx.room:room-compiler:$room_version")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.red_velvet.marvel.data.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.red_velvet.marvel.data.local.daos.MarvelDao
import com.red_velvet.marvel.data.local.entity.CharacterEntity
import com.red_velvet.marvel.data.local.entity.ComicEntity
import com.red_velvet.marvel.data.local.entity.EventEntity

@Database(entities = [CharacterEntity::class,ComicEntity::class,EventEntity::class], version = 1)
abstract class MarvelDatabase : RoomDatabase() {

abstract fun marvelDao():MarvelDao

companion object{

private const val DATABASE_NAME="MarvelDatabase"

@Volatile
private var instance:MarvelDatabase?=null

fun getInstance(context: Context):MarvelDatabase{
return instance?: synchronized(this){ buildDatabase(context).also { instance =it } }
}

fun getInstanceWithoutContext():MarvelDatabase{
return instance!!
}

private fun buildDatabase(context: Context):MarvelDatabase{
return Room.databaseBuilder(context,MarvelDatabase::class.java, DATABASE_NAME).build()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.red_velvet.marvel.data.local.daos

import android.provider.CalendarContract.EventsEntity
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.red_velvet.marvel.data.local.entity.CharacterEntity
import com.red_velvet.marvel.data.local.entity.ComicEntity
import com.red_velvet.marvel.data.local.entity.EventEntity
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable

@Dao
interface MarvelDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertCharacters(characters:List<CharacterEntity>):Completable

@Query("SELECT * FROM CharacterEntity")
fun getAllCharacters():Observable<List<CharacterEntity>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertComics(characters:List<ComicEntity>):Completable

@Query("SELECT * FROM ComicEntity")
fun getAllComics():Observable<List<ComicEntity>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertEvents(characters:List<EventEntity>):Completable

@Query("SELECT * FROM EventEntity")
fun getAllEvents():Observable<List<EventEntity>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.red_velvet.marvel.data.local.entity

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class CharacterEntity(
@PrimaryKey
val id : Long?,
val name : String?,
val description: String?,
val modified : String?,
val imageUrl : String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.red_velvet.marvel.data.local.entity

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class ComicEntity(
@PrimaryKey
val id : Long?,
val name : String?,
val description: String?,
val modified : String?,
val imageUrl : String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.red_velvet.marvel.data.local.entity

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class EventEntity(
@PrimaryKey
val id : Long?,
val name : String?,
val description: String?,
val modified : String?,
val imageUrl : String?
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.red_velvet.marvel.data.remote

import com.red_velvet.marvel.data.model.BaseResponse
import com.red_velvet.marvel.data.model.Character
import com.red_velvet.marvel.data.model.Comic
import com.red_velvet.marvel.data.model.Creator
import com.red_velvet.marvel.data.model.Event
import com.red_velvet.marvel.data.model.Series
import com.red_velvet.marvel.data.model.Story
import com.red_velvet.marvel.data.remote.dtos.BaseResponse
import com.red_velvet.marvel.data.remote.dtos.CharacterDto
import com.red_velvet.marvel.data.remote.dtos.ComicDto
import com.red_velvet.marvel.data.remote.dtos.Creator
import com.red_velvet.marvel.data.remote.dtos.EventDto
import com.red_velvet.marvel.data.remote.dtos.Series
import com.red_velvet.marvel.data.remote.dtos.Story
import io.reactivex.rxjava3.core.Single
import retrofit2.Response
import retrofit2.http.GET
Expand All @@ -19,19 +19,19 @@ interface MarvelService {
fun getAllComics(
@Query("titleStartsWith") titleStartsWith: String? = null,
@Query("dateDescriptor") dateDescriptor: String? = null,
): Single<Response<BaseResponse<List<Comic>>>>
): Single<Response<BaseResponse<List<ComicDto>>>>

@GET("comics/{comicId}")
fun getComicDetailById(
@Path("comicId") comicId: Int
): Single<Response<BaseResponse<List<Comic>>>>
): Single<Response<BaseResponse<List<ComicDto>>>>

@GET("characters/{characterId}/comics")
fun getComicsByCharacterId(
@Path("characterId") characterId: Int,
@Query("titleStartsWith") titleStartsWith: String? = null,
@Query("dateDescriptor") dateDescriptor: String? = null
): Single<Response<BaseResponse<List<Comic>>>>
): Single<Response<BaseResponse<List<ComicDto>>>>

@GET("comics/{comicId}/creators")
fun getCreatorByComicId(
Expand All @@ -52,17 +52,17 @@ interface MarvelService {
@GET("events")
fun getAllEvents(
@Query("nameStartsWith") nameStartsWith: String? = null
): Single<Response<BaseResponse<List<Event>>>>
): Single<Response<BaseResponse<List<EventDto>>>>

@GET("comics/{comicId}/characters")
fun getCharactersByComicId(
@Path("comicId") comicId: Int? = null,
): Single<Response<BaseResponse<List<Character>>>>
): Single<Response<BaseResponse<List<CharacterDto>>>>

@GET("events/{eventId}/characters")
fun getCharactersByEventId(
@Path("eventId") eventId: Int,
): Single<Response<BaseResponse<List<Character>>>>
): Single<Response<BaseResponse<List<CharacterDto>>>>

@GET("events/{eventId}/creators")
fun getCreatorsByEventId(
Expand All @@ -85,17 +85,17 @@ interface MarvelService {
@GET("stories/{storyId}/comics")
fun getComicsByStoryId(
@Path("storyId") storyId: Int
): Single<Response<BaseResponse<List<Comic>>>>
): Single<Response<BaseResponse<List<ComicDto>>>>

@GET("characters")
fun getAllCharacters(
@Query("nameStartsWith") nameStartsWith: String? = null
): Single<Response<BaseResponse<List<Character>>>>
): Single<Response<BaseResponse<List<CharacterDto>>>>

@GET("characters/{characterId}")
fun getCharacterById(
@Path("characterId") characterId: Int
): Single<Response<BaseResponse<List<Character>>>>
): Single<Response<BaseResponse<List<CharacterDto>>>>

@GET("characters/{characterId}/series")
fun getSeriesByCharacterId(
Expand All @@ -110,5 +110,5 @@ interface MarvelService {
@GET("events/{eventId}")
fun getEventById(
@Path("eventId") eventId: Int
): Single<Response<BaseResponse<List<Event>>>>
): Single<Response<BaseResponse<List<EventDto>>>>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos

import com.google.gson.annotations.SerializedName
import com.red_velvet.marvel.data.model.*
import com.red_velvet.marvel.data.remote.dtos.*

data class Character(
data class CharacterDto(
@SerializedName("comics")
val comics: ResourceCollection? = ResourceCollection(),
@SerializedName("description")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName

data class Comic(
data class ComicDto(
@SerializedName("characters")
val characters: ResourceCollection? = ResourceCollection(),
@SerializedName("collectedIssues")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos

import com.google.gson.annotations.SerializedName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName

data class Event(
data class EventDto(
@SerializedName("id")
val id: Int? = 0,
@SerializedName("title")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos

import com.google.gson.annotations.SerializedName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos

import com.google.gson.annotations.SerializedName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.red_velvet.marvel.data.model
package com.red_velvet.marvel.data.remote.dtos


import com.google.gson.annotations.SerializedName
Expand Down
Loading