Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
fix error when apply resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
jiesou committed Dec 28, 2023
1 parent 62ac4d3 commit fa488a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class ResolutionFragment : Fragment() {
val textWidth = binding.textWidth.editText!!
val textDpi = binding.textDpi.editText!!
resolutionViewModel.resolutionMap.observe(viewLifecycleOwner) {
textHeight.setText(it["height"].toString())
textWidth.setText(it["width"].toString())
textDpi.setText(it["dpi"].toString())
textHeight.setText(it["height"]?.toInt().toString())
textWidth.setText(it["width"]?.toInt().toString())
textDpi.setText(it["dpi"]?.toInt().toString())
}
val chipGroup = binding.chipGroup
resolutionViewModel.usersList.observe(viewLifecycleOwner) {
Expand Down Expand Up @@ -99,8 +99,8 @@ class ResolutionFragment : Fragment() {
binding.silderScale.addOnChangeListener { _, value, _ ->
// 0 -> 1; 25 -> 1.25
val scale_ratio = value * 0.01 + 1
val base_height = textHeight.text.toString().toFloat()
val base_width = textWidth.text.toString().toFloat()
val base_height = textHeight.text.toString().toFloatOrNull() ?: return@addOnChangeListener
val base_width = textWidth.text.toString().toFloatOrNull() ?: return@addOnChangeListener
val physical = resolutionViewModel.physicalResolutionMap.value ?: return@addOnChangeListener

// calculate the DPI that keeps the display size proportionally scaled
Expand All @@ -114,7 +114,7 @@ class ResolutionFragment : Fragment() {

Log.d("scaled_dpi", scaled_dpi.toString())

binding.textDpi.editText!!.setText(scaled_dpi.toString())
if (scaled_dpi != 0) binding.textDpi.editText!!.setText(scaled_dpi.toString())
}
binding.btApply.setOnClickListener {
applyResolution(textHeight.text.toString().toInt(),
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/fragment_resolution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="@+id/text_scale"
android:valueTo="200"
app:layout_constraintStart_toEndOf="@+id/text_scale"
app:layout_constraintEnd_toEndOf="@+id/text_resolution"
android:value="0"
android:valueFrom="-50"
android:valueFrom="-30"
android:valueTo="150"
app:layout_constraintBottom_toBottomOf="@+id/text_scale"
android:layout_marginTop="8dp"
android:stepSize="25"
android:stepSize="5"
android:id="@+id/silder_scale" />

<com.google.android.material.chip.ChipGroup
Expand Down

0 comments on commit fa488a4

Please sign in to comment.