From 9eab533251d23899b58e3141b52e3286ffe34ee7 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 16 May 2023 08:44:21 +0200 Subject: [PATCH 1/5] Styling --- .../common/composable/TextComposable.kt | 2 +- .../studeez/common/composable/feed/Feed.kt | 2 +- .../common/composable/feed/FeedEntry.kt | 2 +- .../common/composable/tasks/SubjectEntry.kt | 14 +++- .../friends_overview/FriendsOverviewScreen.kt | 75 +++++++++---------- 5 files changed, 50 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/TextComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/TextComposable.kt index 25fa3c4..425d8f6 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/TextComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/TextComposable.kt @@ -32,7 +32,7 @@ fun Headline( fun DateText(date: String) { Text( text = date, - fontWeight = FontWeight.Bold, + fontWeight = FontWeight.Medium, fontSize = 20.sp, modifier = Modifier.padding(horizontal = 10.dp) ) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/Feed.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/Feed.kt index 54be2ea..fb18f02 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/Feed.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/Feed.kt @@ -81,7 +81,7 @@ fun FeedWithElements( Text( text = "${HoursMinutesSeconds(totalDayStudyTime)}", fontSize = 15.sp, - fontWeight = FontWeight.Bold + fontWeight = FontWeight.Medium ) } feedEntries.forEach { feedEntry -> diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/FeedEntry.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/FeedEntry.kt index ff950d6..016090d 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/FeedEntry.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/feed/FeedEntry.kt @@ -56,7 +56,7 @@ fun FeedEntry( ) { Text( text = feedEntry.subJectName, - fontWeight = FontWeight.Bold, + fontWeight = FontWeight.Medium, overflow = TextOverflow.Ellipsis, maxLines = 1, ) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/tasks/SubjectEntry.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/tasks/SubjectEntry.kt index 63d4fbe..1c98af2 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/tasks/SubjectEntry.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/tasks/SubjectEntry.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.Card import androidx.compose.material.Icon +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.List @@ -65,16 +66,17 @@ fun SubjectEntry( ) { Text( text = subject.name, - fontWeight = FontWeight.Bold, overflow = TextOverflow.Ellipsis, maxLines = 1, + fontWeight = FontWeight.Medium ) Row( horizontalArrangement = Arrangement.spacedBy(10.dp), - verticalAlignment = Alignment.CenterVertically, + verticalAlignment = Alignment.CenterVertically ) { Text( text = HoursMinutesSeconds(studytime).toString(), + color = MaterialTheme.colors.onBackground.copy(alpha = 0.6f) ) Row( verticalAlignment = Alignment.CenterVertically, @@ -82,9 +84,13 @@ fun SubjectEntry( ) { Icon( imageVector = Icons.Default.List, - contentDescription = stringResource(id = AppText.tasks) + contentDescription = stringResource(id = AppText.tasks), + tint = MaterialTheme.colors.onBackground.copy(alpha = 0.6f) + ) + Text( + text = "${completedTaskCount}/${taskCount}", + color = MaterialTheme.colors.onBackground.copy(alpha = 0.6f) ) - Text(text = "${completedTaskCount}/${taskCount}") } } } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_overview/FriendsOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_overview/FriendsOverviewScreen.kt index db76179..a1960d8 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_overview/FriendsOverviewScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_overview/FriendsOverviewScreen.kt @@ -1,10 +1,8 @@ package be.ugent.sel.studeez.screens.friends.friends_overview -import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack @@ -15,7 +13,6 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.modifier.modifierLocalConsumer import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.text.style.TextOverflow @@ -25,7 +22,6 @@ import androidx.compose.ui.unit.sp import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.BasicButton import be.ugent.sel.studeez.common.composable.ProfilePicture -import be.ugent.sel.studeez.common.composable.SearchField import be.ugent.sel.studeez.common.composable.drawer.DrawerEntry import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.data.local.models.Friendship @@ -183,49 +179,52 @@ fun FriendsEntry( viewProfile: (String) -> Unit, removeFriend: (Friendship) -> Unit ) { - Row ( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 15.dp, vertical = 7.dp), - ) { - Box( - modifier = Modifier - .padding(vertical = 4.dp) - ) { - ProfilePicture() - } - - Box ( + Card { + Row ( modifier = Modifier .fillMaxWidth() + .padding(horizontal = 15.dp, vertical = 7.dp), + horizontalArrangement = Arrangement.spacedBy(15.dp) ) { - Column ( + Box( modifier = Modifier .padding(vertical = 4.dp) ) { - Text( - text = user.username, - fontSize = 16.sp, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - Text( - text = "${resources().getString(AppText.app_name)} ${resources().getString(AppText.friend)}", - fontSize = 14.sp, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) + ProfilePicture() } - Box( - modifier = Modifier.fillMaxWidth(), - contentAlignment = Alignment.CenterEnd + Box ( + modifier = Modifier + .fillMaxWidth() ) { - FriendsOverviewDropDown( - friendship = friendship, - viewProfile = viewProfile, - removeFriend = removeFriend - ) + Column ( + modifier = Modifier + .padding(vertical = 4.dp) + ) { + Text( + text = user.username, + fontSize = 16.sp, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + Text( + text = "${resources().getString(AppText.app_name)} ${resources().getString(AppText.friend)}", + fontSize = 14.sp, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.CenterEnd + ) { + FriendsOverviewDropDown( + friendship = friendship, + viewProfile = viewProfile, + removeFriend = removeFriend + ) + } } } } From ef08a773f8e78f45dff35ae2cacbd10fa3e195e4 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 16 May 2023 08:44:56 +0200 Subject: [PATCH 2/5] Fix own profile showing up in search friends --- .../friends/friends_search/SearchFriendsViewModel.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_search/SearchFriendsViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_search/SearchFriendsViewModel.kt index 39aabf6..05bf6d6 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_search/SearchFriendsViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/friends/friends_search/SearchFriendsViewModel.kt @@ -10,7 +10,7 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations import be.ugent.sel.studeez.screens.StudeezViewModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.map import javax.inject.Inject @HiltViewModel @@ -49,8 +49,8 @@ class SearchFriendsViewModel @Inject constructor( */ fun getAllUsers(): Flow> { return userDAO.getAllUsers() - .filter { users -> - users.any { user -> + .map { users -> + users.filter { user -> user.id != userDAO.getCurrentUserId() } } From af23a29f6c4cc17b5a319aeabb1c5af0099e09ca Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 16 May 2023 09:10:39 +0200 Subject: [PATCH 3/5] Forbid adding friends twice --- .../implementation/FirebaseFriendshipDAO.kt | 52 ++++++++++++------- .../public_profile/PublicProfileScreen.kt | 17 +++--- .../public_profile/PublicProfileViewModel.kt | 6 ++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseFriendshipDAO.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseFriendshipDAO.kt index bd429e1..2583bed 100644 --- a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseFriendshipDAO.kt +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseFriendshipDAO.kt @@ -1,11 +1,10 @@ package be.ugent.sel.studeez.domain.implementation -import androidx.compose.runtime.collectAsState import be.ugent.sel.studeez.common.snackbar.SnackbarManager import be.ugent.sel.studeez.data.local.models.Friendship import be.ugent.sel.studeez.data.remote.FirebaseFriendship.ACCEPTED -import be.ugent.sel.studeez.data.remote.FirebaseFriendship.FRIENDSSINCE import be.ugent.sel.studeez.data.remote.FirebaseFriendship.FRIENDID +import be.ugent.sel.studeez.data.remote.FirebaseFriendship.FRIENDSSINCE import be.ugent.sel.studeez.domain.AccountDAO import be.ugent.sel.studeez.domain.FriendshipDAO import be.ugent.sel.studeez.domain.implementation.FirebaseCollections.FRIENDS_COLLECTION @@ -18,6 +17,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map +import kotlinx.coroutines.tasks.await import javax.inject.Inject import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException @@ -75,24 +75,40 @@ class FirebaseFriendshipDAO @Inject constructor( val currentUserId: String = auth.currentUserId val otherUserId: String = id - // Add entry to current user - currentUserDocument() - .collection(FRIENDS_COLLECTION) - .add(mapOf( - FRIENDID to otherUserId, - ACCEPTED to true, // TODO Make it not automatically accepted. - FRIENDSSINCE to Timestamp.now() - )) - - // Add entry to other user + // Check if the friendship already exists for the logged in user + var allowed = false firestore.collection(USER_COLLECTION) - .document(otherUserId) + .document(currentUserId) .collection(FRIENDS_COLLECTION) - .add(mapOf( - FRIENDID to currentUserId, - ACCEPTED to true, // TODO Make it not automatically accepted. - FRIENDSSINCE to Timestamp.now() - )) + .whereEqualTo(FRIENDID, otherUserId) + .get() + .addOnSuccessListener { + allowed = it.documents.isEmpty() + + if (allowed) { + // Add entry to current user + currentUserDocument() + .collection(FRIENDS_COLLECTION) + .add(mapOf( + FRIENDID to otherUserId, + ACCEPTED to true, // TODO Make it not automatically accepted. + FRIENDSSINCE to Timestamp.now() + )) + + // Add entry to other user + firestore.collection(USER_COLLECTION) + .document(otherUserId) + .collection(FRIENDS_COLLECTION) + .add(mapOf( + FRIENDID to currentUserId, + ACCEPTED to true, // TODO Make it not automatically accepted. + FRIENDSSINCE to Timestamp.now() + )) + } + }.addOnSuccessListener { + val message = if (allowed) AppText.success else AppText.already_friend + SnackbarManager.showMessage(message) + } return true } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt index 41e33c5..8fd9d89 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt @@ -18,6 +18,7 @@ import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.Headline import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate import be.ugent.sel.studeez.common.composable.drawer.DrawerEntry +import be.ugent.sel.studeez.common.snackbar.SnackbarManager import be.ugent.sel.studeez.data.local.models.User import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.screens.profile.AmountOfFriendsButton @@ -30,7 +31,7 @@ data class PublicProfileActions( val getUserDetails: () -> Flow, val getAmountOfFriends: () -> Flow, val onViewFriendsClick: () -> Unit, - val sendFriendRequest: () -> Boolean + val sendFriendRequest: () -> Unit ) fun getPublicProfileActions( @@ -43,9 +44,11 @@ fun getPublicProfileActions( userId = viewModel.uiState.value.userId ) }, onViewFriendsClick = { viewModel.onViewFriendsClick(open) }, - sendFriendRequest = { viewModel.sendFriendRequest( - userId = viewModel.uiState.value.userId - ) } + sendFriendRequest = { + viewModel.sendFriendRequest( + userId = viewModel.uiState.value.userId + ) + } ) } @@ -129,7 +132,7 @@ fun PublicProfilePreview() { }, getAmountOfFriends = { flowOf(113) }, onViewFriendsClick = {}, - sendFriendRequest = { true } + sendFriendRequest = {} ), popUp = {} ) @@ -138,7 +141,7 @@ fun PublicProfilePreview() { @Composable fun PublicProfileEllipsis( - sendFriendRequest: () -> Boolean + sendFriendRequest: () -> Unit ) { var expanded by remember { mutableStateOf(false) } @@ -172,7 +175,7 @@ fun PublicProfileEllipsis( fun PublicProfileEllipsisPreview() { StudeezTheme { PublicProfileEllipsis( - sendFriendRequest = { true } + sendFriendRequest = {} ) } } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileViewModel.kt index 031950c..700084f 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileViewModel.kt @@ -1,6 +1,7 @@ package be.ugent.sel.studeez.screens.profile.public_profile import androidx.compose.runtime.mutableStateOf +import be.ugent.sel.studeez.common.snackbar.SnackbarManager import be.ugent.sel.studeez.data.SelectedUserId import be.ugent.sel.studeez.data.local.models.User import be.ugent.sel.studeez.domain.FriendshipDAO @@ -11,6 +12,7 @@ import be.ugent.sel.studeez.screens.StudeezViewModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import javax.inject.Inject +import be.ugent.sel.studeez.R.string as AppText @HiltViewModel class PublicProfileViewModel @Inject constructor( @@ -53,8 +55,8 @@ class PublicProfileViewModel @Inject constructor( fun sendFriendRequest( userId: String - ): Boolean { - return friendshipDAO.sendFriendshipRequest(userId) + ) { + friendshipDAO.sendFriendshipRequest(userId) } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4aa7cb..4544ddd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -136,6 +136,7 @@ Show profile Click to search friends Searching friends + You are already befriended with that person. From 45bd215004633d5c13267ddf586c410061e24910 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 16 May 2023 09:16:03 +0200 Subject: [PATCH 4/5] Add friends to FAB --- .../common/composable/navbar/NavigationBarViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt index d2f4f09..3afc87b 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt @@ -4,6 +4,7 @@ import be.ugent.sel.studeez.common.snackbar.SnackbarManager import be.ugent.sel.studeez.domain.LogService 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.SEARCH_FRIENDS_SCREEN import be.ugent.sel.studeez.navigation.StudeezDestinations.SELECT_SUBJECT import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN @@ -38,8 +39,7 @@ class NavigationBarViewModel @Inject constructor( } fun onAddFriendClick(open: (String) -> Unit) { - // TODO open(SEARCH_FRIENDS_SCREEN) - SnackbarManager.showMessage(AppText.add_friend_not_possible_yet) // TODO Remove + open(SEARCH_FRIENDS_SCREEN) } fun onAddSessionClick(open: (String) -> Unit) { From 57668d31643cc5dfe418ea5c3c9a31154f57815b Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 16 May 2023 09:32:20 +0200 Subject: [PATCH 5/5] Fix public profile string not showing --- .../screens/profile/public_profile/PublicProfileScreen.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt index 8fd9d89..fdc2e97 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/public_profile/PublicProfileScreen.kt @@ -150,8 +150,7 @@ fun PublicProfileEllipsis( ) { Icon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_more_horizontal), - contentDescription = resources().getString(AppText.view_more), - modifier = Modifier.fillMaxSize() + contentDescription = resources().getString(AppText.view_more) ) }