Skip to content

Commit 756ec02

Browse files
committed
fix element size while switched to market price
1 parent 243c209 commit 756ec02

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

exampleAppJapan/src/main/kotlin/it/trade/android/japanapp/MainActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MainActivity : AppCompatActivity() {
1212
setContentView(R.layout.main_activity)
1313
if (savedInstanceState == null) {
1414
supportFragmentManager.beginTransaction()
15-
.replace(R.id.container, OrderInputFragment.newInstance())
15+
.replace(R.id.container, OrderInputFragment.newInstance("8704"))
1616
.commitNow()
1717
}
1818
}

exampleAppJapan/src/main/kotlin/it/trade/android/japanapp/ui/orderinput/OrderInputFragment.kt

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ class OrderInputFragment : Fragment() {
1616

1717
companion object {
1818
fun newInstance() = OrderInputFragment()
19+
fun newInstance(symbol: String): OrderInputFragment {
20+
val args = Bundle()
21+
args.putString("symbol", symbol)
22+
val fragment = OrderInputFragment()
23+
fragment.arguments = args
24+
return fragment
25+
}
1926
}
2027

2128
private lateinit var viewModel: OrderInputViewModel
@@ -29,6 +36,9 @@ class OrderInputFragment : Fragment() {
2936
super.onActivityCreated(savedInstanceState)
3037
viewModel = ViewModelProviders.of(activity!!).get(OrderInputViewModel::class.java)
3138
// TODO: Use the ViewModel
39+
arguments?.getString("symbol")?.let {
40+
viewModel.init(it)
41+
}
3242
viewModel.getOrderModel().observe(this, Observer { orderForm ->
3343
orderForm?.run {
3444
tvSymbolName.text = symbol.name
@@ -71,6 +81,7 @@ class OrderInputFragment : Fragment() {
7181
btLimit.isChecked = false
7282
btMarket.isChecked = true
7383
togglePriceType()
84+
viewModel.resetPrice()
7485
}
7586
btLimit.setOnClickListener {
7687
btLimit.isChecked = true

exampleAppJapan/src/main/kotlin/it/trade/android/japanapp/ui/orderinput/OrderInputViewModel.kt

+21-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ class OrderInputViewModel : ViewModel() {
5656
}
5757
}
5858

59+
fun init(symbol: String?) {
60+
// TODO need a cleaner way to initialize the OrderForm
61+
if (symbol != null) {
62+
if (!this::orderForm.isInitialized || (this::orderForm.isInitialized && symbol != orderForm.value?.symbol?.symbol)) {
63+
orderForm = MutableLiveData()
64+
orderForm.value = OrderForm(
65+
TradeItSDKHolder.getSymbolProvider().getJapanSymbol(symbol),
66+
TradeItSDKHolder.getBuyingPower())
67+
}
68+
}
69+
}
70+
71+
fun resetPrice() {
72+
val value = orderForm.value
73+
orderForm.value = value?.apply {
74+
orderInfo = orderInfo.copy(limitPrice = symbol.price)
75+
}
76+
}
5977
}
6078

6179
class OrderForm(val symbol: JapanSymbol, val buyingPower: BuyingPower) {
@@ -94,13 +112,13 @@ class OrderForm(val symbol: JapanSymbol, val buyingPower: BuyingPower) {
94112

95113
//TODO temp solutions below
96114
interface JapanSymbolProvider {
97-
fun getJapanSymbol(symol: String): JapanSymbol
115+
fun getJapanSymbol(symbol: String): JapanSymbol
98116
}
99117

100118
class SampleJapanSymbol : JapanSymbolProvider {
101-
override fun getJapanSymbol(symol: String): JapanSymbol {
119+
override fun getJapanSymbol(symbol: String): JapanSymbol {
102120
return JapanSymbol("カブドットコム証券(株)",
103-
"8703", "東証1部", 386.0,
121+
symbol, "東証1部", 386.0,
104122
384.0, 286.0, 486.0, 100)
105123
}
106124
}

exampleAppJapan/src/main/res/layout/order_input_fragment.xml

+7-6
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@
190190

191191
<android.support.v7.widget.LinearLayoutCompat
192192
android:id="@+id/orderInfo"
193-
android:layout_width="wrap_content"
193+
android:layout_width="0dp"
194194
android:layout_height="wrap_content"
195195
android:gravity="center"
196196
android:orientation="vertical"
197-
app:layout_constraintEnd_toEndOf="parent"
197+
app:layout_constraintEnd_toEndOf="@+id/quantityInput"
198+
app:layout_constraintStart_toStartOf="@+id/quantityInput"
198199
app:layout_constraintTop_toBottomOf="@+id/divider3">
199200

200201

@@ -342,8 +343,8 @@
342343
android:layout_width="0dp"
343344
android:layout_height="wrap_content"
344345
android:orientation="vertical"
345-
app:layout_constraintEnd_toEndOf="@+id/orderInfo"
346-
app:layout_constraintStart_toStartOf="@+id/orderInfo"
346+
app:layout_constraintEnd_toEndOf="@+id/quantityInput"
347+
app:layout_constraintStart_toStartOf="@+id/quantityInput"
347348
app:layout_constraintTop_toBottomOf="@+id/divider4">
348349

349350
<android.support.v7.widget.LinearLayoutCompat
@@ -417,8 +418,8 @@
417418
android:layout_width="0dp"
418419
android:layout_height="wrap_content"
419420
android:orientation="vertical"
420-
app:layout_constraintEnd_toEndOf="@+id/orderInfo"
421-
app:layout_constraintStart_toStartOf="@+id/orderInfo"
421+
app:layout_constraintEnd_toEndOf="@+id/quantityInput"
422+
app:layout_constraintStart_toStartOf="@+id/quantityInput"
422423
app:layout_constraintTop_toBottomOf="@+id/divider5">
423424

424425
<android.support.v7.widget.LinearLayoutCompat

0 commit comments

Comments
 (0)