-
Notifications
You must be signed in to change notification settings - Fork 868
App Layout invites empty state #6985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,14 @@ import com.airbnb.mvrx.MavericksViewModelFactory | |
| import dagger.assisted.Assisted | ||
| import dagger.assisted.AssistedFactory | ||
| import dagger.assisted.AssistedInject | ||
| import im.vector.app.R | ||
| import im.vector.app.SpaceStateHandler | ||
| import im.vector.app.core.di.MavericksAssistedViewModelFactory | ||
| import im.vector.app.core.di.hiltMavericksViewModelFactory | ||
| import im.vector.app.core.platform.StateView | ||
| import im.vector.app.core.platform.VectorViewModel | ||
| import im.vector.app.core.resources.StringProvider | ||
| import im.vector.app.features.displayname.getBestName | ||
| import im.vector.app.features.home.room.list.home.filter.HomeRoomFilter | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||
|
|
@@ -52,17 +55,20 @@ import org.matrix.android.sdk.api.session.room.RoomSortOrder | |
| import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams | ||
| import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult | ||
| import org.matrix.android.sdk.api.session.room.model.Membership | ||
| import org.matrix.android.sdk.api.session.room.model.RoomSummary | ||
| import org.matrix.android.sdk.api.session.room.model.tag.RoomTag | ||
| import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams | ||
| import org.matrix.android.sdk.api.session.room.state.isPublic | ||
| import org.matrix.android.sdk.api.util.Optional | ||
| import org.matrix.android.sdk.api.util.toMatrixItem | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| import org.matrix.android.sdk.flow.flow | ||
|
|
||
| class HomeRoomListViewModel @AssistedInject constructor( | ||
| @Assisted initialState: HomeRoomListViewState, | ||
| private val session: Session, | ||
| private val spaceStateHandler: SpaceStateHandler, | ||
| private val preferencesStore: HomeLayoutPreferencesStore, | ||
| private val stringProvider: StringProvider, | ||
| ) : VectorViewModel<HomeRoomListViewState, HomeRoomListAction, HomeRoomListViewEvents>(initialState) { | ||
|
|
||
| @AssistedFactory | ||
|
|
@@ -82,6 +88,9 @@ class HomeRoomListViewModel @AssistedInject constructor( | |
| private val _sections = MutableSharedFlow<Set<HomeRoomSection>>(replay = 1) | ||
| val sections = _sections.asSharedFlow() | ||
|
|
||
| private val _emptyStateFlow = MutableSharedFlow<Optional<StateView.State.Empty>>(replay = 1) | ||
| val emptyStateFlow = _emptyStateFlow.asSharedFlow() | ||
|
|
||
| private var filteredPagedRoomSummariesLive: UpdatableLivePageResult? = null | ||
|
|
||
| init { | ||
|
|
@@ -230,11 +239,11 @@ class HomeRoomListViewModel @AssistedInject constructor( | |
|
|
||
| private fun getFilteredQueryParams(filter: HomeRoomFilter, currentParams: RoomSummaryQueryParams): RoomSummaryQueryParams { | ||
| return when (filter) { | ||
| HomeRoomFilter.ALL -> currentParams.copy( | ||
| HomeRoomFilter.ALL -> currentParams.copy( | ||
| roomCategoryFilter = null, | ||
| roomTagQueryFilter = null | ||
| ) | ||
| HomeRoomFilter.UNREADS -> currentParams.copy( | ||
| HomeRoomFilter.UNREADS -> currentParams.copy( | ||
| roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS, | ||
| roomTagQueryFilter = RoomTagQueryFilter(null, false, null) | ||
| ) | ||
|
|
@@ -243,27 +252,57 @@ class HomeRoomListViewModel @AssistedInject constructor( | |
| roomCategoryFilter = null, | ||
| roomTagQueryFilter = RoomTagQueryFilter(true, null, null) | ||
| ) | ||
| HomeRoomFilter.PEOPlE -> currentParams.copy( | ||
| HomeRoomFilter.PEOPlE -> currentParams.copy( | ||
| roomCategoryFilter = RoomCategoryFilter.ONLY_DM, | ||
| roomTagQueryFilter = null | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun getEmptyStateData(filter: HomeRoomFilter, selectedSpace: RoomSummary?): StateView.State.Empty? { | ||
| return when (filter) { | ||
| HomeRoomFilter.ALL -> | ||
| if (selectedSpace != null) { | ||
| StateView.State.Empty( | ||
| title = stringProvider.getString(R.string.home_empty_space_no_rooms_title, selectedSpace.displayName), | ||
| message = stringProvider.getString(R.string.home_empty_space_no_rooms_message) | ||
| ) | ||
| } else { | ||
| val userName = session.userService().getUser(session.myUserId)?.displayName ?: "" | ||
| StateView.State.Empty( | ||
| title = stringProvider.getString(R.string.home_empty_no_rooms_title, userName), | ||
| message = stringProvider.getString(R.string.home_empty_no_rooms_message) | ||
| ) | ||
| } | ||
| HomeRoomFilter.UNREADS -> | ||
| StateView.State.Empty( | ||
| title = stringProvider.getString(R.string.home_empty_no_unreads_title), | ||
| message = stringProvider.getString(R.string.home_empty_no_unreads_message) | ||
| ) | ||
| else -> | ||
| null | ||
| } | ||
| } | ||
|
|
||
| override fun handle(action: HomeRoomListAction) { | ||
| when (action) { | ||
| is HomeRoomListAction.SelectRoom -> handleSelectRoom(action) | ||
| is HomeRoomListAction.LeaveRoom -> handleLeaveRoom(action) | ||
| is HomeRoomListAction.SelectRoom -> handleSelectRoom(action) | ||
| is HomeRoomListAction.LeaveRoom -> handleLeaveRoom(action) | ||
| is HomeRoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action) | ||
| is HomeRoomListAction.ToggleTag -> handleToggleTag(action) | ||
| is HomeRoomListAction.ChangeRoomFilter -> handleChangeRoomFilter(action) | ||
| is HomeRoomListAction.ToggleTag -> handleToggleTag(action) | ||
| is HomeRoomListAction.ChangeRoomFilter -> handleChangeRoomFilter(action) | ||
| } | ||
| } | ||
|
|
||
| private fun handleChangeRoomFilter(action: HomeRoomListAction.ChangeRoomFilter) { | ||
| filteredPagedRoomSummariesLive?.let { liveResults -> | ||
| liveResults.queryParams = getFilteredQueryParams(action.filter, liveResults.queryParams) | ||
| } | ||
|
|
||
| viewModelScope.launch { | ||
| val emptyState = getEmptyStateData(action.filter, spaceStateHandler.getCurrentSpace()) | ||
| _emptyStateFlow.emit(Optional.from(emptyState)) | ||
| } | ||
| } | ||
|
|
||
| fun isPublicRoom(roomId: String): Boolean { | ||
|
|
@@ -322,9 +361,9 @@ class HomeRoomListViewModel @AssistedInject constructor( | |
|
|
||
| private fun String.otherTag(): String? { | ||
| return when (this) { | ||
| RoomTag.ROOM_TAG_FAVOURITE -> RoomTag.ROOM_TAG_LOW_PRIORITY | ||
| RoomTag.ROOM_TAG_FAVOURITE -> RoomTag.ROOM_TAG_LOW_PRIORITY | ||
| RoomTag.ROOM_TAG_LOW_PRIORITY -> RoomTag.ROOM_TAG_FAVOURITE | ||
| else -> null | ||
| else -> null | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package im.vector.app.features.home.room.list.home | |
|
|
||
| import androidx.lifecycle.LiveData | ||
| import androidx.paging.PagedList | ||
| import im.vector.app.core.platform.StateView | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| import im.vector.app.features.home.room.list.home.filter.HomeRoomFilter | ||
| import kotlinx.coroutines.flow.SharedFlow | ||
| import org.matrix.android.sdk.api.session.room.model.RoomSummary | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (c) 2022 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.room.list.home | ||
|
|
||
| import com.airbnb.epoxy.EpoxyAttribute | ||
| import com.airbnb.epoxy.EpoxyModelClass | ||
| import com.google.android.material.tabs.TabLayout | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| import im.vector.app.R | ||
| import im.vector.app.core.epoxy.VectorEpoxyHolder | ||
| import im.vector.app.core.epoxy.VectorEpoxyModel | ||
| import im.vector.app.core.platform.StateView | ||
| import im.vector.app.features.home.room.list.home.filter.HomeRoomFilter | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| import im.vector.app.features.home.room.list.home.filter.RoomFilterHeaderItem | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| @EpoxyModelClass | ||
| abstract class RoomListEmptyItem : VectorEpoxyModel<RoomListEmptyItem.Holder>(R.layout.item_room_list_empty) { | ||
|
|
||
| @EpoxyAttribute | ||
| var emptyData: StateView.State.Empty? = null | ||
|
|
||
| override fun bind(holder: Holder) { | ||
| super.bind(holder) | ||
| holder.stateView.state = emptyData ?: StateView.State.Content | ||
| } | ||
|
|
||
| class Holder : VectorEpoxyHolder() { | ||
| val stateView by bind<StateView>(R.id.stateView) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <im.vector.app.core.platform.StateView xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:id="@+id/stateView" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:background="?android:colorBackground"> | ||
|
|
||
| </im.vector.app.core.platform.StateView> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.