mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-25 17:44:24 +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")
|
Log.d("Main", "Opening session: $currentSession")
|
||||||
currentSession.open()
|
currentSession.open()
|
||||||
currentSession.syncService().startSync(true)
|
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..."
|
"Login activity returned a successful result, trying to get session..."
|
||||||
)
|
)
|
||||||
fetchLastSession()
|
fetchLastSession()
|
||||||
session?.open()
|
openSession()
|
||||||
resetContent()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
Log.d("Main", "Login activity was cancelled.")
|
Log.d("Main", "Login activity was cancelled.")
|
||||||
}
|
}
|
||||||
|
@ -114,11 +119,16 @@ class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
private fun onClickLogout() {
|
private fun onClickLogout() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
Log.d("Main", "Clicked logout, signing out...")
|
val signedOutSession = session!!
|
||||||
session!!.signOutService().signOut(true)
|
|
||||||
|
Log.d("Main", "Clicked logout, recomposing...")
|
||||||
session = null
|
session = null
|
||||||
Log.d("Main", "Done logging out, recomposing...")
|
|
||||||
resetContent()
|
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)
|
onClickRoom(roomSummary.roomId)
|
||||||
},
|
},
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
Text(roomSummary.name)
|
Text(roomSummary.displayName)
|
||||||
},
|
},
|
||||||
leadingContent = {
|
leadingContent = {
|
||||||
Box(
|
Box(
|
||||||
|
|
|
@ -2,5 +2,6 @@ package eu.steffo.twom.room
|
||||||
|
|
||||||
import androidx.compose.runtime.staticCompositionLocalOf
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
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
|
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.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import eu.steffo.twom.theme.TwoMPadding
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview(showBackground = true)
|
|
||||||
fun RoomActivityContent(
|
fun RoomActivityContent(
|
||||||
modifier: Modifier = Modifier,
|
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.draw.clip
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.semantics.Role
|
import androidx.compose.ui.semantics.Role
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import eu.steffo.twom.R
|
import eu.steffo.twom.R
|
||||||
import eu.steffo.twom.matrix.avatar.AvatarFromURL
|
import eu.steffo.twom.matrix.avatar.AvatarFromURL
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview(showBackground = true)
|
|
||||||
fun RoomActivityRoomIconButton(
|
fun RoomActivityRoomIconButton(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
|
avatarUrl: String,
|
||||||
) {
|
) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ fun RoomActivityRoomIconButton(
|
||||||
) { expanded = true },
|
) { expanded = true },
|
||||||
) {
|
) {
|
||||||
AvatarFromURL(
|
AvatarFromURL(
|
||||||
url = LocalRoom.current!!.avatarUrl,
|
url = avatarUrl,
|
||||||
contentDescription = LocalContext.current.getString(R.string.room_options_label),
|
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.material3.Scaffold
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import eu.steffo.twom.matrix.LocalSession
|
import eu.steffo.twom.matrix.LocalSession
|
||||||
import eu.steffo.twom.theme.TwoMTheme
|
import eu.steffo.twom.theme.TwoMTheme
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RoomActivityScaffold(
|
fun RoomActivityScaffold(
|
||||||
|
@ -16,7 +17,7 @@ fun RoomActivityScaffold(
|
||||||
roomId: String,
|
roomId: String,
|
||||||
onBack: () -> Unit = {},
|
onBack: () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val roomSummary = session.getRoomSummary(roomId)
|
val roomSummary by session.roomService().getRoomSummaryLive(roomId).observeAsState()
|
||||||
|
|
||||||
TwoMTheme {
|
TwoMTheme {
|
||||||
CompositionLocalProvider(LocalSession provides session) {
|
CompositionLocalProvider(LocalSession provides session) {
|
||||||
|
|
|
@ -2,6 +2,8 @@ package eu.steffo.twom.room
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
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.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
@ -10,19 +12,20 @@ import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.res.stringResource
|
||||||
import eu.steffo.twom.R
|
import eu.steffo.twom.R
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
|
||||||
fun RoomActivityTopBar(
|
fun RoomActivityTopBar(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onBack: () -> Unit = {},
|
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(
|
TopAppBar(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
|
@ -34,10 +37,20 @@ fun RoomActivityTopBar(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title = {
|
title = {
|
||||||
Text(LocalRoom.current!!.name)
|
if (roomSummary != null) {
|
||||||
|
Text(roomSummary.displayName)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
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_description_label">Description</string>
|
||||||
<string name="create_complete_text">Create</string>
|
<string name="create_complete_text">Create</string>
|
||||||
<string name="room_options_label">Room options</string>
|
<string name="room_options_label">Room options</string>
|
||||||
|
<string name="error">Error</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue