Login: change server screen WIP
This commit is contained in:
parent
ae17ff1b58
commit
0840602069
12 changed files with 398 additions and 117 deletions
|
|
@ -48,4 +48,5 @@ dependencies {
|
|||
implementation 'androidx.fragment:fragment-ktx:1.5.3'
|
||||
|
||||
implementation 'com.airbnb.android:mavericks-compose:3.0.1'
|
||||
implementation 'androidx.compose.foundation:foundation-layout:1.3.1'
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package io.element.android.x.core.compose
|
||||
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.isImeVisible
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
||||
/**
|
||||
* Inspired from https://stackoverflow.com/questions/68847559/how-can-i-detect-keyboard-opening-and-closing-in-jetpack-compose
|
||||
*/
|
||||
enum class Keyboard {
|
||||
Opened, Closed
|
||||
}
|
||||
|
||||
// Note: it does not work as expected...
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
fun keyboardAsState(): State<Keyboard> {
|
||||
val lifecycle = LocalLifecycleOwner.current.lifecycle
|
||||
val isResumed = lifecycle.currentState == Lifecycle.State.RESUMED
|
||||
return rememberUpdatedState(if (WindowInsets.isImeVisible && isResumed) Keyboard.Opened else Keyboard.Closed)
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@ import io.element.android.x.matrix.util.logError
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.rustcomponents.sdk.AuthenticationService
|
||||
import org.matrix.rustcomponents.sdk.Client
|
||||
|
|
@ -27,6 +26,7 @@ class Matrix(
|
|||
private val baseFolder = File(context.filesDir, "matrix")
|
||||
private val sessionStore = SessionStore(context)
|
||||
private val matrixClient = MutableStateFlow<Optional<MatrixClient>>(Optional.empty())
|
||||
private val authService = AuthenticationService(baseFolder.absolutePath)
|
||||
|
||||
init {
|
||||
sessionStore.isLoggedIn()
|
||||
|
|
@ -70,10 +70,14 @@ class Matrix(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun login(homeserver: String, username: String, password: String): MatrixClient =
|
||||
suspend fun setHomeserver(homeserver: String) {
|
||||
withContext(coroutineDispatchers.io) {
|
||||
val authService = AuthenticationService(baseFolder.absolutePath)
|
||||
authService.configureHomeserver(homeserver)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun login(username: String, password: String): MatrixClient =
|
||||
withContext(coroutineDispatchers.io) {
|
||||
val client = authService.login(username, password, "MatrixRustSDKSample", null)
|
||||
sessionStore.storeData(client.session())
|
||||
createMatrixClient(client)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue