Make the sdk targeting android to win time

This commit is contained in:
ganfra 2018-10-04 15:19:03 +02:00
parent 54fb54a695
commit c4316d5055
80 changed files with 380 additions and 261 deletions

View File

@ -10,7 +10,6 @@
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/matrix-sdk-android" /> <option value="$PROJECT_DIR$/matrix-sdk-android" />
<option value="$PROJECT_DIR$/matrix-sdk-core" />
<option value="$PROJECT_DIR$/matrix-sdk-rx" /> <option value="$PROJECT_DIR$/matrix-sdk-rx" />
</set> </set>
</option> </option>

View File

@ -22,16 +22,17 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) 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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' 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' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile project(path: ':matrix-sdk-android')
} }

View File

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name=".Riot"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"

View File

@ -1,13 +1,14 @@
package im.vector.riotredesign package im.vector.riotredesign
import android.app.Application import android.app.Application
import im.vector.riotredesign.core.di.AppModule
import org.koin.standalone.StandAloneContext.startKoin import org.koin.standalone.StandAloneContext.startKoin
class Riot : Application() { class Riot : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
startKoin(emptyList()) startKoin(listOf(AppModule(this)))
} }
} }

View File

@ -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()
}

View File

@ -3,22 +3,21 @@ package im.vector.riotredesign.features.login
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import im.vector.matrix.android.thread.MainThreadExecutor import im.vector.matrix.android.api.Matrix
import im.vector.matrix.core.api.Matrix import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.core.api.MatrixCallback import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.core.api.MatrixOptions import im.vector.matrix.android.api.login.data.Credentials
import im.vector.matrix.core.api.failure.Failure import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
import im.vector.matrix.core.api.login.data.Credentials
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.platform.RiotActivity import im.vector.riotredesign.core.platform.RiotActivity
import im.vector.riotredesign.features.home.HomeActivity import im.vector.riotredesign.features.home.HomeActivity
import kotlinx.android.synthetic.main.activity_login.* import kotlinx.android.synthetic.main.activity_login.*
import org.koin.android.ext.android.inject
class LoginActivity : RiotActivity() { class LoginActivity : RiotActivity() {
private val matrixOptions = MatrixOptions(mainExecutor = MainThreadExecutor()) private val matrix by inject<Matrix>()
private val matrix = Matrix(matrixOptions)
private val homeServerConnectionConfig = HomeServerConnectionConfig("https://matrix.org/") private val homeServerConnectionConfig = HomeServerConnectionConfig("https://matrix.org/")
private val session = matrix.createSession(homeServerConnectionConfig) private val session = matrix.createSession(homeServerConnectionConfig)
private val authenticator = session.authenticator() private val authenticator = session.authenticator()

View File

@ -1,5 +1,24 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' 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 { android {
compileSdkVersion 28 compileSdkVersion 28
@ -24,10 +43,28 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) 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 "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' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

View 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
}

View File

@ -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.android.api.login.data.HomeServerConnectionConfig
import im.vector.matrix.core.internal.DefaultSession import im.vector.matrix.android.internal.DefaultSession
import im.vector.matrix.core.internal.MatrixModule import im.vector.matrix.android.internal.di.MatrixModule
import im.vector.matrix.core.internal.network.NetworkModule import im.vector.matrix.android.internal.di.NetworkModule
import org.koin.standalone.StandAloneContext.loadKoinModules import org.koin.standalone.StandAloneContext.loadKoinModules
class Matrix(matrixOptions: MatrixOptions) { class Matrix(matrixOptions: MatrixOptions) {

View File

@ -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> { interface MatrixCallback<in T> {

View File

@ -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())

View File

@ -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()
}

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.api.events package im.vector.matrix.android.api.events
data class Event(val sender: String, data class Event(val sender: String,
val eventType: EventType) val eventType: EventType)

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.api.events package im.vector.matrix.android.api.events
sealed class EventType(val str: String) { sealed class EventType(val str: String) {

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.api.failure package im.vector.matrix.android.api.failure
sealed class Failure { sealed class Failure {

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.api.failure package im.vector.matrix.android.api.failure
import com.squareup.moshi.Json import com.squareup.moshi.Json

View File

@ -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
}

View File

@ -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)
}

View File

@ -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.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
@Entity
@JsonClass(generateAdapter = true) @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 = "home_server") val homeServer: String,
@Json(name = "access_token") val accessToken: String, @Json(name = "access_token") val accessToken: String,
@Json(name = "refresh_token") val refreshToken: String?, @Json(name = "refresh_token") val refreshToken: String?,

View File

@ -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 import com.squareup.moshi.JsonClass

View File

@ -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>
}

View File

@ -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
}

