Cleanup and properly inject the controller
This commit is contained in:
parent
8114d52d7d
commit
3d174b0a25
|
@ -30,24 +30,19 @@ import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
||||||
import im.vector.app.databinding.BottomSheetGenericListWithTitleBinding
|
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.action.TimelineEventFragmentArgs
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
||||||
import im.vector.app.features.html.EventHtmlRenderer
|
|
||||||
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bottom sheet displaying list of edits for a given event ordered by timestamp
|
* Bottom sheet displaying list of edits for a given event ordered by timestamp
|
||||||
*/
|
*/
|
||||||
class ViewEditHistoryBottomSheet :
|
class ViewEditHistoryBottomSheet:
|
||||||
VectorBaseBottomSheetDialogFragment<BottomSheetGenericListWithTitleBinding>() {
|
VectorBaseBottomSheetDialogFragment<BottomSheetGenericListWithTitleBinding>() {
|
||||||
|
|
||||||
private val viewModel: ViewEditHistoryViewModel by fragmentViewModel(ViewEditHistoryViewModel::class)
|
private val viewModel: ViewEditHistoryViewModel by fragmentViewModel(ViewEditHistoryViewModel::class)
|
||||||
|
|
||||||
@Inject lateinit var viewEditHistoryViewModelFactory: ViewEditHistoryViewModel.Factory
|
@Inject lateinit var viewEditHistoryViewModelFactory: ViewEditHistoryViewModel.Factory
|
||||||
@Inject lateinit var eventHtmlRenderer: EventHtmlRenderer
|
@Inject lateinit var epoxyController: ViewEditHistoryEpoxyController
|
||||||
|
|
||||||
private val epoxyController by lazy {
|
|
||||||
ViewEditHistoryEpoxyController(requireContext(), viewModel.dateFormatter, eventHtmlRenderer)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun injectWith(injector: ScreenComponent) {
|
override fun injectWith(injector: ScreenComponent) {
|
||||||
injector.inject(this)
|
injector.inject(this)
|
||||||
|
|
|
@ -15,9 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.home.room.detail.timeline.edithistory
|
package im.vector.app.features.home.room.detail.timeline.edithistory
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.Incomplete
|
import com.airbnb.mvrx.Incomplete
|
||||||
|
@ -25,6 +23,8 @@ import com.airbnb.mvrx.Success
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.date.DateFormatKind
|
import im.vector.app.core.date.DateFormatKind
|
||||||
import im.vector.app.core.date.VectorDateFormatter
|
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.genericFooterItem
|
||||||
import im.vector.app.core.ui.list.genericItem
|
import im.vector.app.core.ui.list.genericItem
|
||||||
import im.vector.app.core.ui.list.genericItemHeader
|
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.api.util.ContentUtils.extractUsefulTextFromReply
|
||||||
import org.matrix.android.sdk.internal.session.room.send.TextContent
|
import org.matrix.android.sdk.internal.session.room.send.TextContent
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Epoxy controller for edit history list
|
* Epoxy controller for edit history list
|
||||||
*/
|
*/
|
||||||
class ViewEditHistoryEpoxyController(private val context: Context,
|
class ViewEditHistoryEpoxyController @Inject constructor(
|
||||||
val dateFormatter: VectorDateFormatter,
|
private val stringProvider: StringProvider,
|
||||||
val eventHtmlRenderer: EventHtmlRenderer) : TypedEpoxyController<ViewEditHistoryViewState>() {
|
private val colorProvider: ColorProvider,
|
||||||
|
private val eventHtmlRenderer: EventHtmlRenderer,
|
||||||
|
private val dateFormatter: VectorDateFormatter
|
||||||
|
) : TypedEpoxyController<ViewEditHistoryViewState>() {
|
||||||
|
|
||||||
override fun buildModels(state: ViewEditHistoryViewState) {
|
override fun buildModels(state: ViewEditHistoryViewState) {
|
||||||
val host = this
|
val host = this
|
||||||
|
@ -57,8 +61,7 @@ class ViewEditHistoryEpoxyController(private val context: Context,
|
||||||
is Fail -> {
|
is Fail -> {
|
||||||
genericFooterItem {
|
genericFooterItem {
|
||||||
id("failure")
|
id("failure")
|
||||||
// FIXME Should use stringprovider
|
text(host.stringProvider.getString(R.string.unknown_error))
|
||||||
text(host.context.getString(R.string.unknown_error))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Success -> {
|
is Success -> {
|
||||||
|
@ -72,8 +75,7 @@ class ViewEditHistoryEpoxyController(private val context: Context,
|
||||||
if (sourceEvents.isEmpty()) {
|
if (sourceEvents.isEmpty()) {
|
||||||
genericItem {
|
genericItem {
|
||||||
id("footer")
|
id("footer")
|
||||||
// TODO use a stringProvider
|
title(host.stringProvider.getString(R.string.no_message_edits_found))
|
||||||
title(host.context.getString(R.string.no_message_edits_found))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var lastDate: Calendar? = null
|
var lastDate: Calendar? = null
|
||||||
|
@ -110,14 +112,14 @@ class ViewEditHistoryEpoxyController(private val context: Context,
|
||||||
diff_match_patch.Operation.DELETE -> {
|
diff_match_patch.Operation.DELETE -> {
|
||||||
span {
|
span {
|
||||||
text = it.text.replace("\n", " ")
|
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"
|
textDecorationLine = "line-through"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff_match_patch.Operation.INSERT -> {
|
diff_match_patch.Operation.INSERT -> {
|
||||||
span {
|
span {
|
||||||
text = it.text
|
text = it.text
|
||||||
textColor = ContextCompat.getColor(context, R.color.vector_success_color)
|
textColor = colorProvider.getColor(R.color.vector_success_color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import com.airbnb.mvrx.ViewModelContext
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.core.date.VectorDateFormatter
|
|
||||||
import im.vector.app.core.platform.EmptyAction
|
import im.vector.app.core.platform.EmptyAction
|
||||||
import im.vector.app.core.platform.EmptyViewEvents
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
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 timber.log.Timber
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted
|
class ViewEditHistoryViewModel @AssistedInject constructor(
|
||||||
initialState: ViewEditHistoryViewState,
|
@Assisted initialState: ViewEditHistoryViewState,
|
||||||
val session: Session,
|
private val session: Session
|
||||||
val dateFormatter: VectorDateFormatter
|
|
||||||
) : VectorViewModel<ViewEditHistoryViewState, EmptyAction, EmptyViewEvents>(initialState) {
|
) : VectorViewModel<ViewEditHistoryViewState, EmptyAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
private val roomId = initialState.roomId
|
private val roomId = initialState.roomId
|
||||||
|
|
Loading…
Reference in New Issue