Skip to content

Commit

Permalink
Fix first server add crash (#88)
Browse files Browse the repository at this point in the history
Closes #87
  • Loading branch information
siper committed Jun 2, 2024
1 parent 17fbdca commit 7903b25
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
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

0 comments on commit 7903b25

Please sign in to comment.