Hot fix: fix home navigation issue

This commit is contained in:
ganfra 2019-10-01 17:39:20 +02:00
parent 716999eec6
commit 588e5d6e63
7 changed files with 15 additions and 64 deletions

View File

@ -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

View File

@ -22,15 +22,7 @@ import io.reactivex.schedulers.Schedulers
open class RxStore<T>(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<T> {
return storeRelay.hide().observeOn(Schedulers.computation())

View File

@ -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()
}

View File

@ -98,8 +98,6 @@ class HomeActivityViewModel @AssistedInject constructor(@Assisted initialState:
override fun onCleared() {
super.onCleared()
selectedGroupStore.clear()
homeRoomListStore.clear()
session.removeListener(this)
}

View File

@ -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)
}
}
}

View File

@ -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)
}
}

View File

@ -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)