diff --git a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt index e209a0ca..dbb94a91 100644 --- a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt +++ b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt @@ -21,23 +21,24 @@ import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import io.reactivex.Observable +import io.reactivex.schedulers.Schedulers class RxRoom(private val room: Room) { fun liveRoomSummary(fetchLastEvent: Boolean): Observable { - return room.liveRoomSummary(fetchLastEvent).asObservable() + return room.liveRoomSummary(fetchLastEvent).asObservable().observeOn(Schedulers.computation()) } fun liveRoomMemberIds(): Observable> { - return room.getRoomMemberIdsLive().asObservable() + return room.getRoomMemberIdsLive().asObservable().observeOn(Schedulers.computation()) } fun liveAnnotationSummary(eventId: String): Observable { - return room.getEventSummaryLive(eventId).asObservable() + return room.getEventSummaryLive(eventId).asObservable().observeOn(Schedulers.computation()) } fun liveTimelineEvent(eventId: String): Observable { - return room.liveTimeLineEvent(eventId).asObservable() + return room.liveTimeLineEvent(eventId).asObservable().observeOn(Schedulers.computation()) } } diff --git a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt index 64900839..5fd76f0b 100644 --- a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt +++ b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt @@ -22,23 +22,24 @@ import im.vector.matrix.android.api.session.pushers.Pusher import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.sync.SyncState import io.reactivex.Observable +import io.reactivex.schedulers.Schedulers class RxSession(private val session: Session) { fun liveRoomSummaries(fetchLastEvents: Boolean): Observable> { - return session.liveRoomSummaries(fetchLastEvents).asObservable() + return session.liveRoomSummaries(fetchLastEvents).asObservable().observeOn(Schedulers.computation()) } fun liveGroupSummaries(): Observable> { - return session.liveGroupSummaries().asObservable() + return session.liveGroupSummaries().asObservable().observeOn(Schedulers.computation()) } fun liveSyncState(): Observable { - return session.syncState().asObservable() + return session.syncState().asObservable().observeOn(Schedulers.computation()) } fun livePushers(): Observable> { - return session.livePushers().asObservable() + return session.livePushers().asObservable().observeOn(Schedulers.computation()) } } diff --git a/vector/src/main/java/im/vector/riotx/core/utils/RxStore.kt b/vector/src/main/java/im/vector/riotx/core/utils/RxStore.kt index bf359973..89780b24 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/RxStore.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/RxStore.kt @@ -18,6 +18,7 @@ package im.vector.riotx.core.utils import com.jakewharton.rxrelay2.BehaviorRelay import io.reactivex.Observable +import io.reactivex.schedulers.Schedulers open class RxStore(defaultValue: T? = null) { @@ -28,7 +29,7 @@ open class RxStore(defaultValue: T? = null) { } fun observe(): Observable { - return storeSubject.hide().distinctUntilChanged() + return storeSubject.hide().observeOn(Schedulers.computation()) } fun post(value: T) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewModel.kt index 2b5a993e..7f0b610d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewModel.kt @@ -24,6 +24,7 @@ import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.session.Session import im.vector.matrix.rx.rx import im.vector.riotx.core.platform.VectorViewModel +import io.reactivex.schedulers.Schedulers /** * View model used to update the home bottom bar notification counts @@ -68,6 +69,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho private fun observeRoomSummaries() { homeRoomListStore .observe() + .observeOn(Schedulers.computation()) .subscribe { list -> list.let { summaries -> val peopleNotifications = summaries diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeRoomListObservableStore.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeRoomListObservableStore.kt index f1f7e551..4e0b5b70 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeRoomListObservableStore.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeRoomListObservableStore.kt @@ -21,18 +21,9 @@ import im.vector.riotx.core.utils.RxStore import im.vector.riotx.features.home.room.list.RoomListDisplayModeFilter import im.vector.riotx.features.home.room.list.RoomListFragment import io.reactivex.Observable +import io.reactivex.schedulers.Schedulers import javax.inject.Inject import javax.inject.Singleton @Singleton -class HomeRoomListObservableStore @Inject constructor() : RxStore>() { - - fun observeFilteredBy(displayMode: RoomListFragment.DisplayMode): Observable> { - return observe() - .flatMapSingle { - Observable.fromIterable(it).filter(RoomListDisplayModeFilter(displayMode)).toList() - } - } - - -} \ No newline at end of file +class HomeRoomListObservableStore @Inject constructor() : RxStore>() diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListDisplayModeFilter.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListDisplayModeFilter.kt index 96fad483..78bad61b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListDisplayModeFilter.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListDisplayModeFilter.kt @@ -23,6 +23,9 @@ import io.reactivex.functions.Predicate class RoomListDisplayModeFilter(private val displayMode: RoomListFragment.DisplayMode) : Predicate { override fun test(roomSummary: RoomSummary): Boolean { + if (roomSummary.membership.isLeft()) { + return false + } return when (displayMode) { RoomListFragment.DisplayMode.HOME -> roomSummary.notificationCount > 0 || roomSummary.membership == Membership.INVITE RoomListFragment.DisplayMode.PEOPLE -> roomSummary.isDirect && roomSummary.membership == Membership.JOIN diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt index 6b814bb9..a42e1295 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt @@ -31,6 +31,7 @@ import im.vector.matrix.android.api.session.room.model.tag.RoomTag import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.utils.LiveEvent import im.vector.riotx.features.home.HomeRoomListObservableStore +import io.reactivex.schedulers.Schedulers import timber.log.Timber class RoomListViewModel @AssistedInject constructor(@Assisted initialState: RoomListViewState, @@ -55,6 +56,7 @@ class RoomListViewModel @AssistedInject constructor(@Assisted initialState: Room } private val displayMode = initialState.displayMode + private val roomListDisplayModeFilter = RoomListDisplayModeFilter(displayMode) private val _openRoomLiveData = MutableLiveData>() val openRoomLiveData: LiveData> @@ -95,7 +97,9 @@ class RoomListViewModel @AssistedInject constructor(@Assisted initialState: Room copy(asyncRooms = asyncRooms) } - homeRoomListObservableSource.observeFilteredBy(displayMode) + homeRoomListObservableSource + .observe() + .observeOn(Schedulers.computation()) .map { buildRoomSummaries(it) } .execute { async -> copy(asyncFilteredRooms = async) @@ -182,23 +186,24 @@ class RoomListViewModel @AssistedInject constructor(@Assisted initialState: Room val lowPriorities = ArrayList() val serverNotices = ArrayList() - for (room in rooms) { - if (room.membership.isLeft()) continue - val tags = room.tags.map { it.name } - when { - room.membership == Membership.INVITE -> invites.add(room) - tags.contains(RoomTag.ROOM_TAG_SERVER_NOTICE) -> serverNotices.add(room) - tags.contains(RoomTag.ROOM_TAG_FAVOURITE) -> favourites.add(room) - tags.contains(RoomTag.ROOM_TAG_LOW_PRIORITY) -> lowPriorities.add(room) - room.isDirect -> directChats.add(room) - else -> groupRooms.add(room) - } - } + rooms + .filter { roomListDisplayModeFilter.test(it) } + .forEach { room -> + val tags = room.tags.map { it.name } + when { + room.membership == Membership.INVITE -> invites.add(room) + tags.contains(RoomTag.ROOM_TAG_SERVER_NOTICE) -> serverNotices.add(room) + tags.contains(RoomTag.ROOM_TAG_FAVOURITE) -> favourites.add(room) + tags.contains(RoomTag.ROOM_TAG_LOW_PRIORITY) -> lowPriorities.add(room) + room.isDirect -> directChats.add(room) + else -> groupRooms.add(room) + } + } val roomComparator = when (displayMode) { RoomListFragment.DisplayMode.HOME -> chronologicalRoomComparator RoomListFragment.DisplayMode.PEOPLE -> chronologicalRoomComparator - RoomListFragment.DisplayMode.ROOMS -> alphabeticalRoomComparator + RoomListFragment.DisplayMode.ROOMS -> chronologicalRoomComparator } return RoomSummaries().apply { @@ -210,6 +215,4 @@ class RoomListViewModel @AssistedInject constructor(@Assisted initialState: Room put(RoomCategory.SERVER_NOTICE, serverNotices.sortedWith(roomComparator)) } } - - } \ No newline at end of file