Merge pull request #4116 from vector-im/feature/bca/spaces_fix_3933

App doesn't take you to a Space after choosing to Join it
This commit is contained in:
Benoit Marty 2021-10-04 09:49:42 +02:00 committed by GitHub
commit a0cd7163c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 115 additions and 52 deletions

1
changelog.d/3933.bugfix Normal file
View File

@ -0,0 +1 @@
App doesn't take you to a Space after choosing to Join it

View File

@ -27,6 +27,8 @@ import android.view.MenuItem
import androidx.core.view.GravityCompat import androidx.core.view.GravityCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.viewModel
import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.appbar.MaterialToolbar
@ -96,7 +98,8 @@ class HomeActivity :
UnreadMessagesSharedViewModel.Factory, UnreadMessagesSharedViewModel.Factory,
PromoteRestrictedViewModel.Factory, PromoteRestrictedViewModel.Factory,
NavigationInterceptor, NavigationInterceptor,
SpaceInviteBottomSheet.InteractionListener { SpaceInviteBottomSheet.InteractionListener,
MatrixToBottomSheet.InteractionListener {
private lateinit var sharedActionViewModel: HomeSharedActionViewModel private lateinit var sharedActionViewModel: HomeSharedActionViewModel
@ -145,6 +148,22 @@ class HomeActivity :
} }
} }
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = this@HomeActivity
}
super.onFragmentResumed(fm, f)
}
override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = null
}
super.onFragmentPaused(fm, f)
}
}
private val drawerListener = object : DrawerLayout.SimpleDrawerListener() { private val drawerListener = object : DrawerLayout.SimpleDrawerListener() {
override fun onDrawerStateChanged(newState: Int) { override fun onDrawerStateChanged(newState: Int) {
hideKeyboard() hideKeyboard()
@ -173,6 +192,7 @@ class HomeActivity :
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager, vectorPreferences.areNotificationEnabledForDevice()) FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager, vectorPreferences.areNotificationEnabledForDevice())
sharedActionViewModel = viewModelProvider.get(HomeSharedActionViewModel::class.java) sharedActionViewModel = viewModelProvider.get(HomeSharedActionViewModel::class.java)
views.drawerLayout.addDrawerListener(drawerListener) views.drawerLayout.addDrawerListener(drawerListener)
@ -449,6 +469,7 @@ class HomeActivity :
override fun onDestroy() { override fun onDestroy() {
views.drawerLayout.removeDrawerListener(drawerListener) views.drawerLayout.removeDrawerListener(drawerListener)
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
super.onDestroy() super.onDestroy()
} }
@ -530,30 +551,15 @@ class HomeActivity :
} }
override fun navToMemberProfile(userId: String, deepLink: Uri): Boolean { override fun navToMemberProfile(userId: String, deepLink: Uri): Boolean {
val listener = object : MatrixToBottomSheet.InteractionListener {
override fun navigateToRoom(roomId: String) {
navigator.openRoom(this@HomeActivity, roomId)
}
}
// TODO check if there is already one?? // TODO check if there is already one??
MatrixToBottomSheet.withLink(deepLink.toString(), listener) MatrixToBottomSheet.withLink(deepLink.toString())
.show(supportFragmentManager, "HA#MatrixToBottomSheet") .show(supportFragmentManager, "HA#MatrixToBottomSheet")
return true return true
} }
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?): Boolean { override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?): Boolean {
if (roomId == null) return false if (roomId == null) return false
val listener = object : MatrixToBottomSheet.InteractionListener { MatrixToBottomSheet.withLink(deepLink.toString())
override fun navigateToRoom(roomId: String) {
navigator.openRoom(this@HomeActivity, roomId)
}
override fun switchToSpace(spaceId: String) {
navigator.switchToSpace(this@HomeActivity, spaceId, Navigator.PostSwitchSpaceAction.None)
}
}
MatrixToBottomSheet.withLink(deepLink.toString(), listener)
.show(supportFragmentManager, "HA#MatrixToBottomSheet") .show(supportFragmentManager, "HA#MatrixToBottomSheet")
return true return true
} }
@ -586,4 +592,12 @@ class HomeActivity :
} }
override fun create(initialState: ActiveSpaceViewState) = promoteRestrictedViewModelFactory.create(initialState) override fun create(initialState: ActiveSpaceViewState) = promoteRestrictedViewModelFactory.create(initialState)
override fun mxToBottomSheetNavigateToRoom(roomId: String) {
navigator.openRoom(this, roomId)
}
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {
navigator.switchToSpace(this, spaceId, Navigator.PostSwitchSpaceAction.None)
}
} }

