migrating to ViewBinding part 1: Dialogs + Views (#2091)
This commit is contained in:
parent
e7c514c28e
commit
5167b8578e
6 changed files with 43 additions and 47 deletions
|
|
@ -3,14 +3,14 @@ package com.keylesspalace.tusky.view
|
|||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.databinding.ViewBackgroundMessageBinding
|
||||
import com.keylesspalace.tusky.util.visible
|
||||
import kotlinx.android.synthetic.main.view_background_message.view.*
|
||||
|
||||
|
||||
/**
|
||||
* This view is used for screens with downloadable content which may fail.
|
||||
|
|
@ -22,8 +22,9 @@ class BackgroundMessageView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val binding = ViewBackgroundMessageBinding.inflate(LayoutInflater.from(context), this)
|
||||
|
||||
init {
|
||||
View.inflate(context, R.layout.view_background_message, this)
|
||||
gravity = Gravity.CENTER_HORIZONTAL
|
||||
orientation = VERTICAL
|
||||
|
||||
|
|
@ -36,11 +37,14 @@ class BackgroundMessageView @JvmOverloads constructor(
|
|||
* Setup image, message and button.
|
||||
* If [clickListener] is `null` then the button will be hidden.
|
||||
*/
|
||||
fun setup(@DrawableRes imageRes: Int, @StringRes messageRes: Int,
|
||||
clickListener: ((v: View) -> Unit)? = null) {
|
||||
messageTextView.setText(messageRes)
|
||||
imageView.setImageResource(imageRes)
|
||||
button.setOnClickListener(clickListener)
|
||||
button.visible(clickListener != null)
|
||||
fun setup(
|
||||
@DrawableRes imageRes: Int,
|
||||
@StringRes messageRes: Int,
|
||||
clickListener: ((v: View) -> Unit)? = null
|
||||
) {
|
||||
binding.messageTextView.setText(messageRes)
|
||||
binding.imageView.setImageResource(imageRes)
|
||||
binding.button.setOnClickListener(clickListener)
|
||||
binding.button.visible(clickListener != null)
|
||||
}
|
||||
}
|
||||
|
|
@ -17,12 +17,13 @@ package com.keylesspalace.tusky.view
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.databinding.CardLicenseBinding
|
||||
import com.keylesspalace.tusky.util.LinkHelper
|
||||
import com.keylesspalace.tusky.util.ThemeUtils
|
||||
import com.keylesspalace.tusky.util.hide
|
||||
import kotlinx.android.synthetic.main.card_license.view.*
|
||||
|
||||
class LicenseCard
|
||||
@JvmOverloads constructor(
|
||||
|
|
@ -32,7 +33,7 @@ class LicenseCard
|
|||
) : MaterialCardView(context, attrs, defStyleAttr) {
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.card_license, this)
|
||||
val binding = CardLicenseBinding.inflate(LayoutInflater.from(context), this)
|
||||
|
||||
setCardBackgroundColor(ThemeUtils.getColor(context, R.attr.colorSurface))
|
||||
|
||||
|
|
@ -43,12 +44,12 @@ class LicenseCard
|
|||
val link: String? = a.getString(R.styleable.LicenseCard_link)
|
||||
a.recycle()
|
||||
|
||||
licenseCardName.text = name
|
||||
licenseCardLicense.text = license
|
||||
binding.licenseCardName.text = name
|
||||
binding.licenseCardLicense.text = license
|
||||
if(link.isNullOrBlank()) {
|
||||
licenseCardLink.hide()
|
||||
binding.licenseCardLink.hide()
|
||||
} else {
|
||||
licenseCardLink.text = link
|
||||
binding.licenseCardLink.text = link
|
||||
setOnClickListener { LinkHelper.openLink(link, context) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,29 +3,24 @@
|
|||
package com.keylesspalace.tusky.view
|
||||
|
||||
import android.app.Activity
|
||||
import android.widget.CheckBox
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.databinding.DialogMuteAccountBinding
|
||||
|
||||
fun showMuteAccountDialog(
|
||||
activity: Activity,
|
||||
accountUsername: String,
|
||||
onOk: (notifications: Boolean, duration: Int) -> Unit
|
||||
) {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_mute_account, null)
|
||||
(view.findViewById(R.id.warning) as TextView).text =
|
||||
activity.getString(R.string.dialog_mute_warning, accountUsername)
|
||||
val checkbox: CheckBox = view.findViewById(R.id.checkbox)
|
||||
checkbox.isChecked = true
|
||||
val binding = DialogMuteAccountBinding.inflate(activity.layoutInflater)
|
||||
binding.warning.text = activity.getString(R.string.dialog_mute_warning, accountUsername)
|
||||
binding.checkbox.isChecked = true
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setView(view)
|
||||
.setView(binding.root)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
val spinner: Spinner = view.findViewById(R.id.duration)
|
||||
val durationValues = activity.resources.getIntArray(R.array.mute_duration_values)
|
||||
onOk(checkbox.isChecked, durationValues[spinner.selectedItemPosition])
|
||||
onOk(binding.checkbox.isChecked, durationValues[binding.duration.selectedItemPosition])
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue