Updated on 2026-08-14
This commit is contained in:
parent
2b3f6360e3
commit
7ddea4dbd8
5 changed files with 169 additions and 156 deletions
|
|
@ -4,6 +4,9 @@ import android.animation.Animator
|
|||
import android.animation.AnimatorListenerAdapter
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.View
|
||||
import android.view.View.OnFocusChangeListener
|
||||
import android.view.inputmethod.EditorInfo
|
||||
|
|
@ -12,7 +15,9 @@ import androidx.activity.OnBackPressedCallback
|
|||
import by.kirich1409.viewbindingdelegate.viewBinding
|
||||
import com.tangem.tap.common.GlobalLayoutStateHandler
|
||||
import com.tangem.tap.common.KeyboardObserver
|
||||
import com.tangem.tap.common.extensions.getColorCompat
|
||||
import com.tangem.tap.common.extensions.getQuantityString
|
||||
import com.tangem.tap.common.extensions.hide
|
||||
import com.tangem.tap.common.extensions.show
|
||||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.common.shop.data.ProductType
|
||||
|
|
@ -23,14 +28,27 @@ import com.tangem.tap.store
|
|||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.databinding.FragmentShopBinding
|
||||
import org.rekotlin.StoreSubscriber
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
class ShopFragment : BaseStoreFragment(R.layout.fragment_shop), StoreSubscriber<ShopState> {
|
||||
|
||||
private val dateFormat = SimpleDateFormat("dd MMMM", Locale.getDefault())
|
||||
private val binding: FragmentShopBinding by viewBinding(FragmentShopBinding::bind)
|
||||
private val endPreorderTime = Calendar.getInstance()
|
||||
private val isBuyAvailable: Boolean
|
||||
|
||||
private var cardTranslationY = 70f
|
||||
|
||||
private lateinit var keyboardObserver: KeyboardObserver
|
||||
|
||||
init {
|
||||
endPreorderTime.clear()
|
||||
endPreorderTime.set(END_DATE_SOLD_OUT_YEAR, END_DATE_SOLD_OUT_MONTH, END_DATE_SOLD_OUT_DAY)
|
||||
isBuyAvailable = System.currentTimeMillis() > endPreorderTime.timeInMillis
|
||||
}
|
||||
|
||||
override fun subscribeToStore() {
|
||||
store.subscribe(this) { state ->
|
||||
state.skipRepeats { oldState, newState ->
|
||||
|
|
@ -65,6 +83,7 @@ class ShopFragment : BaseStoreFragment(R.layout.fragment_shop), StoreSubscriber<
|
|||
setupCardsImages()
|
||||
setupProductSelection()
|
||||
setupPromoCodeEditText()
|
||||
setupSoldOutDescription()
|
||||
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
requireActivity().onBackPressed()
|
||||
|
|
@ -127,6 +146,26 @@ class ShopFragment : BaseStoreFragment(R.layout.fragment_shop), StoreSubscriber<
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupSoldOutDescription() = with(binding) {
|
||||
context?.let { cntx ->
|
||||
if (!isBuyAvailable) {
|
||||
val date = "${dateFormat.format(endPreorderTime.time)}!"
|
||||
val soldOutTitle = cntx.getString(R.string.shop_sold_out_description_prefix)
|
||||
val generalString = "$soldOutTitle $date"
|
||||
val wordToSpan: Spannable = SpannableString(generalString)
|
||||
wordToSpan.setSpan(
|
||||
ForegroundColorSpan(cntx.getColorCompat(R.color.textBlack)),
|
||||
generalString.length - date.length,
|
||||
generalString.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
)
|
||||
tvSoldOutDesc.text = wordToSpan
|
||||
} else {
|
||||
tvSoldOutDesc.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun newState(state: ShopState) {
|
||||
if (activity == null || view == null) return
|
||||
|
||||
|
|
@ -174,9 +213,16 @@ class ShopFragment : BaseStoreFragment(R.layout.fragment_shop), StoreSubscriber<
|
|||
}
|
||||
|
||||
private fun handleButtonsState(state: ShopState) = with(binding) {
|
||||
btnPayGooglePay.root.show(state.isGooglePayAvailable)
|
||||
btnAlternativePayment.show(state.isGooglePayAvailable)
|
||||
btnMainAction.show(!state.isGooglePayAvailable)
|
||||
if (isBuyAvailable) {
|
||||
btnPayGooglePay.root.show(state.isGooglePayAvailable)
|
||||
btnAlternativePayment.show(state.isGooglePayAvailable)
|
||||
btnMainAction.show(!state.isGooglePayAvailable)
|
||||
} else {
|
||||
btnPayGooglePay.root.hide()
|
||||
btnAlternativePayment.hide()
|
||||
btnMainAction.show()
|
||||
btnMainAction.text = context?.getString(R.string.shop_pre_order_now)
|
||||
}
|
||||
|
||||
if (state.total != null) {
|
||||
btnAlternativePayment.setOnClickListener { store.dispatch(ShopAction.StartWebCheckout) }
|
||||
|
|
@ -189,4 +235,10 @@ class ShopFragment : BaseStoreFragment(R.layout.fragment_shop), StoreSubscriber<
|
|||
store.dispatch(ShopAction.ResetState)
|
||||
super.handleOnBackPressed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val END_DATE_SOLD_OUT_YEAR = 2023
|
||||
private const val END_DATE_SOLD_OUT_MONTH = 5 // June, month start counting from zero!
|
||||
private const val END_DATE_SOLD_OUT_DAY = 10
|
||||
}
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@
|
|||
android:paddingStart="3dp"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingEnd="3dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintBottom_toTopOf="@id/ll_total"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:selectionRequired="true"
|
||||
|
|
@ -156,162 +156,125 @@
|
|||
app:chipMinTouchTargetSize="0dp" />
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
|
||||
<View
|
||||
android:id="@+id/v_shipping_discount_background"
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_total"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="93dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="@drawable/shape_rectangle_rounded_4"
|
||||
app:layout_constraintBottom_toTopOf="@id/v_total_background" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_delivery"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:src="@drawable/ic_shipping"
|
||||
app:layout_constraintBottom_toTopOf="@id/v_divider"
|
||||
app:layout_constraintStart_toStartOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintTop_toTopOf="@id/v_shipping_discount_background" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_delivery_worldwide"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:text="@string/shop_shipping"
|
||||
android:textColor="@color/textBlack"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/v_divider"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_delivery"
|
||||
app:layout_constraintTop_toTopOf="@id/v_shipping_discount_background" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_delivery_cost"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:text="@string/shop_free"
|
||||
android:textColor="@color/textBlack"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/v_divider"
|
||||
app:layout_constraintEnd_toEndOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintTop_toTopOf="@id/v_shipping_discount_background" />
|
||||
|
||||
<View
|
||||
android:id="@+id/v_divider"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0.5dp"
|
||||
android:background="#BEBEBE"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintStart_toStartOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintTop_toTopOf="@id/v_shipping_discount_background" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_promo_code"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:src="@drawable/ic_promo_code"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintStart_toStartOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintTop_toBottomOf="@id/v_divider" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_promo_code"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:hint="@string/shop_i_have_a_promo_code"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textCapCharacters"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/textBlack"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_promo_code"
|
||||
app:layout_constraintTop_toBottomOf="@id/v_divider" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_promo_code"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="28dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:indeterminateTint="@color/darkGray2"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/v_shipping_discount_background"
|
||||
app:layout_constraintTop_toBottomOf="@id/v_divider" />
|
||||
|
||||
|
||||
<View
|
||||
android:id="@+id/v_total_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="21dp"
|
||||
android:background="@drawable/shape_rectangle_rounded_4"
|
||||
app:layout_constraintBottom_toTopOf="@id/ll_buttons" />
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toTopOf="@id/ll_buttons">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:text="@string/shop_total"
|
||||
android:textColor="@color/textBlack"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_total_background"
|
||||
app:layout_constraintStart_toStartOf="@id/v_total_background"
|
||||
app:layout_constraintTop_toTopOf="@id/v_total_background" />
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/size48"
|
||||
android:background="@drawable/shape_rectangle_rounded_4">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total_before_discount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:background="@drawable/shape_line"
|
||||
android:textColor="@color/darkGray6"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_total_background"
|
||||
app:layout_constraintEnd_toStartOf="@id/tv_total"
|
||||
app:layout_constraintTop_toTopOf="@id/v_total_background"
|
||||
tools:text="$44.20" />
|
||||
<EditText
|
||||
android:id="@+id/et_promo_code"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:hint="@string/shop_i_have_a_promo_code"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textCapCharacters"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/textBlack"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:textColor="@color/darkGray6"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_total_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/v_total_background"
|
||||
app:layout_constraintTop_toTopOf="@id/v_total_background"
|
||||
tools:text="$44.20" />
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_promo_code"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="28dp"
|
||||
android:indeterminateTint="@color/darkGray2"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:indeterminateTint="@color/darkGray2"
|
||||
app:layout_constraintBottom_toBottomOf="@id/v_total_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/v_total_background"
|
||||
app:layout_constraintTop_toTopOf="@id/v_total_background" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/v_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:background="#BEBEBE" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/size48"
|
||||
android:background="@drawable/shape_rectangle_rounded_4">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:text="@string/shop_total"
|
||||
android:textColor="@color/textBlack"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total_before_discount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:background="@drawable/shape_line"
|
||||
android:textColor="@color/darkGray6"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/tv_total"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="$44.20" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:textColor="@color/darkGray6"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="$44.20" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:indeterminateTint="@color/darkGray2"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sold_out_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing14"
|
||||
android:background="@drawable/shape_rectangle_rounded_4"
|
||||
android:padding="@dimen/spacing16"
|
||||
android:text="@string/shop_sold_out_description_prefix"
|
||||
android:textColor="@color/text_tertiary"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_buttons"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue