mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-25 01:24:24 +00:00
Checkpoint
This commit is contained in:
parent
4ab3fa168c
commit
a6e562c14b
8 changed files with 100 additions and 34 deletions
|
@ -1,7 +1,7 @@
|
|||
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
|
||||
import org.matrix.android.sdk.api.session.room.Room
|
||||
import java.util.Optional
|
||||
|
||||
val LocalRoom = staticCompositionLocalOf<Optional<RoomSummary>?> { null }
|
||||
val LocalRoom = staticCompositionLocalOf<Optional<Room>?> { null }
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
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 LocalRoomSummary = staticCompositionLocalOf<Optional<RoomSummary>?> { null }
|
|
@ -14,8 +14,9 @@ import eu.steffo.twom.theme.iconMaybe
|
|||
import eu.steffo.twom.theme.iconNoway
|
||||
import eu.steffo.twom.theme.iconSure
|
||||
import eu.steffo.twom.theme.iconUnknown
|
||||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
|
||||
enum class RSVPAnswer {
|
||||
enum class RSVPAnswer : JsonDict {
|
||||
SURE,
|
||||
LATER,
|
||||
MAYBE,
|
||||
|
|
|
@ -5,30 +5,49 @@ import androidx.compose.foundation.layout.Row
|
|||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
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.theme.ErrorText
|
||||
import eu.steffo.twom.theme.TwoMPadding
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
|
||||
@Composable
|
||||
fun RoomActivityContent(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val isLoading = (LocalRoom.current == null)
|
||||
val roomSummary = LocalRoom.current?.getOrNull()
|
||||
val isError = (!isLoading && roomSummary == null)
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
var rsvpAnswer by rememberSaveable { mutableStateOf<RSVPAnswer?>(null) }
|
||||
var rsvpComment by rememberSaveable { mutableStateOf("") }
|
||||
val session = LocalSession.current
|
||||
val roomRequest = LocalRoom.current
|
||||
val room = roomRequest?.getOrNull()
|
||||
val roomSummaryRequest = LocalRoomSummary.current
|
||||
val roomSummary = roomSummaryRequest?.getOrNull()
|
||||
|
||||
val myRsvp = room?.stateService()?.getStateEventLive(
|
||||
eventType = "eu.steffo.twom.rsvp",
|
||||
stateKey = QueryStringValue.Equals(session!!.myUserId),
|
||||
)?.observeAsState()
|
||||
// TODO: I stopped here; how to retrieve the RSVP from this?
|
||||
|
||||
Column(modifier) {
|
||||
if (roomSummary != null) {
|
||||
if (session == null) {
|
||||
ErrorText(stringResource(R.string.room_error_session_missing))
|
||||
} else if (roomRequest == null) {
|
||||
ErrorText(stringResource(R.string.room_error_room_missing))
|
||||
} else if (!roomRequest.isPresent) {
|
||||
ErrorText(stringResource(R.string.room_error_room_notfound))
|
||||
} else if (roomSummaryRequest == null) {
|
||||
// Loading
|
||||
} else if (!roomSummaryRequest.hasValue()) {
|
||||
ErrorText(stringResource(R.string.room_error_room_notfound))
|
||||
} else if (roomSummary != null) {
|
||||
Row(TwoMPadding.base) {
|
||||
Text(
|
||||
text = stringResource(R.string.room_topic_title),
|
||||
|
@ -47,11 +66,21 @@ fun RoomActivityContent(
|
|||
}
|
||||
|
||||
RoomActivityAnswerForm(
|
||||
currentRsvpAnswer = rsvpAnswer,
|
||||
currentRsvpComment = rsvpComment,
|
||||
currentRsvpAnswer = myRsvp,
|
||||
currentRsvpComment = myRsvp,
|
||||
onUpdate = { answer, comment ->
|
||||
rsvpAnswer = answer
|
||||
rsvpComment = comment
|
||||
scope.launch SendStateEvent@{
|
||||
room!!.stateService().sendStateEvent(
|
||||
eventType = "eu.steffo.twom.rsvp",
|
||||
stateKey = session.myUserId,
|
||||
body = mapOf(
|
||||
pairs = arrayOf(
|
||||
"answer" to answer.toString(),
|
||||
"comment" to comment,
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -62,7 +91,6 @@ fun RoomActivityContent(
|
|||
)
|
||||
}
|
||||
|
||||
// TODO: Risky assertion?
|
||||
Column(TwoMPadding.base) {
|
||||
MemberListItem(
|
||||
memberId = LocalSession.current!!.myUserId,
|
||||
|
@ -78,6 +106,14 @@ fun RoomActivityContent(
|
|||
)
|
||||
}
|
||||
}
|
||||
} else if (isError) {
|
||||
Row(TwoMPadding.base) {
|
||||
Text(
|
||||
// TODO: Maybe add a better error string
|
||||
text = stringResource(R.string.error),
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ 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 java.util.Optional
|
||||
|
||||
@Composable
|
||||
fun RoomActivityScaffold(
|
||||
|
@ -17,23 +18,26 @@ fun RoomActivityScaffold(
|
|||
roomId: String,
|
||||
onBack: () -> Unit = {},
|
||||
) {
|
||||
val room = Optional.ofNullable(session.roomService().getRoom(roomId))
|
||||
val roomSummary by session.roomService().getRoomSummaryLive(roomId).observeAsState()
|
||||
|
||||
TwoMTheme {
|
||||
CompositionLocalProvider(LocalSession provides session) {
|
||||
CompositionLocalProvider(LocalRoom provides roomSummary) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
RoomActivityTopBar(
|
||||
onBack = onBack,
|
||||
)
|
||||
},
|
||||
content = {
|
||||
RoomActivityContent(
|
||||
modifier = Modifier.padding(it),
|
||||
)
|
||||
},
|
||||
)
|
||||
CompositionLocalProvider(LocalRoom provides room) {
|
||||
CompositionLocalProvider(LocalRoomSummary provides roomSummary) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
RoomActivityTopBar(
|
||||
onBack = onBack,
|
||||
)
|
||||
},
|
||||
content = {
|
||||
RoomActivityContent(
|
||||
modifier = Modifier.padding(it),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ fun RoomActivityTopBar(
|
|||
modifier: Modifier = Modifier,
|
||||
onBack: () -> Unit = {},
|
||||
) {
|
||||
val isLoading = (LocalRoom.current == null)
|
||||
val roomSummary = LocalRoom.current?.getOrNull()
|
||||
val isLoading = (LocalRoomSummary.current == null)
|
||||
val roomSummary = LocalRoomSummary.current?.getOrNull()
|
||||
val isError = (!isLoading && roomSummary == null)
|
||||
|
||||
TopAppBar(
|
||||
|
|
15
app/src/main/java/eu/steffo/twom/theme/ErrorText.kt
Normal file
15
app/src/main/java/eu/steffo/twom/theme/ErrorText.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
package eu.steffo.twom.theme
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun ErrorText(
|
||||
text: String
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
}
|
|
@ -55,4 +55,7 @@
|
|||
<string name="room_rsvp_unknown_response">Hasn\'t answered yet</string>
|
||||
<string name="room_rsvp_unknown_placeholder">Leave a comment…</string>
|
||||
<string name="room_update_label">Update</string>
|
||||
<string name="room_error_session_missing">The Matrix session context has not been initialized.</string>
|
||||
<string name="room_error_room_notfound">Could not find the requested Matrix room.</string>
|
||||
<string name="room_error_room_missing">The Matrix room context has not been initialized.</string>
|
||||
</resources>
|
Loading…
Reference in a new issue