clean up room rendering

master
dfsek 1 year ago
parent 5e0e214bfe
commit 495d6e5b0e
  1. 30
      app/src/main/java/com/dfsek/feldspar/ui/rooms/RoomsUI.kt
  2. 2
      app/src/main/java/com/dfsek/feldspar/ui/settings/VerificationActivity.kt
  3. 7
      app/src/main/java/com/dfsek/feldspar/util/Utils.kt

@ -27,6 +27,7 @@ import coil.decode.BitmapFactoryDecoder
import coil.request.ImageRequest
import com.dfsek.feldspar.AppState
import com.dfsek.feldspar.ui.RoomActivity
import com.dfsek.feldspar.util.DynamicContent
import com.dfsek.feldspar.util.compose_fixes.FixedDefaultFlingBehavior
import com.dfsek.feldspar.util.getAvatarUrl
import com.dfsek.feldspar.util.getPreviewText
@ -72,11 +73,13 @@ fun Avatar(mxUrl: String?, size: Int, clip: Shape = CircleShape, name: String? =
contentAlignment = Alignment.Center
) {
name?.let {
Text(it.substring(0, 1),
Text(
it.substring(0, 1),
modifier = Modifier.align(Alignment.Center),
fontSize = (floor(size * 0.75).sp),
textAlign = TextAlign.Center,
color = Color.White)
color = Color.White
)
}
}
}
@ -106,21 +109,16 @@ fun Activity.RoomList(
filter: (List<RoomSummary>) -> List<RoomSummary>
) {
AppState.session?.let { session ->
val lifecycleOwner = LocalLifecycleOwner.current
var rooms: List<RoomSummary> by remember { mutableStateOf(emptyList()) }
LaunchedEffect(session) {
session.roomService().getRoomSummariesLive(queryParams)
.observe(lifecycleOwner) {
rooms = filter(it)
DynamicContent(session, { session.roomService().getRoomSummariesLive(queryParams) }) {
val rooms = filter(it)
val fling = FixedDefaultFlingBehavior.fixedFlingBehavior()
LazyColumn(flingBehavior = fling) {
items(rooms, key = {
it.roomId
}) {
Log.d("ROOM", it.roomId)
RoomEntry(it)
}
}
val fling = FixedDefaultFlingBehavior.fixedFlingBehavior()
LazyColumn(flingBehavior = fling) {
items(rooms, key = {
it.roomId
}) {
Log.d("ROOM", it.roomId)
RoomEntry(it)
}
}
}

@ -26,7 +26,7 @@ class VerificationActivity : AppCompatActivity() {
AppState.session?.let { session ->
val state = VerificationState(session)
Surface(modifier = Modifier.fillMaxSize()) {
DynamicContent(state.devices) {
DynamicContent(session, { state.devices }) {
Column {
SettingsTopBar("Verification")
Verification(state)

@ -47,10 +47,13 @@ internal const val THEME_KEY = "theme"
internal const val GENERAL_PREFS = "general"
@Composable
fun <T> DynamicContent(data: LiveData<T>, consume: @Composable (T) -> Unit) {
fun <T> DynamicContent(key: Any, data: () -> LiveData<T>, consume: @Composable (T) -> Unit) {
val lifecycleOwner = LocalLifecycleOwner.current
var value: T? by remember { mutableStateOf(null) }
data.observe(lifecycleOwner) { value = it }
LaunchedEffect(key) {
val d = data.invoke()
d.observe(lifecycleOwner) { value = it }
}
value?.let { consume(it) }
}

Loading…
Cancel
Save