Cleanup and properly inject the controller

This commit is contained in:
Benoit Marty 2021-05-19 11:54:19 +02:00
parent 8114d52d7d
commit 3d174b0a25
3 changed files with 18 additions and 23 deletions

View file

@ -30,7 +30,6 @@ import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetGenericListWithTitleBinding
import im.vector.app.features.home.room.detail.timeline.action.TimelineEventFragmentArgs
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
import im.vector.app.features.html.EventHtmlRenderer
import javax.inject.Inject
@ -43,11 +42,7 @@ class ViewEditHistoryBottomSheet :
private val viewModel: ViewEditHistoryViewModel by fragmentViewModel(ViewEditHistoryViewModel::class)
@Inject lateinit var viewEditHistoryViewModelFactory: ViewEditHistoryViewModel.Factory
@Inject lateinit var eventHtmlRenderer: EventHtmlRenderer
private val epoxyController by lazy {
ViewEditHistoryEpoxyController(requireContext(), viewModel.dateFormatter, eventHtmlRenderer)
}
@Inject lateinit var epoxyController: ViewEditHistoryEpoxyController
override fun injectWith(injector: ScreenComponent) {
injector.inject(this)

View file

@ -15,9 +15,7 @@
*/
package im.vector.app.features.home.room.detail.timeline.edithistory
import android.content.Context
import android.text.Spannable
import androidx.core.content.ContextCompat
import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Incomplete
@ -25,6 +23,8 @@ import com.airbnb.mvrx.Success
import im.vector.app.R
import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.genericFooterItem
import im.vector.app.core.ui.list.genericItem
import im.vector.app.core.ui.list.genericItemHeader
@ -38,13 +38,17 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent
import org.matrix.android.sdk.api.util.ContentUtils.extractUsefulTextFromReply
import org.matrix.android.sdk.internal.session.room.send.TextContent
import java.util.Calendar
import javax.inject.Inject
/**
* Epoxy controller for edit history list
*/
class ViewEditHistoryEpoxyController(private val context: Context,
val dateFormatter: VectorDateFormatter,
val eventHtmlRenderer: EventHtmlRenderer) : TypedEpoxyController<ViewEditHistoryViewState>() {
class ViewEditHistoryEpoxyController @Inject constructor(
private val stringProvider: StringProvider,
private val colorProvider: ColorProvider,
private val eventHtmlRenderer: EventHtmlRenderer,
private val dateFormatter: VectorDateFormatter
) : TypedEpoxyController<ViewEditHistoryViewState>() {
override fun buildModels(state: ViewEditHistoryViewState) {
val host = this
@ -57,8 +61,7 @@ class ViewEditHistoryEpoxyController(private val context: Context,
is Fail -> {
genericFooterItem {
id("failure")
// FIXME Should use stringprovider
text(host.context.getString(R.string.unknown_error))
text(host.stringProvider.getString(R.string.unknown_error))
}
}
is Success -> {
@ -72,8 +75,7 @@ class ViewEditHistoryEpoxyController(private val context: Context,
if (sourceEvents.isEmpty()) {
genericItem {
id("footer")
// TODO use a stringProvider
title(host.context.getString(R.string.no_message_edits_found))
title(host.stringProvider.getString(R.string.no_message_edits_found))
}
} else {
var lastDate: Calendar? = null
@ -110,14 +112,14 @@ class ViewEditHistoryEpoxyController(private val context: Context,
diff_match_patch.Operation.DELETE -> {
span {
text = it.text.replace("\n", " ")
textColor = ContextCompat.getColor(context, R.color.vector_error_color)
textColor = colorProvider.getColor(R.color.vector_error_color)
textDecorationLine = "line-through"
}
}
diff_match_patch.Operation.INSERT -> {
span {
text = it.text
textColor = ContextCompat.getColor(context, R.color.vector_success_color)
textColor = colorProvider.getColor(R.color.vector_success_color)
}
}
else -> {

View file

@ -25,7 +25,6 @@ import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.platform.EmptyAction
import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel
@ -37,10 +36,9 @@ import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult
import timber.log.Timber
import java.util.UUID
class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted
initialState: ViewEditHistoryViewState,
val session: Session,
val dateFormatter: VectorDateFormatter
class ViewEditHistoryViewModel @AssistedInject constructor(
@Assisted initialState: ViewEditHistoryViewState,
private val session: Session
) : VectorViewModel<ViewEditHistoryViewState, EmptyAction, EmptyViewEvents>(initialState) {
private val roomId = initialState.roomId