Skip to content

Commit

Permalink
fix elemtn sized when switching between market and limit prices
Browse files Browse the repository at this point in the history
  • Loading branch information
gigiyy committed Oct 4, 2018
1 parent 243c209 commit 5af6983
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.main_activity)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, OrderInputFragment.newInstance())
.replace(R.id.container, OrderInputFragment.newInstance("8704"))
.commitNow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class OrderInputFragment : Fragment() {

companion object {
fun newInstance() = OrderInputFragment()
fun newInstance(symbol: String): OrderInputFragment {
val args = Bundle()
args.putString("symbol", symbol)
val fragment = OrderInputFragment()
fragment.arguments = args
return fragment
}
}

private lateinit var viewModel: OrderInputViewModel
Expand All @@ -29,6 +36,9 @@ class OrderInputFragment : Fragment() {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(activity!!).get(OrderInputViewModel::class.java)
// TODO: Use the ViewModel
arguments?.getString("symbol")?.let {
viewModel.init(it)
}
viewModel.getOrderModel().observe(this, Observer { orderForm ->
orderForm?.run {
tvSymbolName.text = symbol.name
Expand Down Expand Up @@ -71,6 +81,7 @@ class OrderInputFragment : Fragment() {
btLimit.isChecked = false
btMarket.isChecked = true
togglePriceType()
viewModel.resetPrice()
}
btLimit.setOnClickListener {
btLimit.isChecked = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ class OrderInputViewModel : ViewModel() {
}
}

fun init(symbol: String?) {
// TODO need a cleaner way to initialize the OrderForm
if (symbol != null) {
if (!this::orderForm.isInitialized || (this::orderForm.isInitialized && symbol != orderForm.value?.symbol?.symbol)) {
orderForm = MutableLiveData()
orderForm.value = OrderForm(
TradeItSDKHolder.getSymbolProvider().getJapanSymbol(symbol),
TradeItSDKHolder.getBuyingPower())
}
}
}

fun resetPrice() {
val value = orderForm.value
orderForm.value = value?.apply {
orderInfo = orderInfo.copy(limitPrice = symbol.price)
}
}
}

class OrderForm(val symbol: JapanSymbol, val buyingPower: BuyingPower) {
Expand Down Expand Up @@ -94,13 +112,13 @@ class OrderForm(val symbol: JapanSymbol, val buyingPower: BuyingPower) {

//TODO temp solutions below
interface JapanSymbolProvider {
fun getJapanSymbol(symol: String): JapanSymbol
fun getJapanSymbol(symbol: String): JapanSymbol
}

class SampleJapanSymbol : JapanSymbolProvider {
override fun getJapanSymbol(symol: String): JapanSymbol {
override fun getJapanSymbol(symbol: String): JapanSymbol {
return JapanSymbol("カブドットコム証券(株)",
"8703", "東証1部", 386.0,
symbol, "東証1部", 386.0,
384.0, 286.0, 486.0, 100)
}
}
Expand Down
13 changes: 7 additions & 6 deletions exampleAppJapan/src/main/res/layout/order_input_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@

<android.support.v7.widget.LinearLayoutCompat
android:id="@+id/orderInfo"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toEndOf="@+id/quantityInput"
app:layout_constraintStart_toStartOf="@+id/quantityInput"
app:layout_constraintTop_toBottomOf="@+id/divider3">


Expand Down Expand Up @@ -342,8 +343,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="@+id/orderInfo"
app:layout_constraintStart_toStartOf="@+id/orderInfo"
app:layout_constraintEnd_toEndOf="@+id/quantityInput"
app:layout_constraintStart_toStartOf="@+id/quantityInput"
app:layout_constraintTop_toBottomOf="@+id/divider4">

<android.support.v7.widget.LinearLayoutCompat
Expand Down Expand Up @@ -417,8 +418,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="@+id/orderInfo"
app:layout_constraintStart_toStartOf="@+id/orderInfo"
app:layout_constraintEnd_toEndOf="@+id/quantityInput"
app:layout_constraintStart_toStartOf="@+id/quantityInput"
app:layout_constraintTop_toBottomOf="@+id/divider5">

<android.support.v7.widget.LinearLayoutCompat
Expand Down

0 comments on commit 5af6983

Please sign in to comment.