File tree 4 files changed +44
-22
lines changed
app/src/main/java/fr/free/nrw/commons 4 files changed +44
-22
lines changed Original file line number Diff line number Diff line change 1
1
package fr.free.nrw.commons.explore.depictions
2
2
3
- import androidx.recyclerview.widget.DiffUtil
4
- import fr.free.nrw.commons.upload.categories.BaseAdapter
3
+ import fr.free.nrw.commons.upload.categories.BaseDelegateAdapter
5
4
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
6
5
7
6
8
- class DepictionAdapter (clickListener : (DepictedItem ) -> Unit ) : BaseAdapter<DepictedItem>(
9
- object : DiffUtil .ItemCallback <DepictedItem >() {
10
- override fun areItemsTheSame(oldItem: DepictedItem , newItem: DepictedItem ) =
11
- oldItem.id == newItem.id
12
-
13
- override fun areContentsTheSame(oldItem: DepictedItem , newItem: DepictedItem ) =
14
- oldItem == newItem
15
- },
16
- depictionDelegate(clickListener)
7
+ class DepictionAdapter (clickListener : (DepictedItem ) -> Unit ) : BaseDelegateAdapter<DepictedItem>(
8
+ depictionDelegate(clickListener),
9
+ areItemsTheSame = { oldItem, newItem -> oldItem.id == newItem.id }
17
10
)
18
11
19
12
Original file line number Diff line number Diff line change
1
+ package fr.free.nrw.commons.upload.categories
2
+
3
+ import androidx.recyclerview.widget.DiffUtil
4
+ import com.hannesdorfmann.adapterdelegates4.AdapterDelegate
5
+ import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
6
+
7
+
8
+ abstract class BaseDelegateAdapter <T >(
9
+ vararg delegates : AdapterDelegate <List <T >>,
10
+ areItemsTheSame : (T , T ) -> Boolean ,
11
+ areContentsTheSame : (T , T ) -> Boolean = { old, new -> old == new }
12
+ ) : AsyncListDifferDelegationAdapter<T>(
13
+ object : DiffUtil .ItemCallback <T >() {
14
+ override fun areItemsTheSame(oldItem: T , newItem: T ) =
15
+ areItemsTheSame(oldItem, newItem)
16
+
17
+ override fun areContentsTheSame(oldItem: T , newItem: T ) =
18
+ areContentsTheSame(oldItem, newItem)
19
+ },
20
+ *delegates
21
+ ) {
22
+ fun indexOf (item : T ): Int = items.indexOf(item)
23
+
24
+ fun getItemAt (position : Int ) = items[position]
25
+
26
+ fun addAll (newResults : List <T >) {
27
+ items = (items ? : emptyList<T >()) + newResults
28
+ }
29
+
30
+ fun clear () {
31
+ items = emptyList()
32
+ }
33
+ }
34
+
Original file line number Diff line number Diff line change 1
1
package fr.free.nrw.commons.upload.categories
2
2
3
- import androidx.recyclerview.widget.DiffUtil
4
3
import fr.free.nrw.commons.category.CategoryItem
5
4
6
5
class UploadCategoryAdapter (onCategoryClicked : (CategoryItem ) -> Unit ) :
7
- BaseAdapter <CategoryItem >(
8
- object : DiffUtil .ItemCallback <CategoryItem >() {
9
- override fun areItemsTheSame (oldItem : CategoryItem , newItem : CategoryItem ) =
10
- oldItem.name == newItem.name
11
-
12
- override fun areContentsTheSame (oldItem : CategoryItem , newItem : CategoryItem ) =
13
- oldItem.name == newItem.name && oldItem.isSelected == newItem.isSelected
14
- },
15
- uploadCategoryDelegate(onCategoryClicked)
6
+ BaseDelegateAdapter <CategoryItem >(
7
+ uploadCategoryDelegate(onCategoryClicked),
8
+ areItemsTheSame = { oldItem, newItem -> oldItem.name == newItem.name },
9
+ areContentsTheSame = { oldItem, newItem ->
10
+ oldItem.name == newItem.name && oldItem.isSelected == newItem.isSelected
11
+ }
16
12
)
17
13
18
14
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import fr.free.nrw.commons.R
5
5
import fr.free.nrw.commons.category.CategoryItem
6
6
import kotlinx.android.synthetic.main.layout_upload_categories_item.*
7
7
8
-
9
8
fun uploadCategoryDelegate (onCategoryClicked : (CategoryItem ) -> Unit ) =
10
9
adapterDelegateLayoutContainer<CategoryItem , CategoryItem >(R .layout.layout_upload_categories_item) {
11
10
containerView.setOnClickListener {
You can’t perform that action at this time.
0 commit comments