Add a module for the Matrix SDK with the aar of the Rust SDK

This commit is contained in:
Benoit Marty 2022-10-11 14:05:39 +02:00
parent df315ecea6
commit 98eeb08772
14 changed files with 131 additions and 34 deletions

View file

@ -1,2 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View file

@ -0,0 +1,3 @@
package io.element.android.x.sdk.matrix
internal const val LOG_TAG = "Matrix"

View file

@ -1,40 +1,18 @@
package io.element.android.x.sdk.matrix
import android.content.Context
import android.util.Log
import uniffi.matrix_sdk_ffi.AuthenticationService
import java.io.File
private const val LOG_TAG = "Matrix"
class Matrix(
private val context: Context,
context: Context,
) {
fun login(username: String, password: String) {
val authFolder = File(context.filesDir, "auth")
private val authFolder = File(context.filesDir, "auth")
fun login(homeserver: String, username: String, password: String): MatrixClient {
val authService = AuthenticationService(authFolder.absolutePath)
authService.configureHomeserver("matrix.org")
authService.configureHomeserver(homeserver)
val client = authService.login(username, password, "MatrixRustSDKSample", null)
val clientDelegate = object : ClientDelegate {
override fun didReceiveAuthError(isSoftLogout: Boolean) {
Log.v(LOG_TAG, "didReceiveAuthError()")
}
override fun didReceiveSyncUpdate() {
Log.v(LOG_TAG, "didReceiveSyncUpdate()")
}
override fun didUpdateRestoreToken() {
Log.v(LOG_TAG, "didUpdateRestoreToken()")
}
}
client.setDelegate(clientDelegate)
Log.v(LOG_TAG, "DisplayName = ${client.displayName()}")
try {
client.fullSlidingSync()
} catch (failure: Throwable) {
Log.e(LOG_TAG, "fullSlidingSync() fail", failure)
}
client.logout()
return MatrixClient(client)
}
}

View file

@ -0,0 +1,37 @@
package io.element.android.x.sdk.matrix
import android.util.Log
import uniffi.matrix_sdk_ffi.Client
import uniffi.matrix_sdk_ffi.ClientDelegate
class MatrixClient internal constructor(
private val client: Client
) {
fun startSync() {
val clientDelegate = object : ClientDelegate {
override fun didReceiveAuthError(isSoftLogout: Boolean) {
Log.v(LOG_TAG, "didReceiveAuthError()")
}
override fun didReceiveSyncUpdate() {
Log.v(LOG_TAG, "didReceiveSyncUpdate()")
}
override fun didUpdateRestoreToken() {
Log.v(LOG_TAG, "didUpdateRestoreToken()")
}
}
client.setDelegate(clientDelegate)
Log.v(LOG_TAG, "DisplayName = ${client.displayName()}")
try {
client.fullSlidingSync()
} catch (failure: Throwable) {
Log.e(LOG_TAG, "fullSlidingSync() fail", failure)
}
}
fun logout() {
client.logout()
}
}

View file

@ -0,0 +1,18 @@
package io.element.android.x.sdk.matrix
import android.annotation.SuppressLint
import android.content.Context
object MatrixInstance {
@SuppressLint("StaticFieldLeak")
private lateinit var instance: Matrix
fun init(context: Context) {
instance = Matrix(context)
}
fun getInstance(): Matrix {
return instance
}
}