Browse code

Initial commit (losing old history)

Dario Rodriguez authored on 08/04/2026 17:25:38
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) 2023 Samson Achiaga
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+package com.certified.audionote.adapter
18
+
19
+import android.view.LayoutInflater
20
+import android.view.ViewGroup
21
+import androidx.recyclerview.widget.DiffUtil
22
+import androidx.recyclerview.widget.ListAdapter
23
+import androidx.recyclerview.widget.RecyclerView
24
+import com.certified.audionote.databinding.ItemSliderBinding
25
+import com.certified.audionote.model.SliderItem
26
+
27
+class ViewPagerAdapter() :
28
+    ListAdapter<SliderItem, ViewPagerAdapter.ViewHolder>(DIFF_CALLBACK) {
29
+
30
+    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
31
+        val binding = ItemSliderBinding.inflate(LayoutInflater.from(parent.context), parent, false)
32
+        return ViewHolder(binding)
33
+    }
34
+
35
+    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
36
+        val currentItem = getItem(position)
37
+        holder.bind(currentItem)
38
+    }
39
+
40
+    inner class ViewHolder(val binding: ItemSliderBinding) : RecyclerView.ViewHolder(binding.root) {
41
+        fun bind(sliderItem: SliderItem) {
42
+            binding.sliderItem = sliderItem
43
+        }
44
+    }
45
+
46
+    companion object {
47
+        val DIFF_CALLBACK = object : DiffUtil.ItemCallback<SliderItem>() {
48
+            override fun areItemsTheSame(oldItem: SliderItem, newItem: SliderItem) =
49
+                oldItem.title == newItem.title
50
+
51
+            override fun areContentsTheSame(oldItem: SliderItem, newItem: SliderItem) =
52
+                oldItem == newItem
53
+        }
54
+    }
55
+}
0 56
\ No newline at end of file