Skip to content

Commit

Permalink
fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Colombini committed Apr 28, 2018
1 parent 3760ffa commit ea0cd69
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}, {})
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}

}
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_exchange.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit ea0cd69

Please sign in to comment.