From b6199b1f27003a5ce66b09ae2d03995d8b8efb7c Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 8 Nov 2019 19:49:08 +0100 Subject: [PATCH] Fix some issues with fragments managers (Home fragments) and lifecycle --- .../vector/riotx/core/extensions/Fragment.kt | 10 ++++---- .../riotx/core/platform/VectorBaseFragment.kt | 5 ++-- .../im/vector/riotx/core/utils/DataSource.kt | 12 +++++----- .../riotx/features/home/HomeDetailFragment.kt | 24 +++++++++++-------- .../riotx/features/home/HomeDrawerFragment.kt | 6 +++-- .../CreateDirectRoomDirectoryUsersFragment.kt | 7 +++--- .../CreateDirectRoomKnownUsersFragment.kt | 7 +++--- .../features/home/group/GroupListFragment.kt | 5 ++-- .../home/room/detail/RoomDetailFragment.kt | 9 ++++--- .../home/room/list/RoomListFragment.kt | 15 +++++++----- .../riotx/features/login/LoginFragment.kt | 4 ++-- .../reactions/EmojiChooserFragment.kt | 6 +++-- .../reactions/EmojiSearchResultFragment.kt | 6 ++--- .../roomdirectory/PublicRoomsFragment.kt | 2 +- .../createroom/CreateRoomFragment.kt | 5 ++-- .../picker/RoomDirectoryPickerFragment.kt | 8 +++---- .../RoomPreviewNoPreviewFragment.kt | 7 +----- 17 files changed, 75 insertions(+), 63 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/core/extensions/Fragment.kt b/vector/src/main/java/im/vector/riotx/core/extensions/Fragment.kt index e6e83bfd67..f96b773990 100644 --- a/vector/src/main/java/im/vector/riotx/core/extensions/Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/core/extensions/Fragment.kt @@ -41,7 +41,7 @@ fun VectorBaseFragment.replaceFragment(frameId: Int, fragmentClas } fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { - parentFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) } + parentFragmentManager.inTransaction { replace(frameId, fragment, tag).addToBackStack(tag) } } fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { @@ -50,8 +50,8 @@ fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragm } } -fun VectorBaseFragment.addChildFragment(frameId: Int, fragment: Fragment) { - childFragmentManager.inTransaction { add(frameId, fragment) } +fun VectorBaseFragment.addChildFragment(frameId: Int, fragment: Fragment, tag: String? = null) { + childFragmentManager.inTransaction { add(frameId, fragment, tag) } } fun VectorBaseFragment.addChildFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { @@ -60,8 +60,8 @@ fun VectorBaseFragment.addChildFragment(frameId: Int, fragmentCla } } -fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragment: Fragment) { - childFragmentManager.inTransaction { replace(frameId, fragment) } +fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragment: Fragment, tag: String? = null) { + childFragmentManager.inTransaction { replace(frameId, fragment, tag) } } fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { diff --git a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseFragment.kt b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseFragment.kt index 255e18608a..9f94c15edd 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseFragment.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseFragment.kt @@ -114,11 +114,12 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), HasScreenInjector { super.onDestroyView() mUnBinder?.unbind() mUnBinder = null + uiDisposables.clear() } override fun onDestroy() { - super.onDestroy() uiDisposables.dispose() + super.onDestroy() } override fun injector(): ScreenComponent { @@ -181,7 +182,7 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), HasScreenInjector { private val uiDisposables = CompositeDisposable() - protected fun Disposable.disposeOnDestroy(): Disposable { + protected fun Disposable.disposeOnDestroyView(): Disposable { uiDisposables.add(this) return this } diff --git a/vector/src/main/java/im/vector/riotx/core/utils/DataSource.kt b/vector/src/main/java/im/vector/riotx/core/utils/DataSource.kt index 6c317eb977..726d2ea697 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/DataSource.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/DataSource.kt @@ -34,14 +34,14 @@ interface MutableDataSource : DataSource { */ open class BehaviorDataSource(private val defaultValue: T? = null) : MutableDataSource { - private val storeRelay = createRelay() + private val behaviorRelay = createRelay() override fun observe(): Observable { - return storeRelay.hide().observeOn(Schedulers.computation()) + return behaviorRelay.hide().observeOn(Schedulers.computation()) } override fun post(value: T) { - storeRelay.accept(value) + behaviorRelay.accept(value) } private fun createRelay(): BehaviorRelay { @@ -58,13 +58,13 @@ open class BehaviorDataSource(private val defaultValue: T? = null) : MutableD */ open class PublishDataSource : MutableDataSource { - private val storeRelay = PublishRelay.create() + private val publishRelay = PublishRelay.create() override fun observe(): Observable { - return storeRelay.hide() + return publishRelay.hide() } override fun post(value: T) { - storeRelay.accept(value) + publishRelay.accept(value) } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt index 5b56a19648..7aa96d0b8d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt @@ -18,6 +18,7 @@ package im.vector.riotx.features.home import android.os.Bundle import android.view.LayoutInflater +import android.view.View import androidx.core.view.forEachIndexed import androidx.lifecycle.Observer import com.airbnb.mvrx.fragmentViewModel @@ -28,7 +29,8 @@ import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.riotx.R -import im.vector.riotx.core.extensions.addChildFragmentToBackstack +import im.vector.riotx.core.extensions.inTransaction +import im.vector.riotx.core.extensions.replaceChildFragment import im.vector.riotx.core.platform.ToolbarConfigurable import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.ui.views.KeysBackupBanner @@ -59,9 +61,8 @@ class HomeDetailFragment @Inject constructor( return R.layout.fragment_home_detail } - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) setupBottomNavigationView() @@ -165,12 +166,15 @@ class HomeDetailFragment @Inject constructor( private fun updateSelectedFragment(displayMode: RoomListFragment.DisplayMode) { val fragmentTag = "FRAGMENT_TAG_${displayMode.name}" - val fragment = childFragmentManager.findFragmentByTag(fragmentTag) - if (fragment == null) { - val params = RoomListParams(displayMode) - addChildFragmentToBackstack(R.id.roomListContainer, RoomListFragment::class.java, params, fragmentTag) - } else { - addChildFragmentToBackstack(R.id.roomListContainer, fragment, fragmentTag) + val fragmentToShow = childFragmentManager.findFragmentByTag(fragmentTag) + childFragmentManager.inTransaction { + childFragmentManager.fragments.forEach { hide(it) } + if (fragmentToShow == null) { + val params = RoomListParams(displayMode) + add(R.id.roomListContainer, RoomListFragment::class.java, params.toMvRxBundle(), fragmentTag) + } else { + show(fragmentToShow) + } } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt index 5b052f5ff5..f48c5650f5 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt @@ -17,6 +17,7 @@ package im.vector.riotx.features.home import android.os.Bundle +import android.view.View import im.vector.matrix.android.api.session.Session import im.vector.riotx.R import im.vector.riotx.core.extensions.observeK @@ -33,8 +34,8 @@ class HomeDrawerFragment @Inject constructor( override fun getLayoutResId() = R.layout.fragment_home_drawer - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) if (savedInstanceState == null) { replaceChildFragment(R.id.homeDrawerGroupListContainer, GroupListFragment::class.java) } @@ -55,4 +56,5 @@ class HomeDrawerFragment @Inject constructor( navigator.openDebug(requireActivity()) } } + } diff --git a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomDirectoryUsersFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomDirectoryUsersFragment.kt index fe43b89a52..cf6abf12e9 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomDirectoryUsersFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomDirectoryUsersFragment.kt @@ -18,6 +18,7 @@ package im.vector.riotx.features.home.createdirect import android.content.Context import android.os.Bundle +import android.view.View import android.view.inputmethod.InputMethodManager import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState @@ -40,8 +41,8 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor( private lateinit var sharedActionViewModel: CreateDirectRoomSharedActionViewModel - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) sharedActionViewModel = activityViewModelProvider.get(CreateDirectRoomSharedActionViewModel::class.java) setupRecyclerView() setupSearchByMatrixIdView() @@ -61,7 +62,7 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor( .subscribe { viewModel.handle(CreateDirectRoomAction.SearchDirectoryUsers(it.toString())) } - .disposeOnDestroy() + .disposeOnDestroyView() createDirectRoomSearchById.requestFocus() val imm = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager imm?.showSoftInput(createDirectRoomSearchById, InputMethodManager.SHOW_IMPLICIT) diff --git a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomKnownUsersFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomKnownUsersFragment.kt index 26265c8d56..12019fa39e 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomKnownUsersFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomKnownUsersFragment.kt @@ -21,6 +21,7 @@ package im.vector.riotx.features.home.createdirect import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.View import android.widget.ScrollView import androidx.core.view.size import com.airbnb.mvrx.activityViewModel @@ -50,8 +51,8 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor( private val viewModel: CreateDirectRoomViewModel by activityViewModel() private lateinit var sharedActionViewModel: CreateDirectRoomSharedActionViewModel - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) sharedActionViewModel = activityViewModelProvider.get(CreateDirectRoomSharedActionViewModel::class.java) vectorBaseActivity.setSupportActionBar(createDirectRoomToolbar) setupRecyclerView() @@ -113,7 +114,7 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor( } viewModel.handle(action) } - .disposeOnDestroy() + .disposeOnDestroyView() createDirectRoomFilter.setupAsSearch() createDirectRoomFilter.requestFocus() diff --git a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt index bc39491773..39f8c17f05 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListFragment.kt @@ -17,6 +17,7 @@ package im.vector.riotx.features.home.group import android.os.Bundle +import android.view.View import com.airbnb.mvrx.Incomplete import com.airbnb.mvrx.Success import com.airbnb.mvrx.fragmentViewModel @@ -40,8 +41,8 @@ class GroupListFragment @Inject constructor( override fun getLayoutResId() = R.layout.fragment_group_list - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) groupController.callback = this stateView.contentView = groupListEpoxyRecyclerView diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index c5cd46482e..062a4be2d2 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -203,8 +203,8 @@ class RoomDetailFragment @Inject constructor( private var lockSendButton = false - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) sharedActionViewModel = activityViewModelProvider.get(MessageSharedActionViewModel::class.java) attachmentsHelper = AttachmentsHelper.create(this, this).register() keyboardStateUtils = KeyboardStateUtils(requireActivity()) @@ -228,7 +228,7 @@ class RoomDetailFragment @Inject constructor( .subscribe { handleActions(it) } - .disposeOnDestroy() + .disposeOnDestroyView() roomDetailViewModel.navigateToEvent.observeEvent(this) { val scrollPosition = timelineEventController.searchPositionOfEvent(it) @@ -273,7 +273,10 @@ class RoomDetailFragment @Inject constructor( roomDetailViewModel.requestLiveData.observeEvent(this) { displayRoomDetailActionResult(it) } + } + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) if (savedInstanceState == null) { when (val sharedData = roomDetailArgs.sharedData) { is SharedData.Text -> roomDetailViewModel.handle(RoomDetailAction.SendMessage(sharedData.text, false)) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt index 9c78b8688a..92080c1b1f 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt @@ -20,6 +20,7 @@ import android.os.Bundle import android.os.Parcelable import android.view.Menu import android.view.MenuItem +import android.view.View import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat @@ -45,8 +46,10 @@ import im.vector.riotx.features.home.room.list.widget.FabMenuView import im.vector.riotx.features.notifications.NotificationDrawerManager import im.vector.riotx.features.share.SharedData import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.functions.Consumer import kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_room_list.* +import timber.log.Timber import javax.inject.Inject @Parcelize @@ -97,13 +100,13 @@ class RoomListFragment @Inject constructor( super.onPrepareOptionsMenu(menu) } - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) setupCreateRoomButton() setupRecyclerView() - roomListViewModel.subscribe { renderState(it) } + sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java) + roomListViewModel.subscribe { renderState(it) } roomListViewModel.viewEvents .observe() .observeOn(AndroidSchedulers.mainThread()) @@ -113,14 +116,14 @@ class RoomListFragment @Inject constructor( is RoomListViewEvents.Failure -> showError(it) } } - .disposeOnDestroy() + .disposeOnDestroyView() createChatFabMenu.listener = this sharedActionViewModel .observe() .subscribe { handleQuickActions(it) } - .disposeOnDestroy() + .disposeOnDestroyView() } private fun openSelectedRoom(event: RoomListViewEvents.SelectRoom) { diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt index f8295310f9..456e4b2bb3 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt @@ -62,7 +62,7 @@ class LoginFragment @Inject constructor() : VectorBaseFragment() { viewModel.handle(LoginAction.UpdateHomeServer(homeServerField.text.toString())) } } - .disposeOnDestroy() + .disposeOnDestroyView() homeServerField.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_DONE) { @@ -107,7 +107,7 @@ class LoginFragment @Inject constructor() : VectorBaseFragment() { } ) .subscribeBy { authenticateButton.isEnabled = it } - .disposeOnDestroy() + .disposeOnDestroyView() authenticateButton.setOnClickListener { authenticate() } authenticateButtonSso.setOnClickListener { openSso() } diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserFragment.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserFragment.kt index a32fa27bd5..c66e322bae 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserFragment.kt @@ -16,6 +16,7 @@ package im.vector.riotx.features.reactions import android.os.Bundle +import android.view.View import androidx.recyclerview.widget.RecyclerView import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseFragment @@ -27,8 +28,8 @@ class EmojiChooserFragment @Inject constructor() : VectorBaseFragment() { private lateinit var viewModel: EmojiChooserViewModel - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) viewModel = activityViewModelProvider.get(EmojiChooserViewModel::class.java) viewModel.initWithContext(context!!) (view as? RecyclerView)?.let { @@ -36,4 +37,5 @@ class EmojiChooserFragment @Inject constructor() : VectorBaseFragment() { it.adapter?.notifyDataSetChanged() } } + } diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt index ca4f18fe83..029f468b70 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt @@ -16,6 +16,7 @@ package im.vector.riotx.features.reactions import android.os.Bundle +import android.view.View import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -37,9 +38,8 @@ class EmojiSearchResultFragment @Inject constructor( var sharedViewModel: EmojiChooserViewModel? = null - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) sharedViewModel = activityViewModelProvider.get(EmojiChooserViewModel::class.java) epoxyController.listener = object : ReactionClickListener { diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt index 21eedb4b24..b41c563256 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt @@ -67,7 +67,7 @@ class PublicRoomsFragment @Inject constructor( .subscribeBy { viewModel.handle(RoomDirectoryAction.FilterWith(it.toString())) } - .disposeOnDestroy() + .disposeOnDestroyView() publicRoomsCreateNewRoom.setOnClickListener { sharedActionViewModel.post(RoomDirectorySharedAction.CreateRoom) diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomFragment.kt index 0399ea0b57..0dec14f50e 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomFragment.kt @@ -18,6 +18,7 @@ package im.vector.riotx.features.roomdirectory.createroom import android.os.Bundle import android.view.MenuItem +import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import com.airbnb.mvrx.Success import com.airbnb.mvrx.activityViewModel @@ -39,8 +40,8 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C override fun getMenuRes() = R.menu.vector_room_creation - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) vectorBaseActivity.setSupportActionBar(createRoomToolbar) sharedActionViewModel = activityViewModelProvider.get(RoomDirectorySharedActionViewModel::class.java) setupRecyclerView() diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt index bad8486405..87cb8193bf 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt @@ -55,6 +55,9 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie it.setDisplayShowHomeEnabled(true) it.setDisplayHomeAsUpEnabled(true) } + + sharedActionViewModel = activityViewModelProvider.get(RoomDirectorySharedActionViewModel::class.java) + setupRecyclerView() } override fun getMenuRes() = R.menu.menu_directory_server_picker @@ -69,11 +72,6 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie return super.onOptionsItemSelected(item) } - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - sharedActionViewModel = activityViewModelProvider.get(RoomDirectorySharedActionViewModel::class.java) - setupRecyclerView() - } private fun setupRecyclerView() { val layoutManager = LinearLayoutManager(context) diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt index 38e74c035a..9003421dc7 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt @@ -45,16 +45,11 @@ class RoomPreviewNoPreviewFragment @Inject constructor( private val roomPreviewViewModel: RoomPreviewViewModel by fragmentViewModel() private val roomPreviewData: RoomPreviewData by args() - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - setupToolbar(roomPreviewNoPreviewToolbar) - } - override fun getLayoutResId() = R.layout.fragment_room_preview_no_preview override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - + setupToolbar(roomPreviewNoPreviewToolbar) // Toolbar avatarRenderer.render(roomPreviewData.avatarUrl, roomPreviewData.roomId, roomPreviewData.roomName, roomPreviewNoPreviewToolbarAvatar) roomPreviewNoPreviewToolbarTitle.text = roomPreviewData.roomName