1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-21 15:44:26 +00:00

Add progress indicator to RoomListItem

This commit is contained in:
Steffo 2024-02-05 00:04:39 +01:00
parent ffdf046c46
commit b0e337f44b
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0

View file

@ -6,6 +6,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ListItem import androidx.compose.material3.ListItem
@ -51,23 +52,27 @@ fun RoomListItem(
return return
} }
var running by rememberSaveable { mutableStateOf(false) }
var expanded by rememberSaveable { mutableStateOf(false) } var expanded by rememberSaveable { mutableStateOf(false) }
var error by remember { mutableStateOf<LocalizableError?>(null) } var error by remember { mutableStateOf<LocalizableError?>(null) }
// TODO: Display a running indicator
val viewRoomActivityLauncher = rememberLauncherForActivityResult(ViewRoomActivity.Contract()) {} val viewRoomActivityLauncher = rememberLauncherForActivityResult(ViewRoomActivity.Contract()) {}
suspend fun openRoom() { suspend fun openRoom() {
if (roomSummary.membership == Membership.INVITE) { if (roomSummary.membership == Membership.INVITE) {
Log.i("Main", "Opening invite `$roomId`...") Log.i("Main", "Opening invite `$roomId`...")
running = true
try { try {
session.roomService().joinRoom(roomId, "Opened the invite") session.roomService().joinRoom(roomId, "Opened the invite")
} catch (e: Throwable) { } catch (e: Throwable) {
Log.e("Main", "Failed to open invite to room `$roomId`: $error") Log.e("Main", "Failed to open invite to room `$roomId`: $error")
error = LocalizableError(R.string.main_error_join_generic, e) error = LocalizableError(R.string.main_error_join_generic, e)
return return
} finally {
running = false
} }
Log.d("Main", "Successfully opened invite to room `$roomId`!") Log.d("Main", "Successfully opened invite to room `$roomId`!")
} }
@ -77,13 +82,18 @@ fun RoomListItem(
suspend fun leaveRoom() { suspend fun leaveRoom() {
Log.i("Main", "Leaving room `$roomId`...") Log.i("Main", "Leaving room `$roomId`...")
running = true
try { try {
session.roomService().leaveRoom(roomId, "Decided to leave the room") session.roomService().leaveRoom(roomId, "Decided to leave the room")
} catch (e: Throwable) { } catch (e: Throwable) {
Log.e("Main", "Failed to leave room `$roomId`: $error") Log.e("Main", "Failed to leave room `$roomId`: $error")
error = LocalizableError(R.string.main_error_leave_generic, e) error = LocalizableError(R.string.main_error_leave_generic, e)
return return
} finally {
running = false
} }
Log.d("Main", "Successfully left room `$roomId`!") Log.d("Main", "Successfully left room `$roomId`!")
} }
@ -93,6 +103,7 @@ fun RoomListItem(
ListItem( ListItem(
modifier = Modifier.combinedClickable( modifier = Modifier.combinedClickable(
enabled = !running,
onClick = { scope.launch { openRoom() } }, onClick = { scope.launch { openRoom() } },
onLongClick = { expanded = true } onLongClick = { expanded = true }
), ),
@ -108,11 +119,15 @@ fun RoomListItem(
.size(40.dp) .size(40.dp)
.clip(MaterialTheme.shapes.medium) .clip(MaterialTheme.shapes.medium)
) { ) {
AvatarURL( if (running) {
// FIXME: URL can appearently be set before the image is available on the homeserver CircularProgressIndicator()
url = roomSummary.avatarUrl, } else {
alpha = alpha, AvatarURL(
) // FIXME: URL can appearently be set before the image is available on the homeserver
url = roomSummary.avatarUrl,
alpha = alpha,
)
}
} }
}, },
supportingContent = { supportingContent = {