parent
62c269cac2
commit
b95b77bcb9
|
@ -26,6 +26,7 @@ import kr.co.vividnext.sodalive.common.LoadingDialog
|
|||
import kr.co.vividnext.sodalive.databinding.FragmentRouletteSettingsBinding
|
||||
import kr.co.vividnext.sodalive.live.roulette.RoulettePreviewDialog
|
||||
import org.koin.android.ext.android.inject
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
||||
|
@ -103,6 +104,7 @@ class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun bindData() {
|
||||
viewModel.selectedRouletteLiveData.observe(viewLifecycleOwner) {
|
||||
deselectAllRoulette()
|
||||
|
@ -162,6 +164,16 @@ class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
|||
).show()
|
||||
}
|
||||
|
||||
viewModel.totalPercentageLiveData.observe(viewLifecycleOwner) {
|
||||
binding.tvTotalPercentage.text = "( ${
|
||||
String.format(
|
||||
Locale.KOREAN,
|
||||
"%.2f%%",
|
||||
it
|
||||
)
|
||||
} )"
|
||||
}
|
||||
|
||||
compositeDisposable.add(
|
||||
binding.etSetPrice.textChanges().skip(1)
|
||||
.debounce(100, TimeUnit.MILLISECONDS)
|
||||
|
|
|
@ -47,6 +47,10 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
|||
val selectedRouletteLiveData: LiveData<SelectedRoulette>
|
||||
get() = _selectedRouletteLiveData
|
||||
|
||||
private val _totalPercentageLiveData = MutableLiveData(0f)
|
||||
val totalPercentageLiveData: LiveData<Float>
|
||||
get() = _totalPercentageLiveData
|
||||
|
||||
var can = 0
|
||||
var isActive = false
|
||||
private var rouletteId = 0L
|
||||
|
@ -58,6 +62,7 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
|||
if (options.size >= 10) return
|
||||
options.add(newOption)
|
||||
_optionsLiveData.value = options
|
||||
calculateTotalPercentage()
|
||||
}
|
||||
|
||||
fun deleteOption(index: Int) {
|
||||
|
@ -74,6 +79,7 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
|||
fun inputOptionPercentage(optionIndex: Int, percentage: String) {
|
||||
val currentOption = options[optionIndex]
|
||||
options[optionIndex] = currentOption.copy(percentage = percentage)
|
||||
calculateTotalPercentage()
|
||||
}
|
||||
|
||||
fun toggleIsActive() {
|
||||
|
@ -339,15 +345,30 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
|||
isActive = false
|
||||
|
||||
options.clear()
|
||||
options.add(RouletteOption(title = "", percentage = "50.00"))
|
||||
options.add(RouletteOption(title = "", percentage = "50.00"))
|
||||
options.add(RouletteOption(title = "", percentage = ""))
|
||||
options.add(RouletteOption(title = "", percentage = ""))
|
||||
_optionsLiveData.value = options
|
||||
}
|
||||
|
||||
calculateTotalPercentage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeAllAndAddOptions(options: List<RouletteOption>) {
|
||||
this.options.clear()
|
||||
this.options.addAll(options)
|
||||
calculateTotalPercentage()
|
||||
}
|
||||
|
||||
private fun calculateTotalPercentage() {
|
||||
val totalPercent = options.map {
|
||||
try {
|
||||
it.percentage.toFloat()
|
||||
} catch (e: Exception) {
|
||||
0f
|
||||
}
|
||||
}.sum()
|
||||
|
||||
_totalPercentageLiveData.value = totalPercent
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,11 +219,37 @@
|
|||
android:src="@drawable/btn_add" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="21.3dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="옵션 확률 합계"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textSize="14.7sp"
|
||||
tools:ignore="RelativeOverlap" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_total_percentage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textSize="14.7sp"
|
||||
tools:text="( 100.00% )" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_roulette_option_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="21.3dp"
|
||||
android:orientation="vertical" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
Loading…
Reference in New Issue