Skip to content

Commit

Permalink
favorite user interaction is added to mainActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
masooddalman committed Aug 26, 2023
1 parent 290386f commit c82e052
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemChildClickListener
import com.liliputdev.mvvmexample.R
import com.liliputdev.mvvmexample.adapters.ProductListAdapter
import com.liliputdev.mvvmexample.repository.retrofit.apiModel.APIModelAllProductElement
import com.liliputdev.mvvmexample.ui.dialogs.FiltersDialog
import com.liliputdev.mvvmexample.ui.dialogs.SortDialog
import com.liliputdev.mvvmexample.ui.dialogs.dataModel.SortFilterDataModel
Expand Down Expand Up @@ -38,6 +42,19 @@ class MainActivity : AppCompatActivity() {
recyclerView = findViewById(R.id.recyclerViewMainActivity)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = adapter

adapter.setOnItemChildClickListener(object: OnItemChildClickListener{
override fun onItemChildClick(
adapter: BaseQuickAdapter<*, *>,
view: View,
position: Int
) {
viewModel.manageFav(adapter.data[position] as APIModelAllProductElement)
(adapter.data[position] as APIModelAllProductElement).isfaved=!(adapter.data[position] as APIModelAllProductElement).isfaved
adapter.notifyItemChanged(position)
}

})
}

@SuppressLint("NotifyDataSetChanged")
Expand Down

0 comments on commit c82e052

Please sign in to comment.