View File

@ -0,0 +1,7 @@
package im.vector.matrix.android.api.persitence
interface QueryBuilder<DATA, QUERY : Query<DATA>> {
fun build(): QUERY
}

View File

@ -0,0 +1,5 @@
package im.vector.matrix.android.api.persitence;
public interface QueryDataObserver<DATA> {
void onData(DATA data);
}

View File

@ -1,4 +1,4 @@
package im.vector.matrix.android.thread; package im.vector.matrix.android.api.thread;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.api.util package im.vector.matrix.android.api.util
interface Cancelable { interface Cancelable {
fun cancel() fun cancel()

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.api.util package im.vector.matrix.android.api.util
interface Logger { interface Logger {
/** Log a verbose message with optional format args. */ /** Log a verbose message with optional format args. */

View File

@ -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.android.api.Session
import im.vector.matrix.core.api.login.Authenticator import im.vector.matrix.android.api.login.Authenticator
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
import im.vector.matrix.core.internal.login.LoginModule import im.vector.matrix.android.internal.login.LoginModule
import org.koin.core.scope.Scope import org.koin.core.scope.Scope
import org.koin.standalone.KoinComponent import org.koin.standalone.KoinComponent
import org.koin.standalone.StandAloneContext import org.koin.standalone.StandAloneContext

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.internal package im.vector.matrix.android.internal
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher

View File

@ -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()
}

View File

@ -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.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.context.ModuleDefinition import org.koin.dsl.context.ModuleDefinition

View File

@ -1,16 +1,16 @@
package im.vector.matrix.core.internal.login package im.vector.matrix.android.internal.login
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import im.vector.matrix.core.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.core.api.login.Authenticator import im.vector.matrix.android.api.login.Authenticator
import im.vector.matrix.core.api.login.CredentialsStore import im.vector.matrix.android.api.login.CredentialsStore
import im.vector.matrix.core.api.login.data.Credentials import im.vector.matrix.android.api.login.data.Credentials
import im.vector.matrix.core.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.core.internal.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.MatrixCoroutineDispatchers
import im.vector.matrix.core.internal.util.map import im.vector.matrix.android.internal.util.map
import im.vector.matrix.core.internal.login.data.PasswordLoginParams import im.vector.matrix.android.internal.login.data.PasswordLoginParams
import im.vector.matrix.core.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.core.internal.util.CancelableCoroutine import im.vector.matrix.android.internal.util.CancelableCoroutine
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -27,7 +27,7 @@ class DefaultAuthenticator(private val loginApi: LoginApi,
moshi = jsonMapper moshi = jsonMapper
dispatcher = coroutineDispatchers.io dispatcher = coroutineDispatchers.io
}.map { }.map {
it?.apply { credentialsStore.put(it) } it?.apply { credentialsStore.save(it) }
} }
loginResult.either({ callback.onFailure(it) }, { callback.onSuccess(it) }) loginResult.either({ callback.onFailure(it) }, { callback.onSuccess(it) })
} }

View File

@ -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.android.api.login.data.Credentials
import im.vector.matrix.core.internal.login.data.PasswordLoginParams import im.vector.matrix.android.internal.login.data.PasswordLoginParams
import im.vector.matrix.core.internal.network.NetworkConstants import im.vector.matrix.android.internal.network.NetworkConstants
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import retrofit2.Response import retrofit2.Response
import retrofit2.http.Body import retrofit2.http.Body

View File

@ -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.android.api.login.Authenticator
import im.vector.matrix.core.api.login.data.HomeServerConnectionConfig import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig
import im.vector.matrix.core.internal.DefaultSession import im.vector.matrix.android.internal.DefaultSession
import org.koin.dsl.context.ModuleDefinition import org.koin.dsl.context.ModuleDefinition
import org.koin.dsl.module.Module import org.koin.dsl.module.Module
import org.koin.dsl.module.module import org.koin.dsl.module.module

View File

@ -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 import com.squareup.moshi.JsonClass

View File

@ -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 import com.squareup.moshi.JsonClass

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.internal.login.data package im.vector.matrix.android.internal.login.data
object LoginFlowTypes { object LoginFlowTypes {
const val PASSWORD = "m.login.password" const val PASSWORD = "m.login.password"

View File

@ -0,0 +1,5 @@
package im.vector.matrix.android.internal.login.data
interface LoginParams {
val type: String
}

View File

@ -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.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass

View File

@ -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()
}
}

