From 588e5d6e63ecfee9d93ef3da5987b8deb59f412f Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 1 Oct 2019 17:39:20 +0200 Subject: [PATCH] Hot fix: fix home navigation issue --- .../vector/riotx/core/di/VectorComponent.kt | 3 -- .../im/vector/riotx/core/utils/RxStore.kt | 10 +---- .../riotx/features/home/HomeActivity.kt | 9 ++-- .../features/home/HomeActivityViewModel.kt | 2 - .../riotx/features/home/HomeNavigator.kt | 43 ------------------- .../features/home/group/GroupListFragment.kt | 10 +++-- .../features/home/group/GroupListViewModel.kt | 2 +- 7 files changed, 15 insertions(+), 64 deletions(-) delete mode 100644 vector/src/main/java/im/vector/riotx/features/home/HomeNavigator.kt diff --git a/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt index 10b3730022..4aab312e2f 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/VectorComponent.kt @@ -32,7 +32,6 @@ 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.HomeNavigator import im.vector.riotx.features.home.HomeRoomListObservableStore import im.vector.riotx.features.home.group.SelectedGroupStore import im.vector.riotx.features.html.EventHtmlRenderer @@ -81,8 +80,6 @@ interface VectorComponent { fun navigator(): Navigator - fun homeNavigator(): HomeNavigator - fun homeRoomListObservableStore(): HomeRoomListObservableStore fun selectedGroupStore(): SelectedGroupStore 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 94f2a9c912..b539ade931 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 @@ -22,15 +22,7 @@ import io.reactivex.schedulers.Schedulers open class RxStore(private val defaultValue: T? = null) { - var storeRelay = createRelay() - - fun clear() { - storeRelay = createRelay() - } - - fun get(): T? { - return storeRelay.value - } + private val storeRelay = createRelay() fun observe(): Observable { return storeRelay.hide().observeOn(Schedulers.computation()) diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt index c3636cde7a..bca02d3fa4 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt @@ -53,6 +53,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { // Supported navigation actions for this Activity sealed class Navigation { object OpenDrawer : Navigation() + object OpenGroup : Navigation() } private val homeActivityViewModel: HomeActivityViewModel by viewModel() @@ -60,7 +61,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { @Inject lateinit var activeSessionHolder: ActiveSessionHolder @Inject lateinit var homeActivityViewModelFactory: HomeActivityViewModel.Factory - @Inject lateinit var homeNavigator: HomeNavigator @Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler @Inject lateinit var pushManager: PushersManager @Inject lateinit var notificationDrawerManager: NotificationDrawerManager @@ -79,7 +79,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - homeNavigator.activity = this FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager) navigationViewModel = ViewModelProviders.of(this).get(HomeNavigationViewModel::class.java) drawerLayout.addDrawerListener(drawerListener) @@ -93,6 +92,11 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { navigationViewModel.navigateTo.observeEvent(this) { navigation -> when (navigation) { is Navigation.OpenDrawer -> drawerLayout.openDrawer(GravityCompat.START) + is Navigation.OpenGroup -> { + drawerLayout.closeDrawer(GravityCompat.START) + val homeDetailFragment = HomeDetailFragment.newInstance() + replaceFragment(homeDetailFragment, R.id.homeDetailFragmentContainer) + } } } @@ -134,7 +138,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onDestroy() { drawerLayout.removeDrawerListener(drawerListener) - homeNavigator.activity = null super.onDestroy() } diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt index 971f3d602c..6d52d87e7d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt @@ -98,8 +98,6 @@ class HomeActivityViewModel @AssistedInject constructor(@Assisted initialState: override fun onCleared() { super.onCleared() - selectedGroupStore.clear() - homeRoomListStore.clear() session.removeListener(this) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeNavigator.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeNavigator.kt deleted file mode 100644 index ca1d12d95f..0000000000 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeNavigator.kt +++ /dev/null @@ -1,43 +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.riotx.features.home - -import androidx.core.view.GravityCompat -import im.vector.matrix.android.api.session.group.model.GroupSummary -import im.vector.riotx.R -import im.vector.riotx.core.extensions.replaceFragment -import kotlinx.android.synthetic.main.activity_home.* -import timber.log.Timber -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class HomeNavigator @Inject constructor() { - - var activity: HomeActivity? = null - private var rootRoomId: String? = null - - fun openSelectedGroup(groupSummary: GroupSummary) { - Timber.v("Open selected group ${groupSummary.groupId}") - activity?.let { - it.drawerLayout?.closeDrawer(GravityCompat.START) - - val homeDetailFragment = HomeDetailFragment.newInstance() - it.replaceFragment(homeDetailFragment, R.id.homeDetailFragmentContainer) - } - } -} diff --git a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt index 75cc567c81..2615643781 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt @@ -17,8 +17,10 @@ package im.vector.riotx.features.home.group import android.os.Bundle +import androidx.lifecycle.ViewModelProviders import com.airbnb.mvrx.Incomplete import com.airbnb.mvrx.Success +import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.fragmentViewModel import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.riotx.R @@ -26,7 +28,8 @@ import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.platform.StateView import im.vector.riotx.core.platform.VectorBaseFragment -import im.vector.riotx.features.home.HomeNavigator +import im.vector.riotx.features.home.HomeActivity +import im.vector.riotx.features.home.HomeNavigationViewModel import kotlinx.android.synthetic.main.fragment_group_list.* import javax.inject.Inject @@ -38,10 +41,10 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback } } + private lateinit var navigationViewModel: HomeNavigationViewModel private val viewModel: GroupListViewModel by fragmentViewModel() @Inject lateinit var groupListViewModelFactory: GroupListViewModel.Factory - @Inject lateinit var homeNavigator: HomeNavigator @Inject lateinit var groupController: GroupSummaryController override fun getLayoutResId() = R.layout.fragment_group_list @@ -52,12 +55,13 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) + navigationViewModel = ViewModelProviders.of(requireActivity()).get(HomeNavigationViewModel::class.java) groupController.callback = this stateView.contentView = groupListEpoxyRecyclerView groupListEpoxyRecyclerView.setController(groupController) viewModel.subscribe { renderState(it) } viewModel.openGroupLiveData.observeEvent(this) { - homeNavigator.openSelectedGroup(it) + navigationViewModel.goTo(HomeActivity.Navigation.OpenGroup) } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt index c7278ff81d..dbd422e2e5 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt @@ -71,7 +71,7 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro private fun observeSelectionState() { selectSubscribe(GroupListViewState::selectedGroup) { if (it != null) { - val selectedGroup = selectedGroupStore.get()?.orNull() + val selectedGroup = _openGroupLiveData.value?.peekContent() // We only wan to open group if the updated selectedGroup is a different one. if (selectedGroup?.groupId != it.groupId) { _openGroupLiveData.postLiveEvent(it)