@@ -12,7 +12,6 @@ import android.widget.BaseAdapter
12
12
import android.widget.ImageView
13
13
import android.widget.TextView
14
14
import androidx.constraintlayout.widget.ConstraintLayout
15
- import androidx.core.graphics.drawable.DrawableCompat
16
15
import androidx.databinding.BindingAdapter
17
16
import com.absinthe.libraries.utils.extensions.dp
18
17
import com.example.c001apk.R
@@ -21,20 +20,30 @@ import com.example.c001apk.logic.model.HomeFeedResponse
21
20
import com.example.c001apk.util.ImageUtil
22
21
import com.example.c001apk.util.NetWorkUtil
23
22
import com.example.c001apk.util.SpannableStringBuilderUtil
24
- import com.example.c001apk.util.Utils.getColorFromAttr
25
23
import com.example.c001apk.view.LinearAdapterLayout
26
24
import com.example.c001apk.view.LinkTextView
27
25
import com.example.c001apk.view.ninegridimageview.NineGridImageView
26
+ import com.google.android.material.color.MaterialColors
28
27
29
28
@BindingAdapter(" setExtraPic" )
30
29
fun setExtraPic (imageView : ImageView , extraPic : String? ) {
31
30
if (extraPic.isNullOrEmpty())
32
31
imageView.apply {
33
32
setBackgroundColor(
34
- imageView.context.getColorFromAttr(rikka.preference.simplemenu.R .attr.colorPrimary)
33
+ MaterialColors .getColor(
34
+ imageView.context,
35
+ com.google.android.material.R .attr.colorPrimary,
36
+ 0
37
+ )
35
38
)
36
39
val link = imageView.context.getDrawable(R .drawable.ic_link)
37
- link!! .setTint(imageView.context.getColorFromAttr(android.R .attr.windowBackground))
40
+ link?.setTint(
41
+ MaterialColors .getColor(
42
+ imageView.context,
43
+ android.R .attr.windowBackground,
44
+ 0
45
+ )
46
+ )
38
47
setImageDrawable(link)
39
48
}
40
49
else {
@@ -50,7 +59,11 @@ fun setFollowText(textView: TextView, userAction: HomeFeedResponse.UserAction?)
50
59
textView.visibility = View .VISIBLE
51
60
if (userAction.followAuthor == 0 ) {
52
61
textView.text = " 关注"
53
- textView.setTextColor(textView.context.getColorFromAttr(rikka.preference.simplemenu.R .attr.colorPrimary))
62
+ MaterialColors .getColor(
63
+ textView.context,
64
+ com.google.android.material.R .attr.colorPrimary,
65
+ 0
66
+ )
54
67
} else if (userAction.followAuthor == 1 ) {
55
68
textView.text = " 取消关注"
56
69
textView.setTextColor(textView.context.getColor(android.R .color.darker_gray))
@@ -63,13 +76,15 @@ fun setArticleImage(
63
76
imageView : NineGridImageView ,
64
77
setArticleImage : FeedArticleContentBean .Data ,
65
78
) {
66
- val urlList = ArrayList <String >()
67
- urlList.add(" ${setArticleImage.url} .s.jpg" )
68
- val imageLp = ImageUtil .getImageLp(setArticleImage.url!! )
69
- imageView.imgWidth = imageLp.first
70
- imageView.imgHeight = imageLp.second
71
- imageView.isCompress = true
72
- imageView.setUrlList(urlList)
79
+ setArticleImage.url?.let {
80
+ val urlList = ArrayList <String >()
81
+ urlList.add(" $it .s.jpg" )
82
+ val imageLp = ImageUtil .getImageLp(it)
83
+ imageView.imgWidth = imageLp.first
84
+ imageView.imgHeight = imageLp.second
85
+ imageView.isCompress = true
86
+ imageView.setUrlList(urlList)
87
+ }
73
88
}
74
89
75
90
@BindingAdapter(value = [" targetRow" , " relationRows" , " isFeedContent" ], requireAll = true )
@@ -195,12 +210,17 @@ fun setGridView(
195
210
fun setLike (textView : TextView , isLike : Int? ) {
196
211
isLike?.let {
197
212
val color = if (it == 1 )
198
- textView.context.getColorFromAttr(rikka.preference.simplemenu.R .attr.colorPrimary)
213
+ MaterialColors .getColor(
214
+ textView.context,
215
+ com.google.android.material.R .attr.colorPrimary,
216
+ 0
217
+ )
199
218
else textView.context.getColor(android.R .color.darker_gray)
200
219
val size = textView.textSize.toInt()
201
- val drawableLike = textView.context.getDrawable(R .drawable.ic_like)!!
202
- drawableLike.setBounds(0 , 0 , size, size)
203
- DrawableCompat .setTint(drawableLike, color)
220
+ val drawableLike = textView.context.getDrawable(R .drawable.ic_like).also { drawable ->
221
+ drawable?.setBounds(0 , 0 , size, size)
222
+ drawable?.setTint(color)
223
+ }
204
224
textView.setCompoundDrawables(drawableLike, null , null , null )
205
225
textView.setTextColor(color)
206
226
}
0 commit comments