diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index 9b24821ade..4ed8c97588 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -16,6 +16,7 @@ import com.tangem.tap.common.redux.NotificationsHandler import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.domain.TangemSdkManager +import com.tangem.tap.features.home.redux.HomeAction import com.tangem.wallet.R import kotlinx.android.synthetic.main.activity_main.* import kotlinx.coroutines.CoroutineExceptionHandler @@ -67,9 +68,8 @@ class MainActivity : AppCompatActivity() { super.onResume() notificationsHandler = NotificationsHandler(fragment_container) if (supportFragmentManager.backStackEntryCount == 0) { - store.dispatch( - NavigationAction.NavigateTo(AppScreen.Home) - ) + store.dispatch(HomeAction.CheckIfFirstLaunch) + store.dispatch(NavigationAction.NavigateTo(AppScreen.Home)) } } diff --git a/app/src/main/java/com/tangem/tap/TapApplication.kt b/app/src/main/java/com/tangem/tap/TapApplication.kt index 45e7e92da3..fdb8c65fd9 100644 --- a/app/src/main/java/com/tangem/tap/TapApplication.kt +++ b/app/src/main/java/com/tangem/tap/TapApplication.kt @@ -19,11 +19,10 @@ lateinit var preferencesStorage: PreferencesStorage class TapApplication : Application() { override fun onCreate() { super.onCreate() - preferencesStorage = PreferencesStorage(this) - if (BuildConfig.DEBUG) { Timber.plant(Timber.DebugTree()) } NetworkConnectivity.createInstance(store, this) + preferencesStorage = PreferencesStorage(this) } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt b/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt index bf905a0e9e..46072d5765 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt @@ -48,6 +48,10 @@ fun BigDecimal.toFormattedString(decimals: Int): String { return df.format(bd) } +fun BigDecimal.toFormattedCurrencyString(decimals: Int, currency: String): String { + return "${this.toFormattedString(decimals)} $currency" +} + fun BigDecimal.toFiatString(rateValue: BigDecimal, fiatCurrencyName: FiatCurrencyName): String? { var fiatValue = rateValue.multiply(this) fiatValue = fiatValue.setScale(2, RoundingMode.DOWN) diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt index c02184fd51..3420ef1255 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt @@ -2,8 +2,9 @@ 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.SendScreenReducer import com.tangem.tap.features.details.redux.DetailsReducer +import com.tangem.tap.features.home.redux.HomeReducer +import com.tangem.tap.features.send.redux.reducers.SendScreenReducer import com.tangem.tap.features.wallet.redux.WalletReducer import org.rekotlin.Action @@ -14,6 +15,7 @@ fun appReducer(action: Action, state: AppState?): AppState { return AppState( navigationState = NavigationReducer.reduce(action, state), globalState = globalReducer(action, state), + homeState = HomeReducer.reduce(action, state), walletState = WalletReducer.reduce(action, state), sendState = SendScreenReducer.reduce(action, state.sendState), detailsState = DetailsReducer.reduce(action, state) diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppState.kt b/app/src/main/java/com/tangem/tap/common/redux/AppState.kt index 47a422958f..8f5f980c69 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppState.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppState.kt @@ -6,6 +6,7 @@ import com.tangem.tap.common.redux.navigation.NavigationState import com.tangem.tap.common.redux.navigation.navigationMiddleware import com.tangem.tap.features.details.redux.DetailsMiddleware import com.tangem.tap.features.details.redux.DetailsState +import com.tangem.tap.features.home.redux.HomeState import com.tangem.tap.features.home.redux.homeMiddleware import com.tangem.tap.features.send.redux.middlewares.sendMiddleware import com.tangem.tap.features.send.redux.states.SendState @@ -17,6 +18,7 @@ import org.rekotlin.StateType data class AppState( val navigationState: NavigationState = NavigationState(), val globalState: GlobalState = GlobalState(), + val homeState: HomeState = HomeState(), val walletState: WalletState = WalletState(), val sendState: SendState = SendState(), val detailsState: DetailsState = DetailsState() diff --git a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt index 30e36dfd81..cd71354e23 100644 --- a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt @@ -12,6 +12,7 @@ import com.tangem.tap.common.redux.global.CryptoCurrencyName import com.tangem.tap.common.redux.global.FiatCurrencyName import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.domain.tasks.ScanNoteResponse +import com.tangem.tap.features.wallet.redux.Artwork import com.tangem.tap.features.wallet.redux.PayIdState import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.network.NetworkConnectivity @@ -43,8 +44,8 @@ class TapWalletManager { when (result) { is Result.Success -> { store.dispatch(WalletAction.LoadArtwork.Success( - artworkId, result.data.byteStream().readBytes()) - ) + Artwork(artworkId, result.data.byteStream().readBytes()) + )) } is Result.Failure -> store.dispatch(WalletAction.LoadArtwork.Failure) } @@ -74,21 +75,22 @@ class TapWalletManager { suspend fun onCardScanned(data: ScanNoteResponse) { withContext(Dispatchers.Main) { store.dispatch(GlobalAction.SaveScanNoteResponse(data)) + val artworkId = data.verifyResponse?.artworkInfo?.id if (data.walletManager != null) { if (!NetworkConnectivity.getInstance().isOnlineOrConnecting()) { store.dispatch(WalletAction.LoadData.Failure(TapError.NoInternetConnection)) return@withContext } - data.verifyResponse?.artworkInfo?.id?.let { - store.dispatch(WalletAction.LoadArtwork(data.card, it)) - } store.dispatch(WalletAction.LoadWallet) + store.dispatch(WalletAction.LoadArtwork(data.card, artworkId)) store.dispatch(WalletAction.LoadFiatRate) store.dispatch(WalletAction.LoadPayId) } else if (data.card.status == CardStatus.Empty) { store.dispatch(WalletAction.EmptyWallet) + store.dispatch(WalletAction.LoadArtwork(data.card, artworkId)) } else { store.dispatch(WalletAction.LoadData.Failure(TapError.UnknownBlockchain)) + store.dispatch(WalletAction.LoadArtwork(data.card, artworkId)) } } } diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/CreateWalletAndRescanTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/CreateWalletAndRescanTask.kt index 8bd2f97c6a..cc539e426e 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/CreateWalletAndRescanTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/CreateWalletAndRescanTask.kt @@ -2,24 +2,16 @@ package com.tangem.tap.domain.tasks import com.tangem.CardSession import com.tangem.CardSessionRunnable -import com.tangem.commands.ReadCommand +import com.tangem.commands.CreateWalletCommand import com.tangem.common.CompletionResult -import com.tangem.tasks.CreateWalletTask class CreateWalletAndRescanTask : CardSessionRunnable { override val requiresPin2 = false override fun run(session: CardSession, callback: (result: CompletionResult) -> Unit) { - CreateWalletTask().run(session) { result -> + CreateWalletCommand().run(session) { result -> when (result) { - is CompletionResult.Success -> ReadCommand().run(session) { readResult -> - when (readResult) { - is CompletionResult.Success -> { - callback(readResult.data.toScanNoteCompletionResult()) - } - is CompletionResult.Failure -> callback(CompletionResult.Failure(readResult.error)) - } - } + is CompletionResult.Success -> ScanNoteTask().run(session, callback) is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error)) } diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt index 80cf0fd3be..e733a18b30 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt @@ -10,6 +10,7 @@ import com.tangem.commands.CommandResponse import com.tangem.commands.verifycard.VerifyCardCommand import com.tangem.commands.verifycard.VerifyCardResponse import com.tangem.common.CompletionResult +import com.tangem.tasks.ScanTask data class ScanNoteResponse( val walletManager: WalletManager?, @@ -21,26 +22,32 @@ class ScanNoteTask : CardSessionRunnable { override val requiresPin2 = false override fun run(session: CardSession, callback: (result: CompletionResult) -> Unit) { - val card = session.environment.card - card ?: return callback(CompletionResult.Failure(TangemSdkError.CardError())) - val walletManager = try { - WalletManagerFactory.makeWalletManager(card) - } catch (exception: Exception) { - return callback(CompletionResult.Success(ScanNoteResponse(null, card))) - } - VerifyCardCommand(true).run(session) { result -> + ScanTask().run(session) { result -> when (result) { + is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error)) + is CompletionResult.Success -> { - callback(CompletionResult.Success(ScanNoteResponse( - walletManager, card, result.data - ))) - } - is CompletionResult.Failure -> { - callback(CompletionResult.Failure(TangemSdkError.VerificationFailed())) + val card = result.data + val walletManager = try { + WalletManagerFactory.makeWalletManager(card) + } catch (exception: Exception) { + return@run callback(CompletionResult.Success(ScanNoteResponse(null, card))) + } + VerifyCardCommand(true).run(session) { verifyResult -> + when (verifyResult) { + is CompletionResult.Success -> { + callback(CompletionResult.Success(ScanNoteResponse( + walletManager, card, verifyResult.data + ))) + } + is CompletionResult.Failure -> { + callback(CompletionResult.Failure(TangemSdkError.VerificationFailed())) + } + } + } } } } - } } diff --git a/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt b/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt index 4f1338e98e..6f3b1c35fd 100644 --- a/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt @@ -5,11 +5,43 @@ import android.view.View import androidx.fragment.app.Fragment import androidx.transition.TransitionInflater import com.tangem.tap.features.home.redux.HomeAction +import com.tangem.tap.features.home.redux.HomeState import com.tangem.tap.store import com.tangem.wallet.R import kotlinx.android.synthetic.main.fragment_home.* +import org.rekotlin.StoreSubscriber + +class HomeFragment : Fragment(R.layout.fragment_home), StoreSubscriber { + + override fun onStart() { + super.onStart() + store.subscribe(this) { state -> + state.skipRepeats { oldState, newState -> + oldState.homeState == newState.homeState + }.select { it.homeState } + } + } + + override fun onStop() { + super.onStop() + store.unsubscribe(this) + } + + + override fun newState(state: HomeState) { + if (activity == null) return +requireContext().cacheDir + if (state.firstLaunch) { + tv_home_description.text = getText(R.string.home_do_you_have_card) + btn_shop.text = getText(R.string.home_button_no_card) + btn_yes.text = getText(R.string.home_button_yes) + } else { + tv_home_description.text = getText(R.string.home_welcome_back) + btn_shop.text = getText(R.string.home_button_shop) + btn_yes.text = getText(R.string.home_button_scan) + } + } -class HomeFragment : Fragment(R.layout.fragment_home) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt index ab54ccf665..5a9edf9fe7 100644 --- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt +++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt @@ -6,4 +6,7 @@ import org.rekotlin.Action sealed class HomeAction : Action { object ReadCard : HomeAction() data class GoToShop(val context: Context) : HomeAction() + object CheckIfFirstLaunch : HomeAction() { + data class Result(val firstLaunch: Boolean) : HomeAction() + } } diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt index bbb05df3e4..a49a2299ba 100644 --- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt @@ -8,6 +8,7 @@ import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction +import com.tangem.tap.preferencesStorage import com.tangem.tap.scope import com.tangem.tap.store import com.tangem.tap.tangemSdkManager @@ -20,6 +21,11 @@ val homeMiddleware: Middleware = { dispatch, state -> { next -> { action -> when (action) { + is HomeAction.CheckIfFirstLaunch -> { + store.dispatch( + HomeAction.CheckIfFirstLaunch.Result(preferencesStorage.isFirstLaunch()) + ) + } is HomeAction.ReadCard -> { scope.launch { val result = tangemSdkManager.scanNote() diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt new file mode 100644 index 0000000000..b88da93641 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt @@ -0,0 +1,24 @@ +package com.tangem.tap.features.home.redux + +import com.tangem.tap.common.redux.AppState +import org.rekotlin.Action + +class HomeReducer { + companion object { + fun reduce(action: Action, state: AppState): HomeState = internalReduce(action, state) + } +} + +private fun internalReduce(action: Action, state: AppState): HomeState { + + if (action !is HomeAction) return state.homeState + + var homeState = state.homeState + when (action) { + is HomeAction.CheckIfFirstLaunch.Result -> { + homeState = homeState.copy(firstLaunch = action.firstLaunch) + } + } + + return homeState +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt new file mode 100644 index 0000000000..b167e66785 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt @@ -0,0 +1,7 @@ +package com.tangem.tap.features.home.redux + +import org.rekotlin.StateType + +data class HomeState( + val firstLaunch: Boolean = true +) : StateType diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt index 4e1d6ea32e..99f7cae09f 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt @@ -35,8 +35,8 @@ sealed class WalletAction : Action { object Failure : WalletAction() } - data class LoadArtwork(val card: Card, val artworkId: String) : WalletAction() { - data class Success(val artworkId: String, val artwork: ByteArray) : WalletAction() + data class LoadArtwork(val card: Card, val artworkId: String?) : WalletAction() { + data class Success(val artwork: Artwork) : WalletAction() object Failure : WalletAction() } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletMiddleware.kt index 558f348582..6c9f2b85bd 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletMiddleware.kt @@ -19,6 +19,7 @@ import com.tangem.tap.network.NetworkStateChanged import com.tangem.tap.scope import com.tangem.tap.store import com.tangem.tap.tangemSdkManager +import com.tangem.wallet.R import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -46,11 +47,19 @@ val walletMiddleware: Middleware = { dispatch, state -> } } is WalletAction.LoadArtwork -> { - scope.launch { - store.state.globalState.tapWalletManager.loadArtwork( - action.card, action.artworkId - ) + if (action.artworkId != null) { + scope.launch { + store.state.globalState.tapWalletManager.loadArtwork( + action.card, action.artworkId + ) + } + } else { + val artworkRes = R.drawable.card_default + store.dispatch(WalletAction.LoadArtwork.Success(Artwork( + artworkId = artworkRes.toString(), artworkResId = artworkRes + ))) } + } is WalletAction.CreateWallet -> { scope.launch { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt index d015483883..233a6c5500 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt @@ -2,8 +2,8 @@ package com.tangem.tap.features.wallet.redux import com.tangem.blockchain.common.AmountType import com.tangem.common.extensions.isZero -import com.tangem.tap.common.extensions.toBitmap import com.tangem.tap.common.extensions.toFiatString +import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.common.extensions.toFormattedString import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.redux.AppState @@ -98,6 +98,9 @@ private fun internalReduce(action: Action, state: AppState): WalletState { null } val amount = action.wallet.amounts[AmountType.Coin]?.value + val formattedAmount = amount?.toFormattedCurrencyString( + action.wallet.blockchain.decimals(), + action.wallet.blockchain.currency) val fiatRate = state.globalState.conversionRates.getRate(action.wallet.blockchain.currency) val fiatAmount = fiatRate?.let { amount?.toFiatString(it, fiatCurrencySymbol) } @@ -110,7 +113,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState { currencyData = BalanceWidgetData( BalanceStatus.VerifiedOnline, action.wallet.blockchain.fullName, currencySymbol = action.wallet.blockchain.currency, - amount?.toFormattedString(action.wallet.blockchain.decimals()), + formattedAmount, token = tokenData, fiatAmount = fiatAmount ), @@ -163,13 +166,14 @@ private fun internalReduce(action: Action, state: AppState): WalletState { )) } is WalletAction.LoadArtwork.Success -> { - newState = newState.copy(cardImage = Artwork(action.artworkId, action.artwork.toBitmap())) + newState = newState.copy(cardImage = action.artwork) } is WalletAction.ShowQrCode -> { newState = newState.copy( walletDialog = WalletDialog.QrDialog( newState.addressData?.shareUrl?.toQrCode(), - newState.addressData?.shareUrl + newState.addressData?.shareUrl, + newState.currencyData.currency ) ) } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt index 90de886e55..5e6f65ae2a 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt @@ -4,6 +4,8 @@ import android.graphics.Bitmap import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.Wallet import com.tangem.tap.common.entities.Button +import com.tangem.tap.common.extensions.toBitmap +import com.tangem.tap.common.redux.global.CryptoCurrencyName import com.tangem.tap.features.wallet.models.PendingTransaction import com.tangem.tap.features.wallet.ui.BalanceWidgetData import org.rekotlin.StateType @@ -22,7 +24,10 @@ data class WalletState( ) : StateType sealed class WalletDialog { - data class QrDialog(val qrCode: Bitmap?, val shareUrl: String?) : WalletDialog() + data class QrDialog( + val qrCode: Bitmap?, val shareUrl: String?, val currencyName: CryptoCurrencyName? + ) : WalletDialog() + data class CreatePayIdDialog(val creatingPayIdState: CreatingPayIdState?) : WalletDialog() data class SelectAmountToSendDialog(val amounts: List?) : WalletDialog() } @@ -54,5 +59,8 @@ data class AddressData( data class Artwork( val artworkId: String, - val artwork: Bitmap -) \ No newline at end of file + val artwork: Bitmap? = null, + val artworkResId: Int? = null +) { + constructor(artworkId: String, artworkBytes: ByteArray) : this(artworkId, artworkBytes.toBitmap()) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/BalanceWidget.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/BalanceWidget.kt index 78a165d4c1..78e93bddaf 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/BalanceWidget.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/BalanceWidget.kt @@ -52,7 +52,6 @@ class BalanceWidget( fragment.l_token.hide() fragment.tv_currency.text = data.currency - fragment.tv_currency_symbol.text = "-" fragment.tv_amount.text = "" showStatus(R.id.tv_status_loading) @@ -62,7 +61,6 @@ class BalanceWidget( fragment.l_balance_error.hide() fragment.tv_currency.text = data.currency fragment.tv_amount.text = data.amount - fragment.tv_currency_symbol.text = data.currencySymbol fragment.tv_fiat_amount.show() fragment.tv_fiat_amount.text = data.fiatAmount showStatus(R.id.tv_status_verified) @@ -83,7 +81,6 @@ class BalanceWidget( fragment.tv_fiat_amount.hide() fragment.tv_currency.text = data.currency - fragment.tv_currency_symbol.text = "-" fragment.tv_amount.text = "" fragment.tv_status_error_message.text = data.errorMessage diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt index 8aa533ea8d..bd7361c2eb 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt @@ -1,12 +1,13 @@ package com.tangem.tap.features.wallet.ui import android.app.Dialog -import android.graphics.Bitmap import android.os.Bundle import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View +import android.view.animation.AlphaAnimation +import android.view.animation.Animation import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment @@ -35,6 +36,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber { if (walletDialog.qrCode != null && walletDialog.shareUrl != null) { if (dialog == null) dialog = QrDialog(requireContext()).apply { - this.showQr(walletDialog.qrCode, walletDialog.shareUrl) + this.showQr( + walletDialog.qrCode, walletDialog.shareUrl, walletDialog.currencyName + ) } } } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/QrDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/QrDialog.kt index 2c553f3614..8a201aa749 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/QrDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/QrDialog.kt @@ -3,6 +3,9 @@ package com.tangem.tap.features.wallet.ui.dialogs import android.app.Dialog import android.content.Context import android.graphics.Bitmap +import com.tangem.tap.common.extensions.hide +import com.tangem.tap.common.extensions.show +import com.tangem.tap.common.redux.global.CryptoCurrencyName import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.store import com.tangem.wallet.R @@ -14,12 +17,20 @@ class QrDialog(context: Context) : Dialog(context) { this.setContentView(R.layout.dialog_qrcode) } - fun showQr(qrCode: Bitmap, shareUrl: String) { + fun showQr(qrCode: Bitmap, shareUrl: String, currencyName: CryptoCurrencyName?) { this.setOnDismissListener { store.dispatch(WalletAction.HideQrCode) } this.btn_done?.setOnClickListener { store.dispatch(WalletAction.HideQrCode) } this.tv_qr_dialog_address?.text = shareUrl this.iv_qrcode?.setImageBitmap(qrCode) + if (currencyName == null) { + this.tv_qr_dialog_header.hide() + } else { + this.tv_qr_dialog_header.show() + this.tv_qr_dialog_header.text = context.getString( + R.string.wallet_dialog_qr_code_header, currencyName + ) + } super.show() } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt b/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt index bbaa2aa7b2..a60e353874 100644 --- a/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt +++ b/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt @@ -45,10 +45,18 @@ class PreferencesStorage(applicationContext: Application) { return preferences.edit().putString(FIAT_CURRENCIES_KEY, json).apply() } + fun isFirstLaunch(): Boolean { + val isFirst = preferences.contains(FIRST_LAUNCH_CHECK_KEY) + if (isFirst) preferences.edit().putInt(FIRST_LAUNCH_CHECK_KEY, System.currentTimeMillis().toInt()).apply() + + return isFirst + } + companion object { private const val PREFERENCES_NAME = "tapPrefs" private const val APP_CURRENCY_KEY = "appCurrency" private const val FIAT_CURRENCIES_KEY = "fiatCurrencies" + private const val FIRST_LAUNCH_CHECK_KEY = "firstLaunchCheck" } } \ No newline at end of file diff --git a/app/src/main/res/drawable/card_placeholder.xml b/app/src/main/res/drawable/card_placeholder.xml new file mode 100644 index 0000000000..917ac784e2 --- /dev/null +++ b/app/src/main/res/drawable/card_placeholder.xml @@ -0,0 +1,19 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_tangem_pale.xml b/app/src/main/res/drawable/ic_tangem_pale.xml new file mode 100644 index 0000000000..dacddc1972 --- /dev/null +++ b/app/src/main/res/drawable/ic_tangem_pale.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_create_payid.xml b/app/src/main/res/layout/dialog_create_payid.xml index 590c511679..4466080d8a 100644 --- a/app/src/main/res/layout/dialog_create_payid.xml +++ b/app/src/main/res/layout/dialog_create_payid.xml @@ -53,7 +53,7 @@ android:paddingTop="12dp" android:text="@string/wallet_pay_id_address" android:textColor="@color/darkGray4" - android:textSize="13sp" + android:textSize="14sp" app:layout_constraintBottom_toBottomOf="@id/til_payid" app:layout_constraintStart_toEndOf="@id/til_payid" app:layout_constraintTop_toTopOf="@id/til_payid" /> @@ -65,7 +65,7 @@ android:paddingStart="24dp" android:paddingEnd="24dp" android:text="@string/wallet_dialog_pay_id_description" - android:textColor="@color/darkGray4" + android:textColor="@color/darkGray1" android:textSize="13sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -85,7 +85,7 @@ android:paddingBottom="8dp" android:text="@string/wallet_dialog_pay_id_button" android:textColor="@color/blue" - android:textSize="16sp" + android:textSize="14sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> diff --git a/app/src/main/res/layout/dialog_qrcode.xml b/app/src/main/res/layout/dialog_qrcode.xml index 03f149a30f..af37e85986 100644 --- a/app/src/main/res/layout/dialog_qrcode.xml +++ b/app/src/main/res/layout/dialog_qrcode.xml @@ -1,16 +1,30 @@ + + + android:layout_marginTop="12dp" /> + android:paddingTop="8dp" + android:paddingEnd="24dp"/> + android:textSize="14sp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index ce04dd4978..55b20af069 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -4,7 +4,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + + + app:layout_constraintStart_toEndOf="@+id/guideline" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_send.xml b/app/src/main/res/layout/fragment_send.xml index 8fedf3fed1..da7a18eba9 100644 --- a/app/src/main/res/layout/fragment_send.xml +++ b/app/src/main/res/layout/fragment_send.xml @@ -73,32 +73,37 @@ android:layout_marginBottom="24dp" tools:visibility="gone" /> - - + + android:layout_height="wrap_content" + app:layout_constraintStart_toEndOf="@+id/guideline" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + android:layout_marginEnd="30dp" + android:layout_marginStart="8dp"> - + diff --git a/app/src/main/res/layout/fragment_wallet.xml b/app/src/main/res/layout/fragment_wallet.xml index 66d8297ff7..8ef1ecf464 100644 --- a/app/src/main/res/layout/fragment_wallet.xml +++ b/app/src/main/res/layout/fragment_wallet.xml @@ -49,14 +49,28 @@ android:id="@+id/iv_card" android:layout_width="match_parent" android:layout_height="wrap_content" + android:maxHeight="215dp" android:layout_gravity="center" - android:layout_marginTop="38dp" + android:layout_marginStart="16dp" + android:layout_marginTop="8dp" + android:layout_marginEnd="16dp" android:layout_marginBottom="12dp" android:adjustViewBounds="true" - android:elevation="3dp" + android:elevation="4dp" android:scaleType="fitCenter" - android:src="@drawable/card_default" + android:src="@drawable/card_placeholder" app:layout_constraintTop_toTopOf="parent" /> + + + + diff --git a/app/src/main/res/layout/layout_address.xml b/app/src/main/res/layout/layout_address.xml index d54f709499..36accca525 100644 --- a/app/src/main/res/layout/layout_address.xml +++ b/app/src/main/res/layout/layout_address.xml @@ -33,7 +33,7 @@ android:paddingEnd="16dp" android:singleLine="true" android:textColor="@color/darkGray1" - android:textSize="12sp" + android:textSize="13sp" app:layout_constraintEnd_toStartOf="@id/btn_copy" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toStartOf="parent" @@ -48,10 +48,10 @@ android:paddingStart="16dp" android:paddingTop="6dp" android:paddingEnd="16dp" - android:paddingBottom="30dp" + android:paddingBottom="25dp" android:text="@string/wallet_explore_address" android:textColor="@color/darkGray6" - android:textSize="12sp" + android:textSize="14sp" android:textStyle="bold" app:drawableEndCompat="@drawable/ic_angle_bracket_right" app:layout_constraintStart_toStartOf="parent" @@ -111,10 +111,9 @@ android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginStart="16dp" - android:layout_marginTop="83dp" android:layout_marginEnd="16dp" android:background="@color/lightGray5" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@id/tv_explore" /> @@ -83,7 +83,7 @@ android:paddingEnd="16dp" android:text="@string/wallet_balance_is_loading" android:textColor="@color/darkGray6" - android:textSize="12sp" + android:textSize="13sp" android:visibility="gone" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_currency" /> @@ -92,7 +92,7 @@ android:id="@+id/tv_amount" android:layout_width="0dp" android:layout_height="0dp" - android:layout_marginEnd="4dp" + android:layout_marginEnd="16dp" android:ellipsize="end" android:gravity="end|bottom" android:maxLines="1" @@ -104,27 +104,12 @@ app:autoSizeMinTextSize="12sp" app:autoSizeStepGranularity="1sp" app:autoSizeTextType="uniform" - app:layout_constraintEnd_toStartOf="@id/tv_currency_symbol" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toEndOf="@id/tv_currency" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="@id/tv_currency_symbol" - tools:text="0.43" /> - - + app:layout_constraintBottom_toBottomOf="@id/tv_currency" + tools:text="0.43 BTC" /> + + + app:layout_constraintTop_toBottomOf="@id/tv_token_title" + app:layout_constraintBottom_toBottomOf="@id/tv_token_fiat_amount"/> @@ -45,7 +45,7 @@ android:paddingTop="8dp" android:paddingEnd="8dp" android:textColor="@color/darkGray6" - android:textSize="13sp" + android:textSize="14sp" app:layout_constraintEnd_toEndOf="@id/v_token_background" app:layout_constraintTop_toTopOf="@id/v_token_background" tools:text="12.345 NDL" /> @@ -57,9 +57,9 @@ android:paddingStart="16dp" android:paddingTop="2dp" android:paddingEnd="8dp" - android:paddingBottom="6dp" + android:paddingBottom="8dp" android:textColor="@color/darkGray2" - android:textSize="12sp" + android:textSize="14sp" app:layout_constraintEnd_toEndOf="@id/v_token_background" app:layout_constraintTop_toBottomOf="@id/tv_token_amount" tools:text="USD 3 588" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a70f1fea25..9373ea5d54 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,8 +12,11 @@ @string/generic_retry Welcome to Tangem.\nDo you have one of our cards? + Welcome back to Tangem Tap. \nScan your card to start. Yes! - No. Go to shop + Scan card + Shop + No Tangem Tap Scan @@ -40,6 +43,7 @@ PayID name $payid.tangem.com Your PayID is information unique to you, like your phone number, email or ABN. + %s wallet This PayID already exists. Try a different one. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0c965e8d30..61530d2290 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -25,7 +25,7 @@