Use TypedArray.use to obtain attrs (#3349)
17346638ff/core/core-ktx/src/main/java/androidx/core/content/res/TypedArray.kt (L227-L236)
This commit is contained in:
parent
92bd2153e9
commit
2da7bc5bc8
4 changed files with 53 additions and 49 deletions
|
|
@ -19,6 +19,7 @@ import android.content.Context
|
|||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.core.content.res.use
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import com.keylesspalace.tusky.R
|
||||
|
|
@ -38,12 +39,15 @@ class LicenseCard
|
|||
|
||||
setCardBackgroundColor(MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK))
|
||||
|
||||
val a = context.theme.obtainStyledAttributes(attrs, R.styleable.LicenseCard, 0, 0)
|
||||
|
||||
val name: String? = a.getString(R.styleable.LicenseCard_name)
|
||||
val license: String? = a.getString(R.styleable.LicenseCard_license)
|
||||
val link: String? = a.getString(R.styleable.LicenseCard_link)
|
||||
a.recycle()
|
||||
val (name, license, link) = context.theme.obtainStyledAttributes(
|
||||
attrs, R.styleable.LicenseCard, 0, 0
|
||||
).use { a ->
|
||||
Triple(
|
||||
a.getString(R.styleable.LicenseCard_name),
|
||||
a.getString(R.styleable.LicenseCard_license),
|
||||
a.getString(R.styleable.LicenseCard_link),
|
||||
)
|
||||
}
|
||||
|
||||
binding.licenseCardName.text = name
|
||||
binding.licenseCardLicense.text = license
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue