From 3d174b0a259bcd5b5315a22ba862652b745a559a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 May 2021 11:54:19 +0200 Subject: [PATCH] Cleanup and properly inject the controller --- .../edithistory/ViewEditHistoryBottomSheet.kt | 9 ++----- .../ViewEditHistoryEpoxyController.kt | 24 ++++++++++--------- .../edithistory/ViewEditHistoryViewModel.kt | 8 +++---- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt index 095cc4754a..63dfe97d7e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt @@ -30,24 +30,19 @@ 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 /** * Bottom sheet displaying list of edits for a given event ordered by timestamp */ -class ViewEditHistoryBottomSheet : +class ViewEditHistoryBottomSheet: VectorBaseBottomSheetDialogFragment() { 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) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryEpoxyController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryEpoxyController.kt index 870cff0f4d..c3c53084ed 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryEpoxyController.kt @@ -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() { +class ViewEditHistoryEpoxyController @Inject constructor( + private val stringProvider: StringProvider, + private val colorProvider: ColorProvider, + private val eventHtmlRenderer: EventHtmlRenderer, + private val dateFormatter: VectorDateFormatter +) : TypedEpoxyController() { 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 -> { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt index af814f5856..5732326f2e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt @@ -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(initialState) { private val roomId = initialState.roomId