Add friend requests screen
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
515f6882c0
commit
a2ab066d82
@ -0,0 +1,88 @@
|
||||
package fr.iut.alldev.allin.ui.friends.components
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import fr.iut.alldev.allin.R
|
||||
import fr.iut.alldev.allin.ext.asFallbackProfileUsername
|
||||
import fr.iut.alldev.allin.theme.AllInColorToken
|
||||
import fr.iut.alldev.allin.theme.AllInTheme
|
||||
import fr.iut.alldev.allin.ui.core.AllInButton
|
||||
import fr.iut.alldev.allin.ui.core.ProfilePicture
|
||||
|
||||
@Composable
|
||||
fun FriendsScreenRequestLine(
|
||||
username: String,
|
||||
accept: () -> Unit,
|
||||
decline: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
ProfilePicture(
|
||||
fallback = username.asFallbackProfileUsername(),
|
||||
size = 50.dp
|
||||
)
|
||||
|
||||
Text(
|
||||
text = username,
|
||||
color = AllInTheme.colors.onBackground2,
|
||||
style = AllInTheme.typography.sm2,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
fontSize = 15.sp,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.weight(1.5f),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
AllInButton(
|
||||
color = AllInColorToken.allInPurple,
|
||||
text = stringResource(id = R.string.friends_requests_accept),
|
||||
textColor = AllInColorToken.white,
|
||||
isSmall = true,
|
||||
textStyle = AllInTheme.typography.sm2,
|
||||
onClick = accept,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
|
||||
AllInButton(
|
||||
color = AllInTheme.colors.background,
|
||||
text = stringResource(id = R.string.friends_requests_decline),
|
||||
textColor = AllInTheme.colors.onBackground,
|
||||
isSmall = true,
|
||||
textStyle = AllInTheme.typography.sm2,
|
||||
onClick = decline,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Composable
|
||||
private fun FriendsScreenLinePreview() {
|
||||
AllInTheme {
|
||||
FriendsScreenRequestLine(
|
||||
username = "Xx_Bg_du_63",
|
||||
accept = { },
|
||||
decline = { }
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package fr.iut.alldev.allin.ui.friends.tabs
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import fr.iut.alldev.allin.data.model.FriendStatus
|
||||
import fr.iut.alldev.allin.data.model.User
|
||||
import fr.iut.alldev.allin.ext.asPaddingValues
|
||||
import fr.iut.alldev.allin.theme.AllInTheme
|
||||
import fr.iut.alldev.allin.ui.core.AllInTextField
|
||||
import fr.iut.alldev.allin.ui.friends.components.FriendsScreenLine
|
||||
|
||||
@Composable
|
||||
fun FriendsScreenAddTab(
|
||||
friends: List<User>,
|
||||
search: String,
|
||||
onToggleDeleteFriend: (User) -> Unit,
|
||||
setSearch: (String) -> Unit,
|
||||
) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = WindowInsets.navigationBars.asPaddingValues(start = 24.dp, end = 24.dp, top = 18.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(11.dp),
|
||||
) {
|
||||
stickyHeader {
|
||||
AllInTextField(
|
||||
value = search,
|
||||
onValueChange = setSearch,
|
||||
leadingIcon = rememberVectorPainter(image = Icons.Default.Search),
|
||||
modifier = Modifier
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
0.5f to AllInTheme.colors.mainSurface,
|
||||
1f to Color.Transparent
|
||||
)
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
items(friends) {
|
||||
FriendsScreenLine(
|
||||
username = it.username,
|
||||
status = it.friendStatus ?: FriendStatus.NOT_FRIEND,
|
||||
toggleIsFriend = { onToggleDeleteFriend(it) }
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package fr.iut.alldev.allin.ui.friends.tabs
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import fr.iut.alldev.allin.data.model.User
|
||||
import fr.iut.alldev.allin.ext.asPaddingValues
|
||||
import fr.iut.alldev.allin.ui.friends.components.FriendsScreenRequestLine
|
||||
|
||||
@Composable
|
||||
fun FriendsScreenRequestsTab(
|
||||
requests: List<User>,
|
||||
acceptRequest: (User) -> Unit,
|
||||
declineRequest: (User) -> Unit
|
||||
) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = WindowInsets.navigationBars.asPaddingValues(start = 24.dp, end = 24.dp, top = 18.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(11.dp),
|
||||
) {
|
||||
items(requests) {
|
||||
FriendsScreenRequestLine(
|
||||
username = it.username,
|
||||
accept = { acceptRequest(it) },
|
||||
decline = { declineRequest(it) }
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue