RoomList: setup dagger for node (remove fragment bindings)
This commit is contained in:
parent
fc14973049
commit
3ffbba954e
15 changed files with 122 additions and 60 deletions
|
|
@ -16,10 +16,10 @@ import java.util.Locale
|
|||
import javax.inject.Inject
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
class LastMessageFormatter @Inject constructor(
|
||||
private val clock: Clock = Clock.System,
|
||||
class LastMessageFormatter @Inject constructor() {
|
||||
|
||||
private val clock: Clock = Clock.System
|
||||
private val locale: Locale = Locale.getDefault()
|
||||
) {
|
||||
|
||||
private val onlyTimeFormatter: DateTimeFormatter by lazy {
|
||||
val pattern = DateFormat.getBestDateTimePattern(locale, "HH:mm")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package io.element.android.x.features.roomlist
|
||||
|
||||
import com.squareup.anvil.annotations.ContributesTo
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.multibindings.IntoMap
|
||||
import io.element.android.x.core.di.AssistedNodeFactory
|
||||
import io.element.android.x.core.di.NodeKey
|
||||
import io.element.android.x.di.SessionScope
|
||||
|
||||
@Module
|
||||
@ContributesTo(SessionScope::class)
|
||||
abstract class RoomListModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@NodeKey(RoomListNode::class)
|
||||
abstract fun bindRoomListNodeFactory(factory: RoomListNode.Factory): AssistedNodeFactory<*>
|
||||
}
|
||||
|
|
@ -6,15 +6,30 @@ import androidx.compose.runtime.getValue
|
|||
import androidx.compose.ui.Modifier
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.plugin.Plugin
|
||||
import com.bumble.appyx.core.plugin.plugins
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import io.element.android.x.core.di.AssistedNodeFactory
|
||||
import io.element.android.x.features.roomlist.model.RoomListEvents
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.presentation.presenterConnector
|
||||
|
||||
class RoomListNode(
|
||||
buildContext: BuildContext,
|
||||
class RoomListNode @AssistedInject constructor(
|
||||
@Assisted buildContext: BuildContext,
|
||||
@Assisted plugins: List<Plugin>,
|
||||
presenter: RoomListPresenter,
|
||||
private val onRoomClicked: (RoomId) -> Unit
|
||||
) : Node(buildContext) {
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : AssistedNodeFactory<RoomListNode> {
|
||||
override fun create(buildContext: BuildContext, plugins: List<Plugin>): RoomListNode
|
||||
}
|
||||
|
||||
interface Callback : Plugin {
|
||||
fun onRoomClicked(roomId: RoomId)
|
||||
}
|
||||
|
||||
private val connector = presenterConnector(presenter)
|
||||
|
||||
|
|
@ -30,12 +45,16 @@ class RoomListNode(
|
|||
connector.emitEvent(RoomListEvents.Logout)
|
||||
}
|
||||
|
||||
private fun onRoomClicked(roomId: RoomId) {
|
||||
plugins<Callback>().forEach { it.onRoomClicked(roomId) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
val state by connector.stateFlow.collectAsState()
|
||||
RoomListView(
|
||||
state = state,
|
||||
onRoomClicked = onRoomClicked,
|
||||
onRoomClicked = this::onRoomClicked,
|
||||
onFilterChanged = this::updateFilter,
|
||||
onScrollOver = this::updateVisibleRange,
|
||||
onLogoutClicked = this::logout
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ private const val extendedRangeSize = 40
|
|||
|
||||
class RoomListPresenter @Inject constructor(
|
||||
private val client: MatrixClient,
|
||||
private val lastMessageFormatter: LastMessageFormatter = LastMessageFormatter(),
|
||||
private val lastMessageFormatter: LastMessageFormatter,
|
||||
) : Presenter<RoomListState, RoomListEvents> {
|
||||
|
||||
@Composable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue