Merge pull request #4873 from johnjohndoe/kotlin-extensions

Use Kotlin extensions
This commit is contained in:
cketti 2020-07-11 01:06:49 +02:00 committed by GitHub
commit ee85c77391
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 56 deletions

View file

@ -1,12 +1,13 @@
package com.fsck.k9.ui
import android.view.View
import androidx.core.view.isVisible
import androidx.databinding.BindingAdapter
import com.google.android.material.textfield.TextInputLayout
@BindingAdapter("isVisible")
fun setVisibility(view: View, value: Boolean) {
view.visibility = if (value) View.VISIBLE else View.GONE
view.isVisible = value
}
@BindingAdapter("error")

View file

@ -1,7 +1,7 @@
package com.fsck.k9.activity
import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import com.fsck.k9.Account
import com.fsck.k9.Identity
import com.fsck.k9.Preferences
@ -39,17 +39,17 @@ class EditIdentity : K9Activity() {
signature_use.isChecked = identity.signatureUse
signature_use.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
signature_layout.visibility = View.VISIBLE
signature_layout.isVisible = true
signature.setText(identity.signature)
} else {
signature_layout.visibility = View.GONE
signature_layout.isVisible = false
}
}
if (signature_use.isChecked) {
signature.setText(identity.signature)
} else {
signature_layout.visibility = View.GONE
signature_layout.isVisible = false
}
}

View file

