From b6728ce9bec1de3d1e5bb459f1883841e9322100 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 27 Nov 2018 12:23:15 +0100 Subject: [PATCH] Clean some DI code --- .../riotredesign/features/home/HomeModule.kt | 3 +-- .../home/room/detail/RoomDetailFragment.kt | 4 ++-- .../android/internal/session/SessionModule.kt | 9 ++++++++- .../internal/session/room/DefaultRoom.kt | 10 +++++----- .../internal/session/room/RoomModule.kt | 18 +++++++++--------- .../room/timeline/TimelineBoundaryCallback.kt | 4 +--- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt index a74a67c6..0a074220 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt @@ -28,8 +28,7 @@ class HomeModule(private val homeActivity: HomeActivity) : Module { TextItemFactory() } - factory { - val roomId = it.get(0) as String + factory { (roomId: String) -> TimelineEventController(roomId, get(), get(), get()) } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt index d8d550b4..f19d4f5a 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt @@ -22,7 +22,7 @@ import im.vector.riotredesign.features.home.AvatarRenderer import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController import kotlinx.android.synthetic.main.fragment_room_detail.* import org.koin.android.ext.android.inject -import org.koin.core.parameter.ParameterList +import org.koin.core.parameter.parametersOf class RoomDetailFragment : RiotFragment() { @@ -40,7 +40,7 @@ class RoomDetailFragment : RiotFragment() { private val currentSession = matrix.currentSession private var roomId: String by UnsafeFragmentArgumentDelegate() private var eventId: String? by FragmentArgumentDelegate() - private val timelineEventController by inject(parameters = { ParameterList(roomId) }) + private val timelineEventController by inject { parametersOf(roomId) } private lateinit var room: Room private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index e4b2e93c..4b9ddb66 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -1,5 +1,6 @@ package im.vector.matrix.android.internal.session +import android.content.Context import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.session.group.GroupService @@ -18,6 +19,7 @@ import org.koin.dsl.context.ModuleDefinition import org.koin.dsl.module.Module import org.koin.dsl.module.module import retrofit2.Retrofit +import java.io.File internal class SessionModule(private val sessionParams: SessionParams) : Module { @@ -28,8 +30,12 @@ internal class SessionModule(private val sessionParams: SessionParams) : Module } scope(DefaultSession.SCOPE) { + val context = get() + val directory = File(context.filesDir, sessionParams.credentials.userId) + RealmConfiguration.Builder() - .name(sessionParams.credentials.userId) + .directory(directory) + .name("disk_store.realm") .deleteRealmIfMigrationNeeded() .build() } @@ -69,6 +75,7 @@ internal class SessionModule(private val sessionParams: SessionParams) : Module } scope(DefaultSession.SCOPE) { + val roomSummaryUpdater = RoomSummaryUpdater(get(), get(), get(), get(), sessionParams.credentials) val groupSummaryUpdater = GroupSummaryUpdater(get()) val eventsPruner = EventsPruner(get()) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt index 766fea9d..2fd869b3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt @@ -33,8 +33,8 @@ internal data class DefaultRoom( private val loadRoomMembersRequest by inject() private val syncTokenStore by inject() private val monarchy by inject() - private val timelineHolder by inject(parameters = { parametersOf(roomId) }) - private val sendService by inject(parameters = { parametersOf(roomId) }) + private val timelineHolder by inject { parametersOf(roomId) } + private val sendService by inject { parametersOf(roomId) } override val roomSummary: LiveData by lazy { val liveData = monarchy @@ -62,9 +62,9 @@ internal data class DefaultRoom( private fun areAllMembersLoaded(): Boolean { return monarchy - .fetchAllCopiedSync { RoomEntity.where(it, roomId) } - .firstOrNull() - ?.areAllMembersLoaded ?: false + .fetchAllCopiedSync { RoomEntity.where(it, roomId) } + .firstOrNull() + ?.areAllMembersLoaded ?: false } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt index 598bd5f0..e2604ded 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt @@ -10,6 +10,7 @@ import im.vector.matrix.android.internal.session.room.send.DefaultSendService import im.vector.matrix.android.internal.session.room.timeline.DefaultTimelineHolder import im.vector.matrix.android.internal.session.room.timeline.PaginationRequest import im.vector.matrix.android.internal.session.room.timeline.TimelineBoundaryCallback +import im.vector.matrix.android.internal.util.PagingRequestHelper import org.koin.dsl.context.ModuleDefinition import org.koin.dsl.module.Module import org.koin.dsl.module.module @@ -34,20 +35,19 @@ class RoomModule : Module { PaginationRequest(get(), get(), get()) } - - factory { - val roomId: String = it[0] - val timelineBoundaryCallback = TimelineBoundaryCallback(roomId, get(), get(), Executors.newSingleThreadExecutor()) - DefaultTimelineHolder(roomId, get(), timelineBoundaryCallback) as TimelineHolder - } - scope(DefaultSession.SCOPE) { val sessionParams = get() EventFactory(sessionParams.credentials) } - factory { - val roomId: String = it[0] + factory { (roomId: String) -> + val helper = PagingRequestHelper(Executors.newSingleThreadExecutor()) + val timelineBoundaryCallback = TimelineBoundaryCallback(roomId, get(), get(), helper) + DefaultTimelineHolder(roomId, get(), timelineBoundaryCallback) as TimelineHolder + } + + + factory { (roomId: String) -> DefaultSendService(roomId, get(), get()) as SendService } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineBoundaryCallback.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineBoundaryCallback.kt index a899a646..ff06dbb5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineBoundaryCallback.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineBoundaryCallback.kt @@ -13,11 +13,9 @@ import java.util.concurrent.Executor internal class TimelineBoundaryCallback(private val roomId: String, private val paginationRequest: PaginationRequest, private val monarchy: Monarchy, - ioExecutor: Executor + private val helper: PagingRequestHelper ) : PagedList.BoundaryCallback() { - private val helper = PagingRequestHelper(ioExecutor) - var limit = 10 override fun onZeroItemsLoaded() {