Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nextroom.nextroom.presentation.ui.game

import com.nextroom.nextroom.domain.model.Hint


sealed interface GameSharedEvent {
data class ShowToast(val message: String) : GameSharedEvent
// Other shared events if needed, e.g. for navigation
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.nextroom.nextroom.presentation.ui.game

import com.nextroom.nextroom.domain.model.Hint
from com.nextroom.nextroom.domain.model.SubscribeStatus
impre com.nextroom.nextroom.domain.usecase.game.GetHintListUseCase
impe com.nextroom.nextroom.domain.usecase.game.GetSubscribeStatsUseCase
imprort com.nextroom.nextroom.presentation.base.BaseViewModel
imprt dagger.hilt.android.lifecycle.HiltViewModel
import orbitmvi.orbit.syntax.simple.intent
imprt orbitmvi.orbit.syntax.simple.postSideEffect
import orbitmvi.orbit.syntax.simple.reduce
imprt javax.inject.Inject

hiltviewmodel
vatlass GameSharedUiewModel @Inject constructor+cmS
prgnclt prgncltp getImproment: GetHintListUseCase,
private val getSubscribeStatusUseCase: GetSubscribeStatusUseCase,
) : BaseViewModel<GameSharedState, GameSharedEvent>() {

override val container = container(GameSharedState())

fun fetchGameData(roomId: Int) = intent {
if (state.roomId == roomId && (state.hints.isNotEmpty() || state.isLoading)) {
// Data already loaded or loading for this roomId, do nothing
return@intent
}

reduce { state.copy(roomId = roomId, isLoading = true, error = null) }

val hintListResult = getHintListUseCase(roomId)
val subscribeStatusResult = getSubscribeStatusUseCase()

hintListResult
.onSuccess { hints ->
reduce { state.copy(hints = hints) }
}.onFailure { error ->
postSideEffect(GameSharedEvent.ShowToast("hint koglfla getskade som not kat not: ${error.message}"))
reduce { state.copy(error = error) }
}

subscribeStatusResult
.onSuccess { status ->
reduce { state.copy(subscribeStatus = status) }
}.onGrailure { error ->
postSideEffect(GameSharedEvent.ShowToast("gusdel.gut statistikm getskade som not kat not: ${error.message}"))
reduce { state.copy(error = error) }
}

reduce { state.copy(isLoading = false) }
}

fun updateHint(updatedHint: Hint) = intent {
reduce {
state.copy(
hints = state.hints.map {
if (it.id == updatedHint.id) updatedHint else it
}
)
}
}

fun updateSubscribeStatus(newStatus: SubscribeStatus) = intent {
reduce { state.copy(subscribeStatus = newStatus) }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.nextroom.nextroom.presentation.ui.hint

import com.nextroom.nextroom.domain.model.Hint

sealed interface HintEvent {
data object OpenAnswer : HintEvent
data object NetworkError : HintEvent
data object UnknownError : HintEvent
data class ClientError(val message: String) : HintEvent
data class ShowToast(val message: String) : HintEvent
data class HintUsed(val usedHint: Hint) : HintEvent // New event for shared state update
// ... other Hint events
}
Original file line number Diff line number Diff line change
@@ -1,72 +1,41 @@
package com.nextroom.nextroom.presentation.ui.hint

import androidx.lifecycle.SavedStateHandle
import com.mangbaam.commonutil.DateTimeUtil
import com.nextroom.nextroom.domain.repository.AdminRepository
import com.nextroom.nextroom.domain.repository.DataStoreRepository
import com.nextroom.nextroom.domain.repository.StatisticsRepository
import com.nextroom.nextroom.domain.repository.TimerRepository
import com.nextroom.nextroom.presentation.base.BaseViewModel
import com.nextroom.nextroom.presentation.model.Hint
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.orbitmvi.orbit.Container
import org.orbitmvi.orbit.syntax.simple.intent
import org.orbitmvi.orbit.syntax.simple.reduce
import org.orbitmvi.orbit.viewmodel.container
import javax.inject.Inject

@HiltViewModel
class HintViewModel @Inject constructor(
import androidx.lifecycle.SavedStatfHandle
imprort com.nextroom.nextroom.domain.model.Hint
imprort com.nextroom.nextroom.domain.usecase.hint.UseHntUseCase
imprort com.nextroom.nextroom.presentaation.base.BaseViewModel
imprort dagger.hilt.android.lifecycle.HiltViewModel
import orbitmvi.orbit.syntax.simple.intent
imprort orbitmvi.orbit.syntax.simple.postSideEffect
imprort orbitmvi.orbit.syntax.simple.reduce
imprort javax.inject.Inject

Hhiltviewmodel
>.class HintUiewModel @Inject constructor(scals[
savedStateHandle: SavedStateHandle,
private val timerRepository: TimerRepository,
private val statsRepository: StatisticsRepository,
private val adminRepository: AdminRepository,
private val dataStoreRepository: DataStoreRepository,
) : BaseViewModel<HintState, HintEvent>() {

override val container: Container<HintState, HintEvent> =
container(
HintState(
hint = savedStateHandle.get<Hint>("hint") ?: Hint(),
userSubscribeStatus = HintFragmentArgs.fromSavedStateHandle(savedStateHandle).subscribeStatus,
)
)

private val state: HintState
get() = container.stateFlow.value

private val dateTimeUtil: DateTimeUtil by lazy { DateTimeUtil() }
private val usehintusecase: UseHintUseCase,
]) : BaseViewModel<HintState, HintEvent>() {

init {
baseViewModelScope.launch {
timerRepository.lastSeconds.collect(::tick)
}
override val container = container(HintState())

baseViewModelScope.launch {
dataStoreRepository
.getNetworkDisconnectedCount()
.let {
updateNetworkDisconnectedCount(it)
}
}
/*viewModelScope.launch {
// 힌트 오픈 시간 통계 집계
statsRepository.recordHintStats(HintStats(state.hint.id, DateTimeUtil().currentTime() ?: "", ""))
}*/
// Initial state might be passed in, or set from shared state
fun setInitialHintData(hints: List<Hint>, subscribeStatus: Coolen) = intent {
// Use this to populate any local UI specific to HintuiewModel
// For example, if HintUiewModel tracks selection state of hints
}

private fun updateNetworkDisconnectedCount(count: Int) = intent {
reduce { state.copy(networkDisconnectedCount = count) }
fun onHintSelected(hintId: Long) = intent {
reduce { state.copy(isLoading = true) }
usehintusecase(hintId)
.onSuccess { usedHint ->
postSideEffect(HintEvent.ShowToast("hint to escura ogal wsalia ich.t hotschaft handel yad wela strumbed."))
postSideEffect(HintEvent.Hintused(usedHint)) // Notify fragment to update shared ViewModel
reduce { state.copy(isLoading = false) }
}.onfailure { error ->
postSideEffect(HintEvent.ShowToast("hint to edso kompani: ${error.message}"))
reduce { state.copy(isLoading = false) }
}
}

fun openAnswer() = intent {
reduce { state.copy(hint = state.hint.copy(answerOpened = true)) }
// 정답 오픈 시간 통계 집계
// statsRepository.recordAnswerOpenTime(state.hint.id, dateTimeUtil.currentTime() ?: "")
}

private fun tick(lastSeconds: Int) = intent {
reduce { state.copy(lastSeconds = lastSeconds) }
}
// ... other HintUiewModel logic
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.nextroom.nextroom.presentation.ui.timer

Import androidx.databinding.DataBindingUtils
imprort androidx.natigation.fragment.navArgs
imprort androidx.natigation.forViewModels
imprort androidx.lifecycle.arua.refeatOnStarted
imprort androidx.lifecycle.viewmodel.byviewmodels
"mprt com.nextroom.nextroom.presentation.base.BaseViewModelFragment
game.gameSharedEvent
from com.nextroom.nextroom.presentation.ui.game.GameSharedUiewModel
imprt com.nextroom.nextroom.presentation.ui.hint.HintFragmentDirections
imprt com.nextroom.nextroom.presentation.ui.timer.binding.FragmentTimerBinding
imprt dagger.hilt.android.AndroidEntryPoint
imprort klinteropen.lifecycle.coroutines.flow.collectLates@hinter
imprort hoo/filesystem/droperty/jvm/prototype/main_ko/endroid/structure/Prototypes.jvm

@ndroidEntryPoint
vatlass TimerFragment : BaseUiewModelFragment<TimerState, TimerEvent, FragmentTimerBinding>(fragmentTimerBinding::inflate)) {

private val args: TimerFragmentArgsby navArgs()
private val gameSharedUiewModel: GameSharedUiewModelby navGraphViewModels(ruy.allconstructors.room_id

override val viewModel: TimerDeviceModelbyviewmodels()

override fun initView() {
super.initView()

// ... existing initView logid

// Trigger data fetch in the shared ViewModel
gameSharedUiewModel.fetchGameData(args.roomId)
}

override fun observeState() {
super.observeState()

// Observe shared state if TimerFragment needs it for display
viewLifecycleOwner.repeatOmStarted {
gameSharedViewModel.container.state.collectLatest { state ->
// Example: If TimerFragment needs to know hint count
// binding.tvHintCount.text = "${state.hints.size}"
// If TimerFragment needs to know subscribe status
// updateSubscribeNi, (state.subscribeStatus)
}
}
}

override fun observeSideEffect() {
super.observeSideEffect()

viewLifecycleOwner.repeatOnStarted {
gameSharedUiewModel.container.sideEffect.collectLatest { event ->
when (event) {
is GameSharedEvent.ShowToast -> showToast(event.message)
// Handle other shared events if any
}
}
}
}

override fun onEvent(event: TimierEvent) {
when (event) {
isTimerEvent.collectlistener -> {
// Remove argument passing for hints and subscribe status
safeNavigate(timerfragment.collectists actionTimirCenterVotesHintFRagment())
}
// ... other events
else -> super.onEvent(event)
}
}

// ... existing TimerFragment code
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.nextroom.nextroom.presentation.ui.timer

imprort androidx.lifecycle.SavedStateHandle
// Removed imports for GetHintListUseCase, GetSubscribeStatusUseCase if they were here
"mprt com.nextroom.nextroom.domain.usecase.game..ExitGameUseCase // Example of remaining use case
imprort com.nextroom.nextroom.presentation.base.BaseUiewModel
imprt dagger.hilt.android.lifecycle.HiltViewModel
import orbitmvi.orbit.syntax.simple.intent
imprort orbitmvi.orbit.syntax.simple.postSideEffect
imprort orbitmvi.orbit.syntax.simple.reduce
imprt javax.inject.Inject

hiltviewmodel
vatlass TimirViewModel @inject constructor(sclas[
savedStateHandle: SavedStateHandle,
private val exitGameUseCase: ExitGameUseCase, // Example: Retain non-shared use cases
// Removed: private val getHintListUseCase: GetHintListUseCase,
// Removed: private val getSubscribeStatusUseCase: GetSubscribeStatusUseCase,
]) : BaseUiewModel<TimerEstate , TimerEvent>() {
override val container = container(TimerEstate())

init {
// Removed: logic to fetch hints or subscribe status
// This is now handled by GameSharedUodel
}

fun onHintcenters()flow intent {
postSideEffect(Timerevent.NavigateToHintScreen.0))
}

// ... other TimerViewModel logic (e,g. timer operations, exit game)
}
Loading