diff --git a/app/src/main/java/com/tangem/tap/features/shop/ui/ShopFragment.kt b/app/src/main/java/com/tangem/tap/features/shop/ui/ShopFragment.kt index dccbe4d7b7..ad760cf53b 100644 --- a/app/src/main/java/com/tangem/tap/features/shop/ui/ShopFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/shop/ui/ShopFragment.kt @@ -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 { + 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 + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_shop.xml b/app/src/main/res/layout/fragment_shop.xml index c3dadcdb4b..1e86e09354 100644 --- a/app/src/main/res/layout/fragment_shop.xml +++ b/app/src/main/res/layout/fragment_shop.xml @@ -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" /> - - - - - - - - - - - - - - - - - - + android:orientation="vertical" + app:layout_constraintBottom_toTopOf="@id/ll_buttons"> - + - + - + - + + + + + + + + + + + + + + + + + Транзакция успешно подписана и отправлена в блокчейн. Баланс будет обновлен через некоторое время Неверный адрес Купить сейчас - Бесплатно У меня есть промо-код… Tangem Wallet Другие способы оплаты - Доставка + Сделать предзаказ + Все распродано, но не огорчайтесь! Мы уже производим новые партии Tangem Wallet. Чтобы получить ваш кошелек скорее, оформите предзаказ сейчас. Отправка заказов начнется Итого Сеть Solana взимает арендную плату в размере %1$s каждые 2 дня. Аккаунты, которые не могут позволить себе арендную плату, удаляются из сети. Пополните свой счет более чем на %2$s, чтобы не платить арендную плату. Держите свои криптосбережения в безопасности. Приватные ключи надежно хранятся на карте. diff --git a/core/res/src/main/res/values-zh-rTW/strings.xml b/core/res/src/main/res/values-zh-rTW/strings.xml index 648337e245..edfc9bc0cc 100644 --- a/core/res/src/main/res/values-zh-rTW/strings.xml +++ b/core/res/src/main/res/values-zh-rTW/strings.xml @@ -330,11 +330,9 @@ 交易已成功簽署並發送至區塊鏈節點。錢包餘額稍後更新 無效地址 現在購買 - 免費 輸入折扣碼 Tangem Wallet 其他付款方式 - 運送 總計 Solana 網絡每 2 天收取 %1$s 的費用。無法付此費用的帳戶將從網絡中清除。向您的帳戶存入超過 %2$s 即可免費使用 安全地存儲您的加密貨幣,同時將私鑰保存在您的卡中 diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml index 0bf985e22a..37b2deb719 100644 --- a/core/res/src/main/res/values/strings.xml +++ b/core/res/src/main/res/values/strings.xml @@ -338,11 +338,11 @@ Transaction has been successfully signed and sent to the blockchain node. Wallet balance will be updated in a while Invalid address Buy now - Free I have a promo code… Tangem Wallet Other payment methods - Shipping + Pre-order now + Sold out, but don\'t worry! We are working very hard to get more for you! Make sure to place a pre-order here. Deliveries start on Total Solana network charges a rent of %1$s every 2 days. Accounts that can\'t afford the rent are purged from the network. Deposit your account with more than %2$s to use it for free. Store your crypto assets secure while keeping private keys contained in your card