|
|
|
@ -1,12 +1,25 @@
|
|
|
|
|
package fr.iut.alldev.allin.ui.friends.components
|
|
|
|
|
|
|
|
|
|
import androidx.compose.animation.core.animateFloatAsState
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
|
|
|
|
import androidx.compose.material.pullrefresh.pullRefresh
|
|
|
|
|
import androidx.compose.material.pullrefresh.rememberPullRefreshState
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.draw.alpha
|
|
|
|
|
import androidx.compose.ui.input.pointer.PointerEventPass
|
|
|
|
|
import androidx.compose.ui.input.pointer.PointerInputChange
|
|
|
|
|
import androidx.compose.ui.input.pointer.pointerInput
|
|
|
|
|
import androidx.compose.ui.platform.LocalDensity
|
|
|
|
|
import androidx.compose.ui.platform.LocalFocusManager
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
@ -23,20 +36,33 @@ import fr.iut.alldev.allin.ui.core.SectionElement
|
|
|
|
|
import fr.iut.alldev.allin.ui.friends.FriendsScreenViewModel
|
|
|
|
|
import fr.iut.alldev.allin.ui.friends.tabs.FriendsScreenAddTab
|
|
|
|
|
import fr.iut.alldev.allin.ui.friends.tabs.FriendsScreenRequestsTab
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun FriendsScreenContent(
|
|
|
|
|
addTabState: FriendsScreenViewModel.AddTabState,
|
|
|
|
|
search: String,
|
|
|
|
|
isRefreshing: Boolean,
|
|
|
|
|
onToggleDeleteFriend: (User) -> Unit,
|
|
|
|
|
setSearch: (String) -> Unit,
|
|
|
|
|
requestsTabState: FriendsScreenViewModel.RequestsTabState,
|
|
|
|
|
acceptRequest: (User) -> Unit,
|
|
|
|
|
declineRequest: (User) -> Unit
|
|
|
|
|
declineRequest: (User) -> Unit,
|
|
|
|
|
refresh: () -> Unit
|
|
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
val focus = LocalFocusManager.current
|
|
|
|
|
val pullRefreshState = rememberPullRefreshState(isRefreshing, refresh)
|
|
|
|
|
val progressAnimation by animateFloatAsState(pullRefreshState.progress * 15, label = "")
|
|
|
|
|
val scope = rememberCoroutineScope()
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.pullRefresh(pullRefreshState)
|
|
|
|
|
.padding(top = with(LocalDensity.current) {
|
|
|
|
|
progressAnimation.toDp()
|
|
|
|
|
})
|
|
|
|
|
) {
|
|
|
|
|
Column(Modifier.fillMaxSize()) {
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
@ -51,6 +77,24 @@ fun FriendsScreenContent(
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
AllInSections(
|
|
|
|
|
modifier = Modifier.let {
|
|
|
|
|
if (isRefreshing) {
|
|
|
|
|
it
|
|
|
|
|
.alpha(.5f)
|
|
|
|
|
.pointerInput(Unit) {
|
|
|
|
|
scope.launch {
|
|
|
|
|
awaitPointerEventScope {
|
|
|
|
|
while (true) {
|
|
|
|
|
awaitPointerEvent(pass = PointerEventPass.Initial)
|
|
|
|
|
.changes
|
|
|
|
|
.forEach(PointerInputChange::consume)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else it
|
|
|
|
|
},
|
|
|
|
|
onLoadSection = { focus.clearFocus() },
|
|
|
|
|
sections = listOf(
|
|
|
|
|
SectionElement(stringResource(id = R.string.friends_add_tab)) {
|
|
|
|
@ -94,6 +138,13 @@ fun FriendsScreenContent(
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PullRefreshIndicator(
|
|
|
|
|
modifier = Modifier.align(Alignment.TopCenter),
|
|
|
|
|
refreshing = isRefreshing,
|
|
|
|
|
state = pullRefreshState
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Preview
|
|
|
|
@ -107,7 +158,9 @@ private fun FriendsScreenContentPreview() {
|
|
|
|
|
onToggleDeleteFriend = {},
|
|
|
|
|
requestsTabState = FriendsScreenViewModel.RequestsTabState.Loaded(emptyList()),
|
|
|
|
|
acceptRequest = {},
|
|
|
|
|
declineRequest = {}
|
|
|
|
|
declineRequest = {},
|
|
|
|
|
refresh = {},
|
|
|
|
|
isRefreshing = false
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|