mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Clean code after Benoit's review
This commit is contained in:
parent
ad9a48d5fa
commit
04f72dfcb8
25 changed files with 180 additions and 148 deletions
|
@ -19,9 +19,9 @@ package im.vector.riotx
|
|||
|
||||
import arrow.core.Option
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotx.core.utils.BehaviorStore
|
||||
import im.vector.riotx.core.utils.BehaviorDataSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ActiveSessionObservableStore @Inject constructor() : BehaviorStore<Option<Session>>()
|
||||
class ActiveSessionDataSource @Inject constructor() : BehaviorDataSource<Option<Session>>()
|
|
@ -23,9 +23,9 @@ import arrow.core.Option
|
|||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.rx.rx
|
||||
import im.vector.riotx.features.home.HomeRoomListObservableStore
|
||||
import im.vector.riotx.features.home.HomeRoomListDataSource
|
||||
import im.vector.riotx.features.home.group.ALL_COMMUNITIES_GROUP_ID
|
||||
import im.vector.riotx.features.home.group.SelectedGroupStore
|
||||
import im.vector.riotx.features.home.group.SelectedGroupDataSource
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
|
@ -41,9 +41,9 @@ import javax.inject.Singleton
|
|||
*/
|
||||
@Singleton
|
||||
class AppStateHandler @Inject constructor(
|
||||
private val sessionObservableStore: ActiveSessionObservableStore,
|
||||
private val homeRoomListObservableStore: HomeRoomListObservableStore,
|
||||
private val selectedGroupStore: SelectedGroupStore) : LifecycleObserver {
|
||||
private val sessionDataSource: ActiveSessionDataSource,
|
||||
private val homeRoomListDataSource: HomeRoomListDataSource,
|
||||
private val selectedGroupDataSource: SelectedGroupDataSource) : LifecycleObserver {
|
||||
|
||||
private val compositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -60,14 +60,14 @@ class AppStateHandler @Inject constructor(
|
|||
private fun observeRoomsAndGroup() {
|
||||
Observable
|
||||
.combineLatest<List<RoomSummary>, Option<GroupSummary>, List<RoomSummary>>(
|
||||
sessionObservableStore.observe()
|
||||
sessionDataSource.observe()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.switchMap {
|
||||
it.orNull()?.rx()?.liveRoomSummaries()
|
||||
?: Observable.just(emptyList())
|
||||
}
|
||||
.throttleLast(300, TimeUnit.MILLISECONDS),
|
||||
selectedGroupStore.observe(),
|
||||
selectedGroupDataSource.observe(),
|
||||
BiFunction { rooms, selectedGroupOption ->
|
||||
val selectedGroup = selectedGroupOption.orNull()
|
||||
val filteredDirectRooms = rooms
|
||||
|
@ -92,7 +92,7 @@ class AppStateHandler @Inject constructor(
|
|||
}
|
||||
)
|
||||
.subscribe {
|
||||
homeRoomListObservableStore.post(it)
|
||||
homeRoomListDataSource.post(it)
|
||||
}
|
||||
.addTo(compositeDisposable)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package im.vector.riotx.core.di
|
|||
import arrow.core.Option
|
||||
import im.vector.matrix.android.api.auth.Authenticator
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotx.ActiveSessionObservableStore
|
||||
import im.vector.riotx.ActiveSessionDataSource
|
||||
import im.vector.riotx.features.crypto.keysrequest.KeyRequestHandler
|
||||
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
@ -28,7 +28,7 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
class ActiveSessionHolder @Inject constructor(private val authenticator: Authenticator,
|
||||
private val sessionObservableStore: ActiveSessionObservableStore,
|
||||
private val sessionObservableStore: ActiveSessionDataSource,
|
||||
private val keyRequestHandler: KeyRequestHandler,
|
||||
private val incomingVerificationRequestHandler: IncomingVerificationRequestHandler
|
||||
) {
|
||||
|
|
|
@ -23,7 +23,7 @@ import dagger.Component
|
|||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.auth.Authenticator
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotx.ActiveSessionObservableStore
|
||||
import im.vector.riotx.ActiveSessionDataSource
|
||||
import im.vector.riotx.EmojiCompatFontProvider
|
||||
import im.vector.riotx.EmojiCompatWrapper
|
||||
import im.vector.riotx.VectorApplication
|
||||
|
@ -33,8 +33,8 @@ import im.vector.riotx.features.configuration.VectorConfiguration
|
|||
import im.vector.riotx.features.crypto.keysrequest.KeyRequestHandler
|
||||
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.HomeRoomListObservableStore
|
||||
import im.vector.riotx.features.home.group.SelectedGroupStore
|
||||
import im.vector.riotx.features.home.HomeRoomListDataSource
|
||||
import im.vector.riotx.features.home.group.SelectedGroupDataSource
|
||||
import im.vector.riotx.features.html.EventHtmlRenderer
|
||||
import im.vector.riotx.features.navigation.Navigator
|
||||
import im.vector.riotx.features.notifications.*
|
||||
|
@ -43,7 +43,7 @@ import im.vector.riotx.features.rageshake.VectorFileLogger
|
|||
import im.vector.riotx.features.rageshake.VectorUncaughtExceptionHandler
|
||||
import im.vector.riotx.features.session.SessionListener
|
||||
import im.vector.riotx.features.settings.VectorPreferences
|
||||
import im.vector.riotx.features.share.ShareRoomListObservableStore
|
||||
import im.vector.riotx.features.share.ShareRoomListDataSource
|
||||
import im.vector.riotx.features.ui.UiStateRepository
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -85,13 +85,13 @@ interface VectorComponent {
|
|||
|
||||
fun navigator(): Navigator
|
||||
|
||||
fun homeRoomListObservableStore(): HomeRoomListObservableStore
|
||||
fun homeRoomListObservableStore(): HomeRoomListDataSource
|
||||
|
||||
fun shareRoomListObservableStore(): ShareRoomListObservableStore
|
||||
fun shareRoomListObservableStore(): ShareRoomListDataSource
|
||||
|
||||
fun selectedGroupStore(): SelectedGroupStore
|
||||
fun selectedGroupStore(): SelectedGroupDataSource
|
||||
|
||||
fun activeSessionObservableStore(): ActiveSessionObservableStore
|
||||
fun activeSessionObservableStore(): ActiveSessionDataSource
|
||||
|
||||
fun incomingVerificationRequestHandler(): IncomingVerificationRequestHandler
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package im.vector.riotx.core.epoxy.bottomsheet
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
@ -24,6 +25,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.ImageViewCompat
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.riotx.R
|
||||
|
@ -51,6 +53,8 @@ abstract class BottomSheetItemAction : VectorEpoxyModel<BottomSheetItemAction.Ho
|
|||
@EpoxyAttribute
|
||||
var subMenuItem = false
|
||||
@EpoxyAttribute
|
||||
var destructive = false
|
||||
@EpoxyAttribute
|
||||
lateinit var listener: View.OnClickListener
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
|
@ -58,8 +62,15 @@ abstract class BottomSheetItemAction : VectorEpoxyModel<BottomSheetItemAction.Ho
|
|||
listener.onClick(it)
|
||||
}
|
||||
holder.startSpace.isVisible = subMenuItem
|
||||
val tintColor = if (destructive) {
|
||||
ContextCompat.getColor(holder.view.context, R.color.riotx_notice)
|
||||
} else {
|
||||
ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_secondary)
|
||||
}
|
||||
holder.icon.setImageResource(iconRes)
|
||||
ImageViewCompat.setImageTintList(holder.icon, ColorStateList.valueOf(tintColor))
|
||||
holder.text.setText(textRes)
|
||||
holder.text.setTextColor(tintColor)
|
||||
holder.selected.isInvisible = !selected
|
||||
if (showExpand) {
|
||||
val expandDrawable = if (expanded) {
|
||||
|
@ -68,7 +79,6 @@ abstract class BottomSheetItemAction : VectorEpoxyModel<BottomSheetItemAction.Ho
|
|||
ContextCompat.getDrawable(holder.view.context, R.drawable.ic_material_expand_more_black)
|
||||
}
|
||||
expandDrawable?.also {
|
||||
val tintColor = ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_secondary)
|
||||
DrawableCompat.setTint(it, tintColor)
|
||||
}
|
||||
holder.text.setCompoundDrawablesWithIntrinsicBounds(null, null, expandDrawable, null)
|
||||
|
|
|
@ -21,18 +21,18 @@ import com.jakewharton.rxrelay2.PublishRelay
|
|||
import io.reactivex.Observable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* An interface to handle InMemory Rx Store from which you can post or observe values.
|
||||
*/
|
||||
interface RxStore<T> {
|
||||
interface DataSource<T> {
|
||||
fun observe(): Observable<T>
|
||||
}
|
||||
|
||||
interface MutableDataSource<T> : DataSource<T> {
|
||||
fun post(value: T)
|
||||
}
|
||||
|
||||
/**
|
||||
* This store emits the most recent value it has observed and all subsequent observed values to each subscriber.
|
||||
* This datasource emits the most recent value it has observed and all subsequent observed values to each subscriber.
|
||||
*/
|
||||
open class BehaviorStore<T>(private val defaultValue: T? = null) : RxStore<T> {
|
||||
open class BehaviorDataSource<T>(private val defaultValue: T? = null) : MutableDataSource<T> {
|
||||
|
||||
private val storeRelay = createRelay()
|
||||
|
||||
|
@ -54,9 +54,9 @@ open class BehaviorStore<T>(private val defaultValue: T? = null) : RxStore<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* This store only emits all subsequent observed values to each subscriber.
|
||||
* This datasource only emits all subsequent observed values to each subscriber.
|
||||
*/
|
||||
open class PublishStore<T> : RxStore<T> {
|
||||
open class PublishDataSource<T> : MutableDataSource<T> {
|
||||
|
||||
private val storeRelay = PublishRelay.create<T>()
|
||||
|
|
@ -26,7 +26,7 @@ import im.vector.matrix.rx.rx
|
|||
import im.vector.riotx.core.di.HasScreenInjector
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.group.SelectedGroupStore
|
||||
import im.vector.riotx.features.home.group.SelectedGroupDataSource
|
||||
import im.vector.riotx.features.home.room.list.RoomListFragment
|
||||
import im.vector.riotx.features.ui.UiStateRepository
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
@ -38,8 +38,8 @@ import io.reactivex.schedulers.Schedulers
|
|||
class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: HomeDetailViewState,
|
||||
private val session: Session,
|
||||
private val uiStateRepository: UiStateRepository,
|
||||
private val selectedGroupStore: SelectedGroupStore,
|
||||
private val homeRoomListStore: HomeRoomListObservableStore,
|
||||
private val selectedGroupStore: SelectedGroupDataSource,
|
||||
private val homeRoomListStore: HomeRoomListDataSource,
|
||||
private val stringProvider: StringProvider)
|
||||
: VectorViewModel<HomeDetailViewState>(initialState) {
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
package im.vector.riotx.features.home
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import im.vector.riotx.core.utils.PublishStore
|
||||
import im.vector.riotx.core.utils.RxStore
|
||||
import im.vector.riotx.core.utils.PublishDataSource
|
||||
import im.vector.riotx.core.utils.MutableDataSource
|
||||
|
||||
class HomeNavigationViewModel(private val store: RxStore<HomeActivity.Navigation> = PublishStore())
|
||||
: ViewModel(), RxStore<HomeActivity.Navigation> by store
|
||||
class HomeNavigationViewModel(private val source: MutableDataSource<HomeActivity.Navigation> = PublishDataSource())
|
||||
: ViewModel(), MutableDataSource<HomeActivity.Navigation> by source
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
package im.vector.riotx.features.home
|
||||
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.riotx.core.utils.BehaviorStore
|
||||
import im.vector.riotx.core.utils.BehaviorDataSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class HomeRoomListObservableStore @Inject constructor() : BehaviorStore<List<RoomSummary>>()
|
||||
class HomeRoomListDataSource @Inject constructor() : BehaviorDataSource<List<RoomSummary>>()
|
|
@ -17,8 +17,8 @@
|
|||
package im.vector.riotx.features.home.createdirect
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import im.vector.riotx.core.utils.PublishStore
|
||||
import im.vector.riotx.core.utils.RxStore
|
||||
import im.vector.riotx.core.utils.PublishDataSource
|
||||
import im.vector.riotx.core.utils.MutableDataSource
|
||||
|
||||
class CreateDirectRoomNavigationViewModel(private val store: RxStore<CreateDirectRoomActivity.Navigation> = PublishStore())
|
||||
: ViewModel(), RxStore<CreateDirectRoomActivity.Navigation> by store
|
||||
class CreateDirectRoomNavigationViewModel(private val dataSource: MutableDataSource<CreateDirectRoomActivity.Navigation> = PublishDataSource())
|
||||
: ViewModel(), MutableDataSource<CreateDirectRoomActivity.Navigation> by dataSource
|
||||
|
|
|
@ -39,7 +39,7 @@ import io.reactivex.functions.BiFunction
|
|||
const val ALL_COMMUNITIES_GROUP_ID = "ALL_COMMUNITIES_GROUP_ID"
|
||||
|
||||
class GroupListViewModel @AssistedInject constructor(@Assisted initialState: GroupListViewState,
|
||||
private val selectedGroupStore: SelectedGroupStore,
|
||||
private val selectedGroupStore: SelectedGroupDataSource,
|
||||
private val session: Session,
|
||||
private val stringProvider: StringProvider
|
||||
) : VectorViewModel<GroupListViewState>(initialState) {
|
||||
|
|
|
@ -18,9 +18,9 @@ package im.vector.riotx.features.home.group
|
|||
|
||||
import arrow.core.Option
|
||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.riotx.core.utils.BehaviorStore
|
||||
import im.vector.riotx.core.utils.BehaviorDataSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class SelectedGroupStore @Inject constructor() : BehaviorStore<Option<GroupSummary>>(Option.empty())
|
||||
class SelectedGroupDataSource @Inject constructor() : BehaviorDataSource<Option<GroupSummary>>(Option.empty())
|
|
@ -99,7 +99,7 @@ import im.vector.riotx.features.home.room.detail.composer.TextComposerViewState
|
|||
import im.vector.riotx.features.home.room.detail.readreceipts.DisplayReadReceiptsBottomSheet
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.action.MessageActionsBottomSheet
|
||||
import im.vector.riotx.features.home.room.detail.timeline.action.MessageActionsStore
|
||||
import im.vector.riotx.features.home.room.detail.timeline.action.MessageActionsDispatcher
|
||||
import im.vector.riotx.features.home.room.detail.timeline.action.SimpleAction
|
||||
import im.vector.riotx.features.home.room.detail.timeline.edithistory.ViewEditHistoryBottomSheet
|
||||
import im.vector.riotx.features.home.room.detail.timeline.item.*
|
||||
|
@ -200,7 +200,7 @@ class RoomDetailFragment :
|
|||
|
||||
override fun getMenuRes() = R.menu.menu_timeline
|
||||
|
||||
private lateinit var messageActionsStore: MessageActionsStore
|
||||
private lateinit var messageActionsDispatcher: MessageActionsDispatcher
|
||||
private lateinit var layoutManager: LinearLayoutManager
|
||||
private lateinit var attachmentsHelper: AttachmentsHelper
|
||||
private lateinit var keyboardStateUtils: KeyboardStateUtils
|
||||
|
@ -217,7 +217,7 @@ class RoomDetailFragment :
|
|||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
messageActionsStore = ViewModelProviders.of(requireActivity()).get(MessageActionsStore::class.java)
|
||||
messageActionsDispatcher = ViewModelProviders.of(requireActivity()).get(MessageActionsDispatcher::class.java)
|
||||
attachmentsHelper = AttachmentsHelper.create(this, this).register()
|
||||
keyboardStateUtils = KeyboardStateUtils(requireActivity())
|
||||
setupToolbar(roomToolbar)
|
||||
|
@ -236,7 +236,7 @@ class RoomDetailFragment :
|
|||
val message = requireContext().getString(pair.first, *pair.second.toTypedArray())
|
||||
showSnackWithMessage(message, Snackbar.LENGTH_LONG)
|
||||
}
|
||||
messageActionsStore
|
||||
messageActionsDispatcher
|
||||
.observe()
|
||||
.subscribe {
|
||||
handleActions(it)
|
||||
|
|
|
@ -47,7 +47,7 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message
|
|||
|
||||
override val showExpanded = true
|
||||
|
||||
private lateinit var messageActionsStore: MessageActionsStore
|
||||
private lateinit var messageActionsStore: MessageActionsDispatcher
|
||||
|
||||
override fun injectWith(screenComponent: ScreenComponent) {
|
||||
screenComponent.inject(this)
|
||||
|
@ -61,7 +61,7 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message
|
|||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
messageActionsStore = ViewModelProviders.of(requireActivity()).get(MessageActionsStore::class.java)
|
||||
messageActionsStore = ViewModelProviders.of(requireActivity()).get(MessageActionsDispatcher::class.java)
|
||||
recyclerView.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false)
|
||||
recyclerView.adapter = messageActionsEpoxyController.adapter
|
||||
// Disable item animation
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
package im.vector.riotx.features.home.room.detail.timeline.action
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import im.vector.riotx.core.utils.PublishStore
|
||||
import im.vector.riotx.core.utils.RxStore
|
||||
import im.vector.riotx.core.utils.PublishDataSource
|
||||
import im.vector.riotx.core.utils.MutableDataSource
|
||||
|
||||
/**
|
||||
* Activity shared view model to handle message actions
|
||||
*/
|
||||
class MessageActionsStore constructor(
|
||||
private val store: RxStore<SimpleAction> = PublishStore()
|
||||
) : ViewModel(), RxStore<SimpleAction> by store
|
||||
class MessageActionsDispatcher constructor(
|
||||
private val dataSource: MutableDataSource<SimpleAction> = PublishDataSource()
|
||||
) : ViewModel(), MutableDataSource<SimpleAction> by dataSource
|
|
@ -21,6 +21,7 @@ import android.os.Parcelable
|
|||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
|
@ -36,8 +37,6 @@ import im.vector.riotx.R
|
|||
import im.vector.riotx.core.di.ScreenComponent
|
||||
import im.vector.riotx.core.epoxy.LayoutManagerStateRestorer
|
||||
import im.vector.riotx.core.error.ErrorFormatter
|
||||
import im.vector.riotx.core.extensions.observeEvent
|
||||
import im.vector.riotx.core.extensions.observeEventFirstThrottle
|
||||
import im.vector.riotx.core.platform.OnBackPressed
|
||||
import im.vector.riotx.core.platform.StateView
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
|
@ -47,6 +46,7 @@ import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsStore
|
|||
import im.vector.riotx.features.home.room.list.widget.FabMenuView
|
||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotx.features.share.SharedData
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.fragment_room_list.*
|
||||
import javax.inject.Inject
|
||||
|
@ -115,30 +115,42 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||
setupCreateRoomButton()
|
||||
setupRecyclerView()
|
||||
roomListViewModel.subscribe { renderState(it) }
|
||||
roomListViewModel.openRoomLiveData.observeEventFirstThrottle(this, 800L) {
|
||||
if (roomListParams.displayMode == DisplayMode.SHARE) {
|
||||
val sharedData = roomListParams.sharedData ?: return@observeEventFirstThrottle
|
||||
navigator.openRoomForSharing(requireActivity(), it, sharedData)
|
||||
} else {
|
||||
navigator.openRoom(requireActivity(), it)
|
||||
}
|
||||
}
|
||||
|
||||
roomListViewModel.viewEvents
|
||||
.observe()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
when (it) {
|
||||
is RoomListViewEvents.SelectRoom -> openSelectedRoom(it)
|
||||
is RoomListViewEvents.Failure -> showError(it)
|
||||
}
|
||||
}
|
||||
.disposeOnDestroy()
|
||||
|
||||
createChatFabMenu.listener = this
|
||||
|
||||
roomListViewModel.invitationAnswerErrorLiveData.observeEvent(this) { throwable ->
|
||||
vectorBaseActivity.coordinatorLayout?.let {
|
||||
Snackbar.make(it, errorFormatter.toHumanReadable(throwable), Snackbar.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
quickActionsDispatcher
|
||||
.observe()
|
||||
.subscribe { handleQuickActions(it) }
|
||||
.disposeOnDestroy()
|
||||
}
|
||||
|
||||
private fun openSelectedRoom(event: RoomListViewEvents.SelectRoom) {
|
||||
if (roomListParams.displayMode == DisplayMode.SHARE) {
|
||||
val sharedData = roomListParams.sharedData ?: return
|
||||
navigator.openRoomForSharing(requireActivity(), event.roomId, sharedData)
|
||||
} else {
|
||||
navigator.openRoom(requireActivity(), event.roomId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showError(event: RoomListViewEvents.Failure) {
|
||||
vectorBaseActivity.coordinatorLayout?.let {
|
||||
Snackbar.make(it, errorFormatter.toHumanReadable(event.throwable), Snackbar.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCreateRoomButton() {
|
||||
when (roomListParams.displayMode) {
|
||||
DisplayMode.HOME -> createChatFabMenu.isVisible = true
|
||||
|
@ -233,7 +245,14 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||
vectorBaseActivity.notImplemented("Opening room settings")
|
||||
}
|
||||
is RoomListQuickActions.Leave -> {
|
||||
roomListViewModel.accept(RoomListActions.LeaveRoom(quickActions.roomId))
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setTitle(R.string.room_participants_leave_prompt_title)
|
||||
.setMessage(R.string.room_participants_leave_prompt_msg)
|
||||
.setPositiveButton(R.string.leave) { _, _ ->
|
||||
roomListViewModel.accept(RoomListActions.LeaveRoom(quickActions.roomId))
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.home.room.list
|
||||
|
||||
/**
|
||||
* Transient events for RoomList
|
||||
*/
|
||||
sealed class RoomListViewEvents {
|
||||
data class Failure(val throwable: Throwable) : RoomListViewEvents()
|
||||
data class SelectRoom(val roomId: String) : RoomListViewEvents()
|
||||
}
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package im.vector.riotx.features.home.room.list
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||
import com.airbnb.mvrx.ViewModelContext
|
||||
|
@ -26,17 +24,16 @@ import im.vector.matrix.android.api.session.Session
|
|||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
|
||||
import im.vector.riotx.core.extensions.postLiveEvent
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.core.utils.LiveEvent
|
||||
import im.vector.riotx.core.utils.RxStore
|
||||
import im.vector.riotx.core.utils.DataSource
|
||||
import im.vector.riotx.core.utils.PublishDataSource
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
||||
private val session: Session,
|
||||
private val roomSummariesStore: RxStore<List<RoomSummary>>,
|
||||
private val roomSummariesSource: DataSource<List<RoomSummary>>,
|
||||
private val alphabeticalRoomComparator: AlphabeticalRoomComparator,
|
||||
private val chronologicalRoomComparator: ChronologicalRoomComparator)
|
||||
: VectorViewModel<RoomListViewState>(initialState) {
|
||||
|
@ -57,13 +54,8 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
private val displayMode = initialState.displayMode
|
||||
private val roomListDisplayModeFilter = RoomListDisplayModeFilter(displayMode)
|
||||
|
||||
private val _openRoomLiveData = MutableLiveData<LiveEvent<String>>()
|
||||
val openRoomLiveData: LiveData<LiveEvent<String>>
|
||||
get() = _openRoomLiveData
|
||||
|
||||
private val _invitationAnswerErrorLiveData = MutableLiveData<LiveEvent<Throwable>>()
|
||||
val invitationAnswerErrorLiveData: LiveData<LiveEvent<Throwable>>
|
||||
get() = _invitationAnswerErrorLiveData
|
||||
private val _viewEvents = PublishDataSource<RoomListViewEvents>()
|
||||
val viewEvents: DataSource<RoomListViewEvents> = _viewEvents
|
||||
|
||||
init {
|
||||
observeRoomSummaries()
|
||||
|
@ -85,7 +77,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
// PRIVATE METHODS *****************************************************************************
|
||||
|
||||
private fun handleSelectRoom(action: RoomListActions.SelectRoom) {
|
||||
_openRoomLiveData.postLiveEvent(action.roomSummary.roomId)
|
||||
_viewEvents.post(RoomListViewEvents.SelectRoom(action.roomSummary.roomId))
|
||||
}
|
||||
|
||||
private fun handleToggleCategory(action: RoomListActions.ToggleCategory) = setState {
|
||||
|
@ -101,7 +93,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
}
|
||||
|
||||
private fun observeRoomSummaries() {
|
||||
roomSummariesStore
|
||||
roomSummariesSource
|
||||
.observe()
|
||||
.observeOn(Schedulers.computation())
|
||||
.map {
|
||||
|
@ -111,7 +103,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
copy(asyncRooms = asyncRooms)
|
||||
}
|
||||
|
||||
roomSummariesStore
|
||||
roomSummariesSource
|
||||
.observe()
|
||||
.observeOn(Schedulers.computation())
|
||||
.map { buildRoomSummaries(it) }
|
||||
|
@ -144,8 +136,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
// Notify the user
|
||||
_invitationAnswerErrorLiveData.postLiveEvent(failure)
|
||||
|
||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||
setState {
|
||||
copy(
|
||||
joiningRoomsIds = joiningRoomsIds - roomId,
|
||||
|
@ -182,8 +173,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
// Notify the user
|
||||
_invitationAnswerErrorLiveData.postLiveEvent(failure)
|
||||
|
||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||
setState {
|
||||
copy(
|
||||
rejectingRoomsIds = rejectingRoomsIds - roomId,
|
||||
|
@ -204,15 +194,19 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||
}
|
||||
|
||||
private fun handleChangeNotificationMode(action: RoomListActions.ChangeRoomNotificationState) {
|
||||
session.getRoom(action.roomId)?.also {
|
||||
it.setRoomNotificationState(action.notificationState, object : MatrixCallback<Unit> {})
|
||||
}
|
||||
session.getRoom(action.roomId)?.setRoomNotificationState(action.notificationState, object : MatrixCallback<Unit> {
|
||||
override fun onFailure(failure: Throwable) {
|
||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun handleLeaveRoom(action: RoomListActions.LeaveRoom) {
|
||||
session.getRoom(action.roomId)?.also {
|
||||
it.leave(object : MatrixCallback<Unit> {})
|
||||
}
|
||||
session.getRoom(action.roomId)?.leave(object : MatrixCallback<Unit> {
|
||||
override fun onFailure(failure: Throwable) {
|
||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun buildRoomSummaries(rooms: List<RoomSummary>): RoomSummaries {
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
package im.vector.riotx.features.home.room.list
|
||||
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotx.features.home.HomeRoomListObservableStore
|
||||
import im.vector.riotx.features.share.ShareRoomListObservableStore
|
||||
import im.vector.riotx.features.home.HomeRoomListDataSource
|
||||
import im.vector.riotx.features.share.ShareRoomListDataSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
class RoomListViewModelFactory @Inject constructor(private val session: Provider<Session>,
|
||||
private val homeRoomListObservableStore: Provider<HomeRoomListObservableStore>,
|
||||
private val shareRoomListObservableStore: Provider<ShareRoomListObservableStore>,
|
||||
private val homeRoomListDataSource: Provider<HomeRoomListDataSource>,
|
||||
private val shareRoomListDataSource: Provider<ShareRoomListDataSource>,
|
||||
private val alphabeticalRoomComparator: Provider<AlphabeticalRoomComparator>,
|
||||
private val chronologicalRoomComparator: Provider<ChronologicalRoomComparator>) : RoomListViewModel.Factory {
|
||||
|
||||
|
@ -32,7 +32,7 @@ class RoomListViewModelFactory @Inject constructor(private val session: Provider
|
|||
return RoomListViewModel(
|
||||
initialState,
|
||||
session.get(),
|
||||
if (initialState.displayMode == RoomListFragment.DisplayMode.SHARE) shareRoomListObservableStore.get() else homeRoomListObservableStore.get(),
|
||||
if (initialState.displayMode == RoomListFragment.DisplayMode.SHARE) shareRoomListDataSource.get() else homeRoomListDataSource.get(),
|
||||
alphabeticalRoomComparator.get(),
|
||||
chronologicalRoomComparator.get())
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import androidx.annotation.DrawableRes
|
|||
import androidx.annotation.StringRes
|
||||
import im.vector.riotx.R
|
||||
|
||||
sealed class RoomListQuickActions(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int) {
|
||||
sealed class RoomListQuickActions(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int, val destructive: Boolean = false) {
|
||||
|
||||
data class NotificationsAllNoisy(val roomId: String) : RoomListQuickActions(
|
||||
R.string.room_list_quick_actions_notifications_all_noisy,
|
||||
|
@ -49,19 +49,7 @@ sealed class RoomListQuickActions(@StringRes val titleRes: Int, @DrawableRes val
|
|||
|
||||
data class Leave(val roomId: String) : RoomListQuickActions(
|
||||
R.string.room_list_quick_actions_leave,
|
||||
R.drawable.ic_room_actions_leave
|
||||
R.drawable.ic_room_actions_leave,
|
||||
true
|
||||
)
|
||||
|
||||
companion object {
|
||||
fun all(roomId: String): List<RoomListQuickActions> {
|
||||
return listOf(
|
||||
NotificationsAllNoisy(roomId),
|
||||
NotificationsAll(roomId),
|
||||
NotificationsMentionsOnly(roomId),
|
||||
NotificationsMute(roomId),
|
||||
Settings(roomId),
|
||||
Leave(roomId)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,22 +18,16 @@ package im.vector.riotx.features.home.room.list.actions
|
|||
import android.view.View
|
||||
import com.airbnb.epoxy.TypedEpoxyController
|
||||
import im.vector.matrix.android.api.session.room.notification.RoomNotificationState
|
||||
import im.vector.riotx.EmojiCompatFontProvider
|
||||
import im.vector.riotx.core.date.VectorDateFormatter
|
||||
import im.vector.riotx.core.epoxy.bottomsheet.BottomSheetItemAction_
|
||||
import im.vector.riotx.core.epoxy.bottomsheet.bottomSheetItemAction
|
||||
import im.vector.riotx.core.epoxy.bottomsheet.bottomSheetItemRoomPreview
|
||||
import im.vector.riotx.core.epoxy.bottomsheet.bottomSheetItemSeparator
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Epoxy controller for room list actions
|
||||
*/
|
||||
class RoomListQuickActionsEpoxyController @Inject constructor(private val stringProvider: StringProvider,
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val dateFormatter: VectorDateFormatter,
|
||||
private val fontProvider: EmojiCompatFontProvider)
|
||||
class RoomListQuickActionsEpoxyController @Inject constructor(private val avatarRenderer: AvatarRenderer)
|
||||
: TypedEpoxyController<RoomListQuickActionsState>() {
|
||||
|
||||
var listener: Listener? = null
|
||||
|
@ -78,13 +72,14 @@ class RoomListQuickActionsEpoxyController @Inject constructor(private val string
|
|||
is RoomListQuickActions.Settings,
|
||||
is RoomListQuickActions.Leave -> false
|
||||
}
|
||||
return BottomSheetItemAction_()
|
||||
.id("action_$index")
|
||||
.selected(selected)
|
||||
.iconRes(iconResId)
|
||||
.textRes(titleRes)
|
||||
.listener(View.OnClickListener { listener?.didSelectMenuAction(this) })
|
||||
.addTo(this@RoomListQuickActionsEpoxyController)
|
||||
return bottomSheetItemAction {
|
||||
id("action_$index")
|
||||
selected(selected)
|
||||
iconRes(iconResId)
|
||||
textRes(titleRes)
|
||||
destructive(this@toBottomSheetItem.destructive)
|
||||
listener(View.OnClickListener { listener?.didSelectMenuAction(this@toBottomSheetItem) })
|
||||
}
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
package im.vector.riotx.features.home.room.list.actions
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import im.vector.riotx.core.utils.PublishStore
|
||||
import im.vector.riotx.core.utils.RxStore
|
||||
import im.vector.riotx.core.utils.PublishDataSource
|
||||
import im.vector.riotx.core.utils.MutableDataSource
|
||||
|
||||
/**
|
||||
* Activity shared view model to handle room list quick actions
|
||||
*/
|
||||
class RoomListQuickActionsStore constructor(
|
||||
private val store: RxStore<RoomListQuickActions> = PublishStore()
|
||||
) : ViewModel(), RxStore<RoomListQuickActions> by store
|
||||
private val store: MutableDataSource<RoomListQuickActions> = PublishDataSource()
|
||||
) : ViewModel(), MutableDataSource<RoomListQuickActions> by store
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
package im.vector.riotx.features.roomdirectory
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import im.vector.riotx.core.utils.PublishStore
|
||||
import im.vector.riotx.core.utils.RxStore
|
||||
import im.vector.riotx.core.utils.PublishDataSource
|
||||
import im.vector.riotx.core.utils.MutableDataSource
|
||||
|
||||
class RoomDirectoryNavigationViewModel(private val store: RxStore<RoomDirectoryActivity.Navigation> = PublishStore())
|
||||
: ViewModel(), RxStore<RoomDirectoryActivity.Navigation> by store
|
||||
class RoomDirectoryNavigationViewModel(private val source: MutableDataSource<RoomDirectoryActivity.Navigation> = PublishDataSource())
|
||||
: ViewModel(), MutableDataSource<RoomDirectoryActivity.Navigation> by source
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.airbnb.mvrx.ViewModelContext
|
|||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.rx.rx
|
||||
import im.vector.riotx.ActiveSessionObservableStore
|
||||
import im.vector.riotx.ActiveSessionDataSource
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
|
@ -35,8 +35,8 @@ data class IncomingShareState(private val dummy: Boolean = false) : MvRxState
|
|||
* View model used to observe the room list and post update to the ShareRoomListObservableStore
|
||||
*/
|
||||
class IncomingShareViewModel @AssistedInject constructor(@Assisted initialState: IncomingShareState,
|
||||
private val sessionObservableStore: ActiveSessionObservableStore,
|
||||
private val shareRoomListObservableStore: ShareRoomListObservableStore)
|
||||
private val sessionObservableStore: ActiveSessionDataSource,
|
||||
private val shareRoomListObservableStore: ShareRoomListDataSource)
|
||||
: VectorViewModel<IncomingShareState>(initialState) {
|
||||
|
||||
@AssistedInject.Factory
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
package im.vector.riotx.features.share
|
||||
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.riotx.core.utils.BehaviorStore
|
||||
import im.vector.riotx.core.utils.BehaviorDataSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ShareRoomListObservableStore @Inject constructor() : BehaviorStore<List<RoomSummary>>()
|
||||
class ShareRoomListDataSource @Inject constructor() : BehaviorDataSource<List<RoomSummary>>()
|
Loading…
Reference in a new issue