2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-01-18 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-17 16:21:09 +00:00
|
|
|
package im.vector.matrix.android.internal.session
|
2018-10-08 15:52:45 +00:00
|
|
|
|
2018-11-27 11:23:15 +00:00
|
|
|
import android.content.Context
|
2018-11-27 11:06:40 +00:00
|
|
|
import com.zhuinden.monarchy.Monarchy
|
2019-06-14 14:32:23 +00:00
|
|
|
import dagger.Module
|
|
|
|
import dagger.Provides
|
|
|
|
import im.vector.matrix.android.api.auth.data.Credentials
|
2018-11-09 08:43:12 +00:00
|
|
|
import im.vector.matrix.android.api.auth.data.SessionParams
|
2018-11-07 19:36:19 +00:00
|
|
|
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
2019-04-12 10:23:05 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.SessionRealmModule
|
2019-06-14 14:32:23 +00:00
|
|
|
import im.vector.matrix.android.internal.session.filter.FilterApi
|
2018-11-05 16:39:07 +00:00
|
|
|
import im.vector.matrix.android.internal.session.group.GroupSummaryUpdater
|
2019-06-14 14:32:23 +00:00
|
|
|
import im.vector.matrix.android.internal.session.room.EventRelationsAggregationUpdater
|
2019-01-14 15:18:39 +00:00
|
|
|
import im.vector.matrix.android.internal.session.room.prune.EventsPruner
|
2019-02-26 18:32:01 +00:00
|
|
|
import im.vector.matrix.android.internal.session.user.UserEntityUpdater
|
2018-11-27 21:42:46 +00:00
|
|
|
import im.vector.matrix.android.internal.util.md5
|
2018-11-27 11:06:40 +00:00
|
|
|
import io.realm.RealmConfiguration
|
2018-10-08 15:52:45 +00:00
|
|
|
import retrofit2.Retrofit
|
2018-11-27 11:23:15 +00:00
|
|
|
import java.io.File
|
2018-10-08 15:52:45 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Module
|
2018-12-12 20:15:01 +00:00
|
|
|
internal class SessionModule(private val sessionParams: SessionParams) {
|
2018-10-08 15:52:45 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Provides
|
|
|
|
fun providesCredentials(): Credentials {
|
|
|
|
return sessionParams.credentials
|
|
|
|
}
|
2019-04-12 13:51:20 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Provides
|
|
|
|
fun providesRealmConfiguration(context: Context): RealmConfiguration {
|
|
|
|
val childPath = sessionParams.credentials.userId.md5()
|
|
|
|
val directory = File(context.filesDir, childPath)
|
|
|
|
|
|
|
|
return RealmConfiguration.Builder()
|
|
|
|
.directory(directory)
|
|
|
|
.name("disk_store.realm")
|
|
|
|
.modules(SessionRealmModule())
|
|
|
|
.deleteRealmIfMigrationNeeded()
|
|
|
|
.build()
|
|
|
|
}
|
2019-04-12 13:51:20 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Provides
|
|
|
|
fun providesMonarchy(realmConfiguration: RealmConfiguration): Monarchy {
|
|
|
|
return Monarchy.Builder()
|
|
|
|
.setRealmConfiguration(realmConfiguration)
|
|
|
|
.build()
|
|
|
|
}
|
2019-04-12 13:51:20 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Provides
|
|
|
|
fun providesRetrofit(retrofitBuilder: Retrofit.Builder): Retrofit {
|
|
|
|
return retrofitBuilder
|
|
|
|
.baseUrl(sessionParams.homeServerConnectionConfig.homeServerUri.toString())
|
|
|
|
.build()
|
|
|
|
}
|
2018-11-05 16:39:07 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Provides
|
|
|
|
fun providesFilterAPI(retrofit: Retrofit): FilterApi {
|
|
|
|
return retrofit.create(FilterApi::class.java)
|
|
|
|
}
|
2018-11-07 19:36:19 +00:00
|
|
|
|
2019-06-14 14:32:23 +00:00
|
|
|
@Provides
|
|
|
|
fun providesLiveEntityObservers(groupSummaryUpdater: GroupSummaryUpdater,
|
|
|
|
userEntityUpdater: UserEntityUpdater,
|
|
|
|
aggregationUpdater: EventRelationsAggregationUpdater,
|
|
|
|
eventsPruner: EventsPruner): List<LiveEntityObserver> {
|
|
|
|
return listOf<LiveEntityObserver>(groupSummaryUpdater, userEntityUpdater, aggregationUpdater, eventsPruner)
|
2018-12-12 20:15:01 +00:00
|
|
|
}
|
2018-10-10 17:46:43 +00:00
|
|
|
|
|
|
|
|
2018-10-08 15:52:45 +00:00
|
|
|
}
|