Clean some DI code
This commit is contained in:
parent
580c898447
commit
b6728ce9be
|
@ -28,8 +28,7 @@ class HomeModule(private val homeActivity: HomeActivity) : Module {
|
||||||
TextItemFactory()
|
TextItemFactory()
|
||||||
}
|
}
|
||||||
|
|
||||||
factory {
|
factory { (roomId: String) ->
|
||||||
val roomId = it.get(0) as String
|
|
||||||
TimelineEventController(roomId, get(), get(), get())
|
TimelineEventController(roomId, get(), get(), get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import im.vector.riotredesign.features.home.AvatarRenderer
|
||||||
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
||||||
import kotlinx.android.synthetic.main.fragment_room_detail.*
|
import kotlinx.android.synthetic.main.fragment_room_detail.*
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import org.koin.core.parameter.ParameterList
|
import org.koin.core.parameter.parametersOf
|
||||||
|
|
||||||
class RoomDetailFragment : RiotFragment() {
|
class RoomDetailFragment : RiotFragment() {
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class RoomDetailFragment : RiotFragment() {
|
||||||
private val currentSession = matrix.currentSession
|
private val currentSession = matrix.currentSession
|
||||||
private var roomId: String by UnsafeFragmentArgumentDelegate()
|
private var roomId: String by UnsafeFragmentArgumentDelegate()
|
||||||
private var eventId: String? by FragmentArgumentDelegate()
|
private var eventId: String? by FragmentArgumentDelegate()
|
||||||
private val timelineEventController by inject<TimelineEventController>(parameters = { ParameterList(roomId) })
|
private val timelineEventController by inject<TimelineEventController> { parametersOf(roomId) }
|
||||||
private lateinit var room: Room
|
private lateinit var room: Room
|
||||||
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
|
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package im.vector.matrix.android.internal.session
|
package im.vector.matrix.android.internal.session
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||||
import im.vector.matrix.android.api.session.group.GroupService
|
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 org.koin.dsl.module.module
|
import org.koin.dsl.module.module
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
internal class SessionModule(private val sessionParams: SessionParams) : Module {
|
internal class SessionModule(private val sessionParams: SessionParams) : Module {
|
||||||
|
|
||||||
|
@ -28,8 +30,12 @@ internal class SessionModule(private val sessionParams: SessionParams) : Module
|
||||||
}
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
|
val context = get<Context>()
|
||||||
|
val directory = File(context.filesDir, sessionParams.credentials.userId)
|
||||||
|
|
||||||
RealmConfiguration.Builder()
|
RealmConfiguration.Builder()
|
||||||
.name(sessionParams.credentials.userId)
|
.directory(directory)
|
||||||
|
.name("disk_store.realm")
|
||||||
.deleteRealmIfMigrationNeeded()
|
.deleteRealmIfMigrationNeeded()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -69,6 +75,7 @@ internal class SessionModule(private val sessionParams: SessionParams) : Module
|
||||||
}
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
|
|
||||||
val roomSummaryUpdater = RoomSummaryUpdater(get(), get(), get(), get(), sessionParams.credentials)
|
val roomSummaryUpdater = RoomSummaryUpdater(get(), get(), get(), get(), sessionParams.credentials)
|
||||||
val groupSummaryUpdater = GroupSummaryUpdater(get())
|
val groupSummaryUpdater = GroupSummaryUpdater(get())
|
||||||
val eventsPruner = EventsPruner(get())
|
val eventsPruner = EventsPruner(get())
|
||||||
|
|
|
@ -33,8 +33,8 @@ internal data class DefaultRoom(
|
||||||
private val loadRoomMembersRequest by inject<LoadRoomMembersRequest>()
|
private val loadRoomMembersRequest by inject<LoadRoomMembersRequest>()
|
||||||
private val syncTokenStore by inject<SyncTokenStore>()
|
private val syncTokenStore by inject<SyncTokenStore>()
|
||||||
private val monarchy by inject<Monarchy>()
|
private val monarchy by inject<Monarchy>()
|
||||||
private val timelineHolder by inject<TimelineHolder>(parameters = { parametersOf(roomId) })
|
private val timelineHolder by inject<TimelineHolder> { parametersOf(roomId) }
|
||||||
private val sendService by inject<SendService>(parameters = { parametersOf(roomId) })
|
private val sendService by inject<SendService> { parametersOf(roomId) }
|
||||||
|
|
||||||
override val roomSummary: LiveData<RoomSummary> by lazy {
|
override val roomSummary: LiveData<RoomSummary> by lazy {
|
||||||
val liveData = monarchy
|
val liveData = monarchy
|
||||||
|
@ -62,9 +62,9 @@ internal data class DefaultRoom(
|
||||||
|
|
||||||
private fun areAllMembersLoaded(): Boolean {
|
private fun areAllMembersLoaded(): Boolean {
|
||||||
return monarchy
|
return monarchy
|
||||||
.fetchAllCopiedSync { RoomEntity.where(it, roomId) }
|
.fetchAllCopiedSync { RoomEntity.where(it, roomId) }
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?.areAllMembersLoaded ?: false
|
?.areAllMembersLoaded ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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.DefaultTimelineHolder
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.PaginationRequest
|
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.session.room.timeline.TimelineBoundaryCallback
|
||||||
|
import im.vector.matrix.android.internal.util.PagingRequestHelper
|
||||||
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
|
||||||
|
@ -34,20 +35,19 @@ class RoomModule : Module {
|
||||||
PaginationRequest(get(), get(), get())
|
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) {
|
scope(DefaultSession.SCOPE) {
|
||||||
val sessionParams = get<SessionParams>()
|
val sessionParams = get<SessionParams>()
|
||||||
EventFactory(sessionParams.credentials)
|
EventFactory(sessionParams.credentials)
|
||||||
}
|
}
|
||||||
|
|
||||||
factory {
|
factory { (roomId: String) ->
|
||||||
val roomId: String = it[0]
|
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
|
DefaultSendService(roomId, get(), get()) as SendService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,9 @@ import java.util.concurrent.Executor
|
||||||
internal class TimelineBoundaryCallback(private val roomId: String,
|
internal class TimelineBoundaryCallback(private val roomId: String,
|
||||||
private val paginationRequest: PaginationRequest,
|
private val paginationRequest: PaginationRequest,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
ioExecutor: Executor
|
private val helper: PagingRequestHelper
|
||||||
) : PagedList.BoundaryCallback<EnrichedEvent>() {
|
) : PagedList.BoundaryCallback<EnrichedEvent>() {
|
||||||
|
|
||||||
private val helper = PagingRequestHelper(ioExecutor)
|
|
||||||
|
|
||||||
var limit = 10
|
var limit = 10
|
||||||
|
|
||||||
override fun onZeroItemsLoaded() {
|
override fun onZeroItemsLoaded() {
|
||||||
|
|
Loading…
Reference in New Issue