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

This commit is contained in:
Benoit Marty
2022-10-11 12:21:46 +02:00
parent 36f2b4dabf
commit df315ecea6
5 changed files with 79 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,5 @@
# Built application files
*.apk
*.aar
*.ap_
*.aab

View File

@@ -0,0 +1,33 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'io.element.android.x.sdk.matrix'
compileSdk 33
defaultConfig {
minSdk 29
targetSdk 33
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation(name: 'sdk-android-release', ext: 'aar')
implementation "net.java.dev.jna:jna:5.10.0@aar"
}

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />

View File

@@ -0,0 +1,40 @@
package io.element.android.x.sdk.matrix
import android.content.Context
import android.util.Log
import java.io.File
private const val LOG_TAG = "Matrix"
class Matrix(
private val context: Context,
) {
fun login(username: String, password: String) {
val authFolder = File(context.filesDir, "auth")
val authService = AuthenticationService(authFolder.absolutePath)
authService.configureHomeserver("matrix.org")
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()
}
}

View File

@@ -10,9 +10,13 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
rootProject.name = "ElementX"
include ':app'
include ':libraries:ui:theme'
include ':libraries:ui:screens:login'
include ':libraries:sdk:matrix'