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

Use LiveData for the rooms list

This commit is contained in:
Steffo 2023-12-01 03:39:57 +01:00
parent 8c468a6d78
commit 293de92ccb
Signed by: steffo
GPG key ID: 2A24051445686895
3 changed files with 11 additions and 17 deletions

View file

@ -69,6 +69,7 @@ dependencies {
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.runtime:runtime-livedata:1.5.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

View file

@ -1,20 +1,17 @@
package eu.steffo.twom.main
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.steffo.twom.R
import eu.steffo.twom.matrix.LocalSession
import eu.steffo.twom.matrix.TwoMMatrix
import eu.steffo.twom.theme.TwoMPadding
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
@Composable
@ -23,18 +20,12 @@ fun MainActivityRoomList(
onClickRoom: (roomId: String) -> Unit = {},
) {
val session = LocalSession.current
var roomSummaries by remember { mutableStateOf<List<RoomSummary>?>(null) }
LaunchedEffect(session) GetRoomSummaries@{
if (session == null) {
Log.d("RoomList", "Not doing anything, session is null.")
return@GetRoomSummaries
}
Log.d("RoomList", "Getting room summaries...")
val queryParamsBuilder = roomSummaryQueryParams()
roomSummaries = session.roomService().getRoomSummaries(queryParamsBuilder)
Log.d("RoomList", "Obtained room summaries: $roomSummaries")
val roomSummaries by session!!.roomService().getRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.includeType = listOf(TwoMMatrix.ROOM_TYPE)
}
).observeAsState()
Column(modifier) {
if (roomSummaries == null) {

View file

@ -36,4 +36,6 @@ object TwoMMatrix {
}
return null
}
const val ROOM_TYPE = "eu.steffo.twom.happening"
}