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.runtime.Composable | ||||
| import androidx.compose.runtime.collectAsState | ||||
| import androidx.compose.runtime.getValue | ||||
| import androidx.compose.ui.Alignment | ||||
| import androidx.compose.ui.Modifier | ||||
| 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.PrimaryScreenTemplate | ||||
| 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.data.local.models.FeedEntry | ||||
| import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | ||||
|  | @ -31,10 +33,11 @@ fun FriendsFeedRoute( | |||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions | ||||
| ) { | ||||
|     val uiState by viewModel.uiState.collectAsState() | ||||
|     FriendsFeedScreen( | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions, | ||||
|         viewModel = viewModel | ||||
|         uiState = uiState, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
|  | @ -42,22 +45,21 @@ fun FriendsFeedRoute( | |||
| fun FriendsFeedScreen( | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
|     viewModel: FriendsFeedViewModel | ||||
|     uiState: FriendsFeedUiState, | ||||
| ) { | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(AppText.friends_feed), | ||||
|         drawerActions = drawerActions, | ||||
|         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 | ||||
|             items(friendsSessions.value) { | ||||
|                     items(friendsSessions) { | ||||
|                         val (day, feedEntries) = it | ||||
|                         DateText(date = day) | ||||
|                         feedEntries.forEach { (name, feedEntry) -> | ||||
|  | @ -66,14 +68,14 @@ fun FriendsFeedScreen( | |||
|                         Spacer(modifier = Modifier.height(10.dp)) | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun FriendsFeedEntry( | ||||
|     name: String, | ||||
|     feedEntry: FeedEntry | ||||
|     name: String, feedEntry: FeedEntry | ||||
| ) { | ||||
|     Card( | ||||
|         modifier = Modifier | ||||
|  | @ -120,11 +122,12 @@ fun FriendsFeedEntry( | |||
|                     } | ||||
|                     Text( | ||||
|                         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 | ||||
| 
 | ||||
| import be.ugent.sel.studeez.data.local.models.FeedEntry | ||||
| import be.ugent.sel.studeez.data.local.models.task.Task | ||||
| import androidx.lifecycle.viewModelScope | ||||
| import be.ugent.sel.studeez.domain.FeedDAO | ||||
| import be.ugent.sel.studeez.domain.LogService | ||||
| import be.ugent.sel.studeez.domain.SessionDAO | ||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | ||||
| 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.toList | ||||
| import kotlinx.coroutines.flow.stateIn | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| @HiltViewModel | ||||
| class FriendsFeedViewModel @Inject constructor( | ||||
|     private val feedDAO: FeedDAO, | ||||
|     feedDAO: FeedDAO, | ||||
|     logService: LogService | ||||
| ) : StudeezViewModel(logService) { | ||||
| 
 | ||||
|     fun getFriendsSessions(): Flow<List<Pair<String, List<Pair<String, FeedEntry>>>>> { | ||||
|         return feedDAO.getFriendsSessions().map { it.toList() } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     val uiState: StateFlow<FriendsFeedUiState> = | ||||
|         feedDAO.getFriendsSessions() | ||||
|             .map { it.toList() } | ||||
|             .map { FriendsFeedUiState.Succes(it) } | ||||
|             .stateIn( | ||||
|                 scope = viewModelScope, | ||||
|                 initialValue = FriendsFeedUiState.Loading, | ||||
|                 started = SharingStarted.Eagerly, | ||||
|             ) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Reference in a new issue
	
	 brreynie
						brreynie