룰렛 최대 개수 수정
AS-IS : 최대 6개 TO-BE : 최대 10개 룰렛 확률 수정 AS-IS : 소수점 없음 TO-BE : 소수점 2자리
This commit is contained in:
parent
8a7406aa22
commit
5634e0787f
|
@ -34,6 +34,7 @@ import okhttp3.MultipartBody
|
|||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import java.io.File
|
||||
import kotlin.math.floor
|
||||
|
||||
class LiveRoomViewModel(
|
||||
private val repository: LiveRepository,
|
||||
|
@ -922,9 +923,10 @@ class LiveRoomViewModel(
|
|||
private fun calculatePercentages(options: List<RouletteItem>): List<RoulettePreviewItem> {
|
||||
val totalWeight = options.sumOf { it.weight }
|
||||
val updatedOptions = options.asSequence().map { option ->
|
||||
val percent = floor(option.weight.toDouble() / totalWeight * 10000) / 100
|
||||
RoulettePreviewItem(
|
||||
title = option.title,
|
||||
percent = "${(option.weight.toDouble() / totalWeight * 100).toInt()}%"
|
||||
percent = "${String.format("%.2f", percent)}%"
|
||||
)
|
||||
}.toList()
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ class RouletteView @JvmOverloads constructor(
|
|||
Color.parseColor("#8FCEEA"),
|
||||
Color.parseColor("#CD5880"),
|
||||
Color.parseColor("#C2C85E"),
|
||||
Color.parseColor("#000000"),
|
||||
Color.parseColor("#888888"),
|
||||
Color.parseColor("#FFFFFF"),
|
||||
Color.parseColor("#000080"),
|
||||
)
|
||||
|
||||
init {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package kr.co.vividnext.sodalive.live.roulette.config
|
||||
|
||||
data class RouletteOption(var title: String, var weight: Int, var percentage: Int = 50)
|
||||
data class RouletteOption(var title: String, var weight: Int, var percentage: String = "50.00")
|
||||
|
|
|
@ -11,6 +11,7 @@ import kr.co.vividnext.sodalive.live.roulette.RouletteItem
|
|||
import kr.co.vividnext.sodalive.live.roulette.RoulettePreview
|
||||
import kr.co.vividnext.sodalive.live.roulette.RoulettePreviewItem
|
||||
import kr.co.vividnext.sodalive.live.roulette.RouletteRepository
|
||||
import kotlin.math.floor
|
||||
|
||||
class RouletteSettingsViewModel(private val repository: RouletteRepository) : BaseViewModel() {
|
||||
|
||||
|
@ -57,7 +58,7 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
|||
}
|
||||
|
||||
fun addOption(newOption: RouletteOption) {
|
||||
if (options.size >= 6) return
|
||||
if (options.size >= 10) return
|
||||
|
||||
options.add(newOption)
|
||||
recalculatePercentages(options)
|
||||
|
@ -77,7 +78,8 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
|||
private fun recalculatePercentages(options: List<RouletteOption>) {
|
||||
val totalWeight = options.sumOf { it.weight }
|
||||
val updatedOptions = options.asSequence().map { option ->
|
||||
option.copy(percentage = (option.weight.toDouble() / totalWeight * 100).toInt())
|
||||
val percent = floor(option.weight.toDouble() / totalWeight * 10000) / 100
|
||||
option.copy(percentage = String.format("%.2f", percent))
|
||||
}.toList()
|
||||
|
||||
removeAllAndAddOptions(updatedOptions)
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:text="※ 룰렛 옵션은 최소 2개,\n최대 6개까지 설정할 수 있습니다."
|
||||
android:text="※ 룰렛 옵션은 최소 2개,\n최대 10개까지 설정할 수 있습니다."
|
||||
android:textColor="@color/color_ff5c49"
|
||||
android:textSize="13.3sp" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue