mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-26 09:33:14 +01:00
Menu: extract management to a common interface / Migrate Fragments
This commit is contained in:
parent
be099dcae0
commit
81505d3802
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user