changed sessions to feed in navbar
This commit is contained in:
		
							parent
							
								
									9bc210c3d0
								
							
						
					
					
						commit
						439bc0ab61
					
				
					 10 changed files with 131 additions and 72 deletions
				
			
		|  | @ -8,13 +8,15 @@ import androidx.compose.material.icons.Icons | |||
| import androidx.compose.material.icons.filled.Check | ||||
| import androidx.compose.material.icons.filled.List | ||||
| import androidx.compose.material.icons.filled.Person | ||||
| import androidx.compose.material.icons.outlined.Check | ||||
| import androidx.compose.material.icons.outlined.DateRange | ||||
| import androidx.compose.material.icons.outlined.Face | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
| import androidx.compose.ui.unit.dp | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.FRIENDS_FEED | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN | ||||
| import be.ugent.sel.studeez.resources | ||||
| import be.ugent.sel.studeez.ui.theme.StudeezTheme | ||||
|  | @ -99,11 +101,11 @@ fun NavigationBar( | |||
|         BottomNavigationItem( | ||||
|             icon = { | ||||
|                 Icon( | ||||
|                     imageVector = Icons.Outlined.DateRange, resources().getString(AppText.sessions) | ||||
|                     imageVector = Icons.Outlined.Face, resources().getString(AppText.friends_feed) | ||||
|                 ) | ||||
|             }, | ||||
|             label = { Text(text = resources().getString(AppText.sessions)) }, | ||||
|             selected = navigationBarActions.isSelectedTab(SESSIONS_SCREEN), | ||||
|             label = { Text(text = resources().getString(AppText.friends_feed)) }, | ||||
|             selected = navigationBarActions.isSelectedTab(FRIENDS_FEED), | ||||
|             onClick = navigationBarActions.onSessionsClick | ||||
|         ) | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,9 +2,9 @@ package be.ugent.sel.studeez.common.composable.navbar | |||
| 
 | ||||
| import be.ugent.sel.studeez.common.snackbar.SnackbarManager | ||||
| import be.ugent.sel.studeez.domain.LogService | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.FRIENDS_FEED | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN | ||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | ||||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||||
|  | @ -25,7 +25,7 @@ class NavigationBarViewModel @Inject constructor( | |||
|     } | ||||
| 
 | ||||
|     fun onSessionsClick(open: (String) -> Unit) { | ||||
|         open(SESSIONS_SCREEN) | ||||
|         open(FRIENDS_FEED) | ||||
|     } | ||||
| 
 | ||||
|     fun onProfileClick(open: (String) -> Unit) { | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ package be.ugent.sel.studeez.domain | |||
| 
 | ||||
| import be.ugent.sel.studeez.data.local.models.SessionReport | ||||
| import be.ugent.sel.studeez.data.local.models.User | ||||
| import be.ugent.sel.studeez.data.local.models.task.Task | ||||
| import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| 
 | ||||
|  | @ -13,7 +14,7 @@ interface SessionDAO { | |||
|     /** | ||||
|      * Return a list of pairs, containing the username and all the studysessions of that user. | ||||
|      */ | ||||
|     fun getFriendsSessions(): Flow<List<Pair<String,List<SessionReport>>>> | ||||
|     fun getFriendsSessions(): Flow<List<Pair<String, List<Task>>>> | ||||
| 
 | ||||
|     fun saveSession(newSessionReport: SessionReport) | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,4 +15,6 @@ interface TaskDAO { | |||
|     fun deleteTask(oldTask: Task) | ||||
| 
 | ||||
|     suspend fun getTask(subjectId: String, taskId: String): Task | ||||
| 
 | ||||
|     suspend fun getTaskFromUser(subjectId: String, taskId: String, userId: String): Task | ||||
| } | ||||
|  | @ -2,14 +2,12 @@ package be.ugent.sel.studeez.domain.implementation | |||
| 
 | ||||
| import be.ugent.sel.studeez.data.local.models.SessionReport | ||||
| import be.ugent.sel.studeez.data.local.models.User | ||||
| import be.ugent.sel.studeez.data.local.models.task.Task | ||||
| import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||
| import be.ugent.sel.studeez.data.remote.FirebaseSessionReport | ||||
| import be.ugent.sel.studeez.data.remote.FirebaseSessionReport.ENDTIME | ||||
| import be.ugent.sel.studeez.data.remote.FirebaseSessionReport.STUDYTIME | ||||
| import be.ugent.sel.studeez.domain.AccountDAO | ||||
| import be.ugent.sel.studeez.domain.FriendshipDAO | ||||
| import be.ugent.sel.studeez.domain.SessionDAO | ||||
| import be.ugent.sel.studeez.domain.UserDAO | ||||
| import be.ugent.sel.studeez.domain.* | ||||
| import be.ugent.sel.studeez.domain.implementation.FirebaseCollections.SESSION_COLLECTION | ||||
| import be.ugent.sel.studeez.domain.implementation.FirebaseCollections.USER_COLLECTION | ||||
| import com.google.firebase.Timestamp | ||||
|  | @ -17,6 +15,7 @@ import com.google.firebase.firestore.CollectionReference | |||
| import com.google.firebase.firestore.FirebaseFirestore | ||||
| import com.google.firebase.firestore.ktx.getField | ||||
| import com.google.firebase.firestore.ktx.snapshots | ||||
| import com.google.firebase.firestore.ktx.toObject | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| import kotlinx.coroutines.flow.emptyFlow | ||||
| import kotlinx.coroutines.flow.map | ||||
|  | @ -27,7 +26,8 @@ class FirebaseSessionDAO @Inject constructor( | |||
|     private val firestore: FirebaseFirestore, | ||||
|     private val auth: AccountDAO, | ||||
|     private val userDAO: UserDAO, | ||||
|     private val friendshipDAO: FriendshipDAO | ||||
|     private val friendshipDAO: FriendshipDAO, | ||||
|     private val taskDAO: TaskDAO, | ||||
| ) : SessionDAO { | ||||
| 
 | ||||
|     override fun getSessions(): Flow<List<SessionReport>> { | ||||
|  | @ -37,29 +37,28 @@ class FirebaseSessionDAO @Inject constructor( | |||
|     } | ||||
| 
 | ||||
|     override suspend fun getSessionsOfUser(userId: String): List<SessionReport> { | ||||
|         val collection = firestore.collection(USER_COLLECTION) | ||||
|         return firestore.collection(USER_COLLECTION) | ||||
|             .document(userId) | ||||
|             .collection(SESSION_COLLECTION) | ||||
|             .get().await() | ||||
|         val list: MutableList<SessionReport> = mutableListOf() | ||||
|         for (document in collection) { | ||||
|             val id = document.id | ||||
|             val studyTime: Int = document.getField<Int>(STUDYTIME)!! | ||||
|             val endTime: Timestamp = document.getField<Timestamp>(ENDTIME)!! | ||||
|             list.add(SessionReport(id, studyTime, endTime)) | ||||
|         } | ||||
|         return list | ||||
|             .map { it.toObject(SessionReport::class.java) } | ||||
|     } | ||||
| 
 | ||||
|     override fun getFriendsSessions(): Flow<List<Pair<String, List<SessionReport>>>> { | ||||
|     override fun getFriendsSessions(): Flow<List<Pair<String, List<Task>>>> { | ||||
|         return friendshipDAO.getAllFriendships(auth.currentUserId) | ||||
|             .map { friendships -> | ||||
|                 friendships.map { friendship -> | ||||
|                     val userId: String = friendship.friendId | ||||
|                     val username = userDAO.getUsername(userId) | ||||
|                     val userSessions = getSessionsOfUser(userId) | ||||
| 
 | ||||
|                     Pair(username, userSessions) | ||||
|                     val userTasks = getSessionsOfUser(userId) | ||||
|                         .map { sessionReport -> | ||||
|                             taskDAO.getTaskFromUser( | ||||
|                                 sessionReport.subjectId, | ||||
|                                 sessionReport.taskId, | ||||
|                                 userId | ||||
|                             ) | ||||
|                         } | ||||
|                     Pair(username, userTasks) | ||||
|                 } | ||||
|             } | ||||
|     } | ||||
|  |  | |||
|  | @ -30,6 +30,13 @@ class FirebaseTaskDAO @Inject constructor( | |||
|         return selectedSubjectTasksCollection(subjectId).document(taskId).get().await().toObject()!! | ||||
|     } | ||||
| 
 | ||||
|     override suspend fun getTaskFromUser(subjectId: String, taskId: String, userId: String): Task { | ||||
|         return selectedSubjectTasksCollection(subjectId, userId) | ||||
|             .document(taskId) | ||||
|             .get() | ||||
|             .await().toObject(Task::class.java)!! | ||||
|     } | ||||
| 
 | ||||
|     override fun saveTask(newTask: Task) { | ||||
|         selectedSubjectTasksCollection(newTask.subjectId).add(newTask) | ||||
|     } | ||||
|  | @ -44,9 +51,9 @@ class FirebaseTaskDAO @Inject constructor( | |||
|         selectedSubjectTasksCollection(oldTask.subjectId).document(oldTask.id).delete() | ||||
|     } | ||||
| 
 | ||||
|     private fun selectedSubjectTasksCollection(subjectId: String): CollectionReference = | ||||
|     private fun selectedSubjectTasksCollection(subjectId: String, id: String = auth.currentUserId): CollectionReference = | ||||
|         firestore.collection(FirebaseCollections.USER_COLLECTION) | ||||
|             .document(auth.currentUserId) | ||||
|             .document(id) | ||||
|             .collection(FirebaseCollections.SUBJECT_COLLECTION) | ||||
|             .document(subjectId) | ||||
|             .collection(FirebaseCollections.TASK_COLLECTION) | ||||
|  |  | |||
|  | @ -16,6 +16,8 @@ import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel | |||
| import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions | ||||
| import be.ugent.sel.studeez.screens.friends.friends_overview.FriendsOveriewRoute | ||||
| import be.ugent.sel.studeez.screens.friends.friends_search.SearchFriendsRoute | ||||
| import be.ugent.sel.studeez.screens.friends_feed.FriendsFeedRoute | ||||
| import be.ugent.sel.studeez.screens.friends_feed.FriendsFeedScreen | ||||
| import be.ugent.sel.studeez.screens.home.HomeRoute | ||||
| import be.ugent.sel.studeez.screens.log_in.LoginRoute | ||||
| import be.ugent.sel.studeez.screens.profile.edit_profile.EditProfileRoute | ||||
|  | @ -23,7 +25,6 @@ import be.ugent.sel.studeez.screens.profile.ProfileRoute | |||
| import be.ugent.sel.studeez.screens.profile.public_profile.PublicProfileRoute | ||||
| import be.ugent.sel.studeez.screens.session.SessionRoute | ||||
| import be.ugent.sel.studeez.screens.session_recap.SessionRecapRoute | ||||
| import be.ugent.sel.studeez.screens.sessions.SessionsRoute | ||||
| import be.ugent.sel.studeez.screens.settings.SettingsRoute | ||||
| import be.ugent.sel.studeez.screens.sign_up.SignUpRoute | ||||
| import be.ugent.sel.studeez.screens.splash.SplashRoute | ||||
|  | @ -127,9 +128,10 @@ fun StudeezNavGraph( | |||
| 
 | ||||
| 
 | ||||
|         composable(StudeezDestinations.SESSIONS_SCREEN) { | ||||
|             SessionsRoute( | ||||
|             FriendsFeedRoute( | ||||
|                 drawerActions = drawerActions, | ||||
|                 navigationBarActions = navigationBarActions | ||||
|                 navigationBarActions = navigationBarActions, | ||||
|                 viewModel = hiltViewModel() | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,65 @@ | |||
| package be.ugent.sel.studeez.screens.friends_feed | ||||
| 
 | ||||
| import androidx.compose.foundation.layout.Column | ||||
| import androidx.compose.foundation.lazy.LazyColumn | ||||
| import androidx.compose.foundation.lazy.items | ||||
| import androidx.compose.material.Divider | ||||
| import androidx.compose.material.Text | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.collectAsState | ||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | ||||
| import be.ugent.sel.studeez.common.composable.TimerEntry | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | ||||
| import be.ugent.sel.studeez.data.local.models.SessionReport | ||||
| import be.ugent.sel.studeez.data.local.models.task.Task | ||||
| import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | ||||
| import be.ugent.sel.studeez.resources | ||||
| import be.ugent.sel.studeez.R.string as AppText | ||||
| 
 | ||||
| @Composable | ||||
| fun FriendsFeedRoute( | ||||
|     viewModel: FriendsFeedViewModel, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions | ||||
| ) { | ||||
|     FriendsFeedScreen( | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions, | ||||
|         viewModel = viewModel | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun FriendsFeedScreen( | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
|     viewModel: FriendsFeedViewModel | ||||
| ) { | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(AppText.upcoming_sessions), | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions | ||||
|     ) { | ||||
| 
 | ||||
|         val friendsSessions = viewModel.getFriendsSessions().collectAsState(initial = emptyList()) | ||||
|         LazyColumn() { | ||||
|             // Default Timers, cannot be edited | ||||
|             items(friendsSessions.value) { | ||||
|                 FriendsFeedEntry(name = it.first, sessions = it.second) | ||||
|                 Divider() | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun FriendsFeedEntry(name: String, sessions: List<Task>) { | ||||
|     Column() { | ||||
|         Text(text = "$name Werkte ") | ||||
|         sessions.forEach { | ||||
|             Text(text = "${HoursMinutesSeconds(it.time)} aan ${it.name}") | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,23 @@ | |||
| package be.ugent.sel.studeez.screens.friends_feed | ||||
| 
 | ||||
| import be.ugent.sel.studeez.data.local.models.task.Task | ||||
| 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 javax.inject.Inject | ||||
| 
 | ||||
| @HiltViewModel | ||||
| class FriendsFeedViewModel @Inject constructor( | ||||
|     private val sessionDAO: SessionDAO, | ||||
|     logService: LogService | ||||
| ) : StudeezViewModel(logService) { | ||||
| 
 | ||||
|     fun getFriendsSessions(): Flow<List<Pair<String, List<Task>>>> { | ||||
|         return sessionDAO.getFriendsSessions() | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | @ -1,42 +0,0 @@ | |||
| package be.ugent.sel.studeez.screens.sessions | ||||
| 
 | ||||
| import androidx.compose.foundation.layout.fillMaxSize | ||||
| import androidx.compose.material.Text | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.ui.Modifier | ||||
| import androidx.compose.ui.text.style.TextAlign | ||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | ||||
| import be.ugent.sel.studeez.resources | ||||
| import be.ugent.sel.studeez.R.string as AppText | ||||
| 
 | ||||
| @Composable | ||||
| fun SessionsRoute( | ||||
|     // viewModel: SessionsViewModel, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions | ||||
| ) { | ||||
|     SessionsScreen( | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun SessionsScreen( | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions | ||||
| ) { | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(AppText.upcoming_sessions), | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions | ||||
|     ) { | ||||
|         Text( | ||||
|             text = resources().getString(AppText.sessions_temp_description), | ||||
|             modifier = Modifier.fillMaxSize(), | ||||
|             textAlign = TextAlign.Center | ||||
|         ) | ||||
|     } | ||||
| } | ||||
		Reference in a new issue
	
	 lbarraga
						lbarraga