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

Feature/check anime is saved #72

Merged
merged 2 commits into from
Oct 12, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ interface AnimeDao {

@Delete
suspend fun deleteAnime(anime: OfflineAnimeModel)

@Query("SELECT EXISTS(SELECT 1 FROM animes WHERE animeUrl = :animeUrl LIMIT 1)")
suspend fun isAnimeWithUrlSaved(animeUrl: String): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ data class AnimeDetailModel(
var genre: List<GenreModel>,
var plotSummary: String,
var status: String,
var type: String
var type: String,
var isSaved: Boolean = false
)

@Entity(tableName = "animes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package divyansh.tech.animeclassroom.animeDetail
import android.util.Log
import divyansh.tech.animeclassroom.ResultWrapper
import divyansh.tech.animeclassroom.api.AnimeDetailScreenApi
import divyansh.tech.animeclassroom.favorites.FavoriteAnimeLocalRepo
import divyansh.tech.animeclassroom.models.home.EpisodeModel
import divyansh.tech.animeclassroom.utils.Parser
import javax.inject.Inject

class AnimeDetailRepo @Inject constructor(
private val animeDetailScreenApi: AnimeDetailScreenApi
private val animeDetailScreenApi: AnimeDetailScreenApi,
private val favoriteAnimeLocalRepo: FavoriteAnimeLocalRepo
) {

/*
Expand All @@ -17,8 +19,10 @@ class AnimeDetailRepo @Inject constructor(
* */
suspend fun getAnimeDetails(url: String): ResultWrapper<*> {
Log.i("HOME-ANIMEREPO", url)
val isAnimeSaved = favoriteAnimeLocalRepo.isAnimeWithUrlSaved(url)
val response = Parser.parseAnimeDetails(
animeDetailScreenApi.getAnimeDetails(url).string()
animeDetailScreenApi.getAnimeDetails(url).string(),
isAnimeSaved
)
return if (response is ResultWrapper.Success) ResultWrapper.Success(response.data)
else ResultWrapper.Error(message = "No Body To parse", data = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class FavoriteAnimeLocalRepo @Inject constructor(
Log.i("ROOM REPO -> ", list.toString())
return list
}

suspend fun isAnimeWithUrlSaved(animeUrl: String) = dao.isAnimeWithUrlSaved(animeUrl)
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object Parser {
* @param response: Response from the anime page
* @returns ResultWrapper<*>
* */
suspend fun parseAnimeDetails(response: String): ResultWrapper<*> {
suspend fun parseAnimeDetails(response: String, isSaved: Boolean): ResultWrapper<*> {
Log.i("Anime Details -> ", response)
return try {
val jsoup = Jsoup.parse(response)
Expand Down Expand Up @@ -149,7 +149,8 @@ object Parser {
status = formatInfoValues(status),
genre = genre,
plotSummary = plotSummary,
endEpisode = endEpisode.toInt()
endEpisode = endEpisode.toInt(),
isSaved = isSaved
)

return ResultWrapper.Success(model)
Expand Down