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.databinding.FragmentRouletteSettingsBinding
|
||||||
import kr.co.vividnext.sodalive.live.roulette.RoulettePreviewDialog
|
import kr.co.vividnext.sodalive.live.roulette.RoulettePreviewDialog
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
|
import java.util.Locale
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
||||||
|
@ -103,6 +104,7 @@ class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
private fun bindData() {
|
private fun bindData() {
|
||||||
viewModel.selectedRouletteLiveData.observe(viewLifecycleOwner) {
|
viewModel.selectedRouletteLiveData.observe(viewLifecycleOwner) {
|
||||||
deselectAllRoulette()
|
deselectAllRoulette()
|
||||||
|
@ -162,6 +164,16 @@ class RouletteSettingsFragment : BaseFragment<FragmentRouletteSettingsBinding>(
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.totalPercentageLiveData.observe(viewLifecycleOwner) {
|
||||||
|
binding.tvTotalPercentage.text = "( ${
|
||||||
|
String.format(
|
||||||
|
Locale.KOREAN,
|
||||||
|
"%.2f%%",
|
||||||
|
it
|
||||||
|
)
|
||||||
|
} )"
|
||||||
|
}
|
||||||
|
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
binding.etSetPrice.textChanges().skip(1)
|
binding.etSetPrice.textChanges().skip(1)
|
||||||
.debounce(100, TimeUnit.MILLISECONDS)
|
.debounce(100, TimeUnit.MILLISECONDS)
|
||||||
|
|
|
@ -47,6 +47,10 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
||||||
val selectedRouletteLiveData: LiveData<SelectedRoulette>
|
val selectedRouletteLiveData: LiveData<SelectedRoulette>
|
||||||
get() = _selectedRouletteLiveData
|
get() = _selectedRouletteLiveData
|
||||||
|
|
||||||
|
private val _totalPercentageLiveData = MutableLiveData(0f)
|
||||||
|
val totalPercentageLiveData: LiveData<Float>
|
||||||
|
get() = _totalPercentageLiveData
|
||||||
|
|
||||||
var can = 0
|
var can = 0
|
||||||
var isActive = false
|
var isActive = false
|
||||||
private var rouletteId = 0L
|
private var rouletteId = 0L
|
||||||
|
@ -58,6 +62,7 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
||||||
if (options.size >= 10) return
|
if (options.size >= 10) return
|
||||||
options.add(newOption)
|
options.add(newOption)
|
||||||
_optionsLiveData.value = options
|
_optionsLiveData.value = options
|
||||||
|
calculateTotalPercentage()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteOption(index: Int) {
|
fun deleteOption(index: Int) {
|
||||||
|
@ -74,6 +79,7 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
||||||
fun inputOptionPercentage(optionIndex: Int, percentage: String) {
|
fun inputOptionPercentage(optionIndex: Int, percentage: String) {
|
||||||
val currentOption = options[optionIndex]
|
val currentOption = options[optionIndex]
|
||||||
options[optionIndex] = currentOption.copy(percentage = percentage)
|
options[optionIndex] = currentOption.copy(percentage = percentage)
|
||||||
|
calculateTotalPercentage()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleIsActive() {
|
fun toggleIsActive() {
|
||||||
|
@ -339,15 +345,30 @@ class RouletteSettingsViewModel(private val repository: RouletteRepository) : Ba
|
||||||
isActive = false
|
isActive = false
|
||||||
|
|
||||||
options.clear()
|
options.clear()
|
||||||
options.add(RouletteOption(title = "", percentage = "50.00"))
|
options.add(RouletteOption(title = "", percentage = ""))
|
||||||
options.add(RouletteOption(title = "", percentage = "50.00"))
|
options.add(RouletteOption(title = "", percentage = ""))
|
||||||
_optionsLiveData.value = options
|
_optionsLiveData.value = options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calculateTotalPercentage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeAllAndAddOptions(options: List<RouletteOption>) {
|
private fun removeAllAndAddOptions(options: List<RouletteOption>) {
|
||||||
this.options.clear()
|
this.options.clear()
|
||||||
this.options.addAll(options)
|
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" />
|
android:src="@drawable/btn_add" />
|
||||||
</RelativeLayout>
|
</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
|
<LinearLayout
|
||||||
android:id="@+id/ll_roulette_option_container"
|
android:id="@+id/ll_roulette_option_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="21.3dp"
|
|
||||||
android:orientation="vertical" />
|
android:orientation="vertical" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
Loading…
Reference in New Issue