feat: starting to rearrange create group fragment for member list

This commit is contained in:
0x330a 2023-10-27 09:05:47 +11:00
parent ae7c27c2e0
commit 5c38c83d05
2 changed files with 78 additions and 48 deletions

View File

@ -8,15 +8,16 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.CircularProgressIndicator
@ -150,16 +151,23 @@ fun CreateGroup(
var name by remember { mutableStateOf(createGroupState.groupName) } var name by remember { mutableStateOf(createGroupState.groupName) }
var description by remember { mutableStateOf(createGroupState.groupDescription) } var description by remember { mutableStateOf(createGroupState.groupDescription) }
val members by remember { mutableStateOf(createGroupState.members) } var members by remember { mutableStateOf(createGroupState.members) }
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
val lazyState = rememberLazyListState()
val onDeleteMember = { contact: Contact ->
members -= contact
}
Box { Box {
Column( Column(
modifier modifier
.fillMaxWidth()) { .fillMaxWidth()) {
Column(modifier.scrollable(scrollState, orientation = Orientation.Vertical)) { LazyColumn(state = lazyState) {
// Top bar // Top bar
item {
Column(modifier.fillMaxWidth()) {
NavigationBar( NavigationBar(
title = stringResource(id = R.string.activity_create_group_title), title = stringResource(id = R.string.activity_create_group_title),
onBack = onBack, onBack = onBack,
@ -197,8 +205,10 @@ fun CreateGroup(
contentDescription = descriptionDescription contentDescription = descriptionDescription
}, },
) )
}
}
// Group list // Group list
MemberList(contacts = members, modifier = Modifier.padding(vertical = 8.dp, horizontal = 24.dp)) memberList(contacts = members.toList(), modifier = Modifier.padding(vertical = 8.dp, horizontal = 24.dp), onDeleteMember)
} }
// Create button // Create button
val createDescription = stringResource(id = R.string.AccessibilityId_create_closed_group_create_button) val createDescription = stringResource(id = R.string.AccessibilityId_create_closed_group_create_button)
@ -236,11 +246,22 @@ fun CreateGroup(
} }
fun LazyListScope.memberList(contacts: List<Contact>, modifier: Modifier = Modifier, onDelete: (Contact)->Unit) {
if (contacts.isEmpty()) {
item {
EmptyPlaceholder(modifier.fillParentMaxWidth())
}
} else {
items(contacts) {
// TODO
}
}
}
@Composable @Composable
fun MemberList(contacts: Collection<Contact>, modifier: Modifier = Modifier) { fun EmptyPlaceholder(modifier: Modifier = Modifier) {
Column(modifier = modifier Column {
.fillMaxWidth()
.defaultMinSize(minHeight = 240.dp)) {
Text(text = stringResource(id = R.string.conversation_settings_group_members), Text(text = stringResource(id = R.string.conversation_settings_group_members),
modifier = Modifier modifier = Modifier
.align(Alignment.Start) .align(Alignment.Start)
@ -261,10 +282,17 @@ fun MemberList(contacts: Collection<Contact>, modifier: Modifier = Modifier) {
fun ClosedGroupPreview( fun ClosedGroupPreview(
@PreviewParameter(ThemeResPreviewParameterProvider::class) themeResId: Int @PreviewParameter(ThemeResPreviewParameterProvider::class) themeResId: Int
) { ) {
val random = "05abcd1234"
val previewMembers = setOf(
Contact(random).apply {
name = "Person"
}
)
PreviewTheme(themeResId) { PreviewTheme(themeResId) {
CreateGroup( CreateGroup(
viewState = CreateGroupFragment.ViewState(false, null), viewState = CreateGroupFragment.ViewState(false, null),
createGroupState = CreateGroupState("Group Name", "Test Group Description", emptySet()), createGroupState = CreateGroupState("Group Name", "Test Group Description", previewMembers),
onCreate = {}, onCreate = {},
onClose = {}, onClose = {},
onBack = {}, onBack = {},

View File

@ -0,0 +1,2 @@
package org.thoughtcrime.securesms.groups