1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-22 08:04:26 +00:00

Checkpoint because GPG key generation distracted me from what I was doing

This commit is contained in:
Steffo 2024-01-13 10:31:59 +01:00
parent 01e744883f
commit d91d0cfc5f
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
11 changed files with 152 additions and 153 deletions

View file

@ -49,7 +49,7 @@
android:theme="@style/Theme.TwoM" /> android:theme="@style/Theme.TwoM" />
<activity <activity
android:name=".activities.CreateRoomActivity" android:name=".activities.ConfigureRoomActivity"
android:theme="@style/Theme.TwoM" /> android:theme="@style/Theme.TwoM" />
<activity <activity

View file

@ -2,6 +2,7 @@ package eu.steffo.twom.activities
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@ -9,32 +10,38 @@ import androidx.activity.result.contract.ActivityResultContract
import eu.steffo.twom.composables.createroom.CreateRoomScaffold import eu.steffo.twom.composables.createroom.CreateRoomScaffold
data class CreateRoomActivityResult( class ConfigureRoomActivity : ComponentActivity() {
val name: String,
val description: String,
val avatarUri: String?,
)
class CreateRoomActivity : ComponentActivity() {
companion object { companion object {
const val NAME_EXTRA = "name" const val NAME_EXTRA = "name"
const val DESCRIPTION_EXTRA = "description" const val DESCRIPTION_EXTRA = "description"
const val AVATAR_EXTRA = "avatar" const val AVATAR_EXTRA = "avatar"
} }
class Contract : ActivityResultContract<Unit, CreateRoomActivityResult?>() { data class Result(
val name: String,
val description: String,
val avatarUri: Uri?,
)
class Contract : ActivityResultContract<Unit, Result?>() {
override fun createIntent(context: Context, input: Unit): Intent { override fun createIntent(context: Context, input: Unit): Intent {
return Intent(context, CreateRoomActivity::class.java) return Intent(context, ConfigureRoomActivity::class.java)
} }
override fun parseResult(resultCode: Int, intent: Intent?): CreateRoomActivityResult? { override fun parseResult(resultCode: Int, intent: Intent?): Result? {
return when (resultCode) { return when (resultCode) {
RESULT_OK -> CreateRoomActivityResult( RESULT_OK -> {
name = intent!!.getStringExtra(NAME_EXTRA)!!, intent!!
description = intent.getStringExtra(DESCRIPTION_EXTRA)!!, val name = intent.getStringExtra(NAME_EXTRA)!!
avatarUri = intent.getStringExtra(AVATAR_EXTRA), val description = intent.getStringExtra(DESCRIPTION_EXTRA)!!
val avatar = intent.getStringExtra(AVATAR_EXTRA)
Result(
name = name,
description = description,
avatarUri = if (avatar != null) Uri.parse(avatar) else null,
) )
}
else -> null else -> null
} }

View file

@ -16,7 +16,7 @@ class InviteUserActivity : ComponentActivity() {
class Contract : ActivityResultContract<Unit, String?>() { class Contract : ActivityResultContract<Unit, String?>() {
override fun createIntent(context: Context, input: Unit): Intent { override fun createIntent(context: Context, input: Unit): Intent {
return Intent(context, CreateRoomActivity::class.java) return Intent(context, ConfigureRoomActivity::class.java)
} }
override fun parseResult(resultCode: Int, intent: Intent?): String? { override fun parseResult(resultCode: Int, intent: Intent?): String? {

View file

@ -1,12 +1,9 @@
package eu.steffo.twom.activities package eu.steffo.twom.activities
import android.content.Intent
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.result.ActivityResult
import androidx.core.net.toFile import androidx.core.net.toFile
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import eu.steffo.twom.composables.main.MainScaffold import eu.steffo.twom.composables.main.MainScaffold
@ -74,24 +71,36 @@ class MainActivity : ComponentActivity() {
} }
} }
private fun onCreate(result: ActivityResult) { private fun resetContent() {
Log.d("Main", "Received result from create activity: $result") Log.d("Main", "Recomposing...")
if (result.resultCode == RESULT_OK) { setContent {
val intent: Intent = result.data!! // TODO: Check this with a clearer mind
val name = intent.getStringExtra(CreateRoomActivity.NAME_EXTRA) MainScaffold(
val description = intent.getStringExtra(CreateRoomActivity.DESCRIPTION_EXTRA) session = session,
@Suppress("DEPRECATION") val avatarUri = processLogin = {
intent.getParcelableExtra<Uri>(CreateRoomActivity.AVATAR_EXTRA) Log.d(
"Main",
"Login activity returned a successful result, trying to get session..."
)
fetchLastSession()
openSession()
if (name == null) { },
Log.w("Main", "Result from create activity did not have `name` extra set") processLogout = {
return val signedOutSession = session!!
}
if (description == null) { Log.d("Main", "Clicked logout, recomposing...")
Log.w("Main", "Result from create activity did not have `description` extra set") session = null
return resetContent()
Log.d("Main", "Done recomposing, now signing out...")
lifecycleScope.launch {
signedOutSession.signOutService().signOut(true)
} }
Log.d("Main", "Done logging out!")
},
processCreate = { name, description, avatarUri ->
lifecycleScope.launch { lifecycleScope.launch {
val currentSession = session val currentSession = session
@ -184,37 +193,6 @@ class MainActivity : ComponentActivity() {
) )
} }
} }
}
private fun resetContent() {
Log.d("Main", "Recomposing...")
setContent {
// TODO: Check this with a clearer mind
MainScaffold(
session = session,
processLogin = {
Log.d(
"Main",
"Login activity returned a successful result, trying to get session..."
)
fetchLastSession()
openSession()
},
processLogout = {
val signedOutSession = session!!
Log.d("Main", "Clicked logout, recomposing...")
session = null
resetContent()
Log.d("Main", "Done recomposing, now signing out...")
lifecycleScope.launch {
signedOutSession.signOutService().signOut(true)
}
Log.d("Main", "Done logging out!")
},
) )
} }
} }

View file

@ -10,7 +10,7 @@ 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.tooling.preview.Preview
import eu.steffo.twom.activities.CreateRoomActivity import eu.steffo.twom.activities.ConfigureRoomActivity
import eu.steffo.twom.composables.theme.TwoMTheme import eu.steffo.twom.composables.theme.TwoMTheme
@Composable @Composable
@ -21,11 +21,11 @@ fun CreateRoomScaffold() {
fun submitActivity(name: String, description: String, avatarUri: Uri?) { fun submitActivity(name: String, description: String, avatarUri: Uri?) {
val resultIntent = Intent() val resultIntent = Intent()
resultIntent.putExtra(CreateRoomActivity.NAME_EXTRA, name) resultIntent.putExtra(ConfigureRoomActivity.NAME_EXTRA, name)
resultIntent.putExtra(CreateRoomActivity.DESCRIPTION_EXTRA, description) resultIntent.putExtra(ConfigureRoomActivity.DESCRIPTION_EXTRA, description)
// Kotlin cannot use nullable types in Java interop generics // Kotlin cannot use nullable types in Java interop generics
if (avatarUri != null) { if (avatarUri != null) {
resultIntent.putExtra(CreateRoomActivity.AVATAR_EXTRA, avatarUri) resultIntent.putExtra(ConfigureRoomActivity.AVATAR_EXTRA, avatarUri)
} }
activity.setResult(ComponentActivity.RESULT_OK, resultIntent) activity.setResult(ComponentActivity.RESULT_OK, resultIntent)
activity.finish() activity.finish()

View file

@ -1,5 +1,6 @@
package eu.steffo.twom.composables.main package eu.steffo.twom.composables.main
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.launch import androidx.activity.result.launch
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -12,16 +13,16 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import eu.steffo.twom.R import eu.steffo.twom.R
import eu.steffo.twom.activities.CreateRoomActivity import eu.steffo.twom.activities.ConfigureRoomActivity
@Composable @Composable
@Preview @Preview
fun CreateRoomFAB( fun CreateRoomFAB(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onCreateParamsSelected: (name: String, description: String, avatarUri: String?) -> Unit = { _, _, _ -> }, onCreateParamsSelected: (name: String, description: String, avatarUri: Uri?) -> Unit = { _, _, _ -> },
) { ) {
val launcher = val launcher =
rememberLauncherForActivityResult(CreateRoomActivity.Contract()) { rememberLauncherForActivityResult(ConfigureRoomActivity.Contract()) {
if (it != null) { if (it != null) {
onCreateParamsSelected(it.name, it.description, it.avatarUri) onCreateParamsSelected(it.name, it.description, it.avatarUri)
} }

View file

@ -1,5 +1,6 @@
package eu.steffo.twom.composables.main package eu.steffo.twom.composables.main
import android.net.Uri
import androidx.compose.foundation.layout.padding 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
@ -15,7 +16,7 @@ import org.matrix.android.sdk.api.session.Session
fun MainScaffold( fun MainScaffold(
processLogin: () -> Unit = {}, processLogin: () -> Unit = {},
processLogout: () -> Unit = {}, processLogout: () -> Unit = {},
processCreate: (name: String, description: String, avatarUri: String?) -> Unit = { _, _, _ -> }, processCreate: (name: String, description: String, avatarUri: Uri?) -> Unit = { _, _, _ -> },
session: Session? = null, session: Session? = null,
) { ) {
TwoMTheme { TwoMTheme {

View file

@ -16,14 +16,14 @@ import eu.steffo.twom.utils.RSVPAnswer
@Preview @Preview
fun RSVPChipRow( fun RSVPChipRow(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
value: RSVPAnswer = RSVPAnswer.UNKNOWN, value: RSVPAnswer = RSVPAnswer.LOADING,
onChange: (answer: RSVPAnswer) -> Unit = {}, onChange: (answer: RSVPAnswer) -> Unit = {},
) { ) {
fun toggleSwitch(representing: RSVPAnswer): () -> Unit { fun toggleSwitch(representing: RSVPAnswer): () -> Unit {
return { return {
onChange( onChange(
when (value) { when (value) {
representing -> RSVPAnswer.UNKNOWN representing -> RSVPAnswer.NONE
else -> representing else -> representing
} }
) )

View file

@ -12,6 +12,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import eu.steffo.twom.R import eu.steffo.twom.R
import eu.steffo.twom.composables.errorhandling.ErrorIconButton import eu.steffo.twom.composables.errorhandling.ErrorIconButton
import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LocalizableError import eu.steffo.twom.composables.errorhandling.LocalizableError
import eu.steffo.twom.composables.navigation.BackIconButton import eu.steffo.twom.composables.navigation.BackIconButton
@ -26,6 +27,16 @@ fun ViewRoomTopBar(
isLoading: Boolean = false, isLoading: Boolean = false,
error: LocalizableError? = null, error: LocalizableError? = null,
) { ) {
val roomSummaryRequest = LocalRoomSummary.current
val isLoading = (roomSummaryRequest == null)
val roomSummary = roomSummaryRequest.getOrNull()
if (roomSummary == null) {
ErrorText(stringResource(R.string.room_error_roomsummary_notfound))
return
}
TopAppBar( TopAppBar(
modifier = modifier, modifier = modifier,
navigationIcon = { navigationIcon = {

View file

@ -65,7 +65,7 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
val answerField = content[TwoMGlobals.RSVP_STATE_ANSWER_FIELD] val answerField = content[TwoMGlobals.RSVP_STATE_ANSWER_FIELD]
?: return RSVP( ?: return RSVP(
event = event, event = event,
answer = RSVPAnswer.UNKNOWN, answer = RSVPAnswer.NONE,
comment = comment, comment = comment,
) )
@ -81,6 +81,7 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
RSVPAnswer.LATER.value -> RSVPAnswer.LATER RSVPAnswer.LATER.value -> RSVPAnswer.LATER
RSVPAnswer.MAYBE.value -> RSVPAnswer.MAYBE RSVPAnswer.MAYBE.value -> RSVPAnswer.MAYBE
RSVPAnswer.NOWAY.value -> RSVPAnswer.NOWAY RSVPAnswer.NOWAY.value -> RSVPAnswer.NOWAY
RSVPAnswer.NONE.value -> RSVPAnswer.NONE
else -> RSVPAnswer.UNKNOWN else -> RSVPAnswer.UNKNOWN
} }

View file

@ -119,8 +119,8 @@ enum class RSVPAnswer {
// An option differing from the previous ones. // An option differing from the previous ones.
UNKNOWN { UNKNOWN {
override val value: String? override val value: String
get() = null get() = ""
override val staticColorRole: StaticColorRole override val staticColorRole: StaticColorRole
get() = NullishColorRole get() = NullishColorRole
@ -143,8 +143,8 @@ enum class RSVPAnswer {
// The answer is still being loaded. // The answer is still being loaded.
LOADING { LOADING {
override val value: String? override val value: String
get() = null get() = ""
override val staticColorRole: StaticColorRole override val staticColorRole: StaticColorRole
get() = NullishColorRole get() = NullishColorRole
@ -166,8 +166,8 @@ enum class RSVPAnswer {
// No answer has been provided yet. // No answer has been provided yet.
NONE { NONE {
override val value: String? override val value: String
get() = null get() = ""
override val staticColorRole: StaticColorRole override val staticColorRole: StaticColorRole
get() = NullishColorRole get() = NullishColorRole
@ -190,8 +190,8 @@ enum class RSVPAnswer {
// Has been invited, but has not accepted yet. // Has been invited, but has not accepted yet.
PENDING { PENDING {
override val value: String? override val value: String
get() = null get() = ""
override val staticColorRole: StaticColorRole override val staticColorRole: StaticColorRole
get() = NullishColorRole get() = NullishColorRole
@ -212,7 +212,7 @@ enum class RSVPAnswer {
stringResource(R.string.room_rsvp_nullish_placeholder) stringResource(R.string.room_rsvp_nullish_placeholder)
}; };
abstract val value: String? abstract val value: String
abstract val staticColorRole: StaticColorRole abstract val staticColorRole: StaticColorRole
abstract val icon: ImageVector abstract val icon: ImageVector