mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Remove HomeListDataSource
This commit is contained in:
parent
38af0caa3f
commit
52f98dc405
6 changed files with 49 additions and 121 deletions
|
@ -33,4 +33,3 @@ sealed class QueryStringValue {
|
|||
INSENSITIVE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,32 +19,19 @@ package im.vector.app
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import arrow.core.Option
|
||||
import im.vector.app.features.grouplist.ALL_COMMUNITIES_GROUP_ID
|
||||
import im.vector.app.features.grouplist.SelectedGroupDataSource
|
||||
import im.vector.app.features.home.HomeRoomListDataSource
|
||||
import im.vector.app.features.home.room.list.ChronologicalRoomComparator
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import org.matrix.android.sdk.api.session.group.model.GroupSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.rx.rx
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* This class handles the global app state. At the moment, it only manages room list.
|
||||
* This class handles the global app state.
|
||||
* It requires to be added to ProcessLifecycleOwner.get().lifecycle
|
||||
*/
|
||||
@Singleton
|
||||
class AppStateHandler @Inject constructor(
|
||||
private val sessionDataSource: ActiveSessionDataSource,
|
||||
private val homeRoomListDataSource: HomeRoomListDataSource,
|
||||
private val selectedGroupDataSource: SelectedGroupDataSource,
|
||||
private val chronologicalRoomComparator: ChronologicalRoomComparator) : LifecycleObserver {
|
||||
|
||||
|
@ -52,45 +39,10 @@ class AppStateHandler @Inject constructor(
|
|||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun entersForeground() {
|
||||
// observeRoomsAndGroup()
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
fun entersBackground() {
|
||||
compositeDisposable.clear()
|
||||
}
|
||||
|
||||
private fun observeRoomsAndGroup() {
|
||||
Observable
|
||||
.combineLatest<List<RoomSummary>, Option<GroupSummary>, List<RoomSummary>>(
|
||||
sessionDataSource.observe()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.switchMap {
|
||||
val query = roomSummaryQueryParams {}
|
||||
it.orNull()?.rx()?.liveRoomSummaries(query)
|
||||
?: Observable.just(emptyList())
|
||||
}
|
||||
.throttleLast(300, TimeUnit.MILLISECONDS),
|
||||
selectedGroupDataSource.observe(),
|
||||
BiFunction { rooms, selectedGroupOption ->
|
||||
val selectedGroup = selectedGroupOption.orNull()
|
||||
val filteredRooms = rooms.filter {
|
||||
if (selectedGroup == null || selectedGroup.groupId == ALL_COMMUNITIES_GROUP_ID) {
|
||||
true
|
||||
} else if (it.isDirect) {
|
||||
it.otherMemberIds
|
||||
.intersect(selectedGroup.userIds)
|
||||
.isNotEmpty()
|
||||
} else {
|
||||
selectedGroup.roomIds.contains(it.roomId)
|
||||
}
|
||||
}
|
||||
filteredRooms.sortedWith(chronologicalRoomComparator)
|
||||
}
|
||||
)
|
||||
.subscribe {
|
||||
homeRoomListDataSource.post(it)
|
||||
}
|
||||
.addTo(compositeDisposable)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import im.vector.app.features.crypto.keysrequest.KeyRequestHandler
|
|||
import im.vector.app.features.crypto.verification.IncomingVerificationRequestHandler
|
||||
import im.vector.app.features.grouplist.SelectedGroupDataSource
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
import im.vector.app.features.home.HomeRoomListDataSource
|
||||
import im.vector.app.features.home.room.detail.RoomDetailPendingActionStore
|
||||
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
|
||||
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHolder
|
||||
|
@ -113,8 +112,6 @@ interface VectorComponent {
|
|||
|
||||
fun errorFormatter(): ErrorFormatter
|
||||
|
||||
fun homeRoomListObservableStore(): HomeRoomListDataSource
|
||||
|
||||
fun selectedGroupStore(): SelectedGroupDataSource
|
||||
|
||||
fun roomDetailPendingActionStore(): RoomDetailPendingActionStore
|
||||
|
|
|
@ -20,18 +20,21 @@ import com.airbnb.mvrx.FragmentViewModelContext
|
|||
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||
import com.airbnb.mvrx.ViewModelContext
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import im.vector.app.core.di.HasScreenInjector
|
||||
import im.vector.app.core.platform.EmptyViewEvents
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.grouplist.SelectedGroupDataSource
|
||||
import im.vector.app.features.ui.UiStateRepository
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.room.RoomCategoryFilter
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.rx.asObservable
|
||||
import org.matrix.android.sdk.rx.rx
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* View model used to update the home bottom bar notification counts, observe the sync state and
|
||||
|
@ -41,7 +44,6 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
|||
private val session: Session,
|
||||
private val uiStateRepository: UiStateRepository,
|
||||
private val selectedGroupStore: SelectedGroupDataSource,
|
||||
private val homeRoomListStore: HomeRoomListDataSource,
|
||||
private val stringProvider: StringProvider)
|
||||
: VectorViewModel<HomeDetailViewState, HomeDetailAction, EmptyViewEvents>(initialState) {
|
||||
|
||||
|
@ -113,43 +115,40 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
|||
}
|
||||
|
||||
private fun observeRoomSummaries() {
|
||||
homeRoomListStore
|
||||
.observe()
|
||||
.observeOn(Schedulers.computation())
|
||||
.map { it.asSequence() }
|
||||
.subscribe { summaries ->
|
||||
val invitesDm = summaries
|
||||
.filter { it.membership == Membership.INVITE && it.isDirect }
|
||||
.count()
|
||||
session.getPagedRoomSummariesLive(roomSummaryQueryParams {
|
||||
memberships = Membership.activeMemberships()
|
||||
})
|
||||
.asObservable()
|
||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||
.subscribe {
|
||||
val dmInvites = session.getRoomSummaries(roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.INVITE)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||
}).size
|
||||
|
||||
val invitesRoom = summaries
|
||||
.filter { it.membership == Membership.INVITE && it.isDirect.not() }
|
||||
.count()
|
||||
val roomsInvite = session.getRoomSummaries(roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.INVITE)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
}).size
|
||||
|
||||
val peopleNotifications = summaries
|
||||
.filter { it.isDirect }
|
||||
.map { it.notificationCount }
|
||||
.sum()
|
||||
val peopleHasHighlight = summaries
|
||||
.filter { it.isDirect }
|
||||
.any { it.highlightCount > 0 }
|
||||
val dmRooms = session.getNotificationCountForRooms(roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||
})
|
||||
|
||||
val roomsNotifications = summaries
|
||||
.filter { !it.isDirect }
|
||||
.map { it.notificationCount }
|
||||
.sum()
|
||||
val roomsHasHighlight = summaries
|
||||
.filter { !it.isDirect }
|
||||
.any { it.highlightCount > 0 }
|
||||
val otherRooms = session.getNotificationCountForRooms(roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
})
|
||||
|
||||
setState {
|
||||
copy(
|
||||
notificationCountCatchup = peopleNotifications + roomsNotifications + invitesDm + invitesRoom,
|
||||
notificationHighlightCatchup = peopleHasHighlight || roomsHasHighlight,
|
||||
notificationCountPeople = peopleNotifications + invitesDm,
|
||||
notificationHighlightPeople = peopleHasHighlight || invitesDm > 0,
|
||||
notificationCountRooms = roomsNotifications + invitesRoom,
|
||||
notificationHighlightRooms = roomsHasHighlight || invitesRoom > 0
|
||||
notificationCountCatchup = dmRooms.totalCount() + otherRooms.totalCount() + roomsInvite + dmInvites,
|
||||
notificationHighlightCatchup = dmRooms.isHighlight() || otherRooms.isHighlight(),
|
||||
notificationCountPeople = dmRooms.totalCount() + dmInvites,
|
||||
notificationHighlightPeople = dmRooms.isHighlight() || dmInvites > 0,
|
||||
notificationCountRooms = otherRooms.totalCount() + roomsInvite,
|
||||
notificationHighlightRooms = otherRooms.isHighlight() || roomsInvite > 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* 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.app.features.home
|
||||
|
||||
import im.vector.app.core.utils.BehaviorDataSource
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class HomeRoomListDataSource @Inject constructor() : BehaviorDataSource<List<RoomSummary>>()
|
|
@ -21,15 +21,20 @@ import android.content.pm.ShortcutManager
|
|||
import android.os.Build
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.disposables.Disposables
|
||||
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.rx.asObservable
|
||||
import javax.inject.Inject
|
||||
|
||||
class ShortcutsHandler @Inject constructor(
|
||||
private val context: Context,
|
||||
private val homeRoomListStore: HomeRoomListDataSource,
|
||||
private val shortcutCreator: ShortcutCreator
|
||||
private val shortcutCreator: ShortcutCreator,
|
||||
private val activeSessionHolder: ActiveSessionHolder
|
||||
) {
|
||||
|
||||
fun observeRoomsAndBuildShortcuts(): Disposable {
|
||||
|
@ -38,19 +43,20 @@ class ShortcutsHandler @Inject constructor(
|
|||
return Observable.empty<Unit>().subscribe()
|
||||
}
|
||||
|
||||
return homeRoomListStore
|
||||
.observe()
|
||||
.distinctUntilChanged()
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe { rooms ->
|
||||
return activeSessionHolder.getSafeActiveSession()?.getPagedRoomSummariesLive(roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.JOIN)
|
||||
this.roomTagQueryFilter = RoomTagQueryFilter(isFavorite = true, null, null)
|
||||
})?.asObservable()
|
||||
?.subscribe { rooms ->
|
||||
val shortcuts = rooms
|
||||
.filter { room -> room.isFavorite }
|
||||
.take(n = 4) // Android only allows us to create 4 shortcuts
|
||||
.map { shortcutCreator.create(it) }
|
||||
|
||||
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
|
||||
ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts)
|
||||
}
|
||||
|
||||
?: Disposables.empty()
|
||||
}
|
||||
|
||||
fun clearShortcuts() {
|
||||
|
|
Loading…
Reference in a new issue