Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/play_billing
Browse files Browse the repository at this point in the history
# Conflicts:
#	android/app/src/main/java/updated/mysterium/vpn/ui/top/up/card/currency/CardCurrencyActivity.kt
#	android/app/src/main/java/updated/mysterium/vpn/ui/top/up/coingate/amount/TopUpAmountActivity.kt
  • Loading branch information
IrynaTsymbaliuk committed Apr 5, 2022
2 parents 1debb17 + b7130c3 commit 1b018b7
Show file tree
Hide file tree
Showing 30 changed files with 543 additions and 220 deletions.
5 changes: 4 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ dependencies {
//QrCode
implementation 'com.journeyapps:zxing-android-embedded:4.1.0'

//Markdown
implementation "io.noties.markwon:core:4.6.2"

//Mysterium
implementation "network.mysterium:terms:0.0.34"
implementation "network.mysterium:terms:0.0.40"
implementation "network.mysterium:mobile-node:1.4.13"
// Change NODE_VERSION in defaultConfig if updating version of mobile-node
// Comment network.mysterium:mobile-node and replace with your local path to use local node build.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@ package updated.mysterium.vpn.model.payment

enum class Gateway(val gateway: String) {
COINGATE("coingate"),
CARDINITY("cardinity")
CARDINITY("cardinity"),
PAYPAL("paypal");

companion object {
fun from(gateway: String?): Gateway {
return values().find { it.gateway == gateway } ?: COINGATE
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package updated.mysterium.vpn.model.payment

import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import network.mysterium.vpn.R

data class GatewayCardItem(
@StringRes val titleId: Int,
@DrawableRes val iconId: Int,
@ColorRes val backgroundId: Int,
@ColorRes val textColorId: Int,
@ColorRes val iconColorId: Int
) {
companion object {
fun from(value: Gateway): GatewayCardItem {
return when (value) {
Gateway.COINGATE -> GatewayCardItem(
R.string.crypto,
R.drawable.icon_crypto,
R.color.payment_method_crypto_background,
R.color.payment_method_crypto_text_color,
R.color.payment_method_crypto_icon_color
)
Gateway.CARDINITY -> GatewayCardItem(
R.string.credit_card,
R.drawable.icon_top_up_now,
R.color.payment_method_card_background,
R.color.payment_method_card_text_color,
R.color.payment_method_card_icon_color
)
Gateway.PAYPAL -> GatewayCardItem(
R.string.paypal,
R.drawable.icon_paypal,
R.color.payment_method_paypal_background,
R.color.payment_method_paypal_text_color,
R.color.payment_method_paypal_icon_color
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -17,6 +18,7 @@ import network.mysterium.vpn.databinding.PopUpRetryRegistrationBinding
import network.mysterium.vpn.databinding.PopUpTopUpAccountBinding
import network.mysterium.vpn.databinding.PopUpWiFiErrorBinding
import org.koin.android.ext.android.inject
import updated.mysterium.vpn.common.extensions.TAG
import updated.mysterium.vpn.common.localisation.LocaleHelper
import updated.mysterium.vpn.model.manual.connect.ConnectionState
import updated.mysterium.vpn.model.pushy.PushyTopic
Expand All @@ -25,6 +27,7 @@ import updated.mysterium.vpn.ui.connection.ConnectionActivity
import updated.mysterium.vpn.ui.custom.view.ConnectionToolbar
import updated.mysterium.vpn.ui.home.selection.HomeSelectionActivity
import updated.mysterium.vpn.ui.payment.method.PaymentMethodActivity
import updated.mysterium.vpn.ui.top.up.coingate.amount.TopUpAmountActivity

abstract class BaseActivity : AppCompatActivity() {

Expand Down Expand Up @@ -141,7 +144,7 @@ abstract class BaseActivity : AppCompatActivity() {
val bindingPopUp = PopUpInsufficientFundsBinding.inflate(layoutInflater)
val dialog = createPopUp(bindingPopUp.root, false)
bindingPopUp.topUpButton.setOnClickListener {
startActivity(Intent(this, PaymentMethodActivity::class.java))
navigateToPayment()
}
bindingPopUp.continueButton.setOnClickListener {
dialog.dismiss()
Expand Down Expand Up @@ -249,7 +252,7 @@ abstract class BaseActivity : AppCompatActivity() {
bindingPopUp.topUpButton.setOnClickListener {
insufficientFoundsDialog?.dismiss()
insufficientFoundsDialog = null
startActivity(Intent(this, PaymentMethodActivity::class.java))
navigateToPayment()
}
bindingPopUp.continueButton.setOnClickListener {
insufficientFoundsDialog?.dismiss()
Expand All @@ -258,4 +261,26 @@ abstract class BaseActivity : AppCompatActivity() {
insufficientFoundsDialog?.show()
}
}

fun navigateToPayment() {
baseViewModel.getGateways().observe(this) {
it.onSuccess { gateways ->
val intent = if (gateways.size == 1) {
Intent(this, TopUpAmountActivity::class.java).apply {
putExtra(
TopUpAmountActivity.PAYMENT_METHOD_EXTRA_KEY,
gateways[0].gateway
)
}
} else {
val gatewayValues = gateways.map { it.gateway }
PaymentMethodActivity.newIntent(this, gatewayValues)
}
startActivity(intent)
}
it.onFailure { error ->
Log.e(TAG, "getPaymentScreen failed with error ${error.message}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import updated.mysterium.vpn.common.extensions.liveDataResult
import updated.mysterium.vpn.common.livedata.SingleLiveEvent
import updated.mysterium.vpn.model.manual.connect.ConnectionState
import updated.mysterium.vpn.model.payment.Gateway
import updated.mysterium.vpn.network.provider.usecase.UseCaseProvider

class BaseViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
Expand Down Expand Up @@ -43,6 +45,7 @@ class BaseViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
private val balanceUseCase = useCaseProvider.balance()
private val connectionUseCase = useCaseProvider.connection()
private val settingsUseCase = useCaseProvider.settings()
private val paymentUseCase = useCaseProvider.payment()
private var isInternetChecking = false
private var numberOfInternetCheck = 0

Expand Down Expand Up @@ -132,4 +135,12 @@ class BaseViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
}
}
}

fun getGateways() = liveDataResult {
paymentUseCase
.getGateways()
.map { Gateway.from(it.name) }
.toMutableList()
.apply { remove(Gateway.PAYPAL) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class ConnectionViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
}

private fun smartConnect(countryCode: String? = null) {
Log.d(TAG, "Smart connect with countryCode $countryCode")
viewModelScope.launch(handler) {
disconnectIfConnectedNode()
val code =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import network.mysterium.vpn.databinding.ActivityFavouritesBinding
import org.koin.android.ext.android.inject
import updated.mysterium.vpn.model.connection.ConnectionType
import updated.mysterium.vpn.model.manual.connect.Proposal
import updated.mysterium.vpn.ui.base.AllNodesViewModel
import updated.mysterium.vpn.ui.base.BaseActivity
Expand Down Expand Up @@ -96,9 +97,11 @@ class FavouritesActivity : BaseActivity() {
}

private fun navigateToConnection(proposal: Proposal) {
val intent = Intent(this, ConnectionActivity::class.java)
intent.putExtra(ConnectionActivity.EXTRA_PROPOSAL_MODEL, proposal)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
val intent = Intent(this, ConnectionActivity::class.java).apply {
putExtra(ConnectionActivity.CONNECTION_TYPE_KEY, ConnectionType.MANUAL_CONNECT.type)
putExtra(ConnectionActivity.EXTRA_PROPOSAL_MODEL, proposal)
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class HomeSelectionActivity : BaseActivity() {
scrollToPositionWithOffset(countryIndex, 0)
} else {
// scroll to top
viewModel.saveNewCountryCode(ALL_COUNTRY_CODE)
sortedCountryInfoList.first().changeSelectionState()
scrollToPositionWithOffset(0, 0)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package updated.mysterium.vpn.ui.payment.method

import android.content.Context
import android.content.Intent
import android.os.Bundle
import network.mysterium.vpn.databinding.ActivityPaymentMethodBinding
Expand All @@ -9,30 +10,53 @@ import updated.mysterium.vpn.ui.top.up.coingate.amount.TopUpAmountActivity

class PaymentMethodActivity : BaseActivity() {

companion object {

private const val GATEWAYS_EXTRA = "gatewaysExtra"

fun newIntent(context: Context, gateways: List<String>): Intent {
val intent = Intent(context, PaymentMethodActivity::class.java)
intent.putExtra(GATEWAYS_EXTRA, gateways.toTypedArray())
return intent
}
}

private lateinit var binding: ActivityPaymentMethodBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPaymentMethodBinding.inflate(layoutInflater)
setContentView(binding.root)
bind()
setUpPaymentMethodList()
}

private fun bind() {
binding.cryptoPayment.setOnClickListener {
val intent = Intent(this, TopUpAmountActivity::class.java).apply {
putExtra(TopUpAmountActivity.PAYMENT_METHOD_EXTRA_KEY, Gateway.COINGATE)
}
startActivity(intent)
binding.backButton.setOnClickListener {
finish()
}
binding.creditCardPayment.setOnClickListener {
val intent = Intent(this, TopUpAmountActivity::class.java).apply {
putExtra(TopUpAmountActivity.PAYMENT_METHOD_EXTRA_KEY, Gateway.CARDINITY)
}

private fun setUpPaymentMethodList() {
val gateways = intent
.getStringArrayExtra(GATEWAYS_EXTRA)
?.map { gateway -> Gateway.from(gateway) }

gateways?.let {
PaymentMethodAdapter().apply {
replaceAll(it)
onItemSelected = {
navigateToTopUp(it)
}
binding.paymentMethodList.adapter = this
}
startActivity(intent)
}
binding.backButton.setOnClickListener {
finish()
}

private fun navigateToTopUp(gateway: Gateway) {
val intent = Intent(this, TopUpAmountActivity::class.java).apply {
putExtra(TopUpAmountActivity.PAYMENT_METHOD_EXTRA_KEY, gateway)
}
startActivity(intent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package updated.mysterium.vpn.ui.payment.method

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.ItemPaymentMethodBinding
import updated.mysterium.vpn.common.adapters.ContentListAdapter
import updated.mysterium.vpn.model.payment.Gateway
import updated.mysterium.vpn.model.payment.GatewayCardItem

class PaymentMethodAdapter :
ContentListAdapter<Gateway, PaymentMethodAdapter.PaymentMethodViewHolder>() {

var onItemSelected: ((Gateway) -> Unit)? = null

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = PaymentMethodViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_payment_method, parent, false)
)

override fun onBindViewHolder(holder: PaymentMethodViewHolder, position: Int) {
holder.bind(items[position])
}

override fun getItemCount() = items.size

inner class PaymentMethodViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val binding = ItemPaymentMethodBinding.bind(itemView)
fun bind(item: Gateway) {
val gatewayCardItem = GatewayCardItem.from(item)
val backgroundColor =
ContextCompat.getDrawable(itemView.context, gatewayCardItem.backgroundId)
val iconColor = ContextCompat.getColor(itemView.context, gatewayCardItem.iconColorId)
val textColor = ContextCompat.getColor(itemView.context, gatewayCardItem.textColorId)
val text = itemView.context.getString(gatewayCardItem.titleId)

binding.paymentMethodItemCard.background = backgroundColor
binding.paymentMethodIcon.setBackgroundResource(gatewayCardItem.iconId)
binding.arrowImageView.setColorFilter(iconColor)
binding.paymentMethodName.setTextColor(textColor)
binding.paymentMethodName.text = text

binding.paymentMethodItemCard.setOnClickListener {
onItemSelected?.invoke(item)
}
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PopUpDownloadKey(layoutInflater: LayoutInflater) {
bindingPopUp.passwordEditText.text?.clear()
passwordEditText.clearFocus()
passwordEditText.hideKeyboard()
bindingPopUp.passwordScrollView.background = ContextCompat.getDrawable(
bindingPopUp.passwordEditText.background = ContextCompat.getDrawable(
dialog.context, R.drawable.shape_wrong_password
)
bindingPopUp.errorText.visibility = View.VISIBLE
Expand All @@ -50,7 +50,7 @@ class PopUpDownloadKey(layoutInflater: LayoutInflater) {
if (hasFocus) {
bindingPopUp.passwordEditText.hint = dialog
.context
.getString(R.string.pop_up_private_key_hint)
.getString(R.string.pop_up_password_account_hint)
clearErrorState()
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ class PopUpDownloadKey(layoutInflater: LayoutInflater) {
}

private fun clearErrorState() {
bindingPopUp.passwordScrollView.background = ContextCompat.getDrawable(
bindingPopUp.passwordEditText.background = ContextCompat.getDrawable(
dialog.context, R.drawable.shape_password_field
)
bindingPopUp.errorText.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import network.mysterium.vpn.databinding.ActivityPrepareTopUpBinding
import network.mysterium.vpn.databinding.PopUpReferralCodeBinding
import network.mysterium.vpn.databinding.PopUpRetryRegistrationBinding
import org.koin.android.ext.android.inject
import updated.mysterium.vpn.model.payment.Gateway
import updated.mysterium.vpn.model.pushy.PushyTopic
import updated.mysterium.vpn.ui.base.BaseActivity
import updated.mysterium.vpn.ui.base.RegistrationViewModel
import updated.mysterium.vpn.ui.home.selection.HomeSelectionActivity
import updated.mysterium.vpn.ui.payment.method.PaymentMethodActivity
import updated.mysterium.vpn.ui.top.up.coingate.amount.TopUpAmountActivity

class PrepareTopUpActivity : BaseActivity() {

Expand Down Expand Up @@ -54,7 +55,7 @@ class PrepareTopUpActivity : BaseActivity() {

private fun bindsAction() {
binding.topUpNow.setOnClickListener {
startActivity(Intent(this, PaymentMethodActivity::class.java))
navigateToPayment()
}
binding.referralProgram.setOnClickListener {
showReferralPopUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import android.util.Log
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import network.mysterium.vpn.R
import network.mysterium.vpn.databinding.ActivityPrivateKeyBinding
import network.mysterium.vpn.databinding.PopUpDownloadKeyBinding
import network.mysterium.vpn.databinding.PopUpRetryRegistrationBinding
import org.koin.android.ext.android.inject
import updated.mysterium.vpn.common.downloads.DownloadsUtil
Expand Down
Loading

0 comments on commit 1b018b7

Please sign in to comment.