mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
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:
commit
a0cd7163c6
7 changed files with 115 additions and 52 deletions
1
changelog.d/3933.bugfix
Normal file
1
changelog.d/3933.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
App doesn't take you to a Space after choosing to Join it
|
|
@ -27,6 +27,8 @@ import android.view.MenuItem
|
|||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.airbnb.mvrx.MvRx
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
|
@ -96,7 +98,8 @@ class HomeActivity :
|
|||
UnreadMessagesSharedViewModel.Factory,
|
||||
PromoteRestrictedViewModel.Factory,
|
||||
NavigationInterceptor,
|
||||
SpaceInviteBottomSheet.InteractionListener {
|
||||
SpaceInviteBottomSheet.InteractionListener,
|
||||
MatrixToBottomSheet.InteractionListener {
|
||||
|
||||
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() {
|
||||
override fun onDrawerStateChanged(newState: Int) {
|
||||
hideKeyboard()
|
||||
|
@ -173,6 +192,7 @@ class HomeActivity :
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
|
||||
FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager, vectorPreferences.areNotificationEnabledForDevice())
|
||||
sharedActionViewModel = viewModelProvider.get(HomeSharedActionViewModel::class.java)
|
||||
views.drawerLayout.addDrawerListener(drawerListener)
|
||||
|
@ -449,6 +469,7 @@ class HomeActivity :
|
|||
|
||||
override fun onDestroy() {
|
||||
views.drawerLayout.removeDrawerListener(drawerListener)
|
||||
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
|
@ -530,30 +551,15 @@ class HomeActivity :
|
|||
}
|
||||
|
||||
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??
|
||||
MatrixToBottomSheet.withLink(deepLink.toString(), listener)
|
||||
MatrixToBottomSheet.withLink(deepLink.toString())
|
||||
.show(supportFragmentManager, "HA#MatrixToBottomSheet")
|
||||
return true
|
||||
}
|
||||
|
||||
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?): Boolean {
|
||||
if (roomId == null) return false
|
||||
val listener = object : MatrixToBottomSheet.InteractionListener {
|
||||
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)
|
||||
MatrixToBottomSheet.withLink(deepLink.toString())
|
||||
.show(supportFragmentManager, "HA#MatrixToBottomSheet")
|
||||
return true
|
||||
}
|
||||
|
@ -586,4 +592,12 @@ class HomeActivity :
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ import android.os.Bundle
|
|||
import android.widget.Toast
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
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.databinding.ActivityRoomDetailBinding
|
||||
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.RequireActiveMembershipViewEvents
|
||||
import im.vector.app.features.room.RequireActiveMembershipViewModel
|
||||
|
@ -44,12 +48,30 @@ class RoomDetailActivity :
|
|||
VectorBaseActivity<ActivityRoomDetailBinding>(),
|
||||
ToolbarConfigurable,
|
||||
RequireActiveMembershipViewModel.Factory,
|
||||
RoomWidgetPermissionViewModel.Factory {
|
||||
RoomWidgetPermissionViewModel.Factory,
|
||||
MatrixToBottomSheet.InteractionListener {
|
||||
|
||||
override fun getBinding(): ActivityRoomDetailBinding {
|
||||
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
|
||||
|
||||
private lateinit var sharedActionViewModel: RoomDetailSharedActionViewModel
|
||||
|
@ -78,6 +100,7 @@ class RoomDetailActivity :
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
|
||||
waitingView = views.waitingView.waitingView
|
||||
val roomDetailArgs: RoomDetailArgs? = if (intent?.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) {
|
||||
RoomDetailArgs(roomId = intent?.extras?.getString(EXTRA_ROOM_ID)!!)
|
||||
|
@ -129,6 +152,7 @@ class RoomDetailActivity :
|
|||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
|
||||
views.drawerLayout.removeDrawerListener(drawerListener)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import im.vector.app.databinding.BottomSheetMatrixToCardBinding
|
|||
import im.vector.app.features.home.AvatarRenderer
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
|
||||
import java.lang.ref.WeakReference
|
||||
import javax.inject.Inject
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
@ -57,13 +56,7 @@ class MatrixToBottomSheet :
|
|||
injector.inject(this)
|
||||
}
|
||||
|
||||
private var weakReference = WeakReference<InteractionListener>(null)
|
||||
|
||||
var interactionListener: InteractionListener?
|
||||
set(value) {
|
||||
weakReference = WeakReference(value)
|
||||
}
|
||||
get() = weakReference.get()
|
||||
var interactionListener: InteractionListener? = null
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetMatrixToCardBinding {
|
||||
return BottomSheetMatrixToCardBinding.inflate(inflater, container, false)
|
||||
|
@ -72,8 +65,8 @@ class MatrixToBottomSheet :
|
|||
private val viewModel by fragmentViewModel(MatrixToBottomSheetViewModel::class)
|
||||
|
||||
interface InteractionListener {
|
||||
fun navigateToRoom(roomId: String)
|
||||
fun switchToSpace(spaceId: String) {}
|
||||
fun mxToBottomSheetNavigateToRoom(roomId: String)
|
||||
fun mxToBottomSheetSwitchToSpace(spaceId: String)
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
|
@ -112,12 +105,12 @@ class MatrixToBottomSheet :
|
|||
viewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is MatrixToViewEvents.NavigateToRoom -> {
|
||||
interactionListener?.navigateToRoom(it.roomId)
|
||||
interactionListener?.mxToBottomSheetNavigateToRoom(it.roomId)
|
||||
dismiss()
|
||||
}
|
||||
MatrixToViewEvents.Dismiss -> dismiss()
|
||||
is MatrixToViewEvents.NavigateToSpace -> {
|
||||
interactionListener?.switchToSpace(it.spaceId)
|
||||
interactionListener?.mxToBottomSheetSwitchToSpace(it.spaceId)
|
||||
dismiss()
|
||||
}
|
||||
is MatrixToViewEvents.ShowModalError -> {
|
||||
|
@ -131,14 +124,13 @@ class MatrixToBottomSheet :
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun withLink(matrixToLink: String, listener: InteractionListener?): MatrixToBottomSheet {
|
||||
fun withLink(matrixToLink: String): MatrixToBottomSheet {
|
||||
return MatrixToBottomSheet().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(MvRx.KEY_ARG, MatrixToArgs(
|
||||
matrixToLink = matrixToLink
|
||||
))
|
||||
}
|
||||
interactionListener = listener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,17 +257,11 @@ class DefaultNavigator @Inject constructor(
|
|||
|
||||
override fun openMatrixToBottomSheet(context: Context, link: String) {
|
||||
if (context is AppCompatActivity) {
|
||||
val listener = object : MatrixToBottomSheet.InteractionListener {
|
||||
override fun navigateToRoom(roomId: String) {
|
||||
openRoom(context, roomId)
|
||||
}
|
||||
|
||||
override fun switchToSpace(spaceId: String) {
|
||||
this@DefaultNavigator.switchToSpace(context, spaceId, Navigator.PostSwitchSpaceAction.None)
|
||||
}
|
||||
if (context !is MatrixToBottomSheet.InteractionListener) {
|
||||
fatalError("Caller context should implement MatrixToBottomSheet.InteractionListener", vectorPreferences.failFast())
|
||||
}
|
||||
// TODO check if there is already one??
|
||||
MatrixToBottomSheet.withLink(link, listener)
|
||||
MatrixToBottomSheet.withLink(link)
|
||||
.show(context.supportFragmentManager, "HA#MatrixToBottomSheet")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import im.vector.app.core.extensions.commitTransaction
|
|||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.databinding.ActivitySimpleBinding
|
||||
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.SpaceDirectoryFragment
|
||||
import im.vector.app.features.spaces.explore.SpaceDirectoryState
|
||||
|
@ -51,18 +52,18 @@ class SpaceExploreActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceD
|
|||
val sharedViewModel: SpaceDirectoryViewModel by viewModel()
|
||||
|
||||
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) {
|
||||
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) {
|
||||
f.interactionListener = null
|
||||
}
|
||||
super.onFragmentDetached(fm, f)
|
||||
super.onFragmentPaused(fm, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,14 +87,14 @@ class SpaceExploreActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceD
|
|||
|
||||
sharedViewModel.observeViewEvents {
|
||||
when (it) {
|
||||
SpaceDirectoryViewEvents.Dismiss -> {
|
||||
SpaceDirectoryViewEvents.Dismiss -> {
|
||||
finish()
|
||||
}
|
||||
is SpaceDirectoryViewEvents.NavigateToRoom -> {
|
||||
is SpaceDirectoryViewEvents.NavigateToRoom -> {
|
||||
navigator.openRoom(this, it.roomId)
|
||||
}
|
||||
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 =
|
||||
spaceDirectoryViewModelFactory.create(initialState)
|
||||
|
||||
override fun navigateToRoom(roomId: String) {
|
||||
override fun mxToBottomSheetNavigateToRoom(roomId: String) {
|
||||
navigator.openRoom(this, roomId)
|
||||
}
|
||||
|
||||
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {
|
||||
navigator.switchToSpace(this, spaceId, Navigator.PostSwitchSpaceAction.None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.widget.Toast
|
|||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.airbnb.mvrx.MvRx
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
|
@ -60,8 +61,25 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
|
|||
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?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
|
||||
|
||||
if (isFirstCreation()) {
|
||||
// should be there early for shared element transition
|
||||
|
@ -74,7 +92,7 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
|
|||
UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY)
|
||||
is UserCodeState.Mode.RESULT -> {
|
||||
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) {
|
||||
if (supportFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
|
||||
supportFragmentManager.commitTransaction {
|
||||
|
@ -110,10 +133,12 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
|
|||
}
|
||||
}
|
||||
|
||||
override fun navigateToRoom(roomId: String) {
|
||||
override fun mxToBottomSheetNavigateToRoom(roomId: String) {
|
||||
navigator.openRoom(this, roomId)
|
||||
}
|
||||
|
||||
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {}
|
||||
|
||||
override fun onBackPressed() = withState(sharedViewModel) {
|
||||
when (it.mode) {
|
||||
UserCodeState.Mode.SHOW -> super.onBackPressed()
|
||||
|
|
Loading…
Reference in a new issue