-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated crypto and card payment flows
- Loading branch information
1 parent
8938d88
commit f45d859
Showing
22 changed files
with
622 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
android/app/src/main/java/updated/mysterium/vpn/model/top/up/CurrencyCardItem.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...sterium/vpn/model/top/up/TopUpCardItem.kt → ...m/vpn/model/top/up/TopUpAmountCardItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android/app/src/main/java/updated/mysterium/vpn/model/top/up/TopUpPriceCardItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package updated.mysterium.vpn.model.top.up | ||
|
||
import android.os.Parcelable | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@Parcelize | ||
data class TopUpPriceCardItem( | ||
val sku: String, | ||
val title: String, | ||
val price: Double, | ||
val mystAmount: Double, | ||
var isSelected: Boolean = false | ||
): Parcelable { | ||
|
||
fun changeState() { | ||
isSelected = !isSelected | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
android/app/src/main/java/updated/mysterium/vpn/ui/top/up/card/price/TopUpPriceActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package updated.mysterium.vpn.ui.top.up.card.price | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import network.mysterium.vpn.R | ||
import network.mysterium.vpn.databinding.ActivityTopUpPriceBinding | ||
import org.koin.android.ext.android.inject | ||
import updated.mysterium.vpn.common.data.WalletEstimatesUtil | ||
import updated.mysterium.vpn.common.extensions.TAG | ||
import updated.mysterium.vpn.model.top.up.TopUpPriceCardItem | ||
import updated.mysterium.vpn.ui.base.BaseActivity | ||
import updated.mysterium.vpn.ui.top.up.TopUpViewModel | ||
import updated.mysterium.vpn.ui.top.up.card.summary.CardSummaryActivity | ||
import updated.mysterium.vpn.ui.top.up.coingate.amount.TopUpAmountViewModel | ||
import updated.mysterium.vpn.ui.top.up.coingate.payment.TopUpPaymentViewModel | ||
import updated.mysterium.vpn.ui.wallet.ExchangeRateViewModel | ||
import java.util.* | ||
|
||
class TopUpPriceActivity : BaseActivity() { | ||
|
||
private lateinit var binding: ActivityTopUpPriceBinding | ||
private val viewModel: TopUpViewModel by inject() | ||
private val walletViewModel: TopUpAmountViewModel by inject() | ||
private val exchangeRateViewModel: ExchangeRateViewModel by inject() | ||
private val paymentViewModel: TopUpPaymentViewModel by inject() | ||
private val topUpAdapter = TopUpPriceAdapter() | ||
private var selectedItem: TopUpPriceCardItem? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityTopUpPriceBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
configure() | ||
bindsAction() | ||
getSkuList() | ||
} | ||
|
||
private fun configure() { | ||
binding.priceRecycler.adapter = topUpAdapter | ||
topUpAdapter.onItemSelected = { | ||
onItemSelected(it) | ||
} | ||
} | ||
|
||
private fun bindsAction() { | ||
binding.backButton.setOnClickListener { | ||
finish() | ||
} | ||
binding.confirmButton.setOnClickListener { | ||
navigateToCardPaymentFlow() | ||
} | ||
binding.freeTrialButtonButton.setOnClickListener { | ||
viewModel.accountFlowShown() | ||
navigateToConnectionOrHome(isBackTransition = false) | ||
} | ||
} | ||
|
||
private fun getSkuList() { | ||
paymentViewModel.getSkuDetailList().observe(this) { | ||
it.onSuccess { skuDetailList -> | ||
skuDetailList?.let { | ||
topUpAdapter.addAll(it) | ||
} | ||
} | ||
it.onFailure { throwable -> | ||
Log.e(TAG, throwable.localizedMessage ?: throwable.toString()) | ||
} | ||
} | ||
topUpAdapter.getSelectedItem()?.let { | ||
onItemSelected(it) | ||
} | ||
} | ||
|
||
private fun updateEquivalent(mystAmount: Double) { | ||
binding.mystEquivalentTextView.text = getString( | ||
R.string.top_up_usd_equivalent, mystAmount | ||
) | ||
} | ||
|
||
private fun updateWalletEstimates(mystAmount: Double) { | ||
walletViewModel.getWalletEquivalent(mystAmount).observe(this) { result -> | ||
result.onSuccess { estimates -> | ||
binding.videoTopUpItem.setData(WalletEstimatesUtil.convertVideoData(estimates)) | ||
binding.videoTopUpItem.setType( | ||
WalletEstimatesUtil.convertVideoType(estimates).toUpperCase(Locale.ROOT) | ||
) | ||
binding.pagesTopUpItem.setData(WalletEstimatesUtil.convertWebData(estimates)) | ||
binding.pagesTopUpItem.setType( | ||
WalletEstimatesUtil.convertWebType(estimates).toUpperCase(Locale.ROOT) | ||
) | ||
binding.trafficTopUpItem.setData( | ||
WalletEstimatesUtil.convertDownloadData(estimates).toString() | ||
) | ||
binding.trafficTopUpItem.setType( | ||
WalletEstimatesUtil.convertDownloadType( | ||
estimates | ||
) | ||
) | ||
binding.musicTopUpItem.setData( | ||
WalletEstimatesUtil.convertMusicTimeData( | ||
estimates | ||
) | ||
) | ||
binding.musicTopUpItem.setType( | ||
WalletEstimatesUtil.convertMusicTimeType(estimates).toUpperCase(Locale.ROOT) | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun onItemSelected(selectedItem: TopUpPriceCardItem) { | ||
this.selectedItem = selectedItem | ||
val mystAmount = exchangeRateViewModel.getMystEquivalent(selectedItem.price) | ||
updateEquivalent(mystAmount) | ||
updateWalletEstimates(mystAmount) | ||
} | ||
|
||
private fun navigateToCardPaymentFlow() { | ||
val intent = Intent(this, CardSummaryActivity::class.java).apply { | ||
putExtra(CardSummaryActivity.SKU_EXTRA_KEY, selectedItem) | ||
} | ||
startActivity(intent) | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
android/app/src/main/java/updated/mysterium/vpn/ui/top/up/card/price/TopUpPriceAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package updated.mysterium.vpn.ui.top.up.card.price | ||
|
||
import android.graphics.Color | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.content.ContextCompat | ||
import androidx.recyclerview.widget.RecyclerView | ||
import network.mysterium.vpn.R | ||
import network.mysterium.vpn.databinding.ItemCardElementBinding | ||
import updated.mysterium.vpn.common.adapters.ContentListAdapter | ||
import updated.mysterium.vpn.common.extensions.dpToPx | ||
import updated.mysterium.vpn.model.top.up.TopUpPriceCardItem | ||
|
||
class TopUpPriceAdapter : | ||
ContentListAdapter<TopUpPriceCardItem, TopUpPriceAdapter.TopUpPriceViewHolder>() { | ||
|
||
private companion object { | ||
const val MARGIN_DP = 24f | ||
} | ||
|
||
private var selectedCardItem: TopUpPriceCardItem? = null | ||
var onItemSelected: ((TopUpPriceCardItem) -> Unit)? = null | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = TopUpPriceViewHolder( | ||
LayoutInflater.from(parent.context).inflate(R.layout.item_card_element, parent, false) | ||
) | ||
|
||
override fun onBindViewHolder(holder: TopUpPriceViewHolder, position: Int) { | ||
if (position == items.lastIndex) { | ||
val params = holder.itemView.layoutParams as RecyclerView.LayoutParams | ||
params.rightMargin = holder.itemView.context.dpToPx(MARGIN_DP) | ||
holder.itemView.layoutParams = params | ||
} else if (position == 0) { | ||
val params = holder.itemView.layoutParams as RecyclerView.LayoutParams | ||
params.leftMargin = holder.itemView.context.dpToPx(MARGIN_DP) | ||
holder.itemView.layoutParams = params | ||
} | ||
holder.bind(items[position]) | ||
} | ||
|
||
fun getSelectedItem() = selectedCardItem | ||
|
||
inner class TopUpPriceViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
|
||
val binding = ItemCardElementBinding.bind(itemView) | ||
|
||
fun bind(cardItem: TopUpPriceCardItem) { | ||
binding.cardItemValue.text = cardItem.title | ||
if (cardItem.isSelected) { | ||
selectedCardItem = cardItem | ||
selectedState() | ||
} else { | ||
unselectedState() | ||
} | ||
binding.cardItemFrame.setOnClickListener { | ||
if (cardItem != selectedCardItem) { | ||
onItemSelected?.invoke(cardItem) | ||
selectedCardItem?.changeState() | ||
cardItem.changeState() | ||
selectedCardItem = cardItem | ||
notifyDataSetChanged() | ||
} | ||
} | ||
} | ||
|
||
private fun selectedState() { | ||
binding.cardItemValue.setTextColor(Color.WHITE) | ||
binding.cardItemFrame.background = ContextCompat.getDrawable( | ||
itemView.context, R.drawable.shape_card_element_selected | ||
) | ||
binding.shadow.visibility = View.VISIBLE | ||
} | ||
|
||
private fun unselectedState() { | ||
binding.cardItemValue.setTextColor( | ||
itemView.context.getColor(R.color.onboarding_title_dark_blue) | ||
) | ||
binding.cardItemFrame.background = ContextCompat.getDrawable( | ||
itemView.context, R.drawable.shape_card_element_unselected | ||
) | ||
binding.shadow.visibility = View.INVISIBLE | ||
} | ||
} | ||
} |
Oops, something went wrong.