feat: auth screen with auto-redirect, sync favorites/history with backend

This commit is contained in:
nk
2026-06-02 19:12:07 +03:00
parent d4adb1e7be
commit a83672b455
2934 changed files with 97351 additions and 163 deletions

View File

@@ -3,7 +3,12 @@ package com.radiola.ui.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.radiola.domain.model.DeeplinkService
import com.radiola.domain.model.StationTestResult
import com.radiola.domain.repository.SettingsRepository
import com.radiola.domain.usecase.TestStationsUseCase
import com.radiola.domain.usecase.auth.GetAuthStateUseCase
import com.radiola.domain.usecase.auth.GetCurrentUserUseCase
import com.radiola.domain.usecase.auth.LogoutUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
@@ -11,7 +16,11 @@ import javax.inject.Inject
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val settingsRepository: SettingsRepository
private val settingsRepository: SettingsRepository,
private val testStationsUseCase: TestStationsUseCase,
getAuthStateUseCase: GetAuthStateUseCase,
getCurrentUserUseCase: GetCurrentUserUseCase,
private val logoutUseCase: LogoutUseCase
) : ViewModel() {
val sleepTimerMinutes: StateFlow<Int> = settingsRepository.getSleepTimerMinutes()
@@ -26,6 +35,24 @@ class SettingsViewModel @Inject constructor(
val isRecordingEnabled: StateFlow<Boolean> = settingsRepository.isRecordingEnabled()
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), false)
val isLoggedIn: StateFlow<Boolean> = getAuthStateUseCase()
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), false)
val currentUser = getCurrentUserUseCase()
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), null)
private val _isTesting = MutableStateFlow(false)
val isTesting: StateFlow<Boolean> = _isTesting.asStateFlow()
private val _testProgress = MutableStateFlow(0)
val testProgress: StateFlow<Int> = _testProgress.asStateFlow()
private val _testTotal = MutableStateFlow(0)
val testTotal: StateFlow<Int> = _testTotal.asStateFlow()
private val _testResults = MutableStateFlow<List<StationTestResult>>(emptyList())
val testResults: StateFlow<List<StationTestResult>> = _testResults.asStateFlow()
fun setSleepTimer(minutes: Int) {
viewModelScope.launch { settingsRepository.setSleepTimerMinutes(minutes) }
}
@@ -45,4 +72,30 @@ class SettingsViewModel @Inject constructor(
fun setRecordingEnabled(enabled: Boolean) {
viewModelScope.launch { settingsRepository.setRecordingEnabled(enabled) }
}
fun startTesting() {
viewModelScope.launch {
_isTesting.value = true
_testProgress.value = 0
_testTotal.value = 0
_testResults.value = emptyList()
val results = mutableListOf<StationTestResult>()
testStationsUseCase().collect { progress ->
_testProgress.value = progress.current
_testTotal.value = progress.total
progress.result?.let { results.add(it) }
}
_testResults.value = results
_isTesting.value = false
}
}
fun clearTestResults() {
_testResults.value = emptyList()
}
fun logout() {
viewModelScope.launch { logoutUseCase() }
}
}