Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-14 13:56:13 +03:00
commit f845fa20b4
39 changed files with 1855 additions and 663 deletions

View file

@ -52,4 +52,19 @@ fun BigDecimal.toFiatString(rateValue: BigDecimal): String? {
return "USD $fiatValue"
}
fun BigDecimal.stripZeroPlainString(): String = this.stripTrailingZeros().toPlainString()
fun BigDecimal.stripZeroPlainString(): String = this.stripTrailingZeros().toPlainString()
fun BigDecimal.isPositive(): Boolean = this.compareTo(BigDecimal.ZERO) == 1
fun BigDecimal.isNegative(): Boolean = this.compareTo(BigDecimal.ZERO) == -1
fun BigDecimal.isGreaterThan(value: BigDecimal): Boolean = this.compareTo(value) == 1
fun BigDecimal.isLessThan(value: BigDecimal): Boolean = this.compareTo(value) == -1
fun BigDecimal.isGreaterThanOrEqual(value: BigDecimal): Boolean {
val compareResult = this.compareTo(value)
return compareResult == 1 || compareResult == 0
}
fun BigDecimal.isLessThanOrEqual(value: BigDecimal): Boolean {
val compareResult = this.compareTo(value)
return compareResult == -1 || compareResult == 0
}

View file

@ -27,10 +27,20 @@ fun EditText.update(text: String?) {
else setSelection(cursorPosition)
}
fun TextSwitcher.update(text: String?) {
fun EditText.setOnImeActionListener(action: Int, handler: (EditText) -> Unit) {
this.setOnEditorActionListener { view, actionId, event ->
if (actionId == action) {
handler.invoke(this)
return@setOnEditorActionListener true
}
return@setOnEditorActionListener false
}
}
fun TextSwitcher.update(text: CharSequence?) {
val textView = this.currentView as? TextView ?: return
if (textView.text?.toString() != text) this.setText(text)
if (textView.text?.toString() != text?.toString()) this.setText(text)
}
// By default the TextInputLayout didn't activates the error state if the message is empty or null

View file

@ -14,6 +14,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.core.text.toSpannable
import androidx.fragment.app.Fragment
@ -27,17 +28,26 @@ fun Context.getDrawableCompat(@DrawableRes drawableResId: Int): Drawable? {
return ContextCompat.getDrawable(this, drawableResId)
}
fun View.show(show: Boolean) {
if (show) this.visibility = View.VISIBLE else this.visibility = View.GONE
fun View.getString(@StringRes id: Int): String {
return context.getString(id)
}
fun View.show() {
fun View.show(show: Boolean, invokeBeforeStateChanged: (() -> Unit)? = null) {
return if (show) this.show(invokeBeforeStateChanged)
else this.hide(invokeBeforeStateChanged)
}
fun View.show(invokeBeforeStateChanged: (() -> Unit)? = null) {
if (this.visibility == View.VISIBLE) return
invokeBeforeStateChanged?.invoke()
this.visibility = View.VISIBLE
}
fun View.hide() {
fun View.hide(invokeBeforeStateChanged: (() -> Unit)? = null) {
if (this.visibility == View.GONE) return
invokeBeforeStateChanged?.invoke()
this.visibility = View.GONE
}

View file

@ -2,9 +2,11 @@ package com.tangem.tap.common.extensions
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.ViewParent
import androidx.transition.AutoTransition
import androidx.transition.Transition
import androidx.transition.TransitionManager
import timber.log.Timber
/**
[REDACTED_AUTHOR]
@ -16,6 +18,11 @@ fun ViewGroup.inflate(viewToInflate: Int, rootView: ViewGroup?, parent: ViewGrou
}
}
fun ViewParent?.beginDelayedTransition(transition: Transition = AutoTransition()) {
if (this == null) Timber.e("Can't invoke beginDelayedTransition, because parent is NULL")
(this as? ViewGroup)?.beginDelayedTransition(transition)
}
fun ViewGroup.beginDelayedTransition(transition: Transition = AutoTransition()) {
TransitionManager.beginDelayedTransition(this, transition)
}

View file

@ -2,8 +2,8 @@ package com.tangem.tap.common.redux
import com.tangem.tap.common.redux.global.globalReducer
import com.tangem.tap.common.redux.navigation.NavigationReducer
import com.tangem.tap.features.send.redux.reducers.SendReducer
import com.tangem.tap.features.details.redux.DetailsReducer
import com.tangem.tap.features.send.redux.SendReducer
import com.tangem.tap.features.wallet.redux.WalletReducer
import org.rekotlin.Action

View file

@ -5,8 +5,8 @@ import com.tangem.tap.common.redux.navigation.NavigationState
import com.tangem.tap.common.redux.navigation.navigationMiddleware
import com.tangem.tap.features.details.redux.DetailsState
import com.tangem.tap.features.home.redux.homeMiddleware
import com.tangem.tap.features.send.redux.SendState
import com.tangem.tap.features.send.redux.sendMiddleware
import com.tangem.tap.features.send.redux.middlewares.sendMiddleware
import com.tangem.tap.features.send.redux.states.SendState
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.redux.walletMiddleware
import org.rekotlin.Middleware