Skip to content

Commit

Permalink
! Update state
Browse files Browse the repository at this point in the history
  • Loading branch information
wahyukharisma committed Apr 1, 2021
1 parent 7a41bc0 commit 4aaf230
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class MovieFavAdapter(private val onMovieClickListener : OnMovieClickListener)
onMovieClickListener.removeMovie(item, items.size)
removeSingle(item)
}

cvItem.setOnClickListener {
onMovieClickListener.onItemClick(item.movieId)
}
}
}
}
Expand All @@ -63,5 +67,6 @@ class MovieFavAdapter(private val onMovieClickListener : OnMovieClickListener)

interface OnMovieClickListener{
fun removeMovie(movie: MovieFavorite, size : Int)
fun onItemClick(id : Int)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.movist.presentation.view.favorite

import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.example.movist.databinding.ActivityFavoriteMoviesBinding
import com.example.movist.presentation.adapter.MovieFavAdapter
import com.example.movist.presentation.view.detail.DetailActivity
import com.example.movist.services.storage.entities.MovieFavorite
import com.example.movist.util.remove
import com.example.movist.util.show
Expand All @@ -21,6 +23,11 @@ class FavoriteActivity : AppCompatActivity() {

private var size = 0

override fun onResume() {
super.onResume()
_viewModel.getFavMovie()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
_binding = ActivityFavoriteMoviesBinding.inflate(layoutInflater)
Expand All @@ -39,6 +46,11 @@ class FavoriteActivity : AppCompatActivity() {
_viewModel.removeFavMovie(movie)
size = mSize
}

override fun onItemClick(id: Int) {
startActivity(Intent(this@FavoriteActivity, DetailActivity::class.java)
.putExtra("movie_id",id))
}
})

ibTrash.setOnClickListener {
Expand All @@ -48,10 +60,15 @@ class FavoriteActivity : AppCompatActivity() {
rvContent.adapter = _adapter

_viewModel.movies.observe(this@FavoriteActivity,{ data ->
_adapter.removeAll()

if(data.isNotEmpty()){
clEmptyFavorite.remove()
ibTrash.isEnabled = true
_adapter.populatedData(data)
}else{
clEmptyFavorite.show()
ibTrash.isEnabled = false
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SplashScreenActivity : AppCompatActivity() {
setContentView(view)

val r = Runnable {
finish()
startActivity(Intent(this, DashboardActivity::class.java))
}

Expand Down

0 comments on commit 4aaf230

Please sign in to comment.