Skip to content

Commit

Permalink
Merge pull request #6894 from vector-im/feature/bma/remove_fragment_m…
Browse files Browse the repository at this point in the history
…odule

Remove fragment module
  • Loading branch information
bmarty authored Aug 24, 2022
2 parents d85a164 + 4c2f853 commit 2b5920e
Show file tree
Hide file tree
Showing 180 changed files with 1,093 additions and 1,659 deletions.
1 change: 1 addition & 0 deletions changelog.d/6894.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove FragmentModule and the Fragment factory. No need to Inject the constructor on your Fragment, just add @AndroidEntryPoint annotation and @Inject class members.
2 changes: 1 addition & 1 deletion docs/hilt_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Hilt is built on top of Dagger 2 and simplify usage by removing needs to create
When you create a new feature, you should have the following:

Annotate your Activity with @AndroidEntryPoint
Annotate your Fragment with @AndroidEntryPoint
If you have a BottomSheetFragment => Annotate it with @AndroidEntryPoint
Otherwise => Add your Fragment to the FragmentModule
Add your ViewModel.Factory to the MavericksViewModelModule
Makes sure your ViewModel as the following code:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import javax.inject.Inject
data class ${fragmentArgsClass}() : Parcelable
</#if>

//TODO add this fragment into FragmentModule
class ${fragmentClass} @Inject constructor(
private val viewModelFactory: ${viewModelClass}.Factory
) : VectorBaseFragment(), ${viewModelClass}.Factory by viewModelFactory {
@AndroidEntryPoint
class ${fragmentClass}() :
VectorBaseFragment(),
${viewModelClass}.Factory by viewModelFactory {

<#if createFragmentArgs>
private val fragmentArgs: ${fragmentArgsClass} by args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentDebugMemoryLeaksBinding

@AndroidEntryPoint
class DebugMemoryLeaksFragment : VectorBaseFragment<FragmentDebugMemoryLeaksBinding>() {
class DebugMemoryLeaksFragment :
VectorBaseFragment<FragmentDebugMemoryLeaksBinding>() {

private val viewModel: DebugMemoryLeaksViewModel by fragmentViewModel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package im.vector.app.core.di

import androidx.fragment.app.FragmentFactory
import androidx.lifecycle.ViewModelProvider
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
Expand All @@ -25,6 +24,5 @@ import dagger.hilt.android.components.ActivityComponent
@InstallIn(ActivityComponent::class)
@EntryPoint
interface ActivityEntryPoint {
fun fragmentFactory(): FragmentFactory
fun viewModelFactory(): ViewModelProvider.Factory
}
27 changes: 0 additions & 27 deletions vector/src/main/java/im/vector/app/core/di/FragmentKey.kt

This file was deleted.

954 changes: 0 additions & 954 deletions vector/src/main/java/im/vector/app/core/di/FragmentModule.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.vector.app.core.dialogs

import androidx.fragment.app.Fragment
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.time.Clock
import javax.inject.Inject

/**
* Factory for [GalleryOrCameraDialogHelper].
*/
class GalleryOrCameraDialogHelperFactory @Inject constructor(
private val colorProvider: ColorProvider,
private val clock: Clock,
) {
fun create(fragment: Fragment): GalleryOrCameraDialogHelper {
return GalleryOrCameraDialogHelper(fragment, colorProvider, clock)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
Expand All @@ -39,8 +38,6 @@ import androidx.core.content.ContextCompat
import androidx.core.util.Consumer
import androidx.core.view.MenuProvider
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
Expand All @@ -67,7 +64,6 @@ import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.restart
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.extensions.singletonEntryPoint
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.resources.BuildMeta
import im.vector.app.core.utils.AndroidSystemSettingsProvider
import im.vector.app.core.utils.ToolbarConfig
Expand Down Expand Up @@ -169,7 +165,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver

lateinit var navigator: Navigator
private set
private lateinit var fragmentFactory: FragmentFactory

private lateinit var activeSessionHolder: ActiveSessionHolder
private lateinit var vectorPreferences: VectorPreferences
Expand Down Expand Up @@ -210,8 +205,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
val singletonEntryPoint = singletonEntryPoint()
val activityEntryPoint = EntryPointAccessors.fromActivity(this, ActivityEntryPoint::class.java)
ThemeUtils.setActivityTheme(this, getOtherThemes())
fragmentFactory = activityEntryPoint.fragmentFactory()
supportFragmentManager.fragmentFactory = fragmentFactory
viewModelFactory = activityEntryPoint.viewModelFactory()
super.onCreate(savedInstanceState)
addOnMultiWindowModeChangedListener(onMultiWindowModeChangedListener)
Expand Down Expand Up @@ -464,12 +457,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
bugReporter.inMultiWindowMode = it.isInMultiWindowMode
}

protected fun createFragment(fragmentClass: Class<out Fragment>, argsParcelable: Parcelable? = null): Fragment {
return fragmentFactory.instantiate(classLoader, fragmentClass.name).apply {
arguments = argsParcelable?.toMvRxBundle()
}
}

/* ==========================================================================================
* PRIVATE METHODS
* ========================================================================================== */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
analyticsTracker = singletonEntryPoint.analyticsTracker()
unrecognizedCertificateDialog = singletonEntryPoint.unrecognizedCertificateDialog()
viewModelFactory = activityEntryPoint.viewModelFactory()
childFragmentManager.fragmentFactory = activityEntryPoint.fragmentFactory()
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.activityViewModel
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.setTextWithColoredPart
import im.vector.app.core.platform.OnBackPressed
Expand All @@ -30,9 +31,12 @@ import im.vector.app.databinding.FragmentAnalyticsOptinBinding
import im.vector.app.features.analytics.AnalyticsConfig
import javax.inject.Inject

class AnalyticsOptInFragment @Inject constructor(
private val analyticsConfig: AnalyticsConfig,
) : VectorBaseFragment<FragmentAnalyticsOptinBinding>(), OnBackPressed {
@AndroidEntryPoint
class AnalyticsOptInFragment :
VectorBaseFragment<FragmentAnalyticsOptinBinding>(),
OnBackPressed {

@Inject lateinit var analyticsConfig: AnalyticsConfig

// Share the view model with the Activity so that the Activity
// can decide what to do when the data has been saved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.yalantis.ucrop.UCrop
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.insertBeforeLast
Expand All @@ -63,15 +64,17 @@ data class AttachmentsPreviewArgs(
val attachments: List<ContentAttachmentData>
) : Parcelable

class AttachmentsPreviewFragment @Inject constructor(
private val attachmentMiniaturePreviewController: AttachmentMiniaturePreviewController,
private val attachmentBigPreviewController: AttachmentBigPreviewController,
private val colorProvider: ColorProvider,
private val clock: Clock,
) : VectorBaseFragment<FragmentAttachmentsPreviewBinding>(),
@AndroidEntryPoint
class AttachmentsPreviewFragment :
VectorBaseFragment<FragmentAttachmentsPreviewBinding>(),
AttachmentMiniaturePreviewController.Callback,
VectorMenuProvider {

@Inject lateinit var attachmentMiniaturePreviewController: AttachmentMiniaturePreviewController
@Inject lateinit var attachmentBigPreviewController: AttachmentBigPreviewController
@Inject lateinit var colorProvider: ColorProvider
@Inject lateinit var clock: Clock

private val fragmentArgs: AttachmentsPreviewArgs by args()
private val viewModel: AttachmentsPreviewViewModel by fragmentViewModel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.hideKeyboard
Expand All @@ -44,9 +45,12 @@ import reactivecircus.flowbinding.android.widget.checkedChanges
import reactivecircus.flowbinding.android.widget.textChanges
import javax.inject.Inject

class ContactsBookFragment @Inject constructor(
private val contactsBookController: ContactsBookController
) : VectorBaseFragment<FragmentContactsBookBinding>(), ContactsBookController.Callback {
@AndroidEntryPoint
class ContactsBookFragment :
VectorBaseFragment<FragmentContactsBookBinding>(),
ContactsBookController.Callback {

@Inject lateinit var contactsBookController: ContactsBookController

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentContactsBookBinding {
return FragmentContactsBookBinding.inflate(inflater, container, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.widget.doOnTextChanged
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.startImportTextFromFileIntent
import im.vector.app.databinding.FragmentKeysBackupRestoreFromKeyBinding
import org.matrix.android.sdk.api.extensions.tryOrNull
import javax.inject.Inject

class KeysBackupRestoreFromKeyFragment @Inject constructor() :
@AndroidEntryPoint
class KeysBackupRestoreFromKeyFragment :
VectorBaseFragment<FragmentKeysBackupRestoreFromKeyBinding>() {

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentKeysBackupRestoreFromKeyBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.text.set
import androidx.core.widget.doOnTextChanged
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentKeysBackupRestoreFromPassphraseBinding
import javax.inject.Inject

class KeysBackupRestoreFromPassphraseFragment @Inject constructor() : VectorBaseFragment<FragmentKeysBackupRestoreFromPassphraseBinding>() {
@AndroidEntryPoint
class KeysBackupRestoreFromPassphraseFragment :
VectorBaseFragment<FragmentKeysBackupRestoreFromPassphraseBinding>() {

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentKeysBackupRestoreFromPassphraseBinding {
return FragmentKeysBackupRestoreFromPassphraseBinding.inflate(inflater, container, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.LiveEvent
import im.vector.app.databinding.FragmentKeysBackupRestoreSuccessBinding
import javax.inject.Inject

class KeysBackupRestoreSuccessFragment @Inject constructor() : VectorBaseFragment<FragmentKeysBackupRestoreSuccessBinding>() {
@AndroidEntryPoint
class KeysBackupRestoreSuccessFragment :
VectorBaseFragment<FragmentKeysBackupRestoreSuccessBinding>() {

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentKeysBackupRestoreSuccessBinding {
return FragmentKeysBackupRestoreSuccessBinding.inflate(inflater, container, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.view.ViewGroup
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
Expand All @@ -30,10 +31,13 @@ import im.vector.app.databinding.FragmentKeysBackupSettingsBinding
import im.vector.app.features.crypto.keysbackup.restore.KeysBackupRestoreActivity
import javax.inject.Inject

class KeysBackupSettingsFragment @Inject constructor(private val keysBackupSettingsRecyclerViewController: KeysBackupSettingsRecyclerViewController) :
@AndroidEntryPoint
class KeysBackupSettingsFragment :
VectorBaseFragment<FragmentKeysBackupSettingsBinding>(),
KeysBackupSettingsRecyclerViewController.Listener {

@Inject lateinit var keysBackupSettingsRecyclerViewController: KeysBackupSettingsRecyclerViewController

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentKeysBackupSettingsBinding {
return FragmentKeysBackupSettingsBinding.inflate(inflater, container, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.LiveEvent
import im.vector.app.databinding.FragmentKeysBackupSetupStep1Binding
import javax.inject.Inject

class KeysBackupSetupStep1Fragment @Inject constructor() : VectorBaseFragment<FragmentKeysBackupSetupStep1Binding>() {
@AndroidEntryPoint
class KeysBackupSetupStep1Fragment :
VectorBaseFragment<FragmentKeysBackupSetupStep1Binding>() {

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentKeysBackupSetupStep1Binding {
return FragmentKeysBackupSetupStep1Binding.inflate(inflater, container, false)
Expand Down
Loading

0 comments on commit 2b5920e

Please sign in to comment.