mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 18:36:21 +03:00
Hot fix: fix home navigation issue
This commit is contained in:
parent
716999eec6
commit
588e5d6e63
7 changed files with 15 additions and 64 deletions
|
@ -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.keysrequest.KeyRequestHandler
|
||||||
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
||||||
import im.vector.riotx.features.home.AvatarRenderer
|
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.HomeRoomListObservableStore
|
||||||
import im.vector.riotx.features.home.group.SelectedGroupStore
|
import im.vector.riotx.features.home.group.SelectedGroupStore
|
||||||
import im.vector.riotx.features.html.EventHtmlRenderer
|
import im.vector.riotx.features.html.EventHtmlRenderer
|
||||||
|
@ -81,8 +80,6 @@ interface VectorComponent {
|
||||||
|
|
||||||
fun navigator(): Navigator
|
fun navigator(): Navigator
|
||||||
|
|
||||||
fun homeNavigator(): HomeNavigator
|
|
||||||
|
|
||||||
fun homeRoomListObservableStore(): HomeRoomListObservableStore
|
fun homeRoomListObservableStore(): HomeRoomListObservableStore
|
||||||
|
|
||||||
fun selectedGroupStore(): SelectedGroupStore
|
fun selectedGroupStore(): SelectedGroupStore
|
||||||
|
|
|
@ -22,15 +22,7 @@ import io.reactivex.schedulers.Schedulers
|
||||||
|
|
||||||
open class RxStore<T>(private val defaultValue: T? = null) {
|
open class RxStore<T>(private val defaultValue: T? = null) {
|
||||||
|
|
||||||
var storeRelay = createRelay()
|
private val storeRelay = createRelay()
|
||||||
|
|
||||||
fun clear() {
|
|
||||||
storeRelay = createRelay()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun get(): T? {
|
|
||||||
return storeRelay.value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun observe(): Observable<T> {
|
fun observe(): Observable<T> {
|
||||||
return storeRelay.hide().observeOn(Schedulers.computation())
|
return storeRelay.hide().observeOn(Schedulers.computation())
|
||||||
|
|
|
@ -53,6 +53,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
// Supported navigation actions for this Activity
|
// Supported navigation actions for this Activity
|
||||||
sealed class Navigation {
|
sealed class Navigation {
|
||||||
object OpenDrawer : Navigation()
|
object OpenDrawer : Navigation()
|
||||||
|
object OpenGroup : Navigation()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val homeActivityViewModel: HomeActivityViewModel by viewModel()
|
private val homeActivityViewModel: HomeActivityViewModel by viewModel()
|
||||||
|
@ -60,7 +61,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
|
|
||||||
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
|
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
|
||||||
@Inject lateinit var homeActivityViewModelFactory: HomeActivityViewModel.Factory
|
@Inject lateinit var homeActivityViewModelFactory: HomeActivityViewModel.Factory
|
||||||
@Inject lateinit var homeNavigator: HomeNavigator
|
|
||||||
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
|
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
|
||||||
@Inject lateinit var pushManager: PushersManager
|
@Inject lateinit var pushManager: PushersManager
|
||||||
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
|
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
|
||||||
|
@ -79,7 +79,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
homeNavigator.activity = this
|
|
||||||
FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager)
|
FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager)
|
||||||
navigationViewModel = ViewModelProviders.of(this).get(HomeNavigationViewModel::class.java)
|
navigationViewModel = ViewModelProviders.of(this).get(HomeNavigationViewModel::class.java)
|
||||||
drawerLayout.addDrawerListener(drawerListener)
|
drawerLayout.addDrawerListener(drawerListener)
|
||||||
|
@ -93,6 +92,11 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
navigationViewModel.navigateTo.observeEvent(this) { navigation ->
|
navigationViewModel.navigateTo.observeEvent(this) { navigation ->
|
||||||
when (navigation) {
|
when (navigation) {
|
||||||
is Navigation.OpenDrawer -> drawerLayout.openDrawer(GravityCompat.START)
|
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() {
|
override fun onDestroy() {
|
||||||
drawerLayout.removeDrawerListener(drawerListener)
|
drawerLayout.removeDrawerListener(drawerListener)
|
||||||
homeNavigator.activity = null
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,6 @@ class HomeActivityViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
selectedGroupStore.clear()
|
|
||||||
homeRoomListStore.clear()
|
|
||||||
session.removeListener(this)
|
session.removeListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,8 +17,10 @@
|
||||||
package im.vector.riotx.features.home.group
|
package im.vector.riotx.features.home.group
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import com.airbnb.mvrx.Incomplete
|
import com.airbnb.mvrx.Incomplete
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
|
import com.airbnb.mvrx.activityViewModel
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||||
import im.vector.riotx.R
|
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.extensions.observeEvent
|
||||||
import im.vector.riotx.core.platform.StateView
|
import im.vector.riotx.core.platform.StateView
|
||||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
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 kotlinx.android.synthetic.main.fragment_group_list.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -38,10 +41,10 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private lateinit var navigationViewModel: HomeNavigationViewModel
|
||||||
private val viewModel: GroupListViewModel by fragmentViewModel()
|
private val viewModel: GroupListViewModel by fragmentViewModel()
|
||||||
|
|
||||||
@Inject lateinit var groupListViewModelFactory: GroupListViewModel.Factory
|
@Inject lateinit var groupListViewModelFactory: GroupListViewModel.Factory
|
||||||
@Inject lateinit var homeNavigator: HomeNavigator
|
|
||||||
@Inject lateinit var groupController: GroupSummaryController
|
@Inject lateinit var groupController: GroupSummaryController
|
||||||
|
|
||||||
override fun getLayoutResId() = R.layout.fragment_group_list
|
override fun getLayoutResId() = R.layout.fragment_group_list
|
||||||
|
@ -52,12 +55,13 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
navigationViewModel = ViewModelProviders.of(requireActivity()).get(HomeNavigationViewModel::class.java)
|
||||||
groupController.callback = this
|
groupController.callback = this
|
||||||
stateView.contentView = groupListEpoxyRecyclerView
|
stateView.contentView = groupListEpoxyRecyclerView
|
||||||
groupListEpoxyRecyclerView.setController(groupController)
|
groupListEpoxyRecyclerView.setController(groupController)
|
||||||
viewModel.subscribe { renderState(it) }
|
viewModel.subscribe { renderState(it) }
|
||||||
viewModel.openGroupLiveData.observeEvent(this) {
|
viewModel.openGroupLiveData.observeEvent(this) {
|
||||||
homeNavigator.openSelectedGroup(it)
|
navigationViewModel.goTo(HomeActivity.Navigation.OpenGroup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro
|
||||||
private fun observeSelectionState() {
|
private fun observeSelectionState() {
|
||||||
selectSubscribe(GroupListViewState::selectedGroup) {
|
selectSubscribe(GroupListViewState::selectedGroup) {
|
||||||
if (it != null) {
|
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.
|
// We only wan to open group if the updated selectedGroup is a different one.
|
||||||
if (selectedGroup?.groupId != it.groupId) {
|
if (selectedGroup?.groupId != it.groupId) {
|
||||||
_openGroupLiveData.postLiveEvent(it)
|
_openGroupLiveData.postLiveEvent(it)
|
||||||
|
|
Loading…
Reference in a new issue