Updated on 2026-08-14
This commit is contained in:
parent
b9429d2710
commit
60a332149e
4 changed files with 55 additions and 6 deletions
|
|
@ -0,0 +1,31 @@
|
|||
package com.tangem.tap.common
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewTreeObserver
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class GlobalLayoutStateHandler<T: View>(
|
||||
private val view: T,
|
||||
attachImmediately: Boolean = true
|
||||
) : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
var onStateChanged: ((T) -> Unit)? = null
|
||||
|
||||
init {
|
||||
if (attachImmediately) attach()
|
||||
}
|
||||
|
||||
fun attach() {
|
||||
view.viewTreeObserver.addOnGlobalLayoutListener(this)
|
||||
}
|
||||
|
||||
fun detach() {
|
||||
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
}
|
||||
|
||||
override fun onGlobalLayout() {
|
||||
onStateChanged?.invoke(view)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,13 @@ package com.tangem.tap.common.extensions
|
|||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewParent
|
||||
import androidx.core.view.forEach
|
||||
import androidx.transition.AutoTransition
|
||||
import androidx.transition.Transition
|
||||
import androidx.transition.TransitionManager
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import com.tangem.tap.common.GlobalLayoutStateHandler
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
|
|
@ -25,4 +29,19 @@ fun ViewParent?.beginDelayedTransition(transition: Transition = AutoTransition()
|
|||
|
||||
fun ViewGroup.beginDelayedTransition(transition: Transition = AutoTransition()) {
|
||||
TransitionManager.beginDelayedTransition(this, transition)
|
||||
}
|
||||
|
||||
fun ChipGroup.fitChipsByGroupWidth() {
|
||||
val layoutStateHandler = GlobalLayoutStateHandler(this)
|
||||
layoutStateHandler.onStateChanged = stateHandler@{
|
||||
if (it.childCount < 2) {
|
||||
layoutStateHandler.detach()
|
||||
return@stateHandler
|
||||
}
|
||||
|
||||
val spacingBetweenViews = it.chipSpacingHorizontal * (it.childCount - 1)
|
||||
val width = (it.width - spacingBetweenViews) / it.childCount
|
||||
it.forEach { chip -> (chip as? Chip)?.width = width }
|
||||
layoutStateHandler.detach()
|
||||
}
|
||||
}
|
||||
|
|
@ -13,9 +13,7 @@ import com.google.android.material.snackbar.Snackbar
|
|||
import com.squareup.picasso.Picasso
|
||||
import com.tangem.blockchain.blockchains.bitcoin.BitcoinAddressType
|
||||
import com.tangem.blockchain.common.address.AddressType
|
||||
import com.tangem.tap.common.extensions.beginDelayedTransition
|
||||
import com.tangem.tap.common.extensions.hide
|
||||
import com.tangem.tap.common.extensions.show
|
||||
import com.tangem.tap.common.extensions.*
|
||||
import com.tangem.tap.common.redux.navigation.AppScreen
|
||||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.domain.TwinCardNumber
|
||||
|
|
@ -230,6 +228,8 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
|
|||
tv_address.setPadding(tv_address.paddingStart, tvAddressPaddingTop / 2,
|
||||
tv_address.paddingEnd, tv_address.paddingBottom)
|
||||
chip_group_segwit.show()
|
||||
chip_group_segwit.fitChipsByGroupWidth()
|
||||
|
||||
val checkedId = SegwitUiHelper.typeToId(state.walletAddresses.selectedAddress.type)
|
||||
if (checkedId != View.NO_ID) chip_group_segwit.check(checkedId)
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,9 @@
|
|||
android:id="@+id/chip_group_segwit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:visibility="visible"
|
||||
android:layout_marginEnd="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue