mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-22 14:38:15 +08:00
Make the sdk targeting android to win time
This commit is contained in:
parent
54fb54a695
commit
c4316d5055
Binary file not shown.
@ -10,7 +10,6 @@
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/matrix-sdk-android" />
|
||||
<option value="$PROJECT_DIR$/matrix-sdk-core" />
|
||||
<option value="$PROJECT_DIR$/matrix-sdk-rx" />
|
||||
</set>
|
||||
</option>
|
||||
|
@ -22,16 +22,17 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation project(":matrix-sdk-core")
|
||||
implementation project(":matrix-sdk-android")
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
implementation "org.koin:koin-core:$koin_version"
|
||||
implementation "org.koin:koin-core-ext:$koin_version"
|
||||
|
||||
implementation "org.koin:koin-android:$koin_version"
|
||||
implementation "org.koin:koin-android-scope:$koin_version"
|
||||
implementation "org.koin:koin-android-viewmodel:$koin_version"
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
compile project(path: ':matrix-sdk-android')
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:name=".Riot"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
@ -1,13 +1,14 @@
|
||||
package im.vector.riotredesign
|
||||
|
||||
import android.app.Application
|
||||
import im.vector.riotredesign.core.di.AppModule
|
||||
import org.koin.standalone.StandAloneContext.startKoin
|
||||
|
||||
class Riot : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
startKoin(emptyList())
|
||||
startKoin(listOf(AppModule(this)))
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package im.vector.riotredesign.core.di
|
||||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.MatrixOptions
|
||||
import org.koin.dsl.context.ModuleDefinition
|
||||
import org.koin.dsl.module.Module
|
||||
import org.koin.dsl.module.module
|
||||
|
||||
class AppModule(private val context: Context) : Module {
|
||||
|
||||
override fun invoke(): ModuleDefinition = module {
|
||||
|
||||
single {
|
||||
val matrixOptions = MatrixOptions(context)
|
||||
Matrix(matrixOptions)
|
||||
}
|
||||
|
||||
}.invoke()
|
||||
}
|
@ -3,22 +3,21 @@ package im.vector.riotredesign.features.login
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import im.vector.matrix.android.thread.MainThreadExecutor
|
||||
import im.vector.matrix.core.api.Matrix
|
||||
import im.vector.matrix.core.api.MatrixCallback
|
||||
import im.vector.matrix.core.api.MatrixOptions
|
||||
import im.vector.matrix.core.api.failure.Failure
|
||||
import im.vector.matrix.core.api.login.data.Credentials
|
||||
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.platform.RiotActivity
|
||||
import im.vector.riotredesign.features.home.HomeActivity
|
||||
import kotlinx.android.synthetic.main.activity_login.*
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class LoginActivity : RiotActivity() {
|
||||
|
||||
private val matrixOptions = MatrixOptions(mainExecutor = MainThreadExecutor())
|
||||
private val matrix = Matrix(matrixOptions)
|
||||
private val matrix by inject<Matrix>()
|
||||
|
||||
private val homeServerConnectionConfig = HomeServerConnectionConfig("https://matrix.org/")
|
||||
private val session = matrix.createSession(homeServerConnectionConfig)
|
||||
private val authenticator = session.authenticator()
|
||||
|
@ -1,5 +1,24 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'io.objectbox'
|
||||
|
||||
ext.support_version = '28.0.0'
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "io.objectbox:objectbox-gradle-plugin:2.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
@ -24,10 +43,28 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
implementation "com.android.support:appcompat-v7:$support_version"
|
||||
implementation "com.android.support:recyclerview-v7:$support_version"
|
||||
|
||||
// Network
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
|
||||
implementation 'com.squareup.okio:okio:1.15.0'
|
||||
implementation 'com.squareup.moshi:moshi-kotlin:1.7.0'
|
||||
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.7.0'
|
||||
|
||||
// Paging
|
||||
implementation "android.arch.paging:runtime:1.0.1"
|
||||
|
||||
// DI
|
||||
implementation "org.koin:koin-core:$koin_version"
|
||||
implementation "org.koin:koin-core-ext:$koin_version"
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
|
50
matrix-sdk-android/objectbox-models/default.json
Normal file
50
matrix-sdk-android/objectbox-models/default.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
|
||||
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
|
||||
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
|
||||
"entities": [
|
||||
{
|
||||
"id": "1:637433444018824383",
|
||||
"lastPropertyId": "6:2515822585258942903",
|
||||
"name": "Credentials",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:6211403495341530846",
|
||||
"name": "id"
|
||||
},
|
||||
{
|
||||
"id": "2:1774175862476960436",
|
||||
"name": "userId"
|
||||
},
|
||||
{
|
||||
"id": "3:5757014528669120452",
|
||||
"name": "homeServer"
|
||||
},
|
||||
{
|
||||
"id": "4:6085081322264805865",
|
||||
"name": "accessToken"
|
||||
},
|
||||
{
|
||||
"id": "5:5476767963007280768",
|
||||
"name": "refreshToken"
|
||||
},
|
||||
{
|
||||
"id": "6:2515822585258942903",
|
||||
"name": "deviceId"
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
}
|
||||
],
|
||||
"lastEntityId": "1:637433444018824383",
|
||||
"lastIndexId": "0:0",
|
||||
"lastRelationId": "0:0",
|
||||
"lastSequenceId": "0:0",
|
||||
"modelVersion": 4,
|
||||
"modelVersionParserMinimum": 4,
|
||||
"retiredEntityUids": [],
|
||||
"retiredIndexUids": [],
|
||||
"retiredPropertyUids": [],
|
||||
"retiredRelationUids": [],
|
||||
"version": 1
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package im.vector.matrix.core.api
|
||||
package im.vector.matrix.android.api
|
||||
|
||||
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.core.internal.DefaultSession
|
||||
import im.vector.matrix.core.internal.MatrixModule
|
||||
import im.vector.matrix.core.internal.network.NetworkModule
|
||||
import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.internal.DefaultSession
|
||||
import im.vector.matrix.android.internal.di.MatrixModule
|
||||
import im.vector.matrix.android.internal.di.NetworkModule
|
||||
import org.koin.standalone.StandAloneContext.loadKoinModules
|
||||
|
||||
class Matrix(matrixOptions: MatrixOptions) {
|
@ -1,6 +1,6 @@
|
||||
package im.vector.matrix.core.api
|
||||
package im.vector.matrix.android.api
|
||||
|
||||
import im.vector.matrix.core.api.failure.Failure
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
|
||||
interface MatrixCallback<in T> {
|
||||
|
@ -0,0 +1,8 @@
|
||||
package im.vector.matrix.android.api
|
||||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.api.thread.MainThreadExecutor
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
data class MatrixOptions(val context: Context,
|
||||
val mainExecutor: Executor = MainThreadExecutor())
|
@ -0,0 +1,11 @@
|
||||
package im.vector.matrix.android.api
|
||||
|
||||
import im.vector.matrix.android.api.login.Authenticator
|
||||
|
||||
interface Session {
|
||||
|
||||
fun authenticator(): Authenticator
|
||||
|
||||
fun close()
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.events
|
||||
package im.vector.matrix.android.api.events
|
||||
|
||||
data class Event(val sender: String,
|
||||
val eventType: EventType)
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.events
|
||||
package im.vector.matrix.android.api.events
|
||||
|
||||
sealed class EventType(val str: String) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.failure
|
||||
package im.vector.matrix.android.api.failure
|
||||
|
||||
sealed class Failure {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.failure
|
||||
package im.vector.matrix.android.api.failure
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
@ -0,0 +1,11 @@
|
||||
package im.vector.matrix.android.api.login
|
||||
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
|
||||
interface Authenticator {
|
||||
|
||||
fun authenticate(login: String, password: String, callback: MatrixCallback<Credentials>): Cancelable
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package im.vector.matrix.android.api.login
|
||||
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
|
||||
interface CredentialsStore {
|
||||
|
||||
fun get(): Credentials?
|
||||
|
||||
fun save(credentials: Credentials)
|
||||
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
package im.vector.matrix.core.api.login.data
|
||||
package im.vector.matrix.android.api.login.data
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import io.objectbox.annotation.Entity
|
||||
import io.objectbox.annotation.Id
|
||||
|
||||
@Entity
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Credentials(@Json(name = "user_id") val userId: String,
|
||||
data class Credentials(@Id var id: Long = 0,
|
||||
@Json(name = "user_id") val userId: String,
|
||||
@Json(name = "home_server") val homeServer: String,
|
||||
@Json(name = "access_token") val accessToken: String,
|
||||
@Json(name = "refresh_token") val refreshToken: String?,
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.login.data
|
||||
package im.vector.matrix.android.api.login.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -0,0 +1,15 @@
|
||||
package im.vector.matrix.android.api.persitence
|
||||
|
||||
import android.arch.paging.PagedList
|
||||
|
||||
interface Persister<DATA, KEY> {
|
||||
|
||||
fun put(data: DATA)
|
||||
|
||||
fun remove(data: DATA)
|
||||
|
||||
fun get(id: KEY): DATA?
|
||||
|
||||
fun getAll(): PagedList<DATA>
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package im.vector.matrix.android.api.persitence
|
||||
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
|
||||
interface Query<DATA> {
|
||||
|
||||
fun find(): DATA
|
||||
|
||||
fun subscribe(observer: QueryDataObserver<DATA>): Cancelable
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package im.vector.matrix.android.api.persitence
|
||||
|
||||
interface QueryBuilder<DATA, QUERY : Query<DATA>> {
|
||||
|
||||
fun build(): QUERY
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package im.vector.matrix.android.api.persitence;
|
||||
|
||||
public interface QueryDataObserver<DATA> {
|
||||
void onData(DATA data);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.android.thread;
|
||||
package im.vector.matrix.android.api.thread;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.util
|
||||
package im.vector.matrix.android.api.util
|
||||
|
||||
interface Cancelable {
|
||||
fun cancel()
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.api.util
|
||||
package im.vector.matrix.android.api.util
|
||||
|
||||
interface Logger {
|
||||
/** Log a verbose message with optional format args. */
|
@ -1,9 +1,9 @@
|
||||
package im.vector.matrix.core.internal
|
||||
package im.vector.matrix.android.internal
|
||||
|
||||
import im.vector.matrix.core.api.Session
|
||||
import im.vector.matrix.core.api.login.Authenticator
|
||||
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.core.internal.login.LoginModule
|
||||
import im.vector.matrix.android.api.Session
|
||||
import im.vector.matrix.android.api.login.Authenticator
|
||||
import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.internal.login.LoginModule
|
||||
import org.koin.core.scope.Scope
|
||||
import org.koin.standalone.KoinComponent
|
||||
import org.koin.standalone.StandAloneContext
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal
|
||||
package im.vector.matrix.android.internal
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
|
@ -0,0 +1,41 @@
|
||||
package im.vector.matrix.android.internal.di
|
||||
|
||||
import im.vector.matrix.android.api.MatrixOptions
|
||||
import im.vector.matrix.android.api.login.CredentialsStore
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
import im.vector.matrix.android.api.login.data.MyObjectBox
|
||||
import im.vector.matrix.android.internal.MatrixCoroutineDispatchers
|
||||
import im.vector.matrix.android.internal.login.db.ObjectBoxCredentialsStore
|
||||
import io.objectbox.Box
|
||||
import io.objectbox.BoxStore
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import org.koin.dsl.context.ModuleDefinition
|
||||
import org.koin.dsl.module.Module
|
||||
import org.koin.dsl.module.module
|
||||
|
||||
|
||||
class MatrixModule(private val options: MatrixOptions) : Module {
|
||||
|
||||
override fun invoke(): ModuleDefinition = module {
|
||||
|
||||
single {
|
||||
MatrixCoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.IO, main = options.mainExecutor.asCoroutineDispatcher())
|
||||
}
|
||||
|
||||
single {
|
||||
MyObjectBox.builder().androidContext(options.context).build()
|
||||
}
|
||||
|
||||
single {
|
||||
val boxStore = get() as BoxStore
|
||||
boxStore.boxFor(Credentials::class.java) as Box<Credentials>
|
||||
}
|
||||
|
||||
single {
|
||||
ObjectBoxCredentialsStore(get()) as CredentialsStore
|
||||
}
|
||||
|
||||
}.invoke()
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package im.vector.matrix.core.internal.network
|
||||
package im.vector.matrix.android.internal.di
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import org.koin.dsl.context.ModuleDefinition
|
@ -1,16 +1,16 @@
|
||||
package im.vector.matrix.core.internal.login
|
||||
package im.vector.matrix.android.internal.login
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import im.vector.matrix.core.api.MatrixCallback
|
||||
import im.vector.matrix.core.api.login.Authenticator
|
||||
import im.vector.matrix.core.api.login.CredentialsStore
|
||||
import im.vector.matrix.core.api.login.data.Credentials
|
||||
import im.vector.matrix.core.api.util.Cancelable
|
||||
import im.vector.matrix.core.internal.MatrixCoroutineDispatchers
|
||||
import im.vector.matrix.core.internal.util.map
|
||||
import im.vector.matrix.core.internal.login.data.PasswordLoginParams
|
||||
import im.vector.matrix.core.internal.network.executeRequest
|
||||
import im.vector.matrix.core.internal.util.CancelableCoroutine
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.login.Authenticator
|
||||
import im.vector.matrix.android.api.login.CredentialsStore
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import im.vector.matrix.android.internal.MatrixCoroutineDispatchers
|
||||
import im.vector.matrix.android.internal.util.map
|
||||
import im.vector.matrix.android.internal.login.data.PasswordLoginParams
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.util.CancelableCoroutine
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -27,7 +27,7 @@ class DefaultAuthenticator(private val loginApi: LoginApi,
|
||||
moshi = jsonMapper
|
||||
dispatcher = coroutineDispatchers.io
|
||||
}.map {
|
||||
it?.apply { credentialsStore.put(it) }
|
||||
it?.apply { credentialsStore.save(it) }
|
||||
}
|
||||
loginResult.either({ callback.onFailure(it) }, { callback.onSuccess(it) })
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.login
|
||||
package im.vector.matrix.android.internal.login
|
||||
|
||||
import im.vector.matrix.core.api.login.data.Credentials
|
||||
import im.vector.matrix.core.internal.login.data.PasswordLoginParams
|
||||
import im.vector.matrix.core.internal.network.NetworkConstants
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
import im.vector.matrix.android.internal.login.data.PasswordLoginParams
|
||||
import im.vector.matrix.android.internal.network.NetworkConstants
|
||||
import kotlinx.coroutines.Deferred
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.login
|
||||
package im.vector.matrix.android.internal.login
|
||||
|
||||
import im.vector.matrix.core.api.login.Authenticator
|
||||
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.core.internal.DefaultSession
|
||||
import im.vector.matrix.android.api.login.Authenticator
|
||||
import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.internal.DefaultSession
|
||||
import org.koin.dsl.context.ModuleDefinition
|
||||
import org.koin.dsl.module.Module
|
||||
import org.koin.dsl.module.module
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.login.data
|
||||
package im.vector.matrix.android.internal.login.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.login.data
|
||||
package im.vector.matrix.android.internal.login.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.login.data
|
||||
package im.vector.matrix.android.internal.login.data
|
||||
|
||||
object LoginFlowTypes {
|
||||
const val PASSWORD = "m.login.password"
|
@ -0,0 +1,5 @@
|
||||
package im.vector.matrix.android.internal.login.data
|
||||
|
||||
interface LoginParams {
|
||||
val type: String
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.login.data
|
||||
package im.vector.matrix.android.internal.login.data
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
@ -0,0 +1,18 @@
|
||||
package im.vector.matrix.android.internal.login.db
|
||||
|
||||
import im.vector.matrix.android.api.login.CredentialsStore
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
|
||||
class InMemoryCredentialsStore : CredentialsStore {
|
||||
|
||||
var credentials: Credentials? = null
|
||||
|
||||
override fun get(): Credentials? {
|
||||
return credentials
|
||||
}
|
||||
|
||||
override fun save(credentials: Credentials) {
|
||||
this.credentials = credentials.copy()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package im.vector.matrix.android.internal.login.db
|
||||
|
||||
import im.vector.matrix.android.api.login.CredentialsStore
|
||||
import im.vector.matrix.android.api.login.data.Credentials
|
||||
import io.objectbox.Box
|
||||
|
||||
class ObjectBoxCredentialsStore(private val box: Box<Credentials>) : CredentialsStore {
|
||||
|
||||
override fun save(credentials: Credentials) {
|
||||
box.put(credentials)
|
||||
}
|
||||
|
||||
override fun get(): Credentials? {
|
||||
return box.all.firstOrNull()
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package im.vector.matrix.core.internal.network
|
||||
package im.vector.matrix.android.internal.network
|
||||
|
||||
import im.vector.matrix.core.api.login.CredentialsStore
|
||||
import im.vector.matrix.android.api.login.CredentialsStore
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
@ -10,7 +10,7 @@ class AccessTokenInterceptor(private val credentialsStore: CredentialsStore) : I
|
||||
var request = chain.request()
|
||||
val newRequestBuilder = request.newBuilder()
|
||||
// Add the access token to all requests if it is set
|
||||
val credentials = credentialsStore.getAll().firstOrNull()
|
||||
val credentials = credentialsStore.get()
|
||||
credentials?.let {
|
||||
newRequestBuilder.addHeader("Authorization", "Bearer " + it.accessToken)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.network
|
||||
package im.vector.matrix.android.internal.network
|
||||
|
||||
object NetworkConstants {
|
||||
|
@ -1,9 +1,9 @@
|
||||
package im.vector.matrix.core.internal.network
|
||||
package im.vector.matrix.android.internal.network
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import im.vector.matrix.core.api.failure.Failure
|
||||
import im.vector.matrix.core.api.failure.MatrixError
|
||||
import im.vector.matrix.core.internal.util.Either
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.failure.MatrixError
|
||||
import im.vector.matrix.android.internal.util.Either
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.withContext
|
@ -1,7 +1,7 @@
|
||||
package im.vector.matrix.core.internal.sync
|
||||
package im.vector.matrix.android.internal.sync
|
||||
|
||||
import im.vector.matrix.core.internal.network.NetworkConstants
|
||||
import im.vector.matrix.core.internal.sync.data.SyncResponse
|
||||
import im.vector.matrix.android.internal.network.NetworkConstants
|
||||
import im.vector.matrix.android.internal.sync.data.SyncResponse
|
||||
import kotlinx.coroutines.Deferred
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.GET
|
@ -15,7 +15,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,7 +1,7 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
// PresenceSyncResponse represents the updates to the presence status of other users during server sync v2.
|
||||
@JsonClass(generateAdapter = true)
|
@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
// RoomInviteState represents the state of a room that the user has been invited to.
|
||||
@JsonClass(generateAdapter = true)
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
/**
|
||||
* Class representing a room from a JSON response from room or global initial sync.
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,7 +1,7 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class RoomSyncAccountData(
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
// RoomSyncEphemeral represents the ephemeral events in the room that aren't recorded in the timeline or state of the room (e.g. typing).
|
||||
@JsonClass(generateAdapter = true)
|
@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
// RoomSyncState represents the state updates for a room during server sync v2.
|
||||
@JsonClass(generateAdapter = true)
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
// RoomSyncTimeline represents the timeline of messages and state changes for a room during server sync v2.
|
||||
@JsonClass(generateAdapter = true)
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
/**
|
||||
* `MXRoomSyncUnreadNotifications` represents the unread counts for a room.
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,8 +1,8 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.core.api.events.Event
|
||||
import im.vector.matrix.android.api.events.Event
|
||||
|
||||
// ToDeviceSyncResponse represents the data directly sent to one of user's devices.
|
||||
@JsonClass(generateAdapter = true)
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.sync.data
|
||||
package im.vector.matrix.android.internal.sync.data
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
@ -1,6 +1,6 @@
|
||||
package im.vector.matrix.core.internal.util
|
||||
package im.vector.matrix.android.internal.util
|
||||
|
||||
import im.vector.matrix.core.api.util.Cancelable
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
class CancelableCoroutine(private val job: Job) : Cancelable {
|
@ -1,4 +1,4 @@
|
||||
package im.vector.matrix.core.internal.util
|
||||
package im.vector.matrix.android.internal.util
|
||||
|
||||
sealed class Either<out L, out R> {
|
||||
/** * Represents the left side of [Either] class which by convention is a "Failure". */
|
1
matrix-sdk-core/.gitignore
vendored
1
matrix-sdk-core/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/build
|
@ -1,26 +0,0 @@
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: "kotlin"
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
// Network
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
|
||||
implementation 'com.squareup.okio:okio:1.15.0'
|
||||
implementation 'com.squareup.moshi:moshi-kotlin:1.7.0'
|
||||
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.7.0'
|
||||
|
||||
// DI
|
||||
implementation "org.koin:koin-core:$koin_version"
|
||||
implementation "org.koin:koin-core-ext:$koin_version"
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package im.vector.matrix.core.api
|
||||
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
data class MatrixOptions(val mainExecutor: Executor)
|
@ -1,11 +0,0 @@
|
||||
package im.vector.matrix.core.api
|
||||
|
||||
import im.vector.matrix.core.api.login.Authenticator
|
||||
|
||||
interface Session {
|
||||
|
||||
fun authenticator(): Authenticator
|
||||
|
||||
fun close()
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package im.vector.matrix.core.api.login
|
||||
|
||||
import im.vector.matrix.core.api.MatrixCallback
|
||||
import im.vector.matrix.core.api.util.Cancelable
|
||||
import im.vector.matrix.core.api.login.data.Credentials
|
||||
|
||||
interface Authenticator {
|
||||
|
||||
fun authenticate(login: String, password: String, callback: MatrixCallback<Credentials>): Cancelable
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package im.vector.matrix.core.api.login
|
||||
|
||||
import im.vector.matrix.core.api.login.data.Credentials
|
||||
import im.vector.matrix.core.api.storage.MxStore
|
||||
|
||||
interface CredentialsStore : MxStore<Credentials, String>
|
@ -1,11 +0,0 @@
|
||||
package im.vector.matrix.core.api.storage
|
||||
|
||||
import im.vector.matrix.core.api.util.Cancelable
|
||||
|
||||
interface MxQuery<DATA> {
|
||||
|
||||
fun find(): DATA?
|
||||
|
||||
fun subscribe(observer: MxQueryDataObserver<DATA>): Cancelable
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package im.vector.matrix.core.api.storage
|
||||
|
||||
interface MxQueryBuilder<DATA, QUERY : MxQuery<DATA>> {
|
||||
|
||||
fun build(): QUERY
|
||||
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package im.vector.matrix.core.api.storage;
|
||||
|
||||
public interface MxQueryDataObserver<DATA> {
|
||||
void onData(DATA data);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package im.vector.matrix.core.api.storage
|
||||
|
||||
interface MxStore<DATA, KEY> {
|
||||
|
||||
fun put(data: DATA)
|
||||
|
||||
fun remove(data: DATA)
|
||||
|
||||
fun get(id: KEY): DATA?
|
||||
|
||||
fun getAll(): List<DATA>
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package im.vector.matrix.core.internal
|
||||
|
||||
import im.vector.matrix.core.api.MatrixOptions
|
||||
import im.vector.matrix.core.api.login.CredentialsStore
|
||||
import im.vector.matrix.core.internal.login.db.InMemoryCredentialsStore
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import org.koin.dsl.context.ModuleDefinition
|
||||
import org.koin.dsl.module.Module
|
||||
import org.koin.dsl.module.module
|
||||
|
||||
|
||||
class MatrixModule(private val options: MatrixOptions) : Module {
|
||||
|
||||
override fun invoke(): ModuleDefinition = module {
|
||||
|
||||
single {
|
||||
MatrixCoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.IO, main = options.mainExecutor.asCoroutineDispatcher())
|
||||
}
|
||||
|
||||
single {
|
||||
InMemoryCredentialsStore() as CredentialsStore
|
||||
}
|
||||
|
||||
}.invoke()
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package im.vector.matrix.core.internal.login.data
|
||||
|
||||
interface LoginParams {
|
||||
val type: String
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package im.vector.matrix.core.internal.login.db
|
||||
|
||||
import im.vector.matrix.core.api.login.CredentialsStore
|
||||
import im.vector.matrix.core.api.login.data.Credentials
|
||||
|
||||
class InMemoryCredentialsStore : CredentialsStore {
|
||||
|
||||
var credentials: Credentials? = null
|
||||
|
||||
override fun put(data: Credentials) = synchronized(this) {
|
||||
credentials = data.copy()
|
||||
}
|
||||
|
||||
override fun remove(data: Credentials) = synchronized(this) {
|
||||
credentials = null
|
||||
}
|
||||
|
||||
override fun get(id: String): Credentials? = synchronized(this) {
|
||||
return credentials
|
||||
}
|
||||
|
||||
override fun getAll(): List<Credentials> = synchronized(this) {
|
||||
return credentials?.let { listOf(it) } ?: emptyList()
|
||||
}
|
||||
|
||||
}
|
@ -1 +1 @@
|
||||
include ':app', ':matrix-sdk-core', ':matrix-sdk-rx', ':matrix-sdk-android'
|
||||
include ':app', ':matrix-sdk-rx', ':matrix-sdk-android'
|
||||
|
Loading…
Reference in New Issue
Block a user