Menu: extract management to a common interface / Migrate Fragments

This commit is contained in:
Benoit Marty 2022-07-04 17:28:18 +02:00
parent be099dcae0
commit 81505d3802
18 changed files with 58 additions and 31 deletions

View File

@ -164,12 +164,13 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
}
private fun setupMenu() {
val menuRes = getMenuRes().takeIf { it != -1 } ?: return
if (this !is VectorMenuProvider) return
if (getMenuRes() == -1) return
val menuHost: MenuHost = requireActivity()
menuHost.addMenuProvider(
object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(menuRes, menu)
menuInflater.inflate(getMenuRes(), menu)
handlePostCreateMenu(menu)
}
@ -296,18 +297,6 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
* MENU MANAGEMENT
* ========================================================================================== */
open fun getMenuRes() = -1
// No op by default
open fun handlePostCreateMenu(menu: Menu) = Unit
// No op by default
open fun handlePrepareMenu(menu: Menu) = Unit
open fun handleMenuItemSelected(item: MenuItem): Boolean {
throw NotImplementedError("You must override this method to handle click on menu item")
}
// This should be provided by the framework
protected fun invalidateOptionsMenu() = requireActivity().invalidateOptionsMenu()

View File

@ -44,6 +44,7 @@ import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.insertBeforeLast
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.time.Clock
import im.vector.app.core.utils.OnSnapPositionChangeListener
@ -67,7 +68,9 @@ class AttachmentsPreviewFragment @Inject constructor(
private val attachmentBigPreviewController: AttachmentBigPreviewController,
private val colorProvider: ColorProvider,
private val clock: Clock,
) : VectorBaseFragment<FragmentAttachmentsPreviewBinding>(), AttachmentMiniaturePreviewController.Callback {
) : VectorBaseFragment<FragmentAttachmentsPreviewBinding>(),
AttachmentMiniaturePreviewController.Callback,
VectorMenuProvider {
private val fragmentArgs: AttachmentsPreviewArgs by args()
private val viewModel: AttachmentsPreviewViewModel by fragmentViewModel()

View File

@ -36,6 +36,7 @@ import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.ui.views.CurrentCallsView
import im.vector.app.core.ui.views.CurrentCallsViewPresenter
@ -71,7 +72,8 @@ class HomeDetailFragment @Inject constructor(
) : VectorBaseFragment<FragmentHomeDetailBinding>(),
KeysBackupBanner.Delegate,
CurrentCallsView.Callback,
OnBackPressed {
OnBackPressed,
VectorMenuProvider {
private val viewModel: HomeDetailViewModel by fragmentViewModel()
private val unknownDeviceDetectorSharedViewModel: UnknownDeviceDetectorSharedViewModel by activityViewModel()

View File

@ -88,6 +88,7 @@ import im.vector.app.core.hardware.vibrate
import im.vector.app.core.intent.getFilenameFromUri
import im.vector.app.core.intent.getMimeTypeFromUri
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.platform.lifecycleAwareLazy
import im.vector.app.core.platform.showOptimizedSnackbar
import im.vector.app.core.resources.ColorProvider
@ -279,7 +280,8 @@ class TimelineFragment @Inject constructor(
AttachmentTypeSelectorView.Callback,
AttachmentsHelper.Callback,
GalleryOrCameraDialogHelper.Listener,
CurrentCallsView.Callback {
CurrentCallsView.Callback,
VectorMenuProvider {
companion object {

View File

@ -30,6 +30,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.databinding.FragmentThreadListBinding
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.home.AvatarRenderer
@ -53,7 +54,8 @@ class ThreadListFragment @Inject constructor(
private val threadListController: ThreadListController,
val threadListViewModelFactory: ThreadListViewModel.Factory
) : VectorBaseFragment<FragmentThreadListBinding>(),
ThreadListController.Listener {
ThreadListController.Listener,
VectorMenuProvider {
private val threadListViewModel: ThreadListViewModel by fragmentViewModel()

View File

@ -26,6 +26,7 @@ import com.airbnb.mvrx.args
import com.mapbox.mapboxsdk.maps.MapView
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.openLocation
import im.vector.app.databinding.FragmentLocationPreviewBinding
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
@ -38,7 +39,8 @@ import javax.inject.Inject
class LocationPreviewFragment @Inject constructor(
private val urlMapProvider: UrlMapProvider,
private val locationPinProvider: LocationPinProvider
) : VectorBaseFragment<FragmentLocationPreviewBinding>() {
) : VectorBaseFragment<FragmentLocationPreviewBinding>(),
VectorMenuProvider {
private val args: LocationSharingArgs by args()

View File

@ -30,6 +30,7 @@ import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.trackItemsVisibilityChange
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.platform.showOptimizedSnackbar
import im.vector.app.core.utils.toast
import im.vector.app.databinding.FragmentPublicRoomsBinding
@ -55,7 +56,8 @@ class PublicRoomsFragment @Inject constructor(
private val permalinkHandler: PermalinkHandler,
private val session: Session
) : VectorBaseFragment<FragmentPublicRoomsBinding>(),
PublicRoomsController.Callback {
PublicRoomsController.Callback,
VectorMenuProvider {
private val viewModel: RoomDirectoryViewModel by activityViewModel()
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel

View File

@ -42,6 +42,7 @@ import im.vector.app.core.extensions.copyOnLongClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.platform.StateView
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.startSharePlainTextIntent
import im.vector.app.databinding.DialogBaseEditTextBinding
import im.vector.app.databinding.DialogShareQrCodeBinding
@ -74,7 +75,8 @@ class RoomMemberProfileFragment @Inject constructor(
private val roomDetailPendingActionStore: RoomDetailPendingActionStore,
private val matrixItemColorProvider: MatrixItemColorProvider
) : VectorBaseFragment<FragmentMatrixProfileBinding>(),
RoomMemberProfileController.Callback {
RoomMemberProfileController.Callback,
VectorMenuProvider {
private lateinit var headerViews: ViewStubRoomMemberProfileHeaderBinding

View File

@ -39,6 +39,7 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.copyOnLongClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.copyToClipboard
import im.vector.app.core.utils.startSharePlainTextIntent
import im.vector.app.databinding.FragmentMatrixProfileBinding
@ -70,7 +71,8 @@ class RoomProfileFragment @Inject constructor(
private val roomDetailPendingActionStore: RoomDetailPendingActionStore,
) :
VectorBaseFragment<FragmentMatrixProfileBinding>(),
RoomProfileController.Callback {
RoomProfileController.Callback,
VectorMenuProvider {
private lateinit var headerViews: ViewStubRoomProfileHeaderBinding

View File

@ -36,6 +36,7 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.intent.getFilenameFromUri
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.time.Clock
import im.vector.app.core.utils.toast
@ -64,7 +65,8 @@ class RoomSettingsFragment @Inject constructor(
VectorBaseFragment<FragmentRoomSettingGenericBinding>(),
RoomSettingsController.Callback,
OnBackPressed,
GalleryOrCameraDialogHelper.Listener {
GalleryOrCameraDialogHelper.Listener,
VectorMenuProvider {
private val viewModel: RoomSettingsViewModel by fragmentViewModel()
private lateinit var roomProfileSharedActionViewModel: RoomProfileSharedActionViewModel

View File

@ -34,6 +34,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.safeOpenOutputStream
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.time.Clock
import im.vector.app.core.utils.selectTxtFileToWrite
import im.vector.app.databinding.FragmentDevtoolKeyrequestsBinding
@ -42,7 +43,8 @@ import javax.inject.Inject
class KeyRequestsFragment @Inject constructor(
private val clock: Clock,
) : VectorBaseFragment<FragmentDevtoolKeyrequestsBinding>() {
) : VectorBaseFragment<FragmentDevtoolKeyrequestsBinding>(),
VectorMenuProvider {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentDevtoolKeyrequestsBinding {
return FragmentDevtoolKeyrequestsBinding.inflate(inflater, container, false)

View File

@ -29,6 +29,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.databinding.FragmentGenericRecyclerBinding
import org.matrix.android.sdk.api.session.pushers.Pusher
import javax.inject.Inject
@ -36,7 +37,8 @@ import javax.inject.Inject
// Referenced in vector_settings_notifications.xml
class PushGatewaysFragment @Inject constructor(
private val epoxyController: PushGateWayController
) : VectorBaseFragment<FragmentGenericRecyclerBinding>() {
) : VectorBaseFragment<FragmentGenericRecyclerBinding>(),
VectorMenuProvider {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentGenericRecyclerBinding {
return FragmentGenericRecyclerBinding.inflate(inflater, container, false)

View File

@ -38,6 +38,7 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.utils.colorizeMatchingText
import im.vector.app.core.utils.isValidUrl
@ -67,7 +68,8 @@ class SpaceDirectoryFragment @Inject constructor(
) : VectorBaseFragment<FragmentSpaceDirectoryBinding>(),
SpaceDirectoryController.InteractionListener,
TimelineEventController.UrlClickCallback,
OnBackPressed {
OnBackPressed,
VectorMenuProvider {
override fun getMenuRes() = R.menu.menu_space_directory

View File

@ -32,6 +32,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.ToggleableAppBarLayoutBehavior
import im.vector.app.databinding.FragmentSpaceLeaveAdvancedBinding
import org.matrix.android.sdk.api.session.room.model.RoomSummary
@ -40,7 +41,8 @@ import javax.inject.Inject
class SpaceLeaveAdvancedFragment @Inject constructor(
val controller: SelectChildrenController
) : VectorBaseFragment<FragmentSpaceLeaveAdvancedBinding>(),
SelectChildrenController.Listener {
SelectChildrenController.Listener,
VectorMenuProvider {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?) =
FragmentSpaceLeaveAdvancedBinding.inflate(layoutInflater, container, false)
@ -49,6 +51,8 @@ class SpaceLeaveAdvancedFragment @Inject constructor(
override fun getMenuRes() = R.menu.menu_space_leave
override fun handleMenuItemSelected(item: MenuItem) = false
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

View File

@ -36,6 +36,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.databinding.FragmentSpaceAddRoomsBinding
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.debounce
@ -51,7 +52,9 @@ class SpaceAddRoomFragment @Inject constructor(
private val roomEpoxyController: AddRoomListController,
private val dmEpoxyController: AddRoomListController,
) : VectorBaseFragment<FragmentSpaceAddRoomsBinding>(),
OnBackPressed, AddRoomListController.Listener {
OnBackPressed,
AddRoomListController.Listener,
VectorMenuProvider {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?) =
FragmentSpaceAddRoomsBinding.inflate(layoutInflater, container, false)

View File

@ -37,6 +37,7 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.intent.getFilenameFromUri
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.time.Clock
import im.vector.app.core.utils.toast
@ -66,7 +67,8 @@ class SpaceSettingsFragment @Inject constructor(
) : VectorBaseFragment<FragmentRoomSettingGenericBinding>(),
SpaceSettingsController.Callback,
GalleryOrCameraDialogHelper.Listener,
OnBackPressed {
OnBackPressed,
VectorMenuProvider {
private val viewModel: RoomSettingsViewModel by fragmentViewModel()
private val sharedViewModel: SpaceManageSharedViewModel by activityViewModel()

View File

@ -36,6 +36,7 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.setupAsSearch
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.core.utils.showIdentityServerConsentDialog
import im.vector.app.core.utils.startSharePlainTextIntent
@ -54,7 +55,8 @@ class UserListFragment @Inject constructor(
private val userListController: UserListController,
private val dimensionConverter: DimensionConverter,
) : VectorBaseFragment<FragmentUserListBinding>(),
UserListController.Callback {
UserListController.Callback,
VectorMenuProvider {
private val args: UserListFragmentArgs by args()
private val viewModel: UserListViewModel by activityViewModel()

View File

@ -42,6 +42,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.openUrlInExternalBrowser
import im.vector.app.databinding.FragmentRoomWidgetBinding
import im.vector.app.features.webview.WebEventListener
@ -68,7 +69,8 @@ class WidgetFragment @Inject constructor(
) :
VectorBaseFragment<FragmentRoomWidgetBinding>(),
WebEventListener,
OnBackPressed {
OnBackPressed,
VectorMenuProvider {
private val fragmentArgs: WidgetArgs by args()
private val viewModel: WidgetViewModel by activityViewModel()