Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GrakovNe committed Dec 1, 2024
1 parent 1e6714b commit 610cf82
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fun LibraryScreen(
var pullRefreshing by remember { mutableStateOf(false) }
val recentBookRefreshing by libraryViewModel.recentBookUpdating.observeAsState(false)
val searchRequested by libraryViewModel.searchRequested.observeAsState(false)
val preparingError by playerViewModel.preparingError.observeAsState(false)

val library = when (searchRequested) {
true -> libraryViewModel.searchPager.collectAsLazyPagingItems()
Expand Down Expand Up @@ -131,6 +132,12 @@ fun LibraryScreen(
refreshContent(false)
}

LaunchedEffect(preparingError) {
if (preparingError) {
playerViewModel.clearPlayingBook()
}
}

val pullRefreshState = rememberPullRefreshState(
refreshing = pullRefreshing,
onRefresh = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.grakovne.lissen.R
import org.grakovne.lissen.ui.icons.Search
import org.grakovne.lissen.ui.navigation.AppNavigationService
import org.grakovne.lissen.viewmodel.ContentCachingModelView
import org.grakovne.lissen.viewmodel.LibraryViewModel
import org.grakovne.lissen.viewmodel.PlayerViewModel

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.MenuBook
import androidx.compose.material.icons.automirrored.outlined.MenuOpen
import androidx.compose.material.icons.automirrored.outlined.PlaylistPlay
import androidx.compose.material.icons.outlined.Book
import androidx.compose.material.icons.outlined.Checklist
import androidx.compose.material.icons.outlined.CloudDownload
import androidx.compose.material.icons.outlined.LocalPlay
import androidx.compose.material.icons.outlined.MenuOpen
import androidx.compose.material.icons.outlined.PlayCircleOutline
import androidx.compose.material.icons.outlined.PlayForWork
import androidx.compose.material.icons.outlined.PlayLesson
import androidx.compose.material.icons.outlined.PlaylistAddCircle
import androidx.compose.material.icons.outlined.PlaylistPlay
import androidx.compose.material.icons.outlined.SlowMotionVideo
import androidx.compose.material.icons.outlined.Sync
import androidx.compose.material.icons.outlined.Timer
import androidx.compose.material.icons.rounded.Book
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PlayerViewModel @Inject constructor(

val isPlaybackReady: LiveData<Boolean> = mediaRepository.isPlaybackReady
val playbackSpeed: LiveData<Float> = mediaRepository.playbackSpeed
val preparingError: LiveData<Boolean> = mediaRepository.mediaPreparingError

private val _searchRequested = MutableLiveData(false)
val searchRequested: LiveData<Boolean> = _searchRequested
Expand Down Expand Up @@ -104,6 +105,7 @@ class PlayerViewModel @Inject constructor(
fun togglePlayPause() = mediaRepository.togglePlayPause()

companion object {

private const val EMPTY_SEARCH = ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class MediaRepository @Inject constructor(
private val _playingBook = MutableLiveData<DetailedItem?>()
val playingBook: LiveData<DetailedItem?> = _playingBook

private val _mediaPreparingError = MutableLiveData<Boolean>()
val mediaPreparingError: LiveData<Boolean> = _mediaPreparingError

private val _playbackSpeed = MutableLiveData(preferences.getPlaybackSpeed())
val playbackSpeed: LiveData<Float> = _playbackSpeed

Expand Down Expand Up @@ -279,7 +282,7 @@ class MediaRepository @Inject constructor(
.fetchBook(bookId)
.foldAsync(
onSuccess = { startPreparingPlayback(it, fromBackground) },
onFailure = {},
onFailure = { _mediaPreparingError.postValue(true) },
)
}
}
Expand Down Expand Up @@ -349,6 +352,7 @@ class MediaRepository @Inject constructor(
.value
?.let { updateTimer(timerOption = null) }

_mediaPreparingError.postValue(false)
_isPlaybackReady.postValue(false)
}

Expand Down

0 comments on commit 610cf82

Please sign in to comment.