Skip to content

Commit

Permalink
Fix compilation issue and simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Dec 7, 2021
1 parent bf9f514 commit cb35459
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.features.crypto.recover.SetupMode
Expand Down Expand Up @@ -84,7 +84,7 @@ class SharedSecureStorageActivity :
SharedSecureStorageViewState.Step.ResetAll -> SharedSecuredStorageResetAllFragment::class
}

showFragment(fragment, Bundle())
showFragment(fragment)
}

private fun observeViewEvents(it: SharedSecureStorageViewEvent?) {
Expand Down Expand Up @@ -131,15 +131,14 @@ class SharedSecureStorageActivity :
}
}

private fun showFragment(fragmentClass: KClass<out Fragment>, bundle: Bundle) {
private fun showFragment(fragmentClass: KClass<out Fragment>) {
if (supportFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
supportFragmentManager.commitTransaction {
replace(views.container,
fragmentClass.java,
bundle,
fragmentClass.simpleName
)
}
replaceFragment(
views.container,
fragmentClass.java,
null,
fragmentClass.simpleName
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ class RoomDevToolActivity : SimpleFragmentActivity(), FragmentManager.OnBackStac
if (supportFragmentManager.findFragmentByTag(tag) == null) {
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
.replace(views.container, fragment, tag)
.replace(views.container.id, fragment, tag)
.addToBackStack(tag)
.commit()
} else {
if (!supportFragmentManager.popBackStackImmediate(tag, 0)) {
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
.replace(views.container, fragment, tag)
.replace(views.container.id, fragment, tag)
.addToBackStack(tag)
.commit()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class RoomJoinRuleActivity : VectorBaseActivity<ActivitySimpleBinding>() {
supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
val tag = RoomJoinRuleChooseRestrictedFragment::class.simpleName
replace(views.simpleFragmentContainer,
replace(views.simpleFragmentContainer.id,
RoomJoinRuleChooseRestrictedFragment::class.java,
this@RoomJoinRuleActivity.roomProfileArgs.toMvRxBundle(),
tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>
// Replace the existing Fragment with the new Fragment
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.right_in, R.anim.fade_out, R.anim.fade_in, R.anim.right_out)
.replace(views.vectorSettingsPage, oFragment, pref.title.toString())
.replace(views.vectorSettingsPage.id, oFragment, pref.title.toString())
.addToBackStack(null)
.commit()
return true
Expand Down Expand Up @@ -154,7 +154,7 @@ class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>
fun <T : Fragment> navigateTo(fragmentClass: Class<T>, arguments: Bundle? = null) {
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.right_in, R.anim.fade_out, R.anim.fade_in, R.anim.right_out)
.replace(views.vectorSettingsPage, fragmentClass, arguments)
.replace(views.vectorSettingsPage.id, fragmentClass, arguments)
.addToBackStack(null)
.commit()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class SpaceCreationActivity : SimpleFragmentActivity() {
val frag = supportFragmentManager.findFragmentByTag(fragmentClass.name) ?: createFragment(fragmentClass)
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
.replace(views.container,
.replace(views.container.id,
frag,
fragmentClass.name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.viewModel
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleBinding
import im.vector.app.features.matrixto.MatrixToBottomSheet
Expand Down Expand Up @@ -65,17 +65,12 @@ class SpaceExploreActivity : VectorBaseActivity<ActivitySimpleBinding>(), Matrix
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)

if (isFirstCreation()) {
val simpleName = SpaceDirectoryFragment::class.java.simpleName
val args = intent?.getParcelableExtra<SpaceDirectoryArgs>(Mavericks.KEY_ARG)
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
supportFragmentManager.commitTransaction {
replace(views.simpleFragmentContainer,
SpaceDirectoryFragment::class.java,
Bundle().apply { this.putParcelable(Mavericks.KEY_ARG, args) },
simpleName
)
}
}
replaceFragment(
views.simpleFragmentContainer,
SpaceDirectoryFragment::class.java,
args
)
}

sharedViewModel.observeViewEvents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.Mavericks
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleBinding
import im.vector.app.features.spaces.preview.SpacePreviewArgs
Expand All @@ -44,26 +44,21 @@ class SpacePreviewActivity : VectorBaseActivity<ActivitySimpleBinding>() {
.stream()
.onEach { action ->
when (action) {
SpacePreviewSharedAction.DismissAction -> finish()
SpacePreviewSharedAction.ShowModalLoading -> showWaitingView()
SpacePreviewSharedAction.HideModalLoading -> hideWaitingView()
SpacePreviewSharedAction.DismissAction -> finish()
SpacePreviewSharedAction.ShowModalLoading -> showWaitingView()
SpacePreviewSharedAction.HideModalLoading -> hideWaitingView()
is SpacePreviewSharedAction.ShowErrorMessage -> action.error?.let { showSnackbar(it) }
}
}
.launchIn(lifecycleScope)

if (isFirstCreation()) {
val simpleName = SpacePreviewFragment::class.java.simpleName
val args = intent?.getParcelableExtra<SpacePreviewArgs>(Mavericks.KEY_ARG)
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
supportFragmentManager.commitTransaction {
replace(views.simpleFragmentContainer,
SpacePreviewFragment::class.java,
Bundle().apply { this.putParcelable(Mavericks.KEY_ARG, args) },
simpleName
)
}
}
replaceFragment(
views.simpleFragmentContainer,
SpacePreviewFragment::class.java,
args
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.platform.ToolbarConfigurable
import im.vector.app.core.platform.VectorBaseActivity
Expand Down Expand Up @@ -69,17 +69,11 @@ class SpaceLeaveAdvancedActivity : VectorBaseActivity<ActivitySimpleLoadingBindi
val args = intent?.getParcelableExtra<SpaceBottomSheetSettingsArgs>(Mavericks.KEY_ARG)

if (isFirstCreation()) {
val simpleName = SpaceLeaveAdvancedFragment::class.java.simpleName
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
supportFragmentManager.commitTransaction {
replace(
views.simpleFragmentContainer,
SpaceLeaveAdvancedFragment::class.java,
Bundle().apply { this.putParcelable(Mavericks.KEY_ARG, args) },
simpleName
)
}
}
replaceFragment(
views.simpleFragmentContainer,
SpaceLeaveAdvancedFragment::class.java,
args
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import com.google.android.material.appbar.MaterialToolbar
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.addFragmentToBackstack
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.ToolbarConfigurable
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleLoadingBinding
Expand Down Expand Up @@ -100,28 +100,26 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>(),
ManageType.AddRoomsOnlySpaces -> {
val simpleName = SpaceAddRoomFragment::class.java.simpleName
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
supportFragmentManager.commitTransaction {
replace(views.simpleFragmentContainer,
SpaceAddRoomFragment::class.java,
Bundle().apply { this.putParcelable(Mavericks.KEY_ARG, args) },
simpleName
)
}
replaceFragment(
views.simpleFragmentContainer,
SpaceAddRoomFragment::class.java,
args,
simpleName
)
}
}
ManageType.Settings -> {
ManageType.Settings -> {
val simpleName = SpaceSettingsFragment::class.java.simpleName
if (supportFragmentManager.findFragmentByTag(simpleName) == null && args?.spaceId != null) {
supportFragmentManager.commitTransaction {
replace(views.simpleFragmentContainer,
SpaceSettingsFragment::class.java,
Bundle().apply { this.putParcelable(Mavericks.KEY_ARG, RoomProfileArgs(args.spaceId)) },
simpleName
)
}
replaceFragment(
views.simpleFragmentContainer,
SpaceSettingsFragment::class.java,
RoomProfileArgs(args.spaceId),
simpleName
)
}
}
ManageType.ManageRooms -> {
ManageType.ManageRooms -> {
// no direct access for now
}
}
Expand All @@ -146,14 +144,14 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>(),
CreateRoomArgs("", parentSpaceId = args?.spaceId)
)
}
SpaceManagedSharedViewEvents.NavigateToCreateSpace -> {
SpaceManagedSharedViewEvents.NavigateToCreateSpace -> {
addFragmentToBackstack(
views.simpleFragmentContainer,
CreateRoomFragment::class.java,
CreateRoomArgs("", parentSpaceId = args?.spaceId, isSpace = true)
)
}
SpaceManagedSharedViewEvents.NavigateToManageRooms -> {
SpaceManagedSharedViewEvents.NavigateToManageRooms -> {
args?.spaceId?.let { spaceId ->
addFragmentToBackstack(
views.simpleFragmentContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.Mavericks
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.GenericIdArgs
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleLoadingBinding
Expand Down Expand Up @@ -63,16 +63,11 @@ class SpacePeopleActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>() {
super.onCreate(savedInstanceState)
val args = intent?.getParcelableExtra<GenericIdArgs>(Mavericks.KEY_ARG)
if (isFirstCreation()) {
val simpleName = SpacePeopleFragment::class.java.simpleName
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
supportFragmentManager.commitTransaction {
replace(views.simpleFragmentContainer,
SpacePeopleFragment::class.java,
Bundle().apply { this.putParcelable(Mavericks.KEY_ARG, args) },
simpleName
)
}
}
replaceFragment(
views.simpleFragmentContainer,
SpacePeopleFragment::class.java,
args
)
}

sharedActionViewModel = viewModelProvider.get(SpacePeopleSharedActionViewModel::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
if (supportFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
replace(views.simpleFragmentContainer,
replace(views.simpleFragmentContainer.id,
fragmentClass.java,
bundle,
fragmentClass.simpleName
Expand Down

0 comments on commit cb35459

Please sign in to comment.