View File

@ -22,6 +22,8 @@ import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import androidx.core.view.GravityCompat import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.viewModel
import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.appbar.MaterialToolbar
import im.vector.app.R import im.vector.app.R
@ -32,6 +34,8 @@ import im.vector.app.core.platform.ToolbarConfigurable
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityRoomDetailBinding import im.vector.app.databinding.ActivityRoomDetailBinding
import im.vector.app.features.home.room.breadcrumbs.BreadcrumbsFragment import im.vector.app.features.home.room.breadcrumbs.BreadcrumbsFragment
import im.vector.app.features.matrixto.MatrixToBottomSheet
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.room.RequireActiveMembershipAction import im.vector.app.features.room.RequireActiveMembershipAction
import im.vector.app.features.room.RequireActiveMembershipViewEvents import im.vector.app.features.room.RequireActiveMembershipViewEvents
import im.vector.app.features.room.RequireActiveMembershipViewModel import im.vector.app.features.room.RequireActiveMembershipViewModel
@ -44,12 +48,30 @@ class RoomDetailActivity :
VectorBaseActivity<ActivityRoomDetailBinding>(), VectorBaseActivity<ActivityRoomDetailBinding>(),
ToolbarConfigurable, ToolbarConfigurable,
RequireActiveMembershipViewModel.Factory, RequireActiveMembershipViewModel.Factory,
RoomWidgetPermissionViewModel.Factory { RoomWidgetPermissionViewModel.Factory,
MatrixToBottomSheet.InteractionListener {
override fun getBinding(): ActivityRoomDetailBinding { override fun getBinding(): ActivityRoomDetailBinding {
return ActivityRoomDetailBinding.inflate(layoutInflater) return ActivityRoomDetailBinding.inflate(layoutInflater)
} }
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = this@RoomDetailActivity
}
super.onFragmentResumed(fm, f)
}
override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = null
}
super.onFragmentPaused(fm, f)
}
}
override fun getCoordinatorLayout() = views.coordinatorLayout override fun getCoordinatorLayout() = views.coordinatorLayout
private lateinit var sharedActionViewModel: RoomDetailSharedActionViewModel private lateinit var sharedActionViewModel: RoomDetailSharedActionViewModel
@ -78,6 +100,7 @@ class RoomDetailActivity :
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
waitingView = views.waitingView.waitingView waitingView = views.waitingView.waitingView
val roomDetailArgs: RoomDetailArgs? = if (intent?.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) { val roomDetailArgs: RoomDetailArgs? = if (intent?.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) {
RoomDetailArgs(roomId = intent?.extras?.getString(EXTRA_ROOM_ID)!!) RoomDetailArgs(roomId = intent?.extras?.getString(EXTRA_ROOM_ID)!!)
@ -129,6 +152,7 @@ class RoomDetailActivity :
} }
override fun onDestroy() { override fun onDestroy() {
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
views.drawerLayout.removeDrawerListener(drawerListener) views.drawerLayout.removeDrawerListener(drawerListener)
super.onDestroy() super.onDestroy()
} }
@ -181,4 +205,12 @@ class RoomDetailActivity :
} }
} }
} }
override fun mxToBottomSheetNavigateToRoom(roomId: String) {
navigator.openRoom(this, roomId)
}
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {
navigator.switchToSpace(this, spaceId, Navigator.PostSwitchSpaceAction.None)
}
} }

View File

