@@ -20,6 +20,7 @@ import android.annotation.SuppressLint
20
20
import android.app.Dialog
21
21
import android.content.Context
22
22
import android.content.DialogInterface
23
+ import android.content.res.TypedArray
23
24
import android.graphics.Color
24
25
import android.graphics.Rect
25
26
import android.graphics.drawable.Drawable
@@ -32,7 +33,6 @@ import android.view.Window
32
33
import android.view.inputmethod.EditorInfo
33
34
import android.view.inputmethod.InputMethodManager
34
35
import android.widget.*
35
- import androidx.annotation.ColorRes
36
36
import androidx.appcompat.content.res.AppCompatResources
37
37
import androidx.appcompat.view.ContextThemeWrapper
38
38
import androidx.core.content.res.ResourcesCompat
@@ -120,8 +120,8 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
120
120
maxDialogWidth = it.getDimensionPixelSize(R .styleable.IconDialog_icdMaxWidth , - 1 )
121
121
maxDialogHeight = it.getDimensionPixelSize(R .styleable.IconDialog_icdMaxHeight , - 1 )
122
122
iconSize = it.getDimensionPixelSize(R .styleable.IconDialog_icdIconSize , - 1 )
123
- iconColorNormal = getColor( it.getResourceId (R .styleable.IconDialog_icdIconColor , 0 ) )
124
- iconColorSelected = getColor( it.getResourceId (R .styleable.IconDialog_icdSelectedIconColor , 0 ) )
123
+ iconColorNormal = it.getColorCompat (R .styleable.IconDialog_icdIconColor )
124
+ iconColorSelected = it.getColorCompat (R .styleable.IconDialog_icdSelectedIconColor )
125
125
}
126
126
127
127
progressHandler = Handler ()
@@ -220,8 +220,14 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
220
220
* Inflate color state list with compat library and return default color.
221
221
* `ContextCompat.getColor` doesn't seem to use compat library.
222
222
*/
223
- private fun getColor (@ColorRes color : Int ) =
224
- AppCompatResources .getColorStateList(requireContext(), color).defaultColor
223
+ private fun TypedArray.getColorCompat (index : Int ): Int {
224
+ val resId = this .getResourceId(index, 0 )
225
+ return if (resId == 0 ) {
226
+ this .getColor(index, 0 )
227
+ } else {
228
+ AppCompatResources .getColorStateList(requireContext(), resId).defaultColor
229
+ }
230
+ }
225
231
226
232
override fun onSaveInstanceState (state : Bundle ) {
227
233
super .onSaveInstanceState(state)
@@ -372,7 +378,8 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
372
378
}
373
379
374
380
override fun bindView (icon : Icon , selected : Boolean ) {
375
- val drawable = DrawableCompat .wrap(icon.drawable ? : unavailableIconDrawable).mutate()
381
+ val drawable = DrawableCompat .wrap(icon.drawable
382
+ ? : unavailableIconDrawable).mutate()
376
383
iconImv.setImageDrawable(drawable)
377
384
DrawableCompat .setTint(drawable, if (selected) iconColorSelected else iconColorNormal)
378
385
if (icon.drawable != null ) {
@@ -419,7 +426,8 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
419
426
override fun getItemId (pos : Int ) = presenter?.getItemId(pos) ? : 0
420
427
override fun getItemViewType (pos : Int ) = presenter?.getItemType(pos) ? : 0
421
428
override fun isHeader (pos : Int ) = presenter?.isHeader(pos) == true
422
- override fun getHeaderPositionForItem (pos : Int ) = presenter?.getHeaderPositionForItem(pos) ? : 0
429
+ override fun getHeaderPositionForItem (pos : Int ) = presenter?.getHeaderPositionForItem(pos)
430
+ ? : 0
423
431
}
424
432
425
433
/* *
0 commit comments