Use FilterChip instead of Custom Text component for presence indication. Add some test code(to be removed later).
This commit is contained in:
+94
-53
@@ -21,10 +21,10 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
@@ -59,16 +59,21 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|||||||
import androidx.compose.foundation.text.ClickableText
|
import androidx.compose.foundation.text.ClickableText
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.PlaylistAddCheck
|
||||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||||
import androidx.compose.material.icons.filled.ArrowDropUp
|
import androidx.compose.material.icons.filled.ArrowDropUp
|
||||||
import androidx.compose.material.icons.filled.ContentCopy
|
import androidx.compose.material.icons.filled.ContentCopy
|
||||||
|
import androidx.compose.material.icons.filled.Done
|
||||||
import androidx.compose.material.icons.filled.EditNote
|
import androidx.compose.material.icons.filled.EditNote
|
||||||
import androidx.compose.material.icons.filled.Link
|
import androidx.compose.material.icons.filled.Link
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material.icons.filled.PlaylistAddCheck
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.FilterChip
|
||||||
|
import androidx.compose.material3.FilterChipDefaults
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
@@ -90,6 +95,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.toMutableStateList
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
@@ -110,7 +116,6 @@ import androidx.compose.ui.res.painterResource
|
|||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.IntSize
|
import androidx.compose.ui.unit.IntSize
|
||||||
@@ -203,6 +208,7 @@ import com.vitorpamplona.quartz.events.TwitterIdentity
|
|||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
@@ -901,6 +907,8 @@ private fun ProfileActions(
|
|||||||
baseUser: User,
|
baseUser: User,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
|
val tempFollowLists = remember { generateFollowLists().toMutableStateList() }
|
||||||
|
|
||||||
val isMe by
|
val isMe by
|
||||||
remember(accountViewModel) { derivedStateOf { accountViewModel.userProfile() == baseUser } }
|
remember(accountViewModel) { derivedStateOf { accountViewModel.userProfile() == baseUser } }
|
||||||
|
|
||||||
@@ -914,7 +922,13 @@ private fun ProfileActions(
|
|||||||
} else {
|
} else {
|
||||||
DisplayFollowUnfollowButton(baseUser, accountViewModel)
|
DisplayFollowUnfollowButton(baseUser, accountViewModel)
|
||||||
}
|
}
|
||||||
FollowSetsActionMenu(baseUser.pubkeyHex)
|
FollowSetsActionMenu(
|
||||||
|
userHex = baseUser.pubkeyHex,
|
||||||
|
followLists = tempFollowLists,
|
||||||
|
addUser = { index, list ->
|
||||||
|
list.members = list.members.plus(baseUser.pubkeyHex)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,15 +1019,16 @@ fun WatchIsHiddenUser(
|
|||||||
@Composable
|
@Composable
|
||||||
fun FollowSetsActionMenu(
|
fun FollowSetsActionMenu(
|
||||||
userHex: String,
|
userHex: String,
|
||||||
|
followLists: List<FollowInfo>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
addUser: (listIndex: Int, list: FollowInfo) -> Unit,
|
||||||
) {
|
) {
|
||||||
var isMenuOpen by remember { mutableStateOf(false) }
|
val (isMenuOpen, setMenuValue) = remember { mutableStateOf(false) }
|
||||||
|
val uiScope = rememberCoroutineScope()
|
||||||
|
|
||||||
Box {
|
Column {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = { setMenuValue(true) },
|
||||||
isMenuOpen = !isMenuOpen
|
|
||||||
},
|
|
||||||
shape = ButtonBorder.copy(topStart = CornerSize(0f), bottomStart = CornerSize(0f)),
|
shape = ButtonBorder.copy(topStart = CornerSize(0f), bottomStart = CornerSize(0f)),
|
||||||
colors =
|
colors =
|
||||||
ButtonDefaults
|
ButtonDefaults
|
||||||
@@ -1049,40 +1064,35 @@ fun FollowSetsActionMenu(
|
|||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = isMenuOpen,
|
expanded = isMenuOpen,
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
isMenuOpen = !isMenuOpen
|
uiScope.launch {
|
||||||
|
delay(100L)
|
||||||
|
setMenuValue(false)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
properties = PopupProperties(usePlatformDefaultWidth = true),
|
properties = PopupProperties(usePlatformDefaultWidth = true),
|
||||||
) {
|
) {
|
||||||
DropDownMenuHeader(headerText = "Add to lists")
|
DropDownMenuHeader(headerText = "Add to lists")
|
||||||
DropdownMenuItem(
|
followLists.forEachIndexed { index, list ->
|
||||||
text = {
|
Spacer(StdVertSpacer)
|
||||||
FollowSetItem(
|
DropdownMenuItem(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
text = {
|
||||||
listHeader = "LOLZ List",
|
FollowSetItem(
|
||||||
listIsPublic = true,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
isUserInList = false,
|
listHeader = list.name,
|
||||||
) {
|
listIsPublic = !list.isPrivate,
|
||||||
}
|
isUserInList = list.members.contains(userHex),
|
||||||
},
|
) {
|
||||||
onClick = {},
|
println("List contains user -> ${list.members.contains(userHex)}")
|
||||||
modifier = Modifier.fillMaxWidth(),
|
println("Adding user to List -> ${list.name}")
|
||||||
)
|
addUser(index, list)
|
||||||
Spacer(StdVertSpacer)
|
println("List contains user -> ${list.members.contains(userHex)}")
|
||||||
|
}
|
||||||
DropdownMenuItem(
|
},
|
||||||
text = {
|
onClick = {},
|
||||||
FollowSetItem(
|
modifier = Modifier.fillMaxWidth(),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
)
|
||||||
listHeader = "Private List",
|
}
|
||||||
listIsPublic = false,
|
|
||||||
isUserInList = true,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onClick = {},
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1104,6 +1114,22 @@ private fun DropDownMenuHeader(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FollowInfo(
|
||||||
|
val name: String,
|
||||||
|
val isPrivate: Boolean,
|
||||||
|
memberList: List<String> = mutableListOf(),
|
||||||
|
) {
|
||||||
|
var members by mutableStateOf(memberList)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateFollowLists(): List<FollowInfo> =
|
||||||
|
(1..10).map { index: Int ->
|
||||||
|
FollowInfo(
|
||||||
|
name = "List No $index",
|
||||||
|
isPrivate = index % 2 == 0,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FollowSetItem(
|
fun FollowSetItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@@ -1123,28 +1149,43 @@ fun FollowSetItem(
|
|||||||
.clickable(onClick = onAddUser),
|
.clickable(onClick = onAddUser),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
|
if (isUserInList) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.animateContentSize(),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(5.dp),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.Done,
|
||||||
|
contentDescription = "Done icon",
|
||||||
|
modifier = Modifier.size(FilterChipDefaults.IconSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier.weight(1f),
|
modifier = modifier.weight(1f),
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
Text(listHeader, fontWeight = FontWeight.Bold)
|
Text(listHeader, fontWeight = FontWeight.Bold)
|
||||||
Spacer(modifier = StdVertSpacer)
|
Spacer(modifier = StdVertSpacer)
|
||||||
Text(
|
FilterChip(
|
||||||
if (isUserInList) "Present in List" else "Not present",
|
selected = isUserInList,
|
||||||
overflow = TextOverflow.Ellipsis,
|
enabled = isUserInList,
|
||||||
fontWeight = if (isUserInList) FontWeight.Bold else FontWeight.Normal,
|
onClick = {},
|
||||||
maxLines = 3,
|
label = {
|
||||||
modifier =
|
Text(text = if (isUserInList) "In List" else "Not in List")
|
||||||
Modifier
|
},
|
||||||
.background(
|
leadingIcon =
|
||||||
color =
|
if (isUserInList) {
|
||||||
if (isUserInList) {
|
{
|
||||||
MaterialTheme.colorScheme.primary
|
Icon(
|
||||||
} else {
|
imageVector = Icons.AutoMirrored.Filled.PlaylistAddCheck,
|
||||||
MaterialTheme.colorScheme.background
|
contentDescription = null,
|
||||||
},
|
)
|
||||||
shape = ButtonBorder,
|
}
|
||||||
),
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
shape = ButtonBorder,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user