mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-21 23:54:26 +00:00
Fix rooms not getting displayed upon first login
This commit is contained in:
parent
6333a5e2d1
commit
06f7ddf62b
8 changed files with 59 additions and 22 deletions
|
@ -75,6 +75,13 @@ class MainActivity : ComponentActivity() {
|
|||
Log.d("Main", "Opening session: $currentSession")
|
||||
currentSession.open()
|
||||
currentSession.syncService().startSync(true)
|
||||
currentSession.addListener(OpenSessionListener(this::resetContent))
|
||||
}
|
||||
}
|
||||
|
||||
private class OpenSessionListener(private val resetContent: () -> Unit) : Session.Listener {
|
||||
override fun onSessionStarted(session: Session) {
|
||||
resetContent()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,10 +109,8 @@ class MainActivity : ComponentActivity() {
|
|||
"Login activity returned a successful result, trying to get session..."
|
||||
)
|
||||
fetchLastSession()
|
||||
session?.open()
|
||||
resetContent()
|
||||
openSession()
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log.d("Main", "Login activity was cancelled.")
|
||||
}
|
||||
|
@ -114,11 +119,16 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
private fun onClickLogout() {
|
||||
lifecycleScope.launch {
|
||||
Log.d("Main", "Clicked logout, signing out...")
|
||||
session!!.signOutService().signOut(true)
|
||||
val signedOutSession = session!!
|
||||
|
||||
Log.d("Main", "Clicked logout, recomposing...")
|
||||
session = null
|
||||
Log.d("Main", "Done logging out, recomposing...")
|
||||
resetContent()
|
||||
|
||||
Log.d("Main", "Done recomposing, now signing out...")
|
||||
signedOutSession.signOutService().signOut(true)
|
||||
|
||||
Log.d("Main", "Done logging out!")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ fun RoomListItem(
|
|||
onClickRoom(roomSummary.roomId)
|
||||
},
|
||||
headlineContent = {
|
||||
Text(roomSummary.name)
|
||||
Text(roomSummary.displayName)
|
||||
},
|
||||
leadingContent = {
|
||||
Box(
|
||||
|
|
|
@ -2,5 +2,6 @@ package eu.steffo.twom.room
|
|||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
|
||||
val LocalRoom = staticCompositionLocalOf<RoomSummary?> { null }
|
||||
val LocalRoom = staticCompositionLocalOf<Optional<RoomSummary>?> { null }
|
||||
|
|
|
@ -1,13 +1,25 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import eu.steffo.twom.theme.TwoMPadding
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
fun RoomActivityContent(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val isLoading = (LocalRoom.current == null)
|
||||
val roomSummary = LocalRoom.current?.getOrNull()
|
||||
val isError = (!isLoading && roomSummary == null)
|
||||
|
||||
}
|
||||
Column(modifier) {
|
||||
Row(TwoMPadding.base) {
|
||||
if (roomSummary != null) {
|
||||
Text(roomSummary.topic)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,16 +19,15 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.steffo.twom.R
|
||||
import eu.steffo.twom.matrix.avatar.AvatarFromURL
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
fun RoomActivityRoomIconButton(
|
||||
modifier: Modifier = Modifier,
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
avatarUrl: String,
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
|
@ -51,7 +50,7 @@ fun RoomActivityRoomIconButton(
|
|||
) { expanded = true },
|
||||
) {
|
||||
AvatarFromURL(
|
||||
url = LocalRoom.current!!.avatarUrl,
|
||||
url = avatarUrl,
|
||||
contentDescription = LocalContext.current.getString(R.string.room_options_label),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,11 +4,12 @@ import androidx.compose.foundation.layout.padding
|
|||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Modifier
|
||||
import eu.steffo.twom.matrix.LocalSession
|
||||
import eu.steffo.twom.theme.TwoMTheme
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||
|
||||
@Composable
|
||||
fun RoomActivityScaffold(
|
||||
|
@ -16,7 +17,7 @@ fun RoomActivityScaffold(
|
|||
roomId: String,
|
||||
onBack: () -> Unit = {},
|
||||
) {
|
||||
val roomSummary = session.getRoomSummary(roomId)
|
||||
val roomSummary by session.roomService().getRoomSummaryLive(roomId).observeAsState()
|
||||
|
||||
TwoMTheme {
|
||||
CompositionLocalProvider(LocalSession provides session) {
|
||||
|
|
|
@ -2,6 +2,8 @@ package eu.steffo.twom.room
|
|||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
|
@ -10,19 +12,20 @@ import androidx.compose.material3.TopAppBar
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import eu.steffo.twom.R
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@Preview
|
||||
fun RoomActivityTopBar(
|
||||
modifier: Modifier = Modifier,
|
||||
onBack: () -> Unit = {},
|
||||
roomName: String = "{Room name}",
|
||||
roomAvatarURL: String? = null,
|
||||
) {
|
||||
val isLoading = (LocalRoom.current == null)
|
||||
val roomSummary = LocalRoom.current?.getOrNull()
|
||||
val isError = (!isLoading && roomSummary == null)
|
||||
|
||||
TopAppBar(
|
||||
modifier = modifier,
|
||||
navigationIcon = {
|
||||
|
@ -34,10 +37,20 @@ fun RoomActivityTopBar(
|
|||
}
|
||||
},
|
||||
title = {
|
||||
Text(LocalRoom.current!!.name)
|
||||
if (roomSummary != null) {
|
||||
Text(roomSummary.displayName)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
RoomActivityRoomIconButton()
|
||||
if (isLoading) {
|
||||
CircularProgressIndicator()
|
||||
} else if (isError) {
|
||||
Icon(Icons.Filled.Warning, stringResource(R.string.error))
|
||||
} else {
|
||||
RoomActivityRoomIconButton(
|
||||
avatarUrl = roomSummary!!.avatarUrl,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
|
@ -33,4 +33,5 @@
|
|||
<string name="create_description_label">Description</string>
|
||||
<string name="create_complete_text">Create</string>
|
||||
<string name="room_options_label">Room options</string>
|
||||
<string name="error">Error</string>
|
||||
</resources>
|
Loading…
Reference in a new issue