Merge pull request #124 from SELab1/fixes

Fixes
This commit is contained in:
Tibo De Peuter 2023-05-16 11:06:29 +02:00 committed by GitHub Enterprise
commit e6b2cdba3b
11 changed files with 105 additions and 79 deletions

View file

@ -32,7 +32,7 @@ fun Headline(
fun DateText(date: String) { fun DateText(date: String) {
Text( Text(
text = date, text = date,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Medium,
fontSize = 20.sp, fontSize = 20.sp,
modifier = Modifier.padding(horizontal = 10.dp) modifier = Modifier.padding(horizontal = 10.dp)
) )

View file

@ -81,7 +81,7 @@ fun FeedWithElements(
Text( Text(
text = "${HoursMinutesSeconds(totalDayStudyTime)}", text = "${HoursMinutesSeconds(totalDayStudyTime)}",
fontSize = 15.sp, fontSize = 15.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Medium
) )
} }
feedEntries.forEach { feedEntry -> feedEntries.forEach { feedEntry ->

View file

@ -56,7 +56,7 @@ fun FeedEntry(
) { ) {
Text( Text(
text = feedEntry.subJectName, text = feedEntry.subJectName,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Medium,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
maxLines = 1, maxLines = 1,
) )

View file

@ -4,6 +4,7 @@ import be.ugent.sel.studeez.common.snackbar.SnackbarManager
import be.ugent.sel.studeez.domain.LogService import be.ugent.sel.studeez.domain.LogService
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN 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.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.SELECT_SUBJECT
import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN
import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN
@ -38,8 +39,7 @@ class NavigationBarViewModel @Inject constructor(
} }
fun onAddFriendClick(open: (String) -> Unit) { fun onAddFriendClick(open: (String) -> Unit) {
// TODO open(SEARCH_FRIENDS_SCREEN) open(SEARCH_FRIENDS_SCREEN)
SnackbarManager.showMessage(AppText.add_friend_not_possible_yet) // TODO Remove
} }
fun onAddSessionClick(open: (String) -> Unit) { fun onAddSessionClick(open: (String) -> Unit) {

View file

@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Card import androidx.compose.material.Card
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.List import androidx.compose.material.icons.filled.List
@ -65,16 +66,17 @@ fun SubjectEntry(
) { ) {
Text( Text(
text = subject.name, text = subject.name,
fontWeight = FontWeight.Bold,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
maxLines = 1, maxLines = 1,
fontWeight = FontWeight.Medium
) )
Row( Row(
horizontalArrangement = Arrangement.spacedBy(10.dp), horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically
) { ) {
Text( Text(
text = HoursMinutesSeconds(studytime).toString(), text = HoursMinutesSeconds(studytime).toString(),
color = MaterialTheme.colors.onBackground.copy(alpha = 0.6f)
) )
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
@ -82,9 +84,13 @@ fun SubjectEntry(
) { ) {
Icon( Icon(
imageVector = Icons.Default.List, 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}")
} }
} }
} }

View file

@ -1,11 +1,10 @@
package be.ugent.sel.studeez.domain.implementation 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.common.snackbar.SnackbarManager
import be.ugent.sel.studeez.data.local.models.Friendship 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.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.FRIENDID
import be.ugent.sel.studeez.data.remote.FirebaseFriendship.FRIENDSSINCE
import be.ugent.sel.studeez.domain.AccountDAO import be.ugent.sel.studeez.domain.AccountDAO
import be.ugent.sel.studeez.domain.FriendshipDAO import be.ugent.sel.studeez.domain.FriendshipDAO
import be.ugent.sel.studeez.domain.implementation.FirebaseCollections.FRIENDS_COLLECTION 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.catch
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.tasks.await
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.resume import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException import kotlin.coroutines.resumeWithException
@ -75,6 +75,17 @@ class FirebaseFriendshipDAO @Inject constructor(
val currentUserId: String = auth.currentUserId val currentUserId: String = auth.currentUserId
val otherUserId: String = id val otherUserId: String = id
// Check if the friendship already exists for the logged in user
var allowed = false
firestore.collection(USER_COLLECTION)
.document(currentUserId)
.collection(FRIENDS_COLLECTION)
.whereEqualTo(FRIENDID, otherUserId)
.get()
.addOnSuccessListener {
allowed = it.documents.isEmpty()
if (allowed) {
// Add entry to current user // Add entry to current user
currentUserDocument() currentUserDocument()
.collection(FRIENDS_COLLECTION) .collection(FRIENDS_COLLECTION)
@ -93,6 +104,11 @@ class FirebaseFriendshipDAO @Inject constructor(
ACCEPTED to true, // TODO Make it not automatically accepted. ACCEPTED to true, // TODO Make it not automatically accepted.
FRIENDSSINCE to Timestamp.now() FRIENDSSINCE to Timestamp.now()
)) ))
}
}.addOnSuccessListener {
val message = if (allowed) AppText.success else AppText.already_friend
SnackbarManager.showMessage(message)
}
return true return true
} }

View file

@ -1,10 +1,8 @@
package be.ugent.sel.studeez.screens.friends.friends_overview package be.ugent.sel.studeez.screens.friends.friends_overview
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowBack
@ -15,7 +13,6 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.modifier.modifierLocalConsumer
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.style.TextOverflow 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.R
import be.ugent.sel.studeez.common.composable.BasicButton import be.ugent.sel.studeez.common.composable.BasicButton
import be.ugent.sel.studeez.common.composable.ProfilePicture 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.composable.drawer.DrawerEntry
import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.data.local.models.Friendship import be.ugent.sel.studeez.data.local.models.Friendship
@ -183,10 +179,12 @@ fun FriendsEntry(
viewProfile: (String) -> Unit, viewProfile: (String) -> Unit,
removeFriend: (Friendship) -> Unit removeFriend: (Friendship) -> Unit
) { ) {
Card {
Row ( Row (
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 15.dp, vertical = 7.dp), .padding(horizontal = 15.dp, vertical = 7.dp),
horizontalArrangement = Arrangement.spacedBy(15.dp)
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
@ -229,6 +227,7 @@ fun FriendsEntry(
} }
} }
} }
}
} }
@Preview @Preview

