Skip to content

Commit

Permalink
use view model to drive the market limit order button instead
Browse files Browse the repository at this point in the history
  • Loading branch information
gigiyy committed Oct 5, 2018
1 parent 8412a85 commit f27283a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class OrderInputFragment : Fragment() {

etQuantity.setText(String.format("%d", orderInfo.quantity))
etPrice.setText(String.format("%.0f", orderInfo.limitPrice))
btMarket.isChecked = orderInfo.type == OrderType.MARKET
btLimit.isChecked = orderInfo.type == OrderType.LIMIT

val lower = String.format("%,.0f", symbol.priceLowerLimit)
val upper = String.format("%,.0f", symbol.priceUpperLimit)
Expand All @@ -74,17 +76,12 @@ class OrderInputFragment : Fragment() {
btPriceMinus.setOnClickListener {
viewModel.decreasePrice()
}
btLimit.isChecked = true
btMarket.isChecked = false
btMarket.setOnClickListener {
btLimit.isChecked = false
btMarket.isChecked = true
viewModel.setMarketOrder()
togglePriceType()
viewModel.resetPrice()
}
btLimit.setOnClickListener {
btLimit.isChecked = true
btMarket.isChecked = false
viewModel.setLimitOrder()
togglePriceType()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel

class OrderInputViewModel : ViewModel() {
// TODO: Implement the ViewModel

private lateinit var orderForm: MutableLiveData<OrderForm>

fun getOrderModel(): LiveData<OrderForm> {
Expand Down Expand Up @@ -63,9 +61,15 @@ class OrderInputViewModel : ViewModel() {
}
}

fun resetPrice() {
fun setMarketOrder() {
orderForm.value = orderForm.value?.apply {
orderInfo = orderInfo.copy(type = OrderType.MARKET, limitPrice = symbol.price)
}
}

fun setLimitOrder() {
orderForm.value = orderForm.value?.apply {
orderInfo = orderInfo.copy(limitPrice = symbol.price)
orderInfo = orderInfo.copy(type = OrderType.LIMIT)
}
}
}
Expand Down

0 comments on commit f27283a

Please sign in to comment.