-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd401ad
commit c5cc345
Showing
21 changed files
with
449 additions
and
6 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/example/movieflix/core/adapters/FavAdapters.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.example.movieflix.core.adapters | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.movieflix.R | ||
import com.example.movieflix.core.utils.Constants | ||
import com.example.movieflix.core.utils.isNetworkAvailable | ||
import com.example.movieflix.core.utils.loadImage | ||
import com.example.movieflix.data.local.entity.FavouritesEntity | ||
import com.example.movieflix.data.local.entity.WatchListEntity | ||
import com.example.movieflix.databinding.ItemListBinding | ||
import com.example.movieflix.domain.model.MovieResult | ||
|
||
class FavAdapters(private var onPosterClick: ((movieResult: MovieResult) -> Unit)): | ||
ListAdapter<FavouritesEntity,FavAdapters.ViewHolder >(DiffUtilCallback()) { | ||
inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { | ||
var binding: ItemListBinding | ||
init { | ||
binding = ItemListBinding.bind(itemView) | ||
} | ||
fun bind(favouritesEntity: FavouritesEntity)=binding.apply{ | ||
|
||
val item = favouritesEntity.movieResult | ||
itemListPoster.loadImage(Constants.TMDB_POSTER_IMAGE_BASE_URL_W342.plus(item.posterPath)) | ||
itemListRatingTxt.text = String.format("%.1f", item.voteAverage) | ||
|
||
root.setOnClickListener(){ | ||
if (isNetworkAvailable(root.context)){ | ||
onPosterClick(item) | ||
}else{ | ||
Toast.makeText(root.context, "Internet req", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
class DiffUtilCallback : DiffUtil.ItemCallback<FavouritesEntity>() { | ||
override fun areItemsTheSame( | ||
oldItem: FavouritesEntity, | ||
newItem: FavouritesEntity | ||
): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
override fun areContentsTheSame( | ||
oldItem: FavouritesEntity, | ||
newItem: FavouritesEntity | ||
): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_list,parent,false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
} |
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
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
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
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
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
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
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/example/movieflix/data/local/entity/FavouritesEntity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.movieflix.data.local.entity | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.example.movieflix.core.utils.Constants | ||
import com.example.movieflix.domain.model.MovieResult | ||
|
||
@Entity(Constants.FAVOURITES_TABLE_NAME) | ||
data class FavouritesEntity( | ||
@PrimaryKey val id:Int, | ||
val movieResult: MovieResult | ||
) |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/example/movieflix/data/repository/FavMovieRepositoryImpl.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.movieflix.data.repository | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.example.movieflix.data.local.LocalDataSource | ||
import com.example.movieflix.data.local.entity.FavouritesEntity | ||
import com.example.movieflix.domain.repository.FavMovieRepository | ||
|
||
class FavMovieRepositoryImpl(private val localDataSource: LocalDataSource):FavMovieRepository { | ||
override suspend fun insertFavMovie(favouritesEntity: FavouritesEntity) { | ||
localDataSource.insertFavMovie(favouritesEntity) | ||
} | ||
|
||
override suspend fun deleteFavMovie(favouritesEntity: FavouritesEntity) { | ||
localDataSource.deleteFavMovie(favouritesEntity) | ||
} | ||
|
||
override fun getAllFavMovie(): LiveData<List<FavouritesEntity>> { | ||
return localDataSource.getAllFavMovie() | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/example/movieflix/domain/repository/FavMovieRepository.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.movieflix.domain.repository | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.example.movieflix.data.local.entity.FavouritesEntity | ||
|
||
interface FavMovieRepository { | ||
suspend fun insertFavMovie(favouritesEntity: FavouritesEntity) | ||
|
||
suspend fun deleteFavMovie(favouritesEntity: FavouritesEntity) | ||
|
||
fun getAllFavMovie(): LiveData<List<FavouritesEntity>> | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/example/movieflix/domain/usecases/FavMovie.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.movieflix.domain.usecases | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.example.movieflix.data.local.entity.FavouritesEntity | ||
import com.example.movieflix.domain.repository.FavMovieRepository | ||
import com.example.movieflix.domain.repository.WatchListRepository | ||
import javax.inject.Inject | ||
|
||
class FavMovie @Inject constructor(private val favMovieRepository: FavMovieRepository) { | ||
|
||
suspend fun insertFavMovie(favouritesEntity: FavouritesEntity){ | ||
favMovieRepository.insertFavMovie(favouritesEntity) | ||
} | ||
|
||
suspend fun deleteFavMovie(favouritesEntity: FavouritesEntity){ | ||
favMovieRepository.deleteFavMovie(favouritesEntity) | ||
} | ||
|
||
fun getAllFavMovie(): LiveData<List<FavouritesEntity>>{ | ||
return favMovieRepository.getAllFavMovie() | ||
} | ||
|
||
} |
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
Oops, something went wrong.