View file

@ -10,7 +10,7 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations
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.Flow
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map
import javax.inject.Inject import javax.inject.Inject
@HiltViewModel @HiltViewModel
@ -49,8 +49,8 @@ class SearchFriendsViewModel @Inject constructor(
*/ */
fun getAllUsers(): Flow<List<User>> { fun getAllUsers(): Flow<List<User>> {
return userDAO.getAllUsers() return userDAO.getAllUsers()
.filter { users -> .map { users ->
users.any { user -> users.filter { user ->
user.id != userDAO.getCurrentUserId() user.id != userDAO.getCurrentUserId()
} }
} }

View file

@ -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.Headline
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
import be.ugent.sel.studeez.common.composable.drawer.DrawerEntry 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.data.local.models.User
import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.resources
import be.ugent.sel.studeez.screens.profile.AmountOfFriendsButton import be.ugent.sel.studeez.screens.profile.AmountOfFriendsButton
@ -30,7 +31,7 @@ data class PublicProfileActions(
val getUserDetails: () -> Flow<User>, val getUserDetails: () -> Flow<User>,
val getAmountOfFriends: () -> Flow<Int>, val getAmountOfFriends: () -> Flow<Int>,
val onViewFriendsClick: () -> Unit, val onViewFriendsClick: () -> Unit,
val sendFriendRequest: () -> Boolean val sendFriendRequest: () -> Unit
) )
fun getPublicProfileActions( fun getPublicProfileActions(
@ -43,9 +44,11 @@ fun getPublicProfileActions(
userId = viewModel.uiState.value.userId userId = viewModel.uiState.value.userId
) }, ) },
onViewFriendsClick = { viewModel.onViewFriendsClick(open) }, onViewFriendsClick = { viewModel.onViewFriendsClick(open) },
sendFriendRequest = { viewModel.sendFriendRequest( sendFriendRequest = {
viewModel.sendFriendRequest(
userId = viewModel.uiState.value.userId userId = viewModel.uiState.value.userId
) } )
}
) )
} }
@ -129,7 +132,7 @@ fun PublicProfilePreview() {
}, },
getAmountOfFriends = { flowOf(113) }, getAmountOfFriends = { flowOf(113) },
onViewFriendsClick = {}, onViewFriendsClick = {},
sendFriendRequest = { true } sendFriendRequest = {}
), ),
popUp = {} popUp = {}
) )
@ -138,7 +141,7 @@ fun PublicProfilePreview() {
@Composable @Composable
fun PublicProfileEllipsis( fun PublicProfileEllipsis(
sendFriendRequest: () -> Boolean sendFriendRequest: () -> Unit
) { ) {
var expanded by remember { mutableStateOf(false) } var expanded by remember { mutableStateOf(false) }
@ -147,8 +150,7 @@ fun PublicProfileEllipsis(
) { ) {
Icon( Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_more_horizontal), imageVector = ImageVector.vectorResource(id = R.drawable.ic_more_horizontal),
contentDescription = resources().getString(AppText.view_more), contentDescription = resources().getString(AppText.view_more)
modifier = Modifier.fillMaxSize()
) )
} }
@ -172,7 +174,7 @@ fun PublicProfileEllipsis(
fun PublicProfileEllipsisPreview() { fun PublicProfileEllipsisPreview() {
StudeezTheme { StudeezTheme {
PublicProfileEllipsis( PublicProfileEllipsis(
sendFriendRequest = { true } sendFriendRequest = {}
) )
} }
} }

View file

@ -1,6 +1,7 @@
package be.ugent.sel.studeez.screens.profile.public_profile package be.ugent.sel.studeez.screens.profile.public_profile
import androidx.compose.runtime.mutableStateOf 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.SelectedUserId
import be.ugent.sel.studeez.data.local.models.User import be.ugent.sel.studeez.data.local.models.User
import be.ugent.sel.studeez.domain.FriendshipDAO 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 dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import javax.inject.Inject import javax.inject.Inject
import be.ugent.sel.studeez.R.string as AppText
@HiltViewModel @HiltViewModel
class PublicProfileViewModel @Inject constructor( class PublicProfileViewModel @Inject constructor(
@ -53,8 +55,8 @@ class PublicProfileViewModel @Inject constructor(
fun sendFriendRequest( fun sendFriendRequest(
userId: String userId: String
): Boolean { ) {
return friendshipDAO.sendFriendshipRequest(userId) friendshipDAO.sendFriendshipRequest(userId)
} }
} }

View file

@ -136,6 +136,7 @@
<string name="show_profile">Show profile</string> <string name="show_profile">Show profile</string>
<string name="click_search_friends">Click to search friends</string> <string name="click_search_friends">Click to search friends</string>
<string name="searching_friends">Searching friends</string> <string name="searching_friends">Searching friends</string>
<string name="already_friend">You are already befriended with that person.</string>
<!-- ========== Create & edit screens ========== --> <!-- ========== Create & edit screens ========== -->