mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-21 23:54:26 +00:00
Checkpoint because GPG key generation distracted me from what I was doing
This commit is contained in:
parent
01e744883f
commit
d91d0cfc5f
11 changed files with 152 additions and 153 deletions
|
@ -49,7 +49,7 @@
|
|||
android:theme="@style/Theme.TwoM" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.CreateRoomActivity"
|
||||
android:name=".activities.ConfigureRoomActivity"
|
||||
android:theme="@style/Theme.TwoM" />
|
||||
|
||||
<activity
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.steffo.twom.activities
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
|
@ -9,32 +10,38 @@ import androidx.activity.result.contract.ActivityResultContract
|
|||
import eu.steffo.twom.composables.createroom.CreateRoomScaffold
|
||||
|
||||
|
||||
data class CreateRoomActivityResult(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val avatarUri: String?,
|
||||
)
|
||||
|
||||
|
||||
class CreateRoomActivity : ComponentActivity() {
|
||||
class ConfigureRoomActivity : ComponentActivity() {
|
||||
companion object {
|
||||
const val NAME_EXTRA = "name"
|
||||
const val DESCRIPTION_EXTRA = "description"
|
||||
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 {
|
||||
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) {
|
||||
RESULT_OK -> CreateRoomActivityResult(
|
||||
name = intent!!.getStringExtra(NAME_EXTRA)!!,
|
||||
description = intent.getStringExtra(DESCRIPTION_EXTRA)!!,
|
||||
avatarUri = intent.getStringExtra(AVATAR_EXTRA),
|
||||
RESULT_OK -> {
|
||||
intent!!
|
||||
val name = intent.getStringExtra(NAME_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
|
||||
}
|
|
@ -16,7 +16,7 @@ class InviteUserActivity : ComponentActivity() {
|
|||
|
||||
class Contract : ActivityResultContract<Unit, String?>() {
|
||||
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? {
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package eu.steffo.twom.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.core.net.toFile
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import eu.steffo.twom.composables.main.MainScaffold
|
||||
|
@ -74,24 +71,36 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun onCreate(result: ActivityResult) {
|
||||
Log.d("Main", "Received result from create activity: $result")
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
val intent: Intent = result.data!!
|
||||
val name = intent.getStringExtra(CreateRoomActivity.NAME_EXTRA)
|
||||
val description = intent.getStringExtra(CreateRoomActivity.DESCRIPTION_EXTRA)
|
||||
@Suppress("DEPRECATION") val avatarUri =
|
||||
intent.getParcelableExtra<Uri>(CreateRoomActivity.AVATAR_EXTRA)
|
||||
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()
|
||||
|
||||
if (name == null) {
|
||||
Log.w("Main", "Result from create activity did not have `name` extra set")
|
||||
return
|
||||
}
|
||||
if (description == null) {
|
||||
Log.w("Main", "Result from create activity did not have `description` extra set")
|
||||
return
|
||||
},
|
||||
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!")
|
||||
},
|
||||
processCreate = { name, description, avatarUri ->
|
||||
lifecycleScope.launch {
|
||||
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!")
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ 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.activities.CreateRoomActivity
|
||||
import eu.steffo.twom.activities.ConfigureRoomActivity
|
||||
import eu.steffo.twom.composables.theme.TwoMTheme
|
||||
|
||||
@Composable
|
||||
|
@ -21,11 +21,11 @@ fun CreateRoomScaffold() {
|
|||
|
||||
fun submitActivity(name: String, description: String, avatarUri: Uri?) {
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(CreateRoomActivity.NAME_EXTRA, name)
|
||||
resultIntent.putExtra(CreateRoomActivity.DESCRIPTION_EXTRA, description)
|
||||
resultIntent.putExtra(ConfigureRoomActivity.NAME_EXTRA, name)
|
||||
resultIntent.putExtra(ConfigureRoomActivity.DESCRIPTION_EXTRA, description)
|
||||
// Kotlin cannot use nullable types in Java interop generics
|
||||
if (avatarUri != null) {
|
||||
resultIntent.putExtra(CreateRoomActivity.AVATAR_EXTRA, avatarUri)
|
||||
resultIntent.putExtra(ConfigureRoomActivity.AVATAR_EXTRA, avatarUri)
|
||||
}
|
||||
activity.setResult(ComponentActivity.RESULT_OK, resultIntent)
|
||||
activity.finish()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.steffo.twom.composables.main
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.launch
|
||||
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.tooling.preview.Preview
|
||||
import eu.steffo.twom.R
|
||||
import eu.steffo.twom.activities.CreateRoomActivity
|
||||
import eu.steffo.twom.activities.ConfigureRoomActivity
|
||||
|
||||
@Composable
|
||||
@Preview
|
||||
fun CreateRoomFAB(
|
||||
modifier: Modifier = Modifier,
|
||||
onCreateParamsSelected: (name: String, description: String, avatarUri: String?) -> Unit = { _, _, _ -> },
|
||||
onCreateParamsSelected: (name: String, description: String, avatarUri: Uri?) -> Unit = { _, _, _ -> },
|
||||
) {
|
||||
val launcher =
|
||||
rememberLauncherForActivityResult(CreateRoomActivity.Contract()) {
|
||||
rememberLauncherForActivityResult(ConfigureRoomActivity.Contract()) {
|
||||
if (it != null) {
|
||||
onCreateParamsSelected(it.name, it.description, it.avatarUri)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.steffo.twom.composables.main
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
|
@ -15,7 +16,7 @@ import org.matrix.android.sdk.api.session.Session
|
|||
fun MainScaffold(
|
||||
processLogin: () -> Unit = {},
|
||||
processLogout: () -> Unit = {},
|
||||
processCreate: (name: String, description: String, avatarUri: String?) -> Unit = { _, _, _ -> },
|
||||
processCreate: (name: String, description: String, avatarUri: Uri?) -> Unit = { _, _, _ -> },
|
||||
session: Session? = null,
|
||||
) {
|
||||
TwoMTheme {
|
||||
|
|
|
@ -16,14 +16,14 @@ import eu.steffo.twom.utils.RSVPAnswer
|
|||
@Preview
|
||||
fun RSVPChipRow(
|
||||
modifier: Modifier = Modifier,
|
||||
value: RSVPAnswer = RSVPAnswer.UNKNOWN,
|
||||
value: RSVPAnswer = RSVPAnswer.LOADING,
|
||||
onChange: (answer: RSVPAnswer) -> Unit = {},
|
||||
) {
|
||||
fun toggleSwitch(representing: RSVPAnswer): () -> Unit {
|
||||
return {
|
||||
onChange(
|
||||
when (value) {
|
||||
representing -> RSVPAnswer.UNKNOWN
|
||||
representing -> RSVPAnswer.NONE
|
||||
else -> representing
|
||||
}
|
||||
)
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.compose.ui.res.stringResource
|
|||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import eu.steffo.twom.R
|
||||
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.navigation.BackIconButton
|
||||
|
||||
|
@ -26,6 +27,16 @@ fun ViewRoomTopBar(
|
|||
isLoading: Boolean = false,
|
||||
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(
|
||||
modifier = modifier,
|
||||
navigationIcon = {
|
||||
|
|
|
@ -65,7 +65,7 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
|
|||
val answerField = content[TwoMGlobals.RSVP_STATE_ANSWER_FIELD]
|
||||
?: return RSVP(
|
||||
event = event,
|
||||
answer = RSVPAnswer.UNKNOWN,
|
||||
answer = RSVPAnswer.NONE,
|
||||
comment = comment,
|
||||
)
|
||||
|
||||
|
@ -81,6 +81,7 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
|
|||
RSVPAnswer.LATER.value -> RSVPAnswer.LATER
|
||||
RSVPAnswer.MAYBE.value -> RSVPAnswer.MAYBE
|
||||
RSVPAnswer.NOWAY.value -> RSVPAnswer.NOWAY
|
||||
RSVPAnswer.NONE.value -> RSVPAnswer.NONE
|
||||
else -> RSVPAnswer.UNKNOWN
|
||||
}
|
||||
|
||||
|
|
|
@ -119,8 +119,8 @@ enum class RSVPAnswer {
|
|||
|
||||
// An option differing from the previous ones.
|
||||
UNKNOWN {
|
||||
override val value: String?
|
||||
get() = null
|
||||
override val value: String
|
||||
get() = ""
|
||||
|
||||
override val staticColorRole: StaticColorRole
|
||||
get() = NullishColorRole
|
||||
|
@ -143,8 +143,8 @@ enum class RSVPAnswer {
|
|||
|
||||
// The answer is still being loaded.
|
||||
LOADING {
|
||||
override val value: String?
|
||||
get() = null
|
||||
override val value: String
|
||||
get() = ""
|
||||
|
||||
override val staticColorRole: StaticColorRole
|
||||
get() = NullishColorRole
|
||||
|
@ -166,8 +166,8 @@ enum class RSVPAnswer {
|
|||
|
||||
// No answer has been provided yet.
|
||||
NONE {
|
||||
override val value: String?
|
||||
get() = null
|
||||
override val value: String
|
||||
get() = ""
|
||||
|
||||
override val staticColorRole: StaticColorRole
|
||||
get() = NullishColorRole
|
||||
|
@ -190,8 +190,8 @@ enum class RSVPAnswer {
|
|||
|
||||
// Has been invited, but has not accepted yet.
|
||||
PENDING {
|
||||
override val value: String?
|
||||
get() = null
|
||||
override val value: String
|
||||
get() = ""
|
||||
|
||||
override val staticColorRole: StaticColorRole
|
||||
get() = NullishColorRole
|
||||
|
@ -212,7 +212,7 @@ enum class RSVPAnswer {
|
|||
stringResource(R.string.room_rsvp_nullish_placeholder)
|
||||
};
|
||||
|
||||
abstract val value: String?
|
||||
abstract val value: String
|
||||
abstract val staticColorRole: StaticColorRole
|
||||
abstract val icon: ImageVector
|
||||
|
||||
|
|
Loading…
Reference in a new issue