diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..61a9130 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ccccd12..e17a734 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + diff --git a/app/src/main/java/com/jackandphantom/carousellayout/MainActivity.kt b/app/src/main/java/com/jackandphantom/carousellayout/MainActivity.kt index 1e265f7..218d4ac 100644 --- a/app/src/main/java/com/jackandphantom/carousellayout/MainActivity.kt +++ b/app/src/main/java/com/jackandphantom/carousellayout/MainActivity.kt @@ -22,7 +22,7 @@ class MainActivity : AppCompatActivity() { list.add(DataModel(R.drawable.hobes, "Thi is cool")) list.add(DataModel(R.drawable.guypro, "Thi is cool")) list.add(DataModel(R.drawable.joker, "Thi is cool")) - list.add(DataModel(R.drawable.londonlove, "Thi is cool")) + // list.add(DataModel(R.drawable.londonlove, "Thi is cool")) val adapter = DataAdapter(list) @@ -30,9 +30,11 @@ class MainActivity : AppCompatActivity() { this.adapter = adapter set3DItem(true) setAlpha(true) - setInfinite(true) } - val carouselLayoutManager = binding.recycler.getCarouselLayoutManager() - // carouselLayoutManager.scrollToPosition(4) + + //Trigger the button and put your useCase to test different cases of adapter + binding.button.setOnClickListener { + adapter.removeData() + } } } \ No newline at end of file diff --git a/app/src/main/java/com/jackandphantom/carousellayout/adapter/DataAdapter.kt b/app/src/main/java/com/jackandphantom/carousellayout/adapter/DataAdapter.kt index 11a2ad5..32b0bd2 100644 --- a/app/src/main/java/com/jackandphantom/carousellayout/adapter/DataAdapter.kt +++ b/app/src/main/java/com/jackandphantom/carousellayout/adapter/DataAdapter.kt @@ -9,7 +9,7 @@ import com.bumptech.glide.Glide import com.example.customviewimple.model.DataModel import com.jackandphantom.carousellayout.R -class DataAdapter (private var list : List): RecyclerView.Adapter() { +class DataAdapter (private var list : ArrayList): RecyclerView.Adapter() { class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val image : ImageView = itemView.findViewById(R.id.image) @@ -28,8 +28,24 @@ class DataAdapter (private var list : List): RecyclerView.Adapter) { + fun updateData(list: ArrayList) { this.list = list notifyDataSetChanged() } + + //Use the method for item changed + fun itemChanged() { + // remove last item for test purposes + this.list[0] = (DataModel(R.drawable.londonlove, "Thi is cool")) + notifyItemChanged(0) + + } + + //Use the method for checking the itemRemoved + fun removeData() { + // remove last item for test purposes + val orgListSize = list.size + this.list = this.list.subList(0, orgListSize - 1).toList() as ArrayList + notifyItemRemoved(orgListSize - 1) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d90afc3..250f78e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,14 +1,23 @@ - - \ No newline at end of file +