From ea0cd69ee22ea30347b75d26a970ea66257a8416 Mon Sep 17 00:00:00 2001 From: Bruno Colombini Date: Sat, 28 Apr 2018 00:21:18 -0300 Subject: [PATCH] fix some issues --- README.md | 2 +- app/build.gradle | 2 +- .../feature/exchange/ExchangeFragment.kt | 24 +++++++++---------- .../feature/exchange/ExchangePresenter.kt | 4 ++-- .../wallet/util/TransformToNumber.kt | 8 ++++++- app/src/main/res/layout/fragment_exchange.xml | 1 - .../wallet/util/TransformToNumberTest.kt | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1755682..165d4ad 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Wallet [![Build Status](https://travis-ci.org/bcolombini/Wallet.svg?branch=master)](https://travis-ci.org/bcolombini/Wallet) [![codecov](https://codecov.io/gh/bcolombini/Wallet/branch/master/graph/badge.svg)](https://codecov.io/gh/bcolombini/Wallet) ![version](https://img.shields.io/badge/version-1.0.1-blue.svg) +# Wallet [![Build Status](https://travis-ci.org/bcolombini/Wallet.svg?branch=master)](https://travis-ci.org/bcolombini/Wallet) [![codecov](https://codecov.io/gh/bcolombini/Wallet/branch/master/graph/badge.svg)](https://codecov.io/gh/bcolombini/Wallet) ![version](https://img.shields.io/badge/version-1.0.2-blue.svg) ## Arquitetura MVP diff --git a/app/build.gradle b/app/build.gradle index f9526e5..a3fbc6d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ android { minSdkVersion 17 targetSdkVersion 26 versionCode 1 - versionName "1.0.1" + versionName "1.0.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangeFragment.kt b/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangeFragment.kt index 97a9c4b..cfbeddc 100644 --- a/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangeFragment.kt +++ b/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangeFragment.kt @@ -8,12 +8,10 @@ import android.view.ViewGroup import com.example.brunocolombini.wallet.DAO.user.UserWallet import com.example.brunocolombini.wallet.R import com.example.brunocolombini.wallet.util.TextWatcherCryptoInput -import com.example.brunocolombini.wallet.util.TransformToNumber.removeString -import com.example.brunocolombini.wallet.util.delivery.UpdateBalanceEvent +import com.example.brunocolombini.wallet.util.TransformToNumber.transformStringToDouble import com.example.brunocolombini.wallet.util.enums.BalanceEventType import com.example.brunocolombini.wallet.util.enums.ExchangeEvent import dagger.android.support.DaggerFragment -import io.reactivex.subjects.PublishSubject import kotlinx.android.synthetic.main.fragment_exchange.* import kotlinx.android.synthetic.main.fragment_exchange.view.* import javax.inject.Inject @@ -50,10 +48,10 @@ class ExchangeFragment : DaggerFragment(), ExchangeContract.View { private fun setButtonsListeners() { fragmentView.button_buy.setOnClickListener { - val buyTotal = removeString(buy_total.editText!!.text.toString()) - val buyQuantity = removeString(buy_quantity.editText!!.text.toString()) - val cryptoBalance = removeString(crypto_balance.text.toString()) - val fiatBalance = removeString(fiat_balance.text.toString()) + val buyTotal = buy_total.editText!!.text.toString().toDouble() + val buyQuantity = buy_quantity.editText!!.text.toString().toDouble() + val cryptoBalance = transformStringToDouble(crypto_balance.text.toString()) + val fiatBalance = transformStringToDouble(fiat_balance.text.toString()) val newBalanceFiat = fiatBalance - buyTotal val newBalanceCrypto = cryptoBalance + buyQuantity @@ -63,10 +61,10 @@ class ExchangeFragment : DaggerFragment(), ExchangeContract.View { } fragmentView.button_sell.setOnClickListener { - val sellTotal = removeString(sell_total.editText!!.text.toString()) - val sellQuantity = removeString(sell_quantity.editText!!.text.toString()) - val cryptoBalance = removeString(crypto_balance.text.toString()) - val fiatBalance = removeString(fiat_balance.text.toString()) + val sellTotal = sell_total.editText!!.text.toString().toDouble() + val sellQuantity = sell_quantity.editText!!.text.toString().toDouble() + val cryptoBalance = transformStringToDouble(crypto_balance.text.toString()) + val fiatBalance = transformStringToDouble(fiat_balance.text.toString()) val newBalanceFiat = fiatBalance + sellTotal val newBalanceCrypto = cryptoBalance - sellQuantity @@ -89,11 +87,11 @@ class ExchangeFragment : DaggerFragment(), ExchangeContract.View { private fun textInputListeners() { val buyQuantity = fragmentView.buy_quantity.editText!! - val buyPrice = fragmentView.buy_price.editText!!.text.toString().toDouble() + val buyPrice = transformStringToDouble(fragmentView.buy_price.editText!!.text.toString()) val buyTotal = fragmentView.buy_total.editText!! val sellQuantity = fragmentView.sell_quantity.editText!! - val sellPrice = fragmentView.sell_price.editText!!.text.toString().toDouble() + val sellPrice = transformStringToDouble(fragmentView.sell_price.editText!!.text.toString()) val sellTotal = fragmentView.sell_total.editText!! buyQuantity.addTextChangedListener(TextWatcherCryptoInput(buyQuantity, buyPrice, buyTotal, button_buy)) diff --git a/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangePresenter.kt b/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangePresenter.kt index c4e03b9..dffd10f 100644 --- a/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangePresenter.kt +++ b/app/src/main/java/com/example/brunocolombini/wallet/feature/exchange/ExchangePresenter.kt @@ -78,9 +78,9 @@ class ExchangePresenter @Inject constructor( private fun getBtcPrice() { api.getBtcPrice() .observeOn(AndroidSchedulers.mainThread()) - .subscribe { ticker: MercadoBitcoinModel -> + .subscribe({ ticker: MercadoBitcoinModel -> this.view.setCryptoPrice(BalanceEventType.BTC, ticker.ticker.buy.toDouble(), ticker.ticker.sell.toDouble()) - } + }, {}) } /** diff --git a/app/src/main/java/com/example/brunocolombini/wallet/util/TransformToNumber.kt b/app/src/main/java/com/example/brunocolombini/wallet/util/TransformToNumber.kt index d8512f1..241fe1a 100644 --- a/app/src/main/java/com/example/brunocolombini/wallet/util/TransformToNumber.kt +++ b/app/src/main/java/com/example/brunocolombini/wallet/util/TransformToNumber.kt @@ -1,6 +1,12 @@ package com.example.brunocolombini.wallet.util +import java.text.NumberFormat object TransformToNumber { - fun removeString(string: String): Double = string.replace("R$", "").replace("BTC", "").replace("BRITAS", "").toDouble() + fun transformStringToDouble(string: String): Double { + val numberFormat = NumberFormat.getNumberInstance() + val number = numberFormat.parse(string.replace(Regex("[a-zA-Z$ ]"),"")) + return number.toDouble() + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_exchange.xml b/app/src/main/res/layout/fragment_exchange.xml index c02de42..1bb3130 100644 --- a/app/src/main/res/layout/fragment_exchange.xml +++ b/app/src/main/res/layout/fragment_exchange.xml @@ -171,7 +171,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" - android:text="@string/balance_fiat" app:layout_constraintBottom_toBottomOf="@+id/bid" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@+id/bid" /> diff --git a/app/src/test/java/com/example/brunocolombini/wallet/util/TransformToNumberTest.kt b/app/src/test/java/com/example/brunocolombini/wallet/util/TransformToNumberTest.kt index c7304e2..3537ec1 100644 --- a/app/src/test/java/com/example/brunocolombini/wallet/util/TransformToNumberTest.kt +++ b/app/src/test/java/com/example/brunocolombini/wallet/util/TransformToNumberTest.kt @@ -7,6 +7,6 @@ class TransformToNumberTest { @Test fun remove_string_test() { - Assert.assertEquals(1000.0, TransformToNumber.removeString("R$ 1000.00"), 0.000001) + Assert.assertEquals(123.32, TransformToNumber.transformStringToDouble("R$ 123.32"), 0.000001) } } \ No newline at end of file