Skip to content

Commit 4713bbe

Browse files
authored
Merge pull request #1011 from mikepenz/develop
dev -> main
2 parents d3a7ab7 + 6882dfe commit 4713bbe

File tree

23 files changed

+257
-164
lines changed

23 files changed

+257
-164
lines changed

DEV/default-detekt-config.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ complexity:
6868
threshold: 60
6969
LongParameterList:
7070
active: true
71-
threshold: 10
71+
functionThreshold: 10
72+
constructorThreshold: 10
7273
ignoreDefaultParameters: false
7374
MethodOverloading:
7475
active: false
@@ -114,7 +115,7 @@ empty-blocks:
114115
active: true
115116
EmptyFunctionBlock:
116117
active: false
117-
ignoreOverriddenFunctions: false
118+
ignoreOverridden: false
118119
EmptyIfBlock:
119120
active: true
120121
EmptyInitBlock:
@@ -311,15 +312,15 @@ naming:
311312
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
312313
parameterPattern: '[a-z][A-Za-z0-9]*'
313314
excludeClassPattern: '$^'
314-
ignoreOverriddenFunctions: true
315+
ignoreOverridden: true
315316
InvalidPackageDeclaration:
316317
active: false
317318
rootPackage: ''
318319
MatchingDeclarationName:
319320
active: true
320321
MemberNameEqualsClassName:
321322
active: false
322-
ignoreOverriddenFunction: true
323+
ignoreOverridden: true
323324
ObjectPropertyNaming:
324325
active: true
325326
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.7.0)
4+
addressable (2.8.0)
55
public_suffix (>= 2.0.2, < 5.0)
66
ansi (1.5.0)
77
ast (2.4.2)
@@ -58,7 +58,7 @@ GEM
5858
open4 (1.3.4)
5959
public_suffix (4.0.6)
6060
rchardet (1.8.0)
61-
rexml (3.2.4)
61+
rexml (3.2.5)
6262
ruby-ll (2.1.2)
6363
ansi
6464
ast

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ It's blazing fast, minimizing the code you need to write, and is easy to extend.
4848

4949
## Latest releases 🛠
5050

