mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-21 15:44:26 +00:00
Create the skeleton of the RoomActivity
This commit is contained in:
parent
22b06ab30f
commit
6333a5e2d1
9 changed files with 216 additions and 4 deletions
|
@ -9,7 +9,7 @@ import androidx.compose.foundation.layout.Box
|
|||
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.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
|
@ -26,7 +26,7 @@ fun AvatarSelector(
|
|||
val context = LocalContext.current
|
||||
val resolver = context.contentResolver
|
||||
|
||||
var selection by rememberSaveable { mutableStateOf<Bitmap?>(null) }
|
||||
var selection by remember { mutableStateOf<Bitmap?>(null) }
|
||||
|
||||
val launcher =
|
||||
rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) ImageSelect@{
|
||||
|
|
|
@ -7,7 +7,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
|
@ -23,7 +23,7 @@ fun AvatarFromURL(
|
|||
contentDescription: String = "",
|
||||
) {
|
||||
val session = LocalSession.current
|
||||
var bitmap by rememberSaveable { mutableStateOf<Bitmap?>(null) }
|
||||
var bitmap by remember { mutableStateOf<Bitmap?>(null) }
|
||||
|
||||
LaunchedEffect(session, url) GetAvatar@{
|
||||
if (session == null) {
|
||||
|
|
6
app/src/main/java/eu/steffo/twom/room/LocalRoom.kt
Normal file
6
app/src/main/java/eu/steffo/twom/room/LocalRoom.kt
Normal file
|
@ -0,0 +1,6 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
|
||||
val LocalRoom = staticCompositionLocalOf<RoomSummary?> { null }
|
|
@ -1,9 +1,46 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import eu.steffo.twom.matrix.TwoMMatrix
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
||||
class RoomActivity : ComponentActivity() {
|
||||
companion object {
|
||||
const val ROOM_ID_EXTRA = "roomId"
|
||||
}
|
||||
|
||||
private lateinit var session: Session
|
||||
|
||||
private fun fetchLastSession() {
|
||||
Log.d("Main", "Fetching the last successfully authenticated session...")
|
||||
// FIXME: If this is null, it means that something launched this while no session was authenticated...
|
||||
session = TwoMMatrix.matrix.authenticationService().getLastAuthenticatedSession()!!
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// FIXME: Hopefully, if this succeeds, the session is also open... hopefully.
|
||||
fetchLastSession()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
val roomId = intent.getStringExtra(ROOM_ID_EXTRA)
|
||||
|
||||
setContent {
|
||||
RoomActivityScaffold(
|
||||
session = session,
|
||||
roomId = roomId!!, // FIXME: Again, this should be set. Should.
|
||||
onBack = {
|
||||
setResult(RESULT_CANCELED)
|
||||
finish()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
13
app/src/main/java/eu/steffo/twom/room/RoomActivityContent.kt
Normal file
13
app/src/main/java/eu/steffo/twom/room/RoomActivityContent.kt
Normal file
|
@ -0,0 +1,13 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
fun RoomActivityContent(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.ripple.rememberRipple
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.minimumInteractiveComponentSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
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() },
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
Box(modifier) {
|
||||
// Mostly copied from IconButton's source
|
||||
// TODO: Make sure accessibility works right
|
||||
// FIXME: This will need changes when Material 4 is released
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.minimumInteractiveComponentSize()
|
||||
.size(40.dp)
|
||||
.clip(MaterialTheme.shapes.medium)
|
||||
.clickable(
|
||||
role = Role.Button,
|
||||
interactionSource = interactionSource,
|
||||
indication = rememberRipple(
|
||||
bounded = false,
|
||||
radius = 28.dp
|
||||
)
|
||||
) { expanded = true },
|
||||
) {
|
||||
AvatarFromURL(
|
||||
url = LocalRoom.current!!.avatarUrl,
|
||||
contentDescription = LocalContext.current.getString(R.string.room_options_label),
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text("garasauto")
|
||||
},
|
||||
onClick = {
|
||||
expanded = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
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(
|
||||
session: Session,
|
||||
roomId: String,
|
||||
onBack: () -> Unit = {},
|
||||
) {
|
||||
val roomSummary = session.getRoomSummary(roomId)
|
||||
|
||||
TwoMTheme {
|
||||
CompositionLocalProvider(LocalSession provides session) {
|
||||
CompositionLocalProvider(LocalRoom provides roomSummary) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
RoomActivityTopBar(
|
||||
onBack = onBack,
|
||||
)
|
||||
},
|
||||
content = {
|
||||
RoomActivityContent(
|
||||
modifier = Modifier.padding(it),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
app/src/main/java/eu/steffo/twom/room/RoomActivityTopBar.kt
Normal file
43
app/src/main/java/eu/steffo/twom/room/RoomActivityTopBar.kt
Normal file
|
@ -0,0 +1,43 @@
|
|||
package eu.steffo.twom.room
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
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 eu.steffo.twom.R
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@Preview
|
||||
fun RoomActivityTopBar(
|
||||
modifier: Modifier = Modifier,
|
||||
onBack: () -> Unit = {},
|
||||
roomName: String = "{Room name}",
|
||||
roomAvatarURL: String? = null,
|
||||
) {
|
||||
TopAppBar(
|
||||
modifier = modifier,
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.ArrowBack,
|
||||
contentDescription = LocalContext.current.getString(R.string.back)
|
||||
)
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(LocalRoom.current!!.name)
|
||||
},
|
||||
actions = {
|
||||
RoomActivityRoomIconButton()
|
||||
},
|
||||
)
|
||||
}
|
|
@ -32,4 +32,5 @@
|
|||
<string name="create_avatar_label">Select happening avatar</string>
|
||||
<string name="create_description_label">Description</string>
|
||||
<string name="create_complete_text">Create</string>
|
||||
<string name="room_options_label">Room options</string>
|
||||
</resources>
|
Loading…
Reference in a new issue