refix friendFeed loading
This commit is contained in:
parent
8f3d356502
commit
cefa85ae22
2 changed files with 37 additions and 31 deletions
|
@ -9,6 +9,7 @@ import androidx.compose.material.Card
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
@ -19,6 +20,7 @@ import androidx.compose.ui.unit.dp
|
||||||
import be.ugent.sel.studeez.common.composable.DateText
|
import be.ugent.sel.studeez.common.composable.DateText
|
||||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
||||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
|
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
|
||||||
|
import be.ugent.sel.studeez.common.composable.feed.LoadingFeed
|
||||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
|
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
|
||||||
import be.ugent.sel.studeez.data.local.models.FeedEntry
|
import be.ugent.sel.studeez.data.local.models.FeedEntry
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds
|
import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds
|
||||||
|
@ -31,10 +33,11 @@ fun FriendsFeedRoute(
|
||||||
drawerActions: DrawerActions,
|
drawerActions: DrawerActions,
|
||||||
navigationBarActions: NavigationBarActions
|
navigationBarActions: NavigationBarActions
|
||||||
) {
|
) {
|
||||||
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
FriendsFeedScreen(
|
FriendsFeedScreen(
|
||||||
drawerActions = drawerActions,
|
drawerActions = drawerActions,
|
||||||
navigationBarActions = navigationBarActions,
|
navigationBarActions = navigationBarActions,
|
||||||
viewModel = viewModel
|
uiState = uiState,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,22 +45,21 @@ fun FriendsFeedRoute(
|
||||||
fun FriendsFeedScreen(
|
fun FriendsFeedScreen(
|
||||||
drawerActions: DrawerActions,
|
drawerActions: DrawerActions,
|
||||||
navigationBarActions: NavigationBarActions,
|
navigationBarActions: NavigationBarActions,
|
||||||
viewModel: FriendsFeedViewModel
|
uiState: FriendsFeedUiState,
|
||||||
) {
|
) {
|
||||||
PrimaryScreenTemplate(
|
PrimaryScreenTemplate(
|
||||||
title = resources().getString(AppText.friends_feed),
|
title = resources().getString(AppText.friends_feed),
|
||||||
drawerActions = drawerActions,
|
drawerActions = drawerActions,
|
||||||
navigationBarActions = navigationBarActions
|
navigationBarActions = navigationBarActions
|
||||||
) {
|
) {
|
||||||
|
when (uiState) {
|
||||||
|
FriendsFeedUiState.Loading -> LoadingFeed()
|
||||||
|
is FriendsFeedUiState.Succes -> {
|
||||||
|
val friendsSessions = uiState.friendSessions
|
||||||
|
|
||||||
val friendsSessions = viewModel.getFriendsSessions().collectAsState(initial = emptyList())
|
LazyColumn {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LazyColumn() {
|
|
||||||
// Default Timers, cannot be edited
|
// Default Timers, cannot be edited
|
||||||
items(friendsSessions.value) {
|
items(friendsSessions) {
|
||||||
val (day, feedEntries) = it
|
val (day, feedEntries) = it
|
||||||
DateText(date = day)
|
DateText(date = day)
|
||||||
feedEntries.forEach { (name, feedEntry) ->
|
feedEntries.forEach { (name, feedEntry) ->
|
||||||
|
@ -66,14 +68,14 @@ fun FriendsFeedScreen(
|
||||||
Spacer(modifier = Modifier.height(10.dp))
|
Spacer(modifier = Modifier.height(10.dp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FriendsFeedEntry(
|
fun FriendsFeedEntry(
|
||||||
name: String,
|
name: String, feedEntry: FeedEntry
|
||||||
feedEntry: FeedEntry
|
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
@ -120,11 +122,12 @@ fun FriendsFeedEntry(
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = HoursMinutesSeconds(feedEntry.totalStudyTime).toString(),
|
text = HoursMinutesSeconds(feedEntry.totalStudyTime).toString(),
|
||||||
modifier = Modifier.weight(3f).padding(start = 5.dp),
|
modifier = Modifier
|
||||||
|
.weight(3f)
|
||||||
|
.padding(start = 5.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,27 +1,30 @@
|
||||||
package be.ugent.sel.studeez.screens.friends_feed
|
package be.ugent.sel.studeez.screens.friends_feed
|
||||||
|
|
||||||
import be.ugent.sel.studeez.data.local.models.FeedEntry
|
import androidx.lifecycle.viewModelScope
|
||||||
import be.ugent.sel.studeez.data.local.models.task.Task
|
|
||||||
import be.ugent.sel.studeez.domain.FeedDAO
|
import be.ugent.sel.studeez.domain.FeedDAO
|
||||||
import be.ugent.sel.studeez.domain.LogService
|
import be.ugent.sel.studeez.domain.LogService
|
||||||
import be.ugent.sel.studeez.domain.SessionDAO
|
|
||||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class FriendsFeedViewModel @Inject constructor(
|
class FriendsFeedViewModel @Inject constructor(
|
||||||
private val feedDAO: FeedDAO,
|
feedDAO: FeedDAO,
|
||||||
logService: LogService
|
logService: LogService
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
fun getFriendsSessions(): Flow<List<Pair<String, List<Pair<String, FeedEntry>>>>> {
|
val uiState: StateFlow<FriendsFeedUiState> =
|
||||||
return feedDAO.getFriendsSessions().map { it.toList() }
|
feedDAO.getFriendsSessions()
|
||||||
}
|
.map { it.toList() }
|
||||||
|
.map { FriendsFeedUiState.Succes(it) }
|
||||||
|
.stateIn(
|
||||||
|
scope = viewModelScope,
|
||||||
|
initialValue = FriendsFeedUiState.Loading,
|
||||||
|
started = SharingStarted.Eagerly,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue