Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix first server add crash #88

Merged
merged 1 commit into from
Jun 2, 2024
Merged
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
@@ -1,11 +1,16 @@
package ru.stersh.youamp.main.data

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import ru.stersh.youamp.core.room.server.SubsonicServerDao
import ru.stersh.youamp.main.domain.ServerExistRepository

internal class ServerExistRepositoryImpl(private val serverDao: SubsonicServerDao) :
ServerExistRepository {
override suspend fun hasServer(): Boolean {
return serverDao.getCount() > 0

override suspend fun hasServer(): Flow<Boolean> {
return serverDao
.flowActive()
.map { it != null }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.stersh.youamp.main.domain

import kotlinx.coroutines.flow.Flow

internal interface ServerExistRepository {
suspend fun hasServer(): Boolean
suspend fun hasServer(): Flow<Boolean>
}
2 changes: 1 addition & 1 deletion app/src/main/java/ru/stersh/youamp/main/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MainActivity : ComponentActivity() {
MainScreen.AddServer -> {
ServerScreen(
onBackClick = { rootNavController.popBackStack() },
onCloseScreen = { rootNavController.navigate(Main) }
onCloseScreen = {}
)
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/ru/stersh/youamp/main/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import ru.stersh.youamp.main.domain.AvatarUrlRepository
import ru.stersh.youamp.main.domain.ServerExistRepository
Expand All @@ -22,7 +21,7 @@ internal class MainViewModel(
init {
viewModelScope.launch {
combine(
flowOf(serverExistRepository.hasServer()),
serverExistRepository.hasServer(),
avatarUrlRepository.getAvatarUrl()
) { hasServer, avatarUrl ->
return@combine StateUi(
Expand Down