51-
- Kotlin | [v5.4.1](https://github.com/mikepenz/FastAdapter/tree/v5.4.1)
51+
- Kotlin | [v5.5.0](https://github.com/mikepenz/FastAdapter/tree/v5.5.0)
5252
- Java && AndroidX | [v3.3.1](https://github.com/mikepenz/FastAdapter/tree/v3.3.1)
5353
- Java && AppCompat | [v3.2.9](https://github.com/mikepenz/FastAdapter/tree/v3.2.9)
5454

app/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ dependencies {
133133
//https://github.com/mikepenz/Android-Iconics
134134
implementation 'com.mikepenz:material-design-iconic-typeface:2.2.0.8-kotlin@aar'
135135
implementation 'com.mikepenz:community-material-typeface:5.8.55.0-kotlin@aar'
136-
implementation 'com.mikepenz:google-material-typeface:4.0.0.1-kotlin@aar'
137-
implementation 'com.mikepenz:fontawesome-typeface:5.9.0.2-kotlin@aar'
136+
implementation 'com.mikepenz:google-material-typeface:4.0.0.2-kotlin@aar'
137+
implementation 'com.mikepenz:fontawesome-typeface:5.13.3.0-kotlin@aar'
138138

139139
//Used for the StickyHeaderSample
140140
//https://github.com/timehop/sticky-headers-recyclerview
@@ -148,7 +148,7 @@ dependencies {
148148

149149
//used to load the images in the ImageListSample
150150
//https://github.com/coil-kt/coil
151-
implementation 'io.coil-kt:coil:1.1.1'
151+
implementation 'io.coil-kt:coil:1.3.2'
152152

153153
//Used to provide the drag selection like google photos
154154
implementation 'com.github.MFlisar:DragSelectRecyclerView:0.3'
@@ -191,6 +191,6 @@ buildscript {
191191
}
192192

193193
dependencies {
194-
classpath "io.realm:realm-gradle-plugin:10.4.0"
194+
classpath "io.realm:realm-gradle-plugin:10.8.0"
195195
}
196196
}

app/src/main/java/com/mikepenz/fastadapter/app/PagedActivity.kt

+56-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.mikepenz.fastadapter.app
22

3+
import android.graphics.Color
34
import android.os.Bundle
45
import android.os.Handler
6+
import android.view.Menu
7+
import android.view.MenuItem
8+
import android.widget.Toast
59
import androidx.appcompat.app.AppCompatActivity
610
import androidx.lifecycle.ViewModelProvider
711
import androidx.recyclerview.widget.AsyncDifferConfig
@@ -14,6 +18,10 @@ import com.mikepenz.fastadapter.app.paged.DemoEntity
1418
import com.mikepenz.fastadapter.app.paged.DemoEntityViewModel
1519
import com.mikepenz.fastadapter.paged.PagedModelAdapter
1620
import com.mikepenz.fastadapter.select.getSelectExtension
21+
import com.mikepenz.iconics.IconicsDrawable
22+
import com.mikepenz.iconics.typeface.library.materialdesigniconic.MaterialDesignIconic
23+
import com.mikepenz.iconics.utils.actionBar
24+
import com.mikepenz.iconics.utils.colorInt
1725

1826

1927
class PagedActivity : AppCompatActivity() {
@@ -25,6 +33,8 @@ class PagedActivity : AppCompatActivity() {
2533
//save our FastAdapter
2634
private lateinit var mItemAdapter: PagedModelAdapter<DemoEntity, SimpleImageItem>
2735

36+
private lateinit var viewModel: DemoEntityViewModel
37+
2838
override fun onCreate(savedInstanceState: Bundle?) {
2939
//create the activity
3040
super.onCreate(savedInstanceState)
@@ -36,22 +46,27 @@ class PagedActivity : AppCompatActivity() {
3646
setSupportActionBar(binding.toolbar)
3747
supportActionBar?.setTitle(R.string.sample_paged_list)
3848

39-
val asyncDifferConfig = AsyncDifferConfig.Builder<DemoEntity>(object : DiffUtil.ItemCallback<DemoEntity>() {
40-
override fun areItemsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
41-
return oldItem.identifier == newItem.identifier
42-
}
49+
val asyncDifferConfig =
50+
AsyncDifferConfig.Builder(object : DiffUtil.ItemCallback<DemoEntity>() {
51+
override fun areItemsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
52+
return oldItem.identifier == newItem.identifier
53+
}
4354

44-
override fun areContentsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
45-
return oldItem == newItem
46-
}
47-
}).build()
55+
override fun areContentsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
56+
return oldItem.data1 == newItem.data1
57+
}
58+
}).build()
4859

4960
//create our ItemAdapter which will host our items
50-
mItemAdapter = PagedModelAdapter<DemoEntity, SimpleImageItem>(asyncDifferConfig, { arg: Int -> SimpleImageItem().setPlaceholder() }) {
51-
SimpleImageItem().withName(it.data1 ?: "").withDescription(it.data2 ?: "").apply {
61+
mItemAdapter = PagedModelAdapter<DemoEntity, SimpleImageItem>(
62+
asyncDifferConfig,
63+
{ SimpleImageItem().setPlaceholder() }) {
64+
SimpleImageItem().apply {
5265
identifier = it.identifier.toLong()
5366
isSelectable = true
5467
withImage("https://raw.githubusercontent.com/mikepenz/earthview-wallpapers/develop/thumb/yang_zhuo_yong_cuo,_tibet-china-63.jpg")
68+
withName(it.data1 ?: "")
69+
withDescription(it.data2 ?: "")
5570
}
5671
}
5772

@@ -67,14 +82,17 @@ class PagedActivity : AppCompatActivity() {
6782
binding.rv.layoutManager = LinearLayoutManager(this)
6883
binding.rv.adapter = mFastAdapter
6984

70-
val viewModel = ViewModelProvider(this, DemoEntityViewModel.DemoEntityViewModelFactory(this.application))
85+
viewModel = ViewModelProvider(
86+
this,
87+
DemoEntityViewModel.DemoEntityViewModelFactory(this.application)
88+
)
7189
.get(DemoEntityViewModel::class.java)
7290

7391
//listen to data changes and pass it to adapter for displaying in recycler view
7492
viewModel.demoEntitiesList.observe(this, { t -> mItemAdapter.submitList(t!!) })
7593

7694
//if we do this. the first added items will be animated :D
77-
Handler().postDelayed({
95+
Handler(mainLooper).postDelayed({
7896
//restore selections (this has to be done after the items were added
7997
mFastAdapter.withSavedInstanceState(savedInstanceState)
8098
}, 50)
@@ -92,6 +110,32 @@ class PagedActivity : AppCompatActivity() {
92110
super.onSaveInstanceState(outState)
93111
}
94112

113+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
114+
val inflater = menuInflater
115+
inflater.inflate(R.menu.refresh, menu)
116+
menu.findItem(R.id.item_refresh).icon =
117+
IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_refresh).apply {
118+
colorInt = Color.BLACK; actionBar()
119+
}
120+
return true
121+
}
122+
123+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
124+
//handle the click on the back arrow click
125+
return when (item.itemId) {
126+
android.R.id.home -> {
127+
onBackPressed()
128+
true
129+
}
130+
R.id.item_refresh -> {
131+
viewModel.updateEntities()
132+
Toast.makeText(this, "Refresh DB", Toast.LENGTH_SHORT).show()
133+
true
134+
}
135+
else -> super.onOptionsItemSelected(item)
136+
}
137+
}
138+
95139
override fun onSupportNavigateUp(): Boolean {
96140
onBackPressed()
97141
return true

app/src/main/java/com/mikepenz/fastadapter/app/SwipeDrawerListActivity.kt

+67-17
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import android.os.Bundle
55
import android.text.TextUtils
66
import android.view.Menu
77
import android.view.MenuItem
8+
import android.view.View
89
import android.widget.Toast
910
import androidx.appcompat.app.AppCompatActivity
1011
import androidx.appcompat.widget.SearchView
1112
import androidx.recyclerview.widget.DefaultItemAnimator
1213
import androidx.recyclerview.widget.ItemTouchHelper
1314
import androidx.recyclerview.widget.LinearLayoutManager
1415
import androidx.recyclerview.widget.RecyclerView
16+
import com.mikepenz.fastadapter.IAdapter
1517
import com.mikepenz.fastadapter.adapters.FastItemAdapter
1618
import com.mikepenz.fastadapter.app.adapters.IDraggableViewHolder
1719
import com.mikepenz.fastadapter.app.databinding.ActivitySampleBinding
@@ -28,7 +30,8 @@ import com.mikepenz.iconics.utils.colorInt
2830
import io.reactivex.functions.Consumer
2931
import java.util.*
3032

31-
class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSwipeDrawerCallback.ItemSwipeCallback {
33+
class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback,
34+
SimpleSwipeDrawerCallback.ItemSwipeCallback {
3235
private lateinit var binding: ActivitySampleBinding
3336

3437
//save our FastAdapter
@@ -78,9 +81,20 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
7881
//create our FastAdapter which will manage everything
7982
fastItemDrawerAdapter = FastItemAdapter()
8083
//configure the itemAdapter
81-
fastItemDrawerAdapter.itemFilter.filterPredicate = { item: SwipeableDrawerItem, constraint: CharSequence? ->
82-
item.name?.textString.toString().contains(constraint.toString(), ignoreCase = true)
83-
}
84+
fastItemDrawerAdapter.itemFilter.filterPredicate =
85+
{ item: SwipeableDrawerItem, constraint: CharSequence? ->
86+
item.name?.textString.toString().contains(constraint.toString(), ignoreCase = true)
87+
}
88+
89+
90+
// Item click listener
91+
fastItemDrawerAdapter.onClickListener =
92+
{ _: View?, _: IAdapter<SwipeableDrawerItem>, _: SwipeableDrawerItem, pos: Int ->
93+
run {
94+
println("click! $pos")
95+
true
96+
}
97+
}
8498

8599
//get our recyclerView and do basic setup
86100
binding.rv.layoutManager = LinearLayoutManager(this)
@@ -110,16 +124,18 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
110124
//add drag and drop for item
111125
//and add swipe as well
112126
touchCallback = SimpleSwipeDrawerDragCallback(
113-
this,
114-
ItemTouchHelper.LEFT,
115-
this)
116-
.withNotifyAllDrops(true)
117-
.withSwipeLeft(80) // Width of delete button
118-
.withSwipeRight(160) // Width of archive and share buttons
119-
.withSensitivity(10f)
120-
.withSurfaceThreshold(0.3f)
121-
122-
touchHelper = ItemTouchHelper(touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
127+
this,
128+
ItemTouchHelper.LEFT,
129+
this
130+
)
131+
.withNotifyAllDrops(true)
132+
.withSwipeLeft(80) // Width of delete button
133+
.withSwipeRight(160) // Width of archive and share buttons
134+
.withSensitivity(10f)
135+
.withSurfaceThreshold(0.3f)
136+
137+
touchHelper =
138+
ItemTouchHelper(touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
123139
touchHelper.attachToRecyclerView(binding.rv) // Attach ItemTouchHelper to RecyclerView
124140

125141
//restore selections (this has to be done after the items were added)
@@ -155,7 +171,10 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
155171
inflater.inflate(R.menu.search, menu)
156172

157173
//search icon
158-
menu.findItem(R.id.search).icon = IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_search).apply { colorInt = Color.BLACK; actionBar() }
174+
menu.findItem(R.id.search).icon =
175+
IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_search).apply {
176+
colorInt = Color.BLACK; actionBar()
177+
}
159178

160179
val searchView = menu.findItem(R.id.search).actionView as SearchView
161180
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
@@ -177,7 +196,11 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
177196
}
178197

179198
override fun itemTouchOnMove(oldPosition: Int, newPosition: Int): Boolean {
180-
DragDropUtil.onMove(fastItemDrawerAdapter.itemAdapter, oldPosition, newPosition) // change position
199+
DragDropUtil.onMove(
200+
fastItemDrawerAdapter.itemAdapter,
201+
oldPosition,
202+
newPosition
203+
) // change position
181204
return true
182205
}
183206

@@ -196,7 +219,34 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
196219
}
197220

198221
companion object {
199-
private val ALPHABET = arrayOf("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
222+
private val ALPHABET = arrayOf(
223+
"A",
224+
"B",
225+
"C",
226+
"D",
227+
"E",
228+
"F",
229+
"G",
230+
"H",
231+
"I",
232+
"J",
233+
"K",
234+
"L",
235+
"M",
236+
"N",
237+
"O",
238+
"P",
239+
"Q",
240+
"R",
241+
"S",
242+
"T",
243+
"U",
244+
"V",
245+
"W",
246+
"X",
247+
"Y",
248+
"Z"
249+
)
200250
}
201251

202252
override fun itemSwiped(position: Int, direction: Int) {

app/src/main/java/com/mikepenz/fastadapter/app/items/SimpleImageItem.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class SimpleImageItem : BaseItem<SimpleImageItem.ViewHolder>() {
2323
private var mImageUrl: String? = null
2424
private var mName: String? = null
2525
private var mDescription: String? = null
26-
private var isPlaceholder: Boolean = false // True when used as placeholderInterceptor by PagedModelAdapter
26+
private var isPlaceholder: Boolean =
27+
false // True when used as placeholderInterceptor by PagedModelAdapter
2728

2829
/**
2930
* defines the type defining this item. must be unique. preferably an id
@@ -85,10 +86,18 @@ class SimpleImageItem : BaseItem<SimpleImageItem.ViewHolder>() {
8586
holder.imageView.setImageBitmap(null)
8687

8788
//set the background for the item
88-
val color = ctx.getThemeColor(R.attr.colorPrimary, ContextCompat.getColor(ctx, R.color.colorPrimary))
89+
val color = ctx.getThemeColor(
90+
R.attr.colorPrimary,
91+
ContextCompat.getColor(ctx, R.color.colorPrimary)
92+
)
8993

9094
holder.view.clearAnimation()
91-
holder.view.foreground = FastAdapterUIUtils.getSelectablePressedBackground(ctx, FastAdapterUIUtils.adjustAlpha(color, 100), 50, true)
95+
holder.view.foreground = FastAdapterUIUtils.getSelectablePressedBackground(
96+
ctx,
97+
FastAdapterUIUtils.adjustAlpha(color, 100),
98+
50,
99+
true
100+
)
92101

93102
//load glide
94103
holder.imageView.load(mImageUrl) {

app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableDrawerItem.kt

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class SwipeableDrawerItem : AbstractItem<SwipeableDrawerItem.ViewHolder>(), ISwi
131131
shareBtn.setOnClickListener {
132132
shareActionRunnable?.run()
133133
}
134+
// Important : trigger the ViewHolder's global onClick event
135+
itemContent.setOnClickListener {
136+
(it.parent as View).performClick()
137+
}
134138
}
135139

136140
override fun onDropped() {

0 commit comments

Comments
 (0)