View File

@ -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()
}
}

View File

@ -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.Interceptor
import okhttp3.Response import okhttp3.Response
@ -10,7 +10,7 @@ class AccessTokenInterceptor(private val credentialsStore: CredentialsStore) : I
var request = chain.request() var request = chain.request()
val newRequestBuilder = request.newBuilder() val newRequestBuilder = request.newBuilder()
// Add the access token to all requests if it is set // Add the access token to all requests if it is set
val credentials = credentialsStore.getAll().firstOrNull() val credentials = credentialsStore.get()
credentials?.let { credentials?.let {
newRequestBuilder.addHeader("Authorization", "Bearer " + it.accessToken) newRequestBuilder.addHeader("Authorization", "Bearer " + it.accessToken)
} }

View File

@ -1,4 +1,4 @@
package im.vector.matrix.core.internal.network package im.vector.matrix.android.internal.network
object NetworkConstants { object NetworkConstants {

View File

@ -1,9 +1,9 @@
package im.vector.matrix.core.internal.network package im.vector.matrix.android.internal.network
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import im.vector.matrix.core.api.failure.Failure import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.core.api.failure.MatrixError import im.vector.matrix.android.api.failure.MatrixError
import im.vector.matrix.core.internal.util.Either import im.vector.matrix.android.internal.util.Either
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext

View File

@ -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.android.internal.network.NetworkConstants
import im.vector.matrix.core.internal.sync.data.SyncResponse import im.vector.matrix.android.internal.sync.data.SyncResponse
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import retrofit2.Response import retrofit2.Response
import retrofit2.http.GET import retrofit2.http.GET

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 com.squareup.moshi.JsonClass

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 com.squareup.moshi.JsonClass

View File

@ -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 import com.squareup.moshi.JsonClass

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 com.squareup.moshi.JsonClass

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 com.squareup.moshi.JsonClass

View File

@ -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 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. // PresenceSyncResponse represents the updates to the presence status of other users during server sync v2.
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 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. // RoomInviteState represents the state of a room that the user has been invited to.
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -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 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. * Class representing a room from a JSON response from room or global initial sync.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 com.squareup.moshi.JsonClass

View File

@ -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 com.squareup.moshi.JsonClass
import im.vector.matrix.core.api.events.Event import im.vector.matrix.android.api.events.Event
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class RoomSyncAccountData( data class RoomSyncAccountData(

View File

@ -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 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). // 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) @JsonClass(generateAdapter = true)

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 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. // RoomSyncState represents the state updates for a room during server sync v2.
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -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 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. // RoomSyncTimeline represents the timeline of messages and state changes for a room during server sync v2.
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -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 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. * `MXRoomSyncUnreadNotifications` represents the unread counts for a room.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 com.squareup.moshi.JsonClass

View File

@ -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 import com.squareup.moshi.JsonClass

View File

@ -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 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. // ToDeviceSyncResponse represents the data directly sent to one of user's devices.
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -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 import com.squareup.moshi.JsonClass

View File

@ -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 import kotlinx.coroutines.Job
class CancelableCoroutine(private val job: Job) : Cancelable { class CancelableCoroutine(private val job: Job) : Cancelable {

View File

@ -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> { sealed class Either<out L, out R> {
/** * Represents the left side of [Either] class which by convention is a "Failure". */ /** * Represents the left side of [Either] class which by convention is a "Failure". */

View File

@ -1 +0,0 @@
/build

View File

@ -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'
}

View File

@ -1,5 +0,0 @@
package im.vector.matrix.core.api
import java.util.concurrent.Executor
data class MatrixOptions(val mainExecutor: Executor)

View File

@ -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()
}

View File

@ -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
}

View File

@ -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>

View File

@ -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
}

View File

@ -1,7 +0,0 @@
package im.vector.matrix.core.api.storage
interface MxQueryBuilder<DATA, QUERY : MxQuery<DATA>> {
fun build(): QUERY
}

View File

@ -1,5 +0,0 @@
package im.vector.matrix.core.api.storage;
public interface MxQueryDataObserver<DATA> {
void onData(DATA data);
}

View File

@ -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>
}

View File

@ -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()
}

View File

@ -1,5 +0,0 @@
package im.vector.matrix.core.internal.login.data
interface LoginParams {
val type: String
}

View File

@ -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()
}
}

View File

@ -1 +1 @@
include ':app', ':matrix-sdk-core', ':matrix-sdk-rx', ':matrix-sdk-android' include ':app', ':matrix-sdk-rx', ':matrix-sdk-android'