@ -36,7 +36,6 @@ import im.vector.app.databinding.BottomSheetMatrixToCardBinding
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.permalinks.PermalinkData
import java.lang.ref.WeakReference
import javax.inject.Inject import javax.inject.Inject
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -57,13 +56,7 @@ class MatrixToBottomSheet :
injector.inject(this) injector.inject(this)
} }
private var weakReference = WeakReference<InteractionListener>(null) var interactionListener: InteractionListener? = null
var interactionListener: InteractionListener?
set(value) {
weakReference = WeakReference(value)
}
get() = weakReference.get()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetMatrixToCardBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetMatrixToCardBinding {
return BottomSheetMatrixToCardBinding.inflate(inflater, container, false) return BottomSheetMatrixToCardBinding.inflate(inflater, container, false)
@ -72,8 +65,8 @@ class MatrixToBottomSheet :
private val viewModel by fragmentViewModel(MatrixToBottomSheetViewModel::class) private val viewModel by fragmentViewModel(MatrixToBottomSheetViewModel::class)
interface InteractionListener { interface InteractionListener {
fun navigateToRoom(roomId: String) fun mxToBottomSheetNavigateToRoom(roomId: String)
fun switchToSpace(spaceId: String) {} fun mxToBottomSheetSwitchToSpace(spaceId: String)
} }
override fun invalidate() = withState(viewModel) { state -> override fun invalidate() = withState(viewModel) { state ->
@ -112,12 +105,12 @@ class MatrixToBottomSheet :
viewModel.observeViewEvents { viewModel.observeViewEvents {
when (it) { when (it) {
is MatrixToViewEvents.NavigateToRoom -> { is MatrixToViewEvents.NavigateToRoom -> {
interactionListener?.navigateToRoom(it.roomId) interactionListener?.mxToBottomSheetNavigateToRoom(it.roomId)
dismiss() dismiss()
} }
MatrixToViewEvents.Dismiss -> dismiss() MatrixToViewEvents.Dismiss -> dismiss()
is MatrixToViewEvents.NavigateToSpace -> { is MatrixToViewEvents.NavigateToSpace -> {
interactionListener?.switchToSpace(it.spaceId) interactionListener?.mxToBottomSheetSwitchToSpace(it.spaceId)
dismiss() dismiss()
} }
is MatrixToViewEvents.ShowModalError -> { is MatrixToViewEvents.ShowModalError -> {
@ -131,14 +124,13 @@ class MatrixToBottomSheet :
} }
companion object { companion object {
fun withLink(matrixToLink: String, listener: InteractionListener?): MatrixToBottomSheet { fun withLink(matrixToLink: String): MatrixToBottomSheet {
return MatrixToBottomSheet().apply { return MatrixToBottomSheet().apply {
arguments = Bundle().apply { arguments = Bundle().apply {
putParcelable(MvRx.KEY_ARG, MatrixToArgs( putParcelable(MvRx.KEY_ARG, MatrixToArgs(
matrixToLink = matrixToLink matrixToLink = matrixToLink
)) ))
} }
interactionListener = listener
} }
} }
} }

View File

@ -257,17 +257,11 @@ class DefaultNavigator @Inject constructor(
override fun openMatrixToBottomSheet(context: Context, link: String) { override fun openMatrixToBottomSheet(context: Context, link: String) {
if (context is AppCompatActivity) { if (context is AppCompatActivity) {
val listener = object : MatrixToBottomSheet.InteractionListener { if (context !is MatrixToBottomSheet.InteractionListener) {
override fun navigateToRoom(roomId: String) { fatalError("Caller context should implement MatrixToBottomSheet.InteractionListener", vectorPreferences.failFast())
openRoom(context, roomId)
}
override fun switchToSpace(spaceId: String) {
this@DefaultNavigator.switchToSpace(context, spaceId, Navigator.PostSwitchSpaceAction.None)
}
} }
// TODO check if there is already one?? // TODO check if there is already one??
MatrixToBottomSheet.withLink(link, listener) MatrixToBottomSheet.withLink(link)
.show(context.supportFragmentManager, "HA#MatrixToBottomSheet") .show(context.supportFragmentManager, "HA#MatrixToBottomSheet")
} }
} }

View File

@ -29,6 +29,7 @@ import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.databinding.ActivitySimpleBinding
import im.vector.app.features.matrixto.MatrixToBottomSheet import im.vector.app.features.matrixto.MatrixToBottomSheet
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.spaces.explore.SpaceDirectoryArgs import im.vector.app.features.spaces.explore.SpaceDirectoryArgs
import im.vector.app.features.spaces.explore.SpaceDirectoryFragment import im.vector.app.features.spaces.explore.SpaceDirectoryFragment
import im.vector.app.features.spaces.explore.SpaceDirectoryState import im.vector.app.features.spaces.explore.SpaceDirectoryState
@ -51,18 +52,18 @@ class SpaceExploreActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceD
val sharedViewModel: SpaceDirectoryViewModel by viewModel() val sharedViewModel: SpaceDirectoryViewModel by viewModel()
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() { private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentAttached(fm: FragmentManager, f: Fragment, context: Context) { override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) { if (f is MatrixToBottomSheet) {
f.interactionListener = this@SpaceExploreActivity f.interactionListener = this@SpaceExploreActivity
} }
super.onFragmentAttached(fm, f, context) super.onFragmentResumed(fm, f)
} }
override fun onFragmentDetached(fm: FragmentManager, f: Fragment) { override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) { if (f is MatrixToBottomSheet) {
f.interactionListener = null f.interactionListener = null
} }
super.onFragmentDetached(fm, f) super.onFragmentPaused(fm, f)
} }
} }
@ -86,14 +87,14 @@ class SpaceExploreActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceD
sharedViewModel.observeViewEvents { sharedViewModel.observeViewEvents {
when (it) { when (it) {
SpaceDirectoryViewEvents.Dismiss -> { SpaceDirectoryViewEvents.Dismiss -> {
finish() finish()
} }
is SpaceDirectoryViewEvents.NavigateToRoom -> { is SpaceDirectoryViewEvents.NavigateToRoom -> {
navigator.openRoom(this, it.roomId) navigator.openRoom(this, it.roomId)
} }
is SpaceDirectoryViewEvents.NavigateToMxToBottomSheet -> { is SpaceDirectoryViewEvents.NavigateToMxToBottomSheet -> {
MatrixToBottomSheet.withLink(it.link, this).show(supportFragmentManager, "ShowChild") MatrixToBottomSheet.withLink(it.link).show(supportFragmentManager, "ShowChild")
} }
} }
} }
@ -115,7 +116,11 @@ class SpaceExploreActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceD
override fun create(initialState: SpaceDirectoryState): SpaceDirectoryViewModel = override fun create(initialState: SpaceDirectoryState): SpaceDirectoryViewModel =
spaceDirectoryViewModelFactory.create(initialState) spaceDirectoryViewModelFactory.create(initialState)
override fun navigateToRoom(roomId: String) { override fun mxToBottomSheetNavigateToRoom(roomId: String) {
navigator.openRoom(this, roomId) navigator.openRoom(this, roomId)
} }
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {
navigator.switchToSpace(this, spaceId, Navigator.PostSwitchSpaceAction.None)
}
} }

View File

@ -24,6 +24,7 @@ import android.widget.Toast
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.viewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
@ -60,8 +61,25 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
injector.inject(this) injector.inject(this)
} }
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = this@UserCodeActivity
}
super.onFragmentResumed(fm, f)
}
override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = null
}
super.onFragmentPaused(fm, f)
}
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
if (isFirstCreation()) { if (isFirstCreation()) {
// should be there early for shared element transition // should be there early for shared element transition
@ -74,7 +92,7 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY) UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY)
is UserCodeState.Mode.RESULT -> { is UserCodeState.Mode.RESULT -> {
showFragment(ShowUserCodeFragment::class, Bundle.EMPTY) showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
MatrixToBottomSheet.withLink(mode.rawLink, this).show(supportFragmentManager, "MatrixToBottomSheet") MatrixToBottomSheet.withLink(mode.rawLink).show(supportFragmentManager, "MatrixToBottomSheet")
} }
} }
} }
@ -97,6 +115,11 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
} }
} }
override fun onDestroy() {
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
super.onDestroy()
}
private fun showFragment(fragmentClass: KClass<out Fragment>, bundle: Bundle) { private fun showFragment(fragmentClass: KClass<out Fragment>, bundle: Bundle) {
if (supportFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) { if (supportFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
supportFragmentManager.commitTransaction { supportFragmentManager.commitTransaction {
@ -110,10 +133,12 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
} }
} }
override fun navigateToRoom(roomId: String) { override fun mxToBottomSheetNavigateToRoom(roomId: String) {
navigator.openRoom(this, roomId) navigator.openRoom(this, roomId)
} }
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {}
override fun onBackPressed() = withState(sharedViewModel) { override fun onBackPressed() = withState(sharedViewModel) {
when (it.mode) { when (it.mode) {
UserCodeState.Mode.SHOW -> super.onBackPressed() UserCodeState.Mode.SHOW -> super.onBackPressed()