diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-09 19:59:26 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-09 19:59:26 +0100 |
commit | 9c160ac939ea20d4ed77acf8bc75cd9f60e82bb8 (patch) | |
tree | b87b45731409cd223ac4bbc8574d9bd522718198 /app/src/main/java | |
parent | b39914ed445bdde1a0204b2cbf883f23a5132832 (diff) | |
download | wallet-android-9c160ac939ea20d4ed77acf8bc75cd9f60e82bb8.tar.gz wallet-android-9c160ac939ea20d4ed77acf8bc75cd9f60e82bb8.tar.bz2 wallet-android-9c160ac939ea20d4ed77acf8bc75cd9f60e82bb8.zip |
tos / branding
Diffstat (limited to 'app/src/main/java')
4 files changed, 175 insertions, 11 deletions
diff --git a/app/src/main/java/net/taler/wallet/PromptWithdraw.kt b/app/src/main/java/net/taler/wallet/PromptWithdraw.kt index 785da42..57965f5 100644 --- a/app/src/main/java/net/taler/wallet/PromptWithdraw.kt +++ b/app/src/main/java/net/taler/wallet/PromptWithdraw.kt @@ -62,6 +62,10 @@ class PromptWithdraw : Fragment() { is WithdrawStatus.None -> { } + is WithdrawStatus.TermsOfServiceReviewRequired -> { + val navController = requireActivity().findNavController(R.id.nav_host_fragment) + navController.navigate(R.id.action_promptWithdraw_to_reviewExchangeTOS) + } else -> { val bar = Snackbar.make(view, "Bug: Unexpected result", Snackbar.LENGTH_SHORT) bar.show() @@ -88,6 +92,12 @@ class PromptWithdraw : Fragment() { showWithdrawStatus(view, it) }) + view.findViewById<Button>(R.id.button_cancel_withdraw).setOnClickListener { + val navController = requireActivity().findNavController(R.id.nav_host_fragment) + model.cancelCurrentWithdraw() + navController.navigateUp() + } + view.findViewById<Button>(R.id.button_confirm_withdraw).setOnClickListener { val status = this.model.withdrawStatus.value if (status !is WithdrawStatus.ReceivedDetails) { diff --git a/app/src/main/java/net/taler/wallet/ReviewExchangeTOS.kt b/app/src/main/java/net/taler/wallet/ReviewExchangeTOS.kt new file mode 100644 index 0000000..542b855 --- /dev/null +++ b/app/src/main/java/net/taler/wallet/ReviewExchangeTOS.kt @@ -0,0 +1,76 @@ +package net.taler.wallet + + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.CheckBox +import android.widget.CompoundButton +import android.widget.TextView +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import androidx.navigation.findNavController + +/** + * A simple [Fragment] subclass. + */ +class ReviewExchangeTOS : Fragment() { + + private lateinit var acceptButton: Button + private lateinit var model: WalletViewModel + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + model = activity?.run { + ViewModelProviders.of(this)[WalletViewModel::class.java] + } ?: throw Exception("Invalid Activity") + } + + private fun onAcceptCheck(checked: Boolean) { + acceptButton.isEnabled = checked + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + val view = inflater.inflate(R.layout.fragment_review_exchange_tos, container, false) + val navController = requireActivity().findNavController(R.id.nav_host_fragment) + view.findViewById<Button>(R.id.button_tos_abort).setOnClickListener { + model.cancelCurrentWithdraw() + navController.navigateUp() + } + acceptButton = view.findViewById<Button>(R.id.button_tos_accept) + acceptButton.setOnClickListener { + model.acceptCurrentTermsOfService() + } + val checkbox = view.findViewById<CheckBox>(R.id.checkBox_accept_tos) + checkbox.isChecked = false + checkbox.setOnCheckedChangeListener { buttonView, isChecked -> + onAcceptCheck(isChecked) + } + onAcceptCheck(false) + val tosTextField = view.findViewById<TextView>(R.id.text_tos) + model.withdrawStatus.observe(this, Observer { + when (it) { + is WithdrawStatus.TermsOfServiceReviewRequired -> { + tosTextField.text = it.tosText + } + is WithdrawStatus.Loading -> { + navController.navigate(R.id.action_reviewExchangeTOS_to_promptWithdraw) + } + is WithdrawStatus.ReceivedDetails -> { + navController.navigate(R.id.action_reviewExchangeTOS_to_promptWithdraw) + } + else -> { + } + } + }) + return view + } +} diff --git a/app/src/main/java/net/taler/wallet/WalletViewModel.kt b/app/src/main/java/net/taler/wallet/WalletViewModel.kt index f8acc2d..fd53470 100644 --- a/app/src/main/java/net/taler/wallet/WalletViewModel.kt +++ b/app/src/main/java/net/taler/wallet/WalletViewModel.kt @@ -61,6 +61,12 @@ open class PayStatus { open class WithdrawStatus { class None : WithdrawStatus() data class Loading(val talerWithdrawUri: String) : WithdrawStatus() + data class TermsOfServiceReviewRequired( + val talerWithdrawUri: String, + val exchangeBaseUrl: String, + val tosText: String, + val tosEtag: String + ) : WithdrawStatus() class Success : WithdrawStatus() data class ReceivedDetails( val talerWithdrawUri: String, @@ -118,6 +124,7 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) { private var activeGetPending = 0 private var currentPayRequestId = 0 + private var currentWithdrawRequestId = 0 private val walletBackendApi = WalletBackendApi(app) @@ -299,22 +306,71 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) { withdrawStatus.value = WithdrawStatus.Loading(talerWithdrawUri) - walletBackendApi.sendRequest("getWithdrawalInfo", args) { result -> - Log.v(TAG, "got getWithdrawalInfo result") + this.currentWithdrawRequestId++ + val myWithdrawRequestId = this.currentWithdrawRequestId + + walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { result -> + if (myWithdrawRequestId != this.currentWithdrawRequestId) { + return@sendRequest + } + Log.v(TAG, "got getWithdrawDetailsForUri result") val status = withdrawStatus.value if (status !is WithdrawStatus.Loading) { Log.v(TAG, "ignoring withdrawal info result, not loading.") return@sendRequest } - val suggestedExchange = result.getString("suggestedExchange") - val amount = Amount.fromJson(result.getJSONObject("amount")) - withdrawStatus.postValue( - WithdrawStatus.ReceivedDetails( - status.talerWithdrawUri, - amount, - suggestedExchange + val wi = result.getJSONObject("bankWithdrawDetails") + val suggestedExchange = wi.getString("suggestedExchange") + // We just use the suggested exchange, in the future there will be + // a selection dialog. + getWithdrawalInfoWithExchange(talerWithdrawUri, suggestedExchange) + } + } + + private fun getWithdrawalInfoWithExchange(talerWithdrawUri: String, selectedExchange: String) { + val args = JSONObject() + args.put("talerWithdrawUri", talerWithdrawUri) + args.put("selectedExchange", selectedExchange) + + this.currentWithdrawRequestId++ + val myWithdrawRequestId = this.currentWithdrawRequestId + + walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { result -> + if (myWithdrawRequestId != this.currentWithdrawRequestId) { + return@sendRequest + } + Log.v(TAG, "got getWithdrawDetailsForUri result (with exchange details)") + val status = withdrawStatus.value + if (status !is WithdrawStatus.Loading) { + Log.v(TAG, "ignoring withdrawal info result, not loading.") + return@sendRequest + } + val ei = result.getJSONObject("exchangeWithdrawDetails") + val termsOfServiceAccepted = ei.getBoolean("termsOfServiceAccepted") + if (!termsOfServiceAccepted) { + val exchange = ei.getJSONObject("exchangeInfo") + val tosText = exchange.getString("termsOfServiceText") + val tosEtag = exchange.getString("termsOfServiceLastEtag") + withdrawStatus.postValue( + WithdrawStatus.TermsOfServiceReviewRequired( + status.talerWithdrawUri, + selectedExchange, + tosText, + tosEtag + ) ) - ) + } else { + val wi = result.getJSONObject("bankWithdrawDetails") + val suggestedExchange = wi.getString("suggestedExchange") + val amount = Amount.fromJson(wi.getJSONObject("amount")) + withdrawStatus.postValue( + WithdrawStatus.ReceivedDetails( + status.talerWithdrawUri, + amount, + suggestedExchange + ) + ) + } } } @@ -343,4 +399,26 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) { walletBackendApi.destroy() super.onCleared() } + + /** + * Accept the currently displayed terms of service. + */ + fun acceptCurrentTermsOfService() { + when (val s = withdrawStatus.value) { + is WithdrawStatus.TermsOfServiceReviewRequired -> { + val args = JSONObject() + args.put("exchangeBaseUrl", s.exchangeBaseUrl) + args.put("etag", s.tosEtag) + walletBackendApi.sendRequest("acceptExchangeTermsOfService", args) { + // Try withdrawing again with accepted ToS + getWithdrawalInfo(s.talerWithdrawUri) + } + } + } + } + + fun cancelCurrentWithdraw() { + currentWithdrawRequestId++ + withdrawStatus.value = WithdrawStatus.None() + } } diff --git a/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt b/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt index 26420a1..b387c9c 100644 --- a/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt +++ b/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt @@ -63,7 +63,7 @@ class WalletBackendService : Service() { msg.put("operation", "init") val args = JSONObject() msg.put("args", args) - args.put("persistentStoragePath", "${application.filesDir}/talerwalletdb-v27.json") + args.put("persistentStoragePath", "${application.filesDir}/talerwalletdb-v29.json") akono.sendMessage(msg.toString()) } |