Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.TextAutoSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.PushPin
import androidx.compose.material.icons.outlined.Archive
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.DoneAll
import androidx.compose.material.icons.outlined.Forum
import androidx.compose.material.icons.outlined.Mail
import androidx.compose.material.icons.outlined.Notifications
Expand All @@ -65,6 +68,8 @@ import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.FloatingActionButton
Expand Down Expand Up @@ -128,10 +133,12 @@ import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.view.HapticFeedbackConstantsCompat
import androidx.core.view.ViewCompat
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
Expand Down Expand Up @@ -242,6 +249,7 @@ fun ChatListScreen(
onScanInvite = onScanInvite,
onOpenChannelList = onOpenChannelList,
onMarkAllRead = viewModel::markCurrentScopeRead,
onMarkSelectedRead = viewModel::markSelectedRead,
onMoveNetwork = viewModel::moveNetwork,
onCommitNetworkOrder = viewModel::commitNetworkOrder,
selectedBufferId = selectedBufferId,
Expand Down Expand Up @@ -314,6 +322,7 @@ fun ChatListContent(
onScanInvite: () -> Unit = {},
onOpenChannelList: (Long) -> Unit = {},
onMarkAllRead: () -> Unit = {},
onMarkSelectedRead: (Collection<Long>) -> Unit = {},
// Manual drawer order (see DrawerReorder.kt); defaulted so previews and tests stay terse.
onMoveNetwork: (Long, Int) -> Unit = { _, _ -> },
onCommitNetworkOrder: (List<Long>) -> Unit = {},
Expand Down Expand Up @@ -437,7 +446,17 @@ fun ChatListContent(
) { mode ->
when (mode) {
ChatListTopBarMode.SELECTION -> {
Text(pluralStringResource(R.plurals.chatlist_selected_count, lastSelectedRows.size, lastSelectedRows.size))
// Never wrap: a growing action row must shrink this font instead
// of pushing the count to multiple lines and blowing out the bar's
// height. Ellipsis is only the last-resort floor once even the
// smallest step can't fit (e.g. a huge selected count on a tiny
// screen).
Text(
pluralStringResource(R.plurals.chatlist_selected_count, lastSelectedRows.size, lastSelectedRows.size),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
autoSize = TextAutoSize.StepBased(minFontSize = 14.sp, maxFontSize = 22.sp),
)
}

ChatListTopBarMode.INVITATIONS -> {
Expand Down Expand Up @@ -521,30 +540,65 @@ fun ChatListContent(
// still apply to the live selection.
val pinTarget = aggregateToggleTarget(lastSelectedRows) { it.pinned }
val muteTarget = aggregateToggleTarget(lastSelectedRows) { it.muted }
var overflowOpen by remember { mutableStateOf(false) }
// Only the three most-reached-for actions stay inline; pin and
// archive move behind "more" so a growing action set never
// starves the title (the autoSize/ellipsis fallback above is
// the last resort, not the primary fix) or forces icons to
// shrink/wrap on narrower phones.
IconButton(
onClick = {
onSetPinned(selectedRows.map(ChatListRow::bufferId), pinTarget)
onMarkSelectedRead(selectedRows.map(ChatListRow::bufferId))
selectedIds = emptyList()
},
modifier = Modifier.testTag("chatlist_selection_pin"),
) { Icon(Icons.Filled.PushPin, stringResource(if (pinTarget) R.string.chatlist_pin else R.string.chatlist_unpin)) }
modifier = Modifier.testTag("chatlist_selection_mark_read"),
) { Icon(Icons.Outlined.DoneAll, stringResource(R.string.chatlist_mark_read)) }
IconButton(
onClick = {
onSetMuted(selectedRows.map(ChatListRow::bufferId), muteTarget)
selectedIds = emptyList()
},
modifier = Modifier.testTag("chatlist_selection_mute"),
) { Icon(if (muteTarget) Icons.Outlined.NotificationsOff else Icons.Outlined.Notifications, stringResource(if (muteTarget) R.string.chatlist_mute else R.string.chatlist_unmute)) }
IconButton(
onClick = {
setArchivedWithReveal(selectedRows.map(ChatListRow::bufferId), !archiveMode)
selectedIds = emptyList()
},
modifier = Modifier.testTag("chatlist_selection_archive"),
) { Icon(archiveActionIcon(archiveMode), stringResource(if (archiveMode) R.string.chatlist_unarchive else R.string.chatlist_archive)) }
IconButton(onClick = { confirmRemoval = true }, modifier = Modifier.testTag("chatlist_selection_remove")) {
Icon(Icons.Outlined.Delete, stringResource(R.string.chatlist_remove))
}
Box {
IconButton(
onClick = { overflowOpen = true },
modifier = Modifier.testTag("chatlist_selection_more"),
) {
Icon(Icons.Filled.MoreVert, stringResource(R.string.chatlist_more_actions))
}
DropdownMenu(expanded = overflowOpen, onDismissRequest = { overflowOpen = false }) {
DropdownMenuItem(
text = { Text(stringResource(if (pinTarget) R.string.chatlist_pin else R.string.chatlist_unpin)) },
leadingIcon = { Icon(Icons.Filled.PushPin, contentDescription = null) },
modifier = Modifier.testTag("chatlist_selection_pin"),
onClick = {
onSetPinned(selectedRows.map(ChatListRow::bufferId), pinTarget)
selectedIds = emptyList()
overflowOpen = false
},
)
DropdownMenuItem(
text = {
Text(
stringResource(
if (archiveMode) R.string.chatlist_unarchive else R.string.chatlist_archive,
),
)
},
leadingIcon = { Icon(archiveActionIcon(archiveMode), contentDescription = null) },
modifier = Modifier.testTag("chatlist_selection_archive"),
onClick = {
setArchivedWithReveal(selectedRows.map(ChatListRow::bufferId), !archiveMode)
selectedIds = emptyList()
overflowOpen = false
},
)
}
}
}

ChatListTopBarMode.DEFAULT, ChatListTopBarMode.SCOPED -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ class ChatListViewModel
viewModelScope.launch { markChatsRead(bufferIds, readMarkerRepository, connectionManager) }
}

/**
* Mark an explicit selection read, muted rows included: mark-all deliberately skips muted
* chats, but a user hand-selecting one is opting it in on purpose.
*/
fun markSelectedRead(bufferIds: Collection<Long>) {
val ids = bufferIds.toList().distinct()
if (ids.isEmpty()) return
viewModelScope.launch { markChatsRead(ids, readMarkerRepository, connectionManager) }
}

private fun setSelection(networkId: Long?) {
selection.value = networkId
savedStateHandle[KEY_SELECTED] = networkId
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,8 @@
<string name="chatlist_unpin">Unpin</string>
<string name="chatlist_mute">Mute</string>
<string name="chatlist_unmute">Unmute</string>
<string name="chatlist_mark_read">Mark as read</string>
<string name="chatlist_more_actions">More actions</string>
<string name="chatlist_archive">Archive</string>
<string name="chatlist_unarchive">Unarchive</string>

Expand Down
Loading
Loading