Skip to content

Commit

Permalink
Merge branch 'dev/and' into fix/and/accessibility-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EunhoKang authored Dec 11, 2023
2 parents 6b13df4 + 807ba78 commit dbcdb92
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class AddItemActivity : AppCompatActivity() {
intent.getStringExtra("productCode") ?: "",
intent.getStringExtra("productTitle") ?: "",
intent.getIntExtra("productPrice", 0),
intent.getBooleanExtra("isAdding", true)
intent.getBooleanExtra("isAdding", true),
intent.getIntExtra("productTargetPrice", (intent.getIntExtra("productPrice", 0) * 0.8).toInt())
)
navController.safeNavigate(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class ConfirmItemLinkFragment : Fragment() {
arguments.getString("productCode") ?: "",
arguments.getString("productName") ?: "",
arguments.getInt("productPrice"),
true
true,
(arguments.getInt("productPrice") * 0.8).toInt()
)
findNavController().navigate(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ class SetTargetPriceFragment : Fragment() {
val productCode = arguments.getString("productCode") ?: ""
val title = arguments.getString("productTitle") ?: ""
val price = arguments.getInt("productPrice")
var targetPrice = arguments.getInt("productTargetPrice")

setTargetPriceViewModel.updateTargetPrice((price * 0.8).toInt())
setTargetPriceViewModel.updateTargetPrice(targetPrice)

tvSetPriceCurrentPrice.text =
String.format(
Expand All @@ -84,7 +85,9 @@ class SetTargetPriceFragment : Fragment() {
getString(R.string.current_price_info, tvSetPriceCurrentPrice.text)

setTargetPriceViewModel.setProductInfo(productCode, title, price)
etTargetPrice.setText((price * 0.8).toInt().toString())
etTargetPrice.setText(targetPrice.toString())

updateSlideValueWithPrice(targetPrice.toFloat())
}

private fun FragmentSetTargetPriceBinding.initListener() {
Expand Down Expand Up @@ -127,20 +130,7 @@ class SetTargetPriceFragment : Fragment() {
}

setTargetPriceViewModel.updateTargetPrice(targetPrice.toInt())

val percent =
((targetPrice / setTargetPriceViewModel.state.value.productPrice) * MAX_PERCENT).toInt()

binding.tvTargetPricePercent.text =
String.format(getString(R.string.current_price_percent), percent)

binding.tvTargetPricePercent.contentDescription = getString(
R.string.target_price_percent_and_price,
binding.tvTargetPricePercent.text,
binding.tvSetPriceCurrentPrice.text
)

binding.updateSlideValueWithPrice(targetPrice, percent.roundAtFirstDigit())
binding.updateSlideValueWithPrice(targetPrice)
}
}

Expand Down Expand Up @@ -220,14 +210,22 @@ class SetTargetPriceFragment : Fragment() {
}
}

private fun FragmentSetTargetPriceBinding.updateSlideValueWithPrice(
targetPrice: Float,
percent: Int
) {
private fun FragmentSetTargetPriceBinding.updateSlideValueWithPrice(targetPrice: Float) {
val percent =
((targetPrice / setTargetPriceViewModel.state.value.productPrice) * MAX_PERCENT).toInt().roundAtFirstDigit()

val pricePercent = percent.coerceIn(MIN_PERCENT, MAX_PERCENT)
if (targetPrice > setTargetPriceViewModel.state.value.productPrice) {
tvTargetPricePercent.text = getString(R.string.over_current_price)
} else {
tvTargetPricePercent.text =
String.format(getString(R.string.current_price_percent), percent)
}
binding.tvTargetPricePercent.contentDescription = getString(
R.string.target_price_percent_and_price,
binding.tvTargetPricePercent.text,
binding.tvSetPriceCurrentPrice.text
)
slTargetPrice.value = pricePercent.toFloat()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class DetailActivity : AppCompatActivity(), ConfirmDialogFragment.OnDialogResult
intent.putExtra("productCode", productDetailViewModel.productCode)
intent.putExtra("productTitle", productDetailViewModel.state.value.productName)
intent.putExtra("productPrice", productDetailViewModel.state.value.price)
intent.putExtra("productTargetPrice", productDetailViewModel.state.value.targetPrice)
intent.putExtra("isAdding", false)
this@DetailActivity.startActivity(intent)
}
Expand Down
2 changes: 0 additions & 2 deletions android/app/src/main/res/layout/fragment_set_target_price.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
android:layout_height="wrap_content"
android:focusable="true"
android:stepSize="10"
android:value="80"
android:valueFrom="0"
android:valueTo="100"
app:layout_constraintEnd_toStartOf="@id/gl_vertical_end"
Expand All @@ -104,7 +103,6 @@
android:layout_height="wrap_content"
android:gravity="center_vertical|end"
android:paddingHorizontal="16dp"
android:text="@string/target_price_80"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/gl_vertical_end"
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<argument
android:name="isAdding"
app:argType="boolean" />
<argument
android:name="productTargetPrice"
app:argType="integer" />
</fragment>
<fragment
android:id="@+id/registerItemLinkFragment"
Expand Down

0 comments on commit dbcdb92

Please sign in to comment.