@ -189,14 +189,14 @@ class MessageListAdapter internal constructor(
}
holder.date.text = displayDate
holder.attachment.visibility = if (hasAttachments) View.VISIBLE else View.GONE
holder.attachment.isVisible = hasAttachments
val statusHolder = buildStatusHolder(isForwarded, isAnswered)
if (statusHolder != null) {
holder.status.setImageDrawable(statusHolder)
holder.status.visibility = View.VISIBLE
holder.status.isVisible = true
} else {
holder.status.visibility = View.GONE
holder.status.isVisible = false
}
}
}
@ -274,9 +274,9 @@ class MessageListAdapter internal constructor(
private fun updateWithThreadCount(holder: MessageViewHolder, threadCount: Int) {
if (threadCount > 1) {
holder.threadCount.text = String.format("%d", threadCount)
holder.threadCount.visibility = View.VISIBLE
holder.threadCount.isVisible = true
} else {
holder.threadCount.visibility = View.GONE
holder.threadCount.isVisible = false
}
}

View file

@ -33,6 +33,7 @@ import android.graphics.PorterDuffXfermode
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.isVisible
import com.fsck.k9.ui.R
/**
@ -173,7 +174,7 @@ class SimpleHighlightView private constructor(context: Context, style: Int) : Fr
private fun fadeInHighlight() {
ObjectAnimator.ofFloat(this, ALPHA, INVISIBLE, VISIBLE)
.setDuration(fadeInMillis)
.onAnimationStart { visibility = View.VISIBLE }
.onAnimationStart { isVisible = true }
.start()
}
@ -181,7 +182,7 @@ class SimpleHighlightView private constructor(context: Context, style: Int) : Fr
ObjectAnimator.ofFloat(this, ALPHA, INVISIBLE)
.setDuration(fadeOutMillis)
.onAnimationEnd {
visibility = View.GONE
isVisible = false
clearBitmap()
parent?.removeView(this@SimpleHighlightView)
}

View file

@ -8,7 +8,7 @@ import android.os.Bundle
import android.transition.TransitionInflater
import android.transition.TransitionManager
import android.view.MenuItem
import android.view.View
import androidx.core.view.isVisible
import com.fsck.k9.finishWithErrorToast
import com.fsck.k9.ui.R
import com.fsck.k9.ui.base.K9Activity
@ -51,37 +51,37 @@ class AutocryptKeyTransferActivity : K9Activity() {
}
fun sceneBegin() {
transferSendButton.visibility = View.VISIBLE
transferMsgInfo.visibility = View.VISIBLE
transferLayoutGenerating.visibility = View.GONE
transferLayoutSending.visibility = View.GONE
transferLayoutFinish.visibility = View.GONE
transferErrorSend.visibility = View.GONE
transferButtonShowCode.visibility = View.GONE
transferSendButton.isVisible = true
transferMsgInfo.isVisible = true
transferLayoutGenerating.isVisible = false
transferLayoutSending.isVisible = false
transferLayoutFinish.isVisible = false
transferErrorSend.isVisible = false
transferButtonShowCode.isVisible = false
}
fun sceneGeneratingAndSending() {
setupSceneTransition()
transferSendButton.visibility = View.GONE
transferMsgInfo.visibility = View.GONE
transferLayoutGenerating.visibility = View.VISIBLE
transferLayoutSending.visibility = View.VISIBLE
transferLayoutFinish.visibility = View.GONE
transferErrorSend.visibility = View.GONE
transferButtonShowCode.visibility = View.GONE
transferSendButton.isVisible = false
transferMsgInfo.isVisible = false
transferLayoutGenerating.isVisible = true
transferLayoutSending.isVisible = true
transferLayoutFinish.isVisible = false
transferErrorSend.isVisible = false
transferButtonShowCode.isVisible = false
}
fun sceneSendError() {
setupSceneTransition()
transferSendButton.visibility = View.GONE
transferMsgInfo.visibility = View.GONE
transferLayoutGenerating.visibility = View.VISIBLE
transferLayoutSending.visibility = View.VISIBLE
transferLayoutFinish.visibility = View.GONE
transferErrorSend.visibility = View.VISIBLE
transferButtonShowCode.visibility = View.GONE
transferSendButton.isVisible = false
transferMsgInfo.isVisible = false
transferLayoutGenerating.isVisible = true
transferLayoutSending.isVisible = true
transferLayoutFinish.isVisible = false
transferErrorSend.isVisible = true
transferButtonShowCode.isVisible = false
}
fun sceneFinished(transition: Boolean = false) {
@ -89,13 +89,13 @@ class AutocryptKeyTransferActivity : K9Activity() {
setupSceneTransition()
}
transferSendButton.visibility = View.GONE
transferMsgInfo.visibility = View.GONE
transferLayoutGenerating.visibility = View.VISIBLE
transferLayoutSending.visibility = View.VISIBLE
transferLayoutFinish.visibility = View.VISIBLE
transferErrorSend.visibility = View.GONE
transferButtonShowCode.visibility = View.VISIBLE
transferSendButton.isVisible = false
transferMsgInfo.isVisible = false
transferLayoutGenerating.isVisible = true
transferLayoutSending.isVisible = true
transferLayoutFinish.isVisible = true
transferErrorSend.isVisible = false
transferButtonShowCode.isVisible = true
}
fun setLoadingStateGenerating() {

View file

@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import androidx.core.content.res.TypedArrayUtils
import androidx.core.content.withStyledAttributes
import androidx.preference.PreferenceViewHolder
import androidx.preference.TwoStatePreference
import com.fsck.k9.ui.R
@ -21,13 +22,10 @@ constructor(
) : TwoStatePreference(context, attrs, defStyleAttr, defStyleRes) {
init {
val attributes = context.obtainStyledAttributes(attrs, R.styleable.AutocryptPreferEncryptPreference,
defStyleAttr, defStyleRes)
summaryOn = attributes.getString(R.styleable.AutocryptPreferEncryptPreference_summaryOn)
summaryOff = attributes.getString(R.styleable.AutocryptPreferEncryptPreference_summaryOff)
attributes.recycle()
context.withStyledAttributes(attrs, R.styleable.AutocryptPreferEncryptPreference, defStyleAttr, defStyleRes) {
summaryOn = getString(R.styleable.AutocryptPreferEncryptPreference_summaryOn)
summaryOff = getString(R.styleable.AutocryptPreferEncryptPreference_summaryOff)
}
}
override fun onClick() {

View file

@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.fsck.k9.ui.R
@ -59,32 +60,32 @@ class SettingsExportFragment : Fragment() {
private fun updateUi(model: SettingsExportUiModel) {
when (model.exportButton) {
ButtonState.DISABLED -> {
exportButton.visibility = View.VISIBLE
exportButton.isVisible = true
exportButton.isEnabled = false
}
ButtonState.ENABLED -> {
exportButton.visibility = View.VISIBLE
exportButton.isVisible = true
exportButton.isEnabled = true
}
ButtonState.INVISIBLE -> exportButton.visibility = View.INVISIBLE
ButtonState.GONE -> exportButton.visibility = View.GONE
}
shareButton.visibility = if (model.isShareButtonVisible) View.VISIBLE else View.GONE
progressBar.visibility = if (model.isProgressVisible) View.VISIBLE else View.GONE
shareButton.isVisible = model.isShareButtonVisible
progressBar.isVisible = model.isProgressVisible
when (model.statusText) {
StatusText.HIDDEN -> statusText.visibility = View.GONE
StatusText.HIDDEN -> statusText.isVisible = false
StatusText.EXPORT_SUCCESS -> {
statusText.visibility = View.VISIBLE
statusText.isVisible = true
statusText.text = getString(R.string.settings_export_success_generic)
}
StatusText.PROGRESS -> {
statusText.visibility = View.VISIBLE
statusText.isVisible = true
statusText.text = getString(R.string.settings_export_progress_text)
}
StatusText.EXPORT_FAILURE -> {
statusText.visibility = View.VISIBLE
statusText.isVisible = true
statusText.text = getString(R.string.settings_export_failure)
}
}