From 8871280fabb79a90b591e8784693d5cc5002b4f3 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 5 Nov 2019 18:12:04 +0100 Subject: [PATCH] Fragments: use constructor injections in most of the Fragments --- .../im/vector/riotx/core/di/FragmentKey.kt | 1 - .../im/vector/riotx/core/di/FragmentModule.kt | 166 ++++++++++++++++-- .../vector/riotx/core/di/ScreenComponent.kt | 82 +-------- .../riotx/core/di/VectorFragmentFactory.kt | 2 - .../vector/riotx/core/extensions/Activity.kt | 29 ++- .../vector/riotx/core/extensions/Fragment.kt | 50 +++++- .../riotx/core/platform/VectorBaseActivity.kt | 7 +- .../riotx/core/platform/VectorBaseFragment.kt | 3 +- .../core/platform/VectorPreferenceFragment.kt | 54 ------ .../riotx/features/command/CommandParser.kt | 1 - .../restore/KeysBackupRestoreActivity.kt | 20 +-- .../KeysBackupRestoreFromKeyFragment.kt | 12 +- ...KeysBackupRestoreFromPassphraseFragment.kt | 20 +-- .../KeysBackupRestoreSuccessFragment.kt | 8 +- .../settings/KeysBackupManageActivity.kt | 6 +- .../settings/KeysBackupSettingsFragment.kt | 15 +- .../setup/KeysBackupSetupActivity.kt | 13 +- .../setup/KeysBackupSetupStep1Fragment.kt | 8 +- .../setup/KeysBackupSetupStep2Fragment.kt | 22 +-- .../setup/KeysBackupSetupStep3Fragment.kt | 14 +- .../verification/SASVerificationActivity.kt | 65 +++---- .../SASVerificationIncomingFragment.kt | 16 +- .../SASVerificationShortCodeFragment.kt | 9 +- .../SASVerificationStartFragment.kt | 9 +- .../SASVerificationVerifiedFragment.kt | 7 +- .../riotx/features/home/HomeActivity.kt | 9 +- .../riotx/features/home/HomeDetailFragment.kt | 36 ++-- .../riotx/features/home/HomeDrawerFragment.kt | 23 +-- .../riotx/features/home/LoadingFragment.kt | 10 +- .../createdirect/CreateDirectRoomActivity.kt | 4 +- .../CreateDirectRoomDirectoryUsersFragment.kt | 10 +- .../CreateDirectRoomKnownUsersFragment.kt | 15 +- .../features/home/group/GroupListFragment.kt | 19 +- .../home/room/detail/RoomDetailActivity.kt | 3 +- .../home/room/detail/RoomDetailFragment.kt | 44 ++--- .../room/filtered/FilteredRoomsActivity.kt | 13 +- .../home/room/list/RoomListFragment.kt | 6 - .../riotx/features/login/LoginActivity.kt | 4 +- .../riotx/features/login/LoginFragment.kt | 10 +- .../login/LoginSsoFallbackFragment.kt | 8 +- .../reactions/EmojiSearchResultFragment.kt | 11 +- .../roomdirectory/PublicRoomsFragment.kt | 13 +- .../roomdirectory/RoomDirectoryActivity.kt | 6 +- .../createroom/CreateRoomActivity.kt | 8 +- .../createroom/CreateRoomFragment.kt | 8 +- .../picker/RoomDirectoryPickerFragment.kt | 12 +- .../roompreview/RoomPreviewActivity.kt | 4 +- .../RoomPreviewNoPreviewFragment.kt | 21 +-- .../settings/VectorSettingsActivity.kt | 4 +- ...sAdvancedNotificationPreferenceFragment.kt | 13 +- .../VectorSettingsHelpAboutFragment.kt | 11 +- ...rSettingsNotificationPreferenceFragment.kt | 15 +- ...ttingsNotificationsTroubleshootFragment.kt | 23 +-- .../VectorSettingsPreferencesFragment.kt | 13 +- .../VectorSettingsSecurityPrivacyFragment.kt | 11 +- .../settings/push/PushGatewaysFragment.kt | 10 +- .../features/share/IncomingShareActivity.kt | 14 +- 57 files changed, 432 insertions(+), 618 deletions(-) delete mode 100644 vector/src/main/java/im/vector/riotx/core/platform/VectorPreferenceFragment.kt diff --git a/vector/src/main/java/im/vector/riotx/core/di/FragmentKey.kt b/vector/src/main/java/im/vector/riotx/core/di/FragmentKey.kt index c20768ba10..57b5c902e5 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/FragmentKey.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/FragmentKey.kt @@ -18,7 +18,6 @@ package im.vector.riotx.core.di import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModel import dagger.MapKey import kotlin.reflect.KClass diff --git a/vector/src/main/java/im/vector/riotx/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/riotx/core/di/FragmentModule.kt index b3bb344d5c..df6d2abf88 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/FragmentModule.kt @@ -17,24 +17,33 @@ package im.vector.riotx.core.di +import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentFactory -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap -import im.vector.riotx.core.platform.ConfigurationViewModel -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreFromKeyViewModel -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreFromPassphraseViewModel -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreSharedViewModel -import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupSharedViewModel -import im.vector.riotx.features.crypto.verification.SasVerificationViewModel -import im.vector.riotx.features.home.HomeNavigationViewModel -import im.vector.riotx.features.home.createdirect.CreateDirectRoomNavigationViewModel +import im.vector.riotx.features.crypto.keysbackup.settings.KeysBackupSettingsFragment +import im.vector.riotx.features.crypto.verification.SASVerificationIncomingFragment +import im.vector.riotx.features.crypto.verification.SASVerificationShortCodeFragment +import im.vector.riotx.features.crypto.verification.SASVerificationStartFragment +import im.vector.riotx.features.crypto.verification.SASVerificationVerifiedFragment +import im.vector.riotx.features.home.HomeDetailFragment +import im.vector.riotx.features.home.HomeDrawerFragment +import im.vector.riotx.features.home.LoadingFragment +import im.vector.riotx.features.home.createdirect.CreateDirectRoomDirectoryUsersFragment +import im.vector.riotx.features.home.createdirect.CreateDirectRoomKnownUsersFragment +import im.vector.riotx.features.home.group.GroupListFragment +import im.vector.riotx.features.home.room.detail.RoomDetailFragment import im.vector.riotx.features.home.room.list.RoomListFragment -import im.vector.riotx.features.reactions.EmojiChooserViewModel -import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel -import im.vector.riotx.features.workers.signout.SignOutViewModel +import im.vector.riotx.features.login.LoginFragment +import im.vector.riotx.features.login.LoginSsoFallbackFragment +import im.vector.riotx.features.reactions.EmojiSearchResultFragment +import im.vector.riotx.features.roomdirectory.PublicRoomsFragment +import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment +import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment +import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewNoPreviewFragment +import im.vector.riotx.features.settings.* +import im.vector.riotx.features.settings.push.PushGatewaysFragment @Module interface FragmentModule { @@ -45,11 +54,138 @@ interface FragmentModule { @Binds fun bindFragmentFactory(factory: VectorFragmentFactory): FragmentFactory - @Binds @IntoMap @FragmentKey(RoomListFragment::class) - fun bindRoomListFragment(viewModel: RoomListFragment): ViewModel + fun bindRoomListFragment(fragment: RoomListFragment): Fragment + @Binds + @IntoMap + @FragmentKey(GroupListFragment::class) + fun bindGroupListFragment(fragment: GroupListFragment): Fragment + @Binds + @IntoMap + @FragmentKey(RoomDetailFragment::class) + fun bindRoomDetailFragment(fragment: RoomDetailFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(RoomDirectoryPickerFragment::class) + fun bindRoomDirectoryPickerFragment(fragment: RoomDirectoryPickerFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(CreateRoomFragment::class) + fun bindCreateRoomFragment(fragment: CreateRoomFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(RoomPreviewNoPreviewFragment::class) + fun bindRoomPreviewNoPreviewFragment(fragment: RoomPreviewNoPreviewFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(KeysBackupSettingsFragment::class) + fun bindKeysBackupSettingsFragment(fragment: KeysBackupSettingsFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(LoadingFragment::class) + fun bindLoadingFragment(fragment: LoadingFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(HomeDrawerFragment::class) + fun bindHomeDrawerFragment(fragment: HomeDrawerFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(HomeDetailFragment::class) + fun bindHomeDetailFragment(fragment: HomeDetailFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(EmojiSearchResultFragment::class) + fun bindEmojiSearchResultFragment(fragment: EmojiSearchResultFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(LoginFragment::class) + fun bindLoginFragment(fragment: LoginFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(LoginSsoFallbackFragment::class) + fun bindLoginSsoFallbackFragment(fragment: LoginSsoFallbackFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(CreateDirectRoomDirectoryUsersFragment::class) + fun bindCreateDirectRoomDirectoryUsersFragment(fragment: CreateDirectRoomDirectoryUsersFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(CreateDirectRoomKnownUsersFragment::class) + fun bindCreateDirectRoomKnownUsersFragment(fragment: CreateDirectRoomKnownUsersFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(PushGatewaysFragment::class) + fun bindPushGatewaysFragment(fragment: PushGatewaysFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(VectorSettingsNotificationsTroubleshootFragment::class) + fun bindVectorSettingsNotificationsTroubleshootFragment(fragment: VectorSettingsNotificationsTroubleshootFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(VectorSettingsAdvancedNotificationPreferenceFragment::class) + fun bindVectorSettingsAdvancedNotificationPreferenceFragment(fragment: VectorSettingsAdvancedNotificationPreferenceFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(VectorSettingsNotificationPreferenceFragment::class) + fun bindVectorSettingsNotificationPreferenceFragment(fragment: VectorSettingsNotificationPreferenceFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(VectorSettingsPreferencesFragment::class) + fun bindVectorSettingsPreferencesFragment(fragment: VectorSettingsPreferencesFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(VectorSettingsSecurityPrivacyFragment::class) + fun bindVectorSettingsSecurityPrivacyFragment(fragment: VectorSettingsSecurityPrivacyFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(VectorSettingsHelpAboutFragment::class) + fun bindVectorSettingsHelpAboutFragment(fragment: VectorSettingsHelpAboutFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(SASVerificationIncomingFragment::class) + fun bindSASVerificationIncomingFragment(fragment: SASVerificationIncomingFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(SASVerificationShortCodeFragment::class) + fun bindSASVerificationShortCodeFragment(fragment: SASVerificationShortCodeFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(SASVerificationVerifiedFragment::class) + fun bindSASVerificationVerifiedFragment(fragment: SASVerificationVerifiedFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(SASVerificationStartFragment::class) + fun bindSASVerificationStartFragment(fragment: SASVerificationStartFragment): Fragment + + @Binds + @IntoMap + @FragmentKey(PublicRoomsFragment::class) + fun bindPublicRoomsFragment(fragment: PublicRoomsFragment): Fragment } diff --git a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt index a7c236e033..d9d23c1be5 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt @@ -21,38 +21,21 @@ import androidx.fragment.app.FragmentFactory import androidx.lifecycle.ViewModelProvider import dagger.BindsInstance import dagger.Component -import im.vector.fragments.keysbackup.restore.KeysBackupRestoreFromPassphraseFragment import im.vector.riotx.core.preference.UserAvatarPreference import im.vector.riotx.features.MainActivity -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreFromKeyFragment -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreSuccessFragment import im.vector.riotx.features.crypto.keysbackup.settings.KeysBackupManageActivity -import im.vector.riotx.features.crypto.keysbackup.settings.KeysBackupSettingsFragment -import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupStep1Fragment -import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupStep2Fragment -import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupStep3Fragment -import im.vector.riotx.features.crypto.verification.SASVerificationIncomingFragment import im.vector.riotx.features.home.HomeActivity -import im.vector.riotx.features.home.HomeDetailFragment -import im.vector.riotx.features.home.HomeDrawerFragment import im.vector.riotx.features.home.HomeModule import im.vector.riotx.features.home.createdirect.CreateDirectRoomActivity -import im.vector.riotx.features.home.createdirect.CreateDirectRoomDirectoryUsersFragment -import im.vector.riotx.features.home.createdirect.CreateDirectRoomKnownUsersFragment -import im.vector.riotx.features.home.group.GroupListFragment -import im.vector.riotx.features.home.room.detail.RoomDetailFragment import im.vector.riotx.features.home.room.detail.readreceipts.DisplayReadReceiptsBottomSheet import im.vector.riotx.features.home.room.detail.timeline.action.MessageActionsBottomSheet import im.vector.riotx.features.home.room.detail.timeline.edithistory.ViewEditHistoryBottomSheet import im.vector.riotx.features.home.room.detail.timeline.reactions.ViewReactionsBottomSheet import im.vector.riotx.features.home.room.filtered.FilteredRoomsActivity -import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.room.list.RoomListModule import im.vector.riotx.features.invite.VectorInviteView import im.vector.riotx.features.link.LinkHandlerActivity import im.vector.riotx.features.login.LoginActivity -import im.vector.riotx.features.login.LoginFragment -import im.vector.riotx.features.login.LoginSsoFallbackFragment import im.vector.riotx.features.media.ImageMediaViewerActivity import im.vector.riotx.features.media.VideoMediaViewerActivity import im.vector.riotx.features.navigation.Navigator @@ -60,16 +43,10 @@ import im.vector.riotx.features.rageshake.BugReportActivity import im.vector.riotx.features.rageshake.BugReporter import im.vector.riotx.features.rageshake.RageShake import im.vector.riotx.features.reactions.EmojiReactionPickerActivity -import im.vector.riotx.features.reactions.EmojiSearchResultFragment import im.vector.riotx.features.reactions.widget.ReactionButton -import im.vector.riotx.features.roomdirectory.PublicRoomsFragment import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActivity -import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment -import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment -import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewNoPreviewFragment import im.vector.riotx.features.settings.* -import im.vector.riotx.features.settings.push.PushGatewaysFragment import im.vector.riotx.features.share.IncomingShareActivity import im.vector.riotx.features.ui.UiStateRepository @@ -80,6 +57,7 @@ import im.vector.riotx.features.ui.UiStateRepository modules = [ AssistedInjectModule::class, ViewModelModule::class, + FragmentModule::class, HomeModule::class, RoomListModule::class ] @@ -103,22 +81,6 @@ interface ScreenComponent { fun inject(activity: HomeActivity) - fun inject(roomDetailFragment: RoomDetailFragment) - - fun inject(roomListFragment: RoomListFragment) - - fun inject(groupListFragment: GroupListFragment) - - fun inject(roomDirectoryPickerFragment: RoomDirectoryPickerFragment) - - fun inject(roomPreviewNoPreviewFragment: RoomPreviewNoPreviewFragment) - - fun inject(keysBackupSettingsFragment: KeysBackupSettingsFragment) - - fun inject(homeDrawerFragment: HomeDrawerFragment) - - fun inject(homeDetailFragment: HomeDetailFragment) - fun inject(messageActionsBottomSheet: MessageActionsBottomSheet) fun inject(viewReactionsBottomSheet: ViewReactionsBottomSheet) @@ -127,30 +89,8 @@ interface ScreenComponent { fun inject(vectorSettingsActivity: VectorSettingsActivity) - fun inject(createRoomFragment: CreateRoomFragment) - fun inject(keysBackupManageActivity: KeysBackupManageActivity) - fun inject(keysBackupRestoreFromKeyFragment: KeysBackupRestoreFromKeyFragment) - - fun inject(keysBackupRestoreFromPassphraseFragment: KeysBackupRestoreFromPassphraseFragment) - - fun inject(keysBackupRestoreSuccessFragment: KeysBackupRestoreSuccessFragment) - - fun inject(keysBackupSetupStep1Fragment: KeysBackupSetupStep1Fragment) - - fun inject(keysBackupSetupStep2Fragment: KeysBackupSetupStep2Fragment) - - fun inject(keysBackupSetupStep3Fragment: KeysBackupSetupStep3Fragment) - - fun inject(publicRoomsFragment: PublicRoomsFragment) - - fun inject(loginFragment: LoginFragment) - - fun inject(loginSsoFallbackFragment: LoginSsoFallbackFragment) - - fun inject(sasVerificationIncomingFragment: SASVerificationIncomingFragment) - fun inject(emojiReactionPickerActivity: EmojiReactionPickerActivity) fun inject(loginActivity: LoginActivity) @@ -173,26 +113,8 @@ interface ScreenComponent { fun inject(videoMediaViewerActivity: VideoMediaViewerActivity) - fun inject(vectorSettingsNotificationPreferenceFragment: VectorSettingsNotificationPreferenceFragment) - - fun inject(vectorSettingsPreferencesFragment: VectorSettingsPreferencesFragment) - - fun inject(vectorSettingsAdvancedNotificationPreferenceFragment: VectorSettingsAdvancedNotificationPreferenceFragment) - - fun inject(vectorSettingsSecurityPrivacyFragment: VectorSettingsSecurityPrivacyFragment) - - fun inject(vectorSettingsHelpAboutFragment: VectorSettingsHelpAboutFragment) - fun inject(userAvatarPreference: UserAvatarPreference) - fun inject(vectorSettingsNotificationsTroubleshootFragment: VectorSettingsNotificationsTroubleshootFragment) - - fun inject(pushGatewaysFragment: PushGatewaysFragment) - - fun inject(createDirectRoomKnownUsersFragment: CreateDirectRoomKnownUsersFragment) - - fun inject(createDirectRoomDirectoryUsersFragment: CreateDirectRoomDirectoryUsersFragment) - fun inject(createDirectRoomActivity: CreateDirectRoomActivity) fun inject(displayReadReceiptsBottomSheet: DisplayReadReceiptsBottomSheet) @@ -201,8 +123,6 @@ interface ScreenComponent { fun inject(incomingShareActivity: IncomingShareActivity) - fun inject(emojiSearchResultFragment: EmojiSearchResultFragment) - @Component.Factory interface Factory { fun create(vectorComponent: VectorComponent, diff --git a/vector/src/main/java/im/vector/riotx/core/di/VectorFragmentFactory.kt b/vector/src/main/java/im/vector/riotx/core/di/VectorFragmentFactory.kt index c27509458e..6b33b9e2a7 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/VectorFragmentFactory.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/VectorFragmentFactory.kt @@ -19,8 +19,6 @@ package im.vector.riotx.core.di import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentFactory -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider import timber.log.Timber import javax.inject.Inject import javax.inject.Provider diff --git a/vector/src/main/java/im/vector/riotx/core/extensions/Activity.kt b/vector/src/main/java/im/vector/riotx/core/extensions/Activity.kt index b4afb569c4..6e4ecf4775 100644 --- a/vector/src/main/java/im/vector/riotx/core/extensions/Activity.kt +++ b/vector/src/main/java/im/vector/riotx/core/extensions/Activity.kt @@ -16,21 +16,40 @@ package im.vector.riotx.core.extensions -import androidx.appcompat.app.AppCompatActivity +import android.os.Parcelable import androidx.fragment.app.Fragment +import im.vector.riotx.core.platform.VectorBaseActivity -fun AppCompatActivity.addFragment(fragment: Fragment, frameId: Int) { +fun VectorBaseActivity.addFragment(frameId: Int, fragment: Fragment) { supportFragmentManager.inTransaction { add(frameId, fragment) } } -fun AppCompatActivity.replaceFragment(fragment: Fragment, frameId: Int, tag: String? = null) { +fun VectorBaseActivity.addFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + supportFragmentManager.inTransaction { + add(frameId, fragmentClass, params.toMvRxBundle(), tag) + } +} + +fun VectorBaseActivity.replaceFragment(frameId: Int, fragment: Fragment, tag: String? = null) { supportFragmentManager.inTransaction { replace(frameId, fragment, tag) } } -fun AppCompatActivity.addFragmentToBackstack(fragment: Fragment, frameId: Int, tag: String? = null) { +fun VectorBaseActivity.replaceFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + supportFragmentManager.inTransaction { + replace(frameId, fragmentClass, params.toMvRxBundle(), tag) + } +} + +fun VectorBaseActivity.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { supportFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) } } -fun AppCompatActivity.hideKeyboard() { +fun VectorBaseActivity.addFragmentToBackstack(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + supportFragmentManager.inTransaction { + replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) + } +} + +fun VectorBaseActivity.hideKeyboard() { currentFocus?.hideKeyboard() } 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 11ebf56ec9..e6e83bfd67 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 @@ -16,28 +16,66 @@ package im.vector.riotx.core.extensions +import android.os.Parcelable import androidx.fragment.app.Fragment +import im.vector.riotx.core.platform.VectorBaseFragment -fun Fragment.addFragment(fragment: Fragment, frameId: Int) { +fun VectorBaseFragment.addFragment(frameId: Int, fragment: Fragment) { parentFragmentManager.inTransaction { add(frameId, fragment) } } -fun Fragment.replaceFragment(fragment: Fragment, frameId: Int) { +fun VectorBaseFragment.addFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + parentFragmentManager.inTransaction { + add(frameId, fragmentClass, params.toMvRxBundle(), tag) + } +} + +fun VectorBaseFragment.replaceFragment(frameId: Int, fragment: Fragment) { parentFragmentManager.inTransaction { replace(frameId, fragment) } } -fun Fragment.addFragmentToBackstack(fragment: Fragment, frameId: Int, tag: String? = null) { +fun VectorBaseFragment.replaceFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + parentFragmentManager.inTransaction { + replace(frameId, fragmentClass, params.toMvRxBundle(), tag) + } +} + +fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { parentFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) } } -fun Fragment.addChildFragment(fragment: Fragment, frameId: Int) { +fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + parentFragmentManager.inTransaction { + replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) + } +} + +fun VectorBaseFragment.addChildFragment(frameId: Int, fragment: Fragment) { childFragmentManager.inTransaction { add(frameId, fragment) } } -fun Fragment.replaceChildFragment(fragment: Fragment, frameId: Int) { +fun VectorBaseFragment.addChildFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + childFragmentManager.inTransaction { + add(frameId, fragmentClass, params.toMvRxBundle(), tag) + } +} + +fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragment: Fragment) { childFragmentManager.inTransaction { replace(frameId, fragment) } } -fun Fragment.addChildFragmentToBackstack(fragment: Fragment, frameId: Int, tag: String? = null) { +fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + childFragmentManager.inTransaction { + replace(frameId, fragmentClass, params.toMvRxBundle(), tag) + } +} + +fun VectorBaseFragment.addChildFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { childFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) } } + +fun VectorBaseFragment.addChildFragmentToBackstack(frameId: Int, fragmentClass: Class, params: Parcelable? = null, tag: String? = null) { + childFragmentManager.inTransaction { + replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) + } +} diff --git a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt index 3b80d6d794..ede99e4f28 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt @@ -19,6 +19,7 @@ package im.vector.riotx.core.platform import android.content.Context import android.content.res.Configuration import android.os.Bundle +import android.os.Parcelable import android.view.Menu import android.view.MenuItem import android.view.View @@ -26,7 +27,6 @@ import androidx.annotation.* import androidx.appcompat.widget.Toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.isVisible -import androidx.fragment.app.FragmentFactory import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider @@ -35,6 +35,7 @@ import butterknife.BindView import butterknife.ButterKnife import butterknife.Unbinder import com.airbnb.mvrx.BaseMvRxActivity +import com.airbnb.mvrx.MvRx import com.bumptech.glide.util.Util import com.google.android.material.snackbar.Snackbar import im.vector.riotx.BuildConfig @@ -332,6 +333,10 @@ abstract class VectorBaseActivity : BaseMvRxActivity(), HasScreenInjector { } } + fun Parcelable?.toMvRxBundle(): Bundle? { + return this?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } + } + // ============================================================================================== // Handle loading view (also called waiting view or spinner view) // ============================================================================================== 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 34953bec33..206a1bab06 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 @@ -63,6 +63,7 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), HasScreenInjector { screenComponent = DaggerScreenComponent.factory().create(vectorBaseActivity.getVectorComponent(), vectorBaseActivity) navigator = screenComponent.navigator() viewModelFactory = screenComponent.viewModelFactory() + childFragmentManager.fragmentFactory = screenComponent.fragmentFactory() injectWith(injector()) super.onAttach(context) } @@ -137,7 +138,7 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), HasScreenInjector { arguments = args.toMvRxBundle() } - protected fun Parcelable?.toMvRxBundle(): Bundle? { + fun Parcelable?.toMvRxBundle(): Bundle? { return this?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } } diff --git a/vector/src/main/java/im/vector/riotx/core/platform/VectorPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/core/platform/VectorPreferenceFragment.kt deleted file mode 100644 index d534cd2297..0000000000 --- a/vector/src/main/java/im/vector/riotx/core/platform/VectorPreferenceFragment.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2019 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.riotx.core.platform - -import androidx.annotation.CallSuper -import androidx.preference.PreferenceFragmentCompat -import im.vector.riotx.R -import im.vector.riotx.core.utils.toast -import timber.log.Timber - -abstract class VectorPreferenceFragment : PreferenceFragmentCompat() { - - val vectorActivity: VectorBaseActivity by lazy { - activity as VectorBaseActivity - } - - abstract var titleRes: Int - - /* ========================================================================================== - * Life cycle - * ========================================================================================== */ - - @CallSuper - override fun onResume() { - super.onResume() - - (activity as? VectorBaseActivity)?.supportActionBar?.setTitle(titleRes) - Timber.v("onResume Fragment ${this.javaClass.simpleName}") - } - - /* ========================================================================================== - * Protected - * ========================================================================================== */ - - protected fun notImplemented() { - // Snackbar cannot be display on PreferenceFragment - // Snackbar.make(view!!, R.string.not_implemented, Snackbar.LENGTH_SHORT) - activity?.toast(R.string.not_implemented) - } -} diff --git a/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt b/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt index a9c20a9ec5..3f5808949b 100644 --- a/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt +++ b/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt @@ -56,7 +56,6 @@ object CommandParser { return ParsedCommand.ErrorEmptySlashCommand } - return when (val slashCommand = messageParts.first()) { Command.CHANGE_DISPLAY_NAME.command -> { val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim() diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt index d74a9e9f4f..cd5dc38c3d 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt @@ -22,9 +22,10 @@ import androidx.appcompat.app.AlertDialog import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders -import im.vector.fragments.keysbackup.restore.KeysBackupRestoreFromPassphraseFragment import im.vector.riotx.R +import im.vector.riotx.core.extensions.addFragmentToBackstack import im.vector.riotx.core.extensions.observeEvent +import im.vector.riotx.core.extensions.replaceFragment import im.vector.riotx.core.platform.SimpleFragmentActivity class KeysBackupRestoreActivity : SimpleFragmentActivity() { @@ -49,13 +50,9 @@ class KeysBackupRestoreActivity : SimpleFragmentActivity() { if (keyVersion != null && supportFragmentManager.fragments.isEmpty()) { val isBackupCreatedFromPassphrase = keyVersion.getAuthDataAsMegolmBackupAuthData()?.privateKeySalt != null if (isBackupCreatedFromPassphrase) { - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupRestoreFromPassphraseFragment.newInstance()) - .commitNow() + replaceFragment(R.id.container, KeysBackupRestoreFromPassphraseFragment::class.java) } else { - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupRestoreFromKeyFragment.newInstance()) - .commitNow() + replaceFragment(R.id.container, KeysBackupRestoreFromKeyFragment::class.java) } } }) @@ -80,16 +77,11 @@ class KeysBackupRestoreActivity : SimpleFragmentActivity() { viewModel.navigateEvent.observeEvent(this) { uxStateEvent -> when (uxStateEvent) { KeysBackupRestoreSharedViewModel.NAVIGATE_TO_RECOVER_WITH_KEY -> { - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupRestoreFromKeyFragment.newInstance()) - .addToBackStack(null) - .commit() + addFragmentToBackstack(R.id.container, KeysBackupRestoreFromKeyFragment::class.java) } KeysBackupRestoreSharedViewModel.NAVIGATE_TO_SUCCESS -> { supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupRestoreSuccessFragment.newInstance()) - .commit() + replaceFragment(R.id.container, KeysBackupRestoreSuccessFragment::class.java) } } } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt index 3c9ebc3a50..c30393dd5f 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt @@ -28,15 +28,15 @@ import butterknife.OnClick import butterknife.OnTextChanged import com.google.android.material.textfield.TextInputLayout import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.startImportTextFromFileIntent import timber.log.Timber +import javax.inject.Inject -class KeysBackupRestoreFromKeyFragment : VectorBaseFragment() { +class KeysBackupRestoreFromKeyFragment @Inject constructor() + : VectorBaseFragment() { companion object { - fun newInstance() = KeysBackupRestoreFromKeyFragment() private const val REQUEST_TEXT_FILE_GET = 1 } @@ -51,10 +51,6 @@ class KeysBackupRestoreFromKeyFragment : VectorBaseFragment() { @BindView(R.id.keys_restore_key_enter_edittext) lateinit var mKeyTextEdit: EditText - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) viewModel = ViewModelProviders.of(this, viewModelFactory).get(KeysBackupRestoreFromKeyViewModel::class.java) @@ -72,7 +68,7 @@ class KeysBackupRestoreFromKeyFragment : VectorBaseFragment() { } mKeyInputLayout.error = viewModel.recoveryCodeErrorText.value - viewModel.recoveryCodeErrorText.observe(this, Observer { newValue -> + viewModel.recoveryCodeErrorText.observe(viewLifecycleOwner, Observer { newValue -> mKeyInputLayout.error = newValue }) } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt index c70796e09d..d4468081b8 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.fragments.keysbackup.restore +package im.vector.riotx.features.crypto.keysbackup.restore import android.content.Context import android.os.Bundle @@ -33,13 +33,11 @@ import butterknife.OnClick import butterknife.OnTextChanged import com.google.android.material.textfield.TextInputLayout import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.showPassword import im.vector.riotx.core.platform.VectorBaseFragment -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreFromPassphraseViewModel -import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreSharedViewModel +import javax.inject.Inject -class KeysBackupRestoreFromPassphraseFragment : VectorBaseFragment() { +class KeysBackupRestoreFromPassphraseFragment @Inject constructor(): VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_keys_backup_restore_from_passphrase @@ -63,14 +61,6 @@ class KeysBackupRestoreFromPassphraseFragment : VectorBaseFragment() { viewModel.showPasswordMode.value = !(viewModel.showPasswordMode.value ?: false) } - companion object { - fun newInstance() = KeysBackupRestoreFromPassphraseFragment() - } - - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -79,13 +69,13 @@ class KeysBackupRestoreFromPassphraseFragment : VectorBaseFragment() { ViewModelProviders.of(this, viewModelFactory).get(KeysBackupRestoreSharedViewModel::class.java) } ?: throw Exception("Invalid Activity") - viewModel.passphraseErrorText.observe(this, Observer { newValue -> + viewModel.passphraseErrorText.observe(viewLifecycleOwner, Observer { newValue -> mPassphraseInputLayout.error = newValue }) helperTextWithLink.text = spannableStringForHelperText(context!!) - viewModel.showPasswordMode.observe(this, Observer { + viewModel.showPasswordMode.observe(viewLifecycleOwner, Observer { val shouldBeVisible = it ?: false mPassphraseTextEdit.showPassword(shouldBeVisible) mPassphraseReveal.setImageResource(if (shouldBeVisible) R.drawable.ic_eye_closed_black else R.drawable.ic_eye_black) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt index cb55d664ec..25be8ded47 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt @@ -21,11 +21,11 @@ import androidx.lifecycle.ViewModelProviders import butterknife.BindView import butterknife.OnClick import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.LiveEvent +import javax.inject.Inject -class KeysBackupRestoreSuccessFragment : VectorBaseFragment() { +class KeysBackupRestoreSuccessFragment @Inject constructor() : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_keys_backup_restore_success @@ -36,10 +36,6 @@ class KeysBackupRestoreSuccessFragment : VectorBaseFragment() { private lateinit var sharedViewModel: KeysBackupRestoreSharedViewModel - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) sharedViewModel = activity?.run { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt index 2dabaa792a..a58c99992d 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt @@ -23,6 +23,7 @@ import com.airbnb.mvrx.Loading import com.airbnb.mvrx.viewModel import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent +import im.vector.riotx.core.extensions.replaceFragment import im.vector.riotx.core.platform.SimpleFragmentActivity import im.vector.riotx.core.platform.WaitingViewData import javax.inject.Inject @@ -49,10 +50,7 @@ class KeysBackupManageActivity : SimpleFragmentActivity() { override fun initUiAndData() { super.initUiAndData() if (supportFragmentManager.fragments.isEmpty()) { - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupSettingsFragment.newInstance()) - .commitNow() - + replaceFragment(R.id.container, KeysBackupSettingsFragment::class.java) viewModel.init() } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt index 2194ca9871..288d862413 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt @@ -21,29 +21,20 @@ import androidx.appcompat.app.AlertDialog import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreActivity import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupActivity import kotlinx.android.synthetic.main.fragment_keys_backup_settings.* import javax.inject.Inject -class KeysBackupSettingsFragment : VectorBaseFragment(), - KeysBackupSettingsRecyclerViewController.Listener { - - companion object { - fun newInstance() = KeysBackupSettingsFragment() - } +class KeysBackupSettingsFragment @Inject constructor(private val keysBackupSettingsRecyclerViewController: KeysBackupSettingsRecyclerViewController) + : VectorBaseFragment(), + KeysBackupSettingsRecyclerViewController.Listener { override fun getLayoutResId() = R.layout.fragment_keys_backup_settings - @Inject lateinit var keysBackupSettingsRecyclerViewController: KeysBackupSettingsRecyclerViewController private val viewModel: KeysBackupSettingsViewModel by activityViewModel() - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt index 6868fb84bb..8491435d3a 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt @@ -26,6 +26,7 @@ import im.vector.matrix.android.api.MatrixCallback import im.vector.riotx.R import im.vector.riotx.core.dialogs.ExportKeysDialog import im.vector.riotx.core.extensions.observeEvent +import im.vector.riotx.core.extensions.replaceFragment import im.vector.riotx.core.platform.SimpleFragmentActivity import im.vector.riotx.core.utils.* import im.vector.riotx.features.crypto.keys.KeysExporter @@ -39,9 +40,7 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() { override fun initUiAndData() { super.initUiAndData() if (isFirstCreation()) { - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupSetupStep1Fragment.newInstance()) - .commitNow() + replaceFragment(R.id.container, KeysBackupSetupStep1Fragment::class.java) } viewModel = ViewModelProviders.of(this, viewModelFactory).get(KeysBackupSetupSharedViewModel::class.java) @@ -67,15 +66,11 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() { when (uxStateEvent) { KeysBackupSetupSharedViewModel.NAVIGATE_TO_STEP_2 -> { supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupSetupStep2Fragment.newInstance()) - .commit() + replaceFragment(R.id.container, KeysBackupSetupStep2Fragment::class.java) } KeysBackupSetupSharedViewModel.NAVIGATE_TO_STEP_3 -> { supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) - supportFragmentManager.beginTransaction() - .replace(R.id.container, KeysBackupSetupStep3Fragment.newInstance()) - .commit() + replaceFragment(R.id.container, KeysBackupSetupStep3Fragment::class.java) } KeysBackupSetupSharedViewModel.NAVIGATE_FINISH -> { val resultIntent = Intent() diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt index 8ece6af714..fd7a95bff1 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt @@ -25,11 +25,11 @@ import androidx.lifecycle.ViewModelProviders import butterknife.BindView import butterknife.OnClick import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.LiveEvent +import javax.inject.Inject -class KeysBackupSetupStep1Fragment : VectorBaseFragment() { +class KeysBackupSetupStep1Fragment @Inject constructor(): VectorBaseFragment() { companion object { fun newInstance() = KeysBackupSetupStep1Fragment() @@ -45,10 +45,6 @@ class KeysBackupSetupStep1Fragment : VectorBaseFragment() { @BindView(R.id.keys_backup_setup_step1_manualExport) lateinit var manualExportButton: Button - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt index f4717fa7b3..21e4747a4e 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt @@ -30,13 +30,13 @@ import butterknife.OnTextChanged import com.google.android.material.textfield.TextInputLayout import com.nulabinc.zxcvbn.Zxcvbn import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.showPassword import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.ui.views.PasswordStrengthBar import im.vector.riotx.features.settings.VectorLocale +import javax.inject.Inject -class KeysBackupSetupStep2Fragment : VectorBaseFragment() { +class KeysBackupSetupStep2Fragment @Inject constructor() : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_keys_backup_setup_step2 @@ -76,10 +76,6 @@ class KeysBackupSetupStep2Fragment : VectorBaseFragment() { private lateinit var viewModel: KeysBackupSetupSharedViewModel - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -96,7 +92,7 @@ class KeysBackupSetupStep2Fragment : VectorBaseFragment() { * ========================================================================================== */ private fun bindViewToViewModel() { - viewModel.passwordStrength.observe(this, Observer { strength -> + viewModel.passwordStrength.observe(viewLifecycleOwner, Observer { strength -> if (strength == null) { mPassphraseProgressLevel.strength = 0 mPassphraseInputLayout.error = null @@ -120,7 +116,7 @@ class KeysBackupSetupStep2Fragment : VectorBaseFragment() { } }) - viewModel.passphrase.observe(this, Observer { newValue -> + viewModel.passphrase.observe(viewLifecycleOwner, Observer { newValue -> if (newValue.isEmpty()) { viewModel.passwordStrength.value = null } else { @@ -135,21 +131,21 @@ class KeysBackupSetupStep2Fragment : VectorBaseFragment() { mPassphraseTextEdit.setText(viewModel.passphrase.value) - viewModel.passphraseError.observe(this, Observer { + viewModel.passphraseError.observe(viewLifecycleOwner, Observer { TransitionManager.beginDelayedTransition(rootGroup) mPassphraseInputLayout.error = it }) mPassphraseConfirmTextEdit.setText(viewModel.confirmPassphrase.value) - viewModel.showPasswordMode.observe(this, Observer { + viewModel.showPasswordMode.observe(viewLifecycleOwner, Observer { val shouldBeVisible = it ?: false mPassphraseTextEdit.showPassword(shouldBeVisible) mPassphraseConfirmTextEdit.showPassword(shouldBeVisible) mPassphraseReveal.setImageResource(if (shouldBeVisible) R.drawable.ic_eye_closed_black else R.drawable.ic_eye_black) }) - viewModel.confirmPassphraseError.observe(this, Observer { + viewModel.confirmPassphraseError.observe(viewLifecycleOwner, Observer { TransitionManager.beginDelayedTransition(rootGroup) mPassphraseConfirmInputLayout.error = it }) @@ -203,8 +199,4 @@ class KeysBackupSetupStep2Fragment : VectorBaseFragment() { } } } - - companion object { - fun newInstance() = KeysBackupSetupStep2Fragment() - } } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt index a5cc0510da..008e1b8aef 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt @@ -30,7 +30,6 @@ import butterknife.BindView import butterknife.OnClick import com.google.android.material.bottomsheet.BottomSheetDialog import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.files.addEntryToDownloadManager import im.vector.riotx.core.files.writeToFile import im.vector.riotx.core.platform.VectorBaseFragment @@ -40,8 +39,9 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File +import javax.inject.Inject -class KeysBackupSetupStep3Fragment : VectorBaseFragment() { +class KeysBackupSetupStep3Fragment @Inject constructor() : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_keys_backup_setup_step3 @@ -54,16 +54,8 @@ class KeysBackupSetupStep3Fragment : VectorBaseFragment() { @BindView(R.id.keys_backup_setup_step3_line2_text) lateinit var mRecoveryKeyLabel2TextView: TextView - companion object { - fun newInstance() = KeysBackupSetupStep3Fragment() - } - private lateinit var viewModel: KeysBackupSetupSharedViewModel - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) viewModel = activity?.run { @@ -72,7 +64,7 @@ class KeysBackupSetupStep3Fragment : VectorBaseFragment() { viewModel.shouldPromptOnBack = false - viewModel.passphrase.observe(this, Observer { + viewModel.passphrase.observe(viewLifecycleOwner, Observer { if (it.isNullOrBlank()) { // Recovery was generated, so show key and options to save mRecoveryKeyLabel2TextView.text = getString(R.string.keys_backup_setup_step3_text_line2_no_passphrase) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt index a7fb4c67f3..3890479d91 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt @@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.crypto.sas.IncomingSasVerificationTr import im.vector.matrix.android.api.session.crypto.sas.OutgoingSasVerificationRequest import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState import im.vector.riotx.R +import im.vector.riotx.core.extensions.inTransaction import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.platform.SimpleFragmentActivity import im.vector.riotx.core.platform.WaitingViewData @@ -102,23 +103,23 @@ class SASVerificationActivity : SimpleFragmentActivity() { IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT, IncomingSasVerificationTransaction.UxState.WAIT_FOR_KEY_AGREEMENT -> { supportActionBar?.setTitle(R.string.sas_incoming_request_title) - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationIncomingFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationIncomingFragment::class.java, null) + } } IncomingSasVerificationTransaction.UxState.WAIT_FOR_VERIFICATION, IncomingSasVerificationTransaction.UxState.SHOW_SAS -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationShortCodeFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationShortCodeFragment::class.java, null) + } } IncomingSasVerificationTransaction.UxState.VERIFIED -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationVerifiedFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationVerifiedFragment::class.java, null) + } } IncomingSasVerificationTransaction.UxState.CANCELLED_BY_ME, IncomingSasVerificationTransaction.UxState.CANCELLED_BY_OTHER -> { @@ -133,23 +134,23 @@ class SASVerificationActivity : SimpleFragmentActivity() { OutgoingSasVerificationRequest.UxState.UNKNOWN, OutgoingSasVerificationRequest.UxState.WAIT_FOR_START, OutgoingSasVerificationRequest.UxState.WAIT_FOR_KEY_AGREEMENT -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationStartFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationStartFragment::class.java, null) + } } OutgoingSasVerificationRequest.UxState.SHOW_SAS, OutgoingSasVerificationRequest.UxState.WAIT_FOR_VERIFICATION -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationShortCodeFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationShortCodeFragment::class.java, null) + } } OutgoingSasVerificationRequest.UxState.VERIFIED -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationVerifiedFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationVerifiedFragment::class.java, null) + } } OutgoingSasVerificationRequest.UxState.CANCELLED_BY_ME, OutgoingSasVerificationRequest.UxState.CANCELLED_BY_OTHER -> { @@ -172,16 +173,16 @@ class SASVerificationActivity : SimpleFragmentActivity() { finish() } SasVerificationViewModel.NAVIGATE_SAS_DISPLAY -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationShortCodeFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationShortCodeFragment::class.java, null) + } } SasVerificationViewModel.NAVIGATE_SUCCESS -> { - supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out) - .replace(R.id.container, SASVerificationVerifiedFragment.newInstance()) - .commitNow() + supportFragmentManager.inTransaction { + setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out) + replace(R.id.container, SASVerificationVerifiedFragment::class.java, null) + } } SasVerificationViewModel.NAVIGATE_CANCELLED -> { val isCancelledByMe = viewModel.transaction?.state == SasVerificationTxState.Cancelled diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt index d8d36e0a1d..9bb3661bd7 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt @@ -24,16 +24,13 @@ import butterknife.BindView import butterknife.OnClick import im.vector.matrix.android.api.session.crypto.sas.IncomingSasVerificationTransaction import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.home.AvatarRenderer import javax.inject.Inject -class SASVerificationIncomingFragment : VectorBaseFragment() { - - companion object { - fun newInstance() = SASVerificationIncomingFragment() - } +class SASVerificationIncomingFragment @Inject constructor( + private var avatarRenderer: AvatarRenderer +) : VectorBaseFragment() { @BindView(R.id.sas_incoming_request_user_display_name) lateinit var otherUserDisplayNameTextView: TextView @@ -49,13 +46,8 @@ class SASVerificationIncomingFragment : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_sas_verification_incoming_request - @Inject lateinit var avatarRenderer: AvatarRenderer private lateinit var viewModel: SasVerificationViewModel - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -74,7 +66,7 @@ class SASVerificationIncomingFragment : VectorBaseFragment() { avatarRenderer.render(null, viewModel.otherUserId ?: "", viewModel.otherUserId, avatarImageView) } - viewModel.transactionState.observe(this, Observer { + viewModel.transactionState.observe(viewLifecycleOwner, Observer { val uxState = (viewModel.transaction as? IncomingSasVerificationTransaction)?.uxState when (uxState) { IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT -> { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt index 1c5488c0cd..da19d48bfe 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt @@ -28,15 +28,12 @@ import im.vector.matrix.android.api.session.crypto.sas.IncomingSasVerificationTr import im.vector.matrix.android.api.session.crypto.sas.OutgoingSasVerificationRequest import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseFragment +import javax.inject.Inject -class SASVerificationShortCodeFragment : VectorBaseFragment() { +class SASVerificationShortCodeFragment @Inject constructor(): VectorBaseFragment() { private lateinit var viewModel: SasVerificationViewModel - companion object { - fun newInstance() = SASVerificationShortCodeFragment() - } - @BindView(R.id.sas_decimal_code) lateinit var decimalTextView: TextView @@ -120,7 +117,7 @@ class SASVerificationShortCodeFragment : VectorBaseFragment() { } } - viewModel.transactionState.observe(this, Observer { + viewModel.transactionState.observe(viewLifecycleOwner, Observer { if (viewModel.transaction is IncomingSasVerificationTransaction) { val uxState = (viewModel.transaction as IncomingSasVerificationTransaction).uxState when (uxState) { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt index c101b8f9b4..97a29d9b7b 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt @@ -31,12 +31,9 @@ import im.vector.matrix.android.api.session.crypto.sas.OutgoingSasVerificationRe import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseFragment +import javax.inject.Inject -class SASVerificationStartFragment : VectorBaseFragment() { - - companion object { - fun newInstance() = SASVerificationStartFragment() - } +class SASVerificationStartFragment @Inject constructor(): VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_sas_verification_start @@ -57,7 +54,7 @@ class SASVerificationStartFragment : VectorBaseFragment() { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) viewModel = ViewModelProviders.of(vectorBaseActivity, viewModelFactory).get(SasVerificationViewModel::class.java) - viewModel.transactionState.observe(this, Observer { + viewModel.transactionState.observe(viewLifecycleOwner, Observer { val uxState = (viewModel.transaction as? OutgoingSasVerificationRequest)?.uxState when (uxState) { OutgoingSasVerificationRequest.UxState.WAIT_FOR_KEY_AGREEMENT -> { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt index b9d0546f3a..59825c8282 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt @@ -20,15 +20,12 @@ import androidx.lifecycle.ViewModelProviders import butterknife.OnClick import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseFragment +import javax.inject.Inject -class SASVerificationVerifiedFragment : VectorBaseFragment() { +class SASVerificationVerifiedFragment @Inject constructor() : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_sas_verification_verified - companion object { - fun newInstance() = SASVerificationVerifiedFragment() - } - private lateinit var viewModel: SasVerificationViewModel override fun onActivityCreated(savedInstanceState: Bundle?) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt index af367164fc..200b79925b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt @@ -79,10 +79,8 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { navigationViewModel = ViewModelProviders.of(this).get(HomeNavigationViewModel::class.java) drawerLayout.addDrawerListener(drawerListener) if (isFirstCreation()) { - val homeDrawerFragment = HomeDrawerFragment.newInstance() - val loadingDetail = LoadingFragment.newInstance() - replaceFragment(loadingDetail, R.id.homeDetailFragmentContainer) - replaceFragment(homeDrawerFragment, R.id.homeDrawerFragmentContainer) + replaceFragment(R.id.homeDetailFragmentContainer, LoadingFragment::class.java) + replaceFragment(R.id.homeDrawerFragmentContainer, HomeDrawerFragment::class.java) } navigationViewModel.navigateTo.observeEvent(this) { navigation -> @@ -90,8 +88,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { is Navigation.OpenDrawer -> drawerLayout.openDrawer(GravityCompat.START) is Navigation.OpenGroup -> { drawerLayout.closeDrawer(GravityCompat.START) - val homeDetailFragment = HomeDetailFragment.newInstance() - replaceFragment(homeDetailFragment, R.id.homeDetailFragmentContainer) + replaceFragment(R.id.homeDetailFragmentContainer, HomeDetailFragment::class.java) } } } 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 38fe491bd3..874b566e16 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 @@ -29,8 +29,7 @@ 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.di.ScreenComponent -import im.vector.riotx.core.extensions.inTransaction +import im.vector.riotx.core.extensions.addChildFragmentToBackstack import im.vector.riotx.core.platform.ToolbarConfigurable import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.ui.views.KeysBackupBanner @@ -46,25 +45,21 @@ private const val INDEX_CATCHUP = 0 private const val INDEX_PEOPLE = 1 private const val INDEX_ROOMS = 2 -class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate { +class HomeDetailFragment @Inject constructor( + private val session: Session, + val homeDetailViewModelFactory: HomeDetailViewModel.Factory, + private val avatarRenderer: AvatarRenderer +) : VectorBaseFragment(), KeysBackupBanner.Delegate { private val unreadCounterBadgeViews = arrayListOf() private val viewModel: HomeDetailViewModel by fragmentViewModel() private lateinit var navigationViewModel: HomeNavigationViewModel - @Inject lateinit var session: Session - @Inject lateinit var homeDetailViewModelFactory: HomeDetailViewModel.Factory - @Inject lateinit var avatarRenderer: AvatarRenderer - override fun getLayoutResId(): Int { return R.layout.fragment_home_detail } - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -100,7 +95,7 @@ class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate { model.init(session) - model.keysBackupState.observe(this, Observer { keysBackupState -> + model.keysBackupState.observe(viewLifecycleOwner, Observer { keysBackupState -> when (keysBackupState) { null -> homeKeysBackupBanner.render(KeysBackupBanner.State.Hidden, false) @@ -175,15 +170,11 @@ class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate { val fragmentTag = "FRAGMENT_TAG_${displayMode.name}" val fragment = childFragmentManager.findFragmentByTag(fragmentTag) if (fragment == null) { - childFragmentManager.inTransaction { - replace(R.id.roomListContainer, RoomListFragment::class.java, RoomListParams(displayMode).toMvRxBundle(), fragmentTag).addToBackStack(fragmentTag) - } + val params = RoomListParams(displayMode) + addChildFragmentToBackstack(R.id.roomListContainer, RoomListFragment::class.java, params, fragmentTag) } else { - childFragmentManager.inTransaction { - replace(R.id.roomListContainer, fragment, fragmentTag).addToBackStack(fragmentTag) - } + addChildFragmentToBackstack(R.id.roomListContainer, fragment, fragmentTag) } - } /* ========================================================================================== @@ -205,11 +196,4 @@ class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate { unreadCounterBadgeViews[INDEX_ROOMS].render(UnreadCounterBadgeView.State(it.notificationCountRooms, it.notificationHighlightRooms)) syncStateView.render(it.syncState) } - - companion object { - - fun newInstance(): HomeDetailFragment { - return HomeDetailFragment() - } - } } 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 e5f0c5b2d3..5b052f5ff5 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 @@ -19,7 +19,6 @@ package im.vector.riotx.features.home import android.os.Bundle import im.vector.matrix.android.api.session.Session import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.observeK import im.vector.riotx.core.extensions.replaceChildFragment import im.vector.riotx.core.platform.VectorBaseFragment @@ -27,29 +26,17 @@ import im.vector.riotx.features.home.group.GroupListFragment import kotlinx.android.synthetic.main.fragment_home_drawer.* import javax.inject.Inject -class HomeDrawerFragment : VectorBaseFragment() { - - companion object { - - fun newInstance(): HomeDrawerFragment { - return HomeDrawerFragment() - } - } - - @Inject lateinit var session: Session - @Inject lateinit var avatarRenderer: AvatarRenderer +class HomeDrawerFragment @Inject constructor( + private val session: Session, + private val avatarRenderer: AvatarRenderer +) : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_home_drawer - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) if (savedInstanceState == null) { - val groupListFragment = GroupListFragment.newInstance() - replaceChildFragment(groupListFragment, R.id.homeDrawerGroupListContainer) + replaceChildFragment(R.id.homeDrawerGroupListContainer, GroupListFragment::class.java) } session.liveUser(session.myUserId).observeK(this) { optionalUser -> val user = optionalUser?.getOrNull() diff --git a/vector/src/main/java/im/vector/riotx/features/home/LoadingFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/LoadingFragment.kt index 379ac69154..e376514955 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/LoadingFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/LoadingFragment.kt @@ -22,15 +22,9 @@ import android.view.View import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseFragment import kotlinx.android.synthetic.main.fragment_loading.* +import javax.inject.Inject -class LoadingFragment : VectorBaseFragment() { - - companion object { - - fun newInstance(): LoadingFragment { - return LoadingFragment() - } - } +class LoadingFragment @Inject constructor(): VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_loading diff --git a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomActivity.kt index a94b2b85da..af1cfe89a3 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomActivity.kt @@ -61,13 +61,13 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() { navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(CreateDirectRoomNavigationViewModel::class.java) navigationViewModel.navigateTo.observeEvent(this) { navigation -> when (navigation) { - is Navigation.UsersDirectory -> addFragmentToBackstack(CreateDirectRoomDirectoryUsersFragment(), R.id.container) + is Navigation.UsersDirectory -> addFragmentToBackstack(R.id.container, CreateDirectRoomDirectoryUsersFragment::class.java) Navigation.Close -> finish() Navigation.Previous -> onBackPressed() } } if (isFirstCreation()) { - addFragment(CreateDirectRoomKnownUsersFragment(), R.id.container) + addFragment(R.id.container, CreateDirectRoomKnownUsersFragment::class.java) } viewModel.selectSubscribe(this, CreateDirectRoomViewState::createAndInviteState) { renderCreateAndInviteState(it) 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 6125d1b6b9..3e8f2e0780 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 @@ -25,26 +25,22 @@ import com.airbnb.mvrx.withState import com.jakewharton.rxbinding3.widget.textChanges import im.vector.matrix.android.api.session.user.model.User import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.hideKeyboard import im.vector.riotx.core.extensions.setupAsSearch import im.vector.riotx.core.platform.VectorBaseFragment import kotlinx.android.synthetic.main.fragment_create_direct_room_directory_users.* import javax.inject.Inject -class CreateDirectRoomDirectoryUsersFragment : VectorBaseFragment(), DirectoryUsersController.Callback { +class CreateDirectRoomDirectoryUsersFragment @Inject constructor( + private val directRoomController: DirectoryUsersController +) : VectorBaseFragment(), DirectoryUsersController.Callback { override fun getLayoutResId() = R.layout.fragment_create_direct_room_directory_users private val viewModel: CreateDirectRoomViewModel by activityViewModel() - @Inject lateinit var directRoomController: DirectoryUsersController private lateinit var navigationViewModel: CreateDirectRoomNavigationViewModel - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) navigationViewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(CreateDirectRoomNavigationViewModel::class.java) 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 04e8d16fd7..a05bbf1a21 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 @@ -31,33 +31,26 @@ import com.google.android.material.chip.ChipGroup import com.jakewharton.rxbinding3.widget.textChanges import im.vector.matrix.android.api.session.user.model.User import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.hideKeyboard import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.extensions.setupAsSearch import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.DimensionConverter -import im.vector.riotx.features.home.AvatarRenderer import kotlinx.android.synthetic.main.fragment_create_direct_room.* import javax.inject.Inject -class CreateDirectRoomKnownUsersFragment : VectorBaseFragment(), KnownUsersController.Callback { +class CreateDirectRoomKnownUsersFragment @Inject constructor( + private val directRoomController: KnownUsersController, + private val dimensionConverter: DimensionConverter +) : VectorBaseFragment(), KnownUsersController.Callback { override fun getLayoutResId() = R.layout.fragment_create_direct_room override fun getMenuRes() = R.menu.vector_create_direct_room private val viewModel: CreateDirectRoomViewModel by activityViewModel() - - @Inject lateinit var directRoomController: KnownUsersController - @Inject lateinit var avatarRenderer: AvatarRenderer - @Inject lateinit var dimensionConverter: DimensionConverter private lateinit var navigationViewModel: CreateDirectRoomNavigationViewModel - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) navigationViewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(CreateDirectRoomNavigationViewModel::class.java) 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 54c2044ae4..d3fb40f6dc 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 @@ -23,7 +23,6 @@ import com.airbnb.mvrx.Success import com.airbnb.mvrx.fragmentViewModel import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.platform.StateView import im.vector.riotx.core.platform.VectorBaseFragment @@ -32,26 +31,16 @@ import im.vector.riotx.features.home.HomeNavigationViewModel import kotlinx.android.synthetic.main.fragment_group_list.* import javax.inject.Inject -class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback { - - companion object { - fun newInstance(): GroupListFragment { - return GroupListFragment() - } - } +class GroupListFragment @Inject constructor( + val groupListViewModelFactory: GroupListViewModel.Factory, + private val groupController: GroupSummaryController +) : VectorBaseFragment(), GroupSummaryController.Callback { private lateinit var navigationViewModel: HomeNavigationViewModel private val viewModel: GroupListViewModel by fragmentViewModel() - @Inject lateinit var groupListViewModelFactory: GroupListViewModel.Factory - @Inject lateinit var groupController: GroupSummaryController - override fun getLayoutResId() = R.layout.fragment_group_list - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) navigationViewModel = ViewModelProviders.of(requireActivity()).get(HomeNavigationViewModel::class.java) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActivity.kt index 91addb5744..eb8118a0c9 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActivity.kt @@ -38,8 +38,7 @@ class RoomDetailActivity : VectorBaseActivity(), ToolbarConfigurable { if (isFirstCreation()) { val roomDetailArgs: RoomDetailArgs = intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS) ?: return - val roomDetailFragment = RoomDetailFragment.newInstance(roomDetailArgs) - replaceFragment(roomDetailFragment, R.id.roomDetailContainer) + replaceFragment(R.id.roomDetailContainer, RoomDetailFragment::class.java, roomDetailArgs) } } 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 76d01228b8..667fa9784b 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 @@ -68,7 +68,6 @@ import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent import im.vector.matrix.android.api.session.user.model.User import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.dialogs.withColoredButton import im.vector.riotx.core.epoxy.LayoutManagerStateRestorer import im.vector.riotx.core.error.ErrorFormatter @@ -134,7 +133,22 @@ data class RoomDetailArgs( private const val REACTION_SELECT_REQUEST_CODE = 0 -class RoomDetailFragment : +class RoomDetailFragment @Inject constructor( + private val session: Session, + private val avatarRenderer: AvatarRenderer, + private val timelineEventController: TimelineEventController, + private val commandAutocompletePolicy: CommandAutocompletePolicy, + private val autocompleteCommandPresenter: AutocompleteCommandPresenter, + private val autocompleteUserPresenter: AutocompleteUserPresenter, + private val permalinkHandler: PermalinkHandler, + private val notificationDrawerManager: NotificationDrawerManager, + val roomDetailViewModelFactory: RoomDetailViewModel.Factory, + val textComposerViewModelFactory: TextComposerViewModel.Factory, + private val errorFormatter: ErrorFormatter, + private val eventHtmlRenderer: EventHtmlRenderer, + private val vectorPreferences: VectorPreferences, + private val readMarkerHelper: ReadMarkerHelper +) : VectorBaseFragment(), TimelineEventController.Callback, AutocompleteUserPresenter.Callback, @@ -145,12 +159,6 @@ class RoomDetailFragment : companion object { - fun newInstance(args: RoomDetailArgs): RoomDetailFragment { - return RoomDetailFragment().apply { - setArguments(args) - } - } - /**x * Sanitize the display name. * @@ -178,21 +186,6 @@ class RoomDetailFragment : private val debouncer = Debouncer(createUIHandler()) - @Inject lateinit var session: Session - @Inject lateinit var avatarRenderer: AvatarRenderer - @Inject lateinit var timelineEventController: TimelineEventController - @Inject lateinit var commandAutocompletePolicy: CommandAutocompletePolicy - @Inject lateinit var autocompleteCommandPresenter: AutocompleteCommandPresenter - @Inject lateinit var autocompleteUserPresenter: AutocompleteUserPresenter - @Inject lateinit var permalinkHandler: PermalinkHandler - @Inject lateinit var notificationDrawerManager: NotificationDrawerManager - @Inject lateinit var roomDetailViewModelFactory: RoomDetailViewModel.Factory - @Inject lateinit var textComposerViewModelFactory: TextComposerViewModel.Factory - @Inject lateinit var errorFormatter: ErrorFormatter - @Inject lateinit var eventHtmlRenderer: EventHtmlRenderer - @Inject lateinit var vectorPreferences: VectorPreferences - @Inject lateinit var readMarkerHelper: ReadMarkerHelper - private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback private lateinit var scrollOnHighlightedEventCallback: ScrollOnHighlightedEventCallback @@ -211,10 +204,6 @@ class RoomDetailFragment : private var lockSendButton = false - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) actionViewModel = ViewModelProviders.of(requireActivity()).get(ActionsHandler::class.java) @@ -959,6 +948,7 @@ class RoomDetailFragment : val roomId = roomDetailArgs.roomId this.view?.hideKeyboard() + MessageActionsBottomSheet .newInstance(roomId, informationData) .show(requireActivity().supportFragmentManager, "MESSAGE_CONTEXTUAL_ACTIONS") diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt index b9f8579dd5..a3302d40c3 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt @@ -30,7 +30,10 @@ import kotlinx.android.synthetic.main.activity_filtered_rooms.* class FilteredRoomsActivity : VectorBaseActivity() { - private lateinit var roomListFragment: RoomListFragment + private val roomListFragment: RoomListFragment? + get() { + return supportFragmentManager.findFragmentByTag(FRAGMENT_TAG) as? RoomListFragment + } override fun getLayoutRes(): Int { return R.layout.activity_filtered_rooms @@ -44,18 +47,16 @@ class FilteredRoomsActivity : VectorBaseActivity() { super.onCreate(savedInstanceState) configureToolbar(filteredRoomsToolbar) if (isFirstCreation()) { - replaceFragment(roomListFragment, R.id.filteredRoomsFragmentContainer, FRAGMENT_TAG) - } else { - roomListFragment = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG) as RoomListFragment + val params = RoomListParams(RoomListFragment.DisplayMode.FILTERED) + replaceFragment(R.id.filteredRoomsFragmentContainer, RoomListFragment::class.java, params, FRAGMENT_TAG) } - filteredRoomsSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { return true } override fun onQueryTextChange(newText: String): Boolean { - roomListFragment.filterRoomsWith(newText) + roomListFragment?.filterRoomsWith(newText) return true } }) 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 671559b73b..bd91d09aa7 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 @@ -31,7 +31,6 @@ import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.epoxy.LayoutManagerStateRestorer import im.vector.riotx.core.error.ErrorFormatter import im.vector.riotx.core.extensions.observeEvent @@ -73,11 +72,6 @@ class RoomListFragment @Inject constructor( override fun getLayoutResId() = R.layout.fragment_room_list - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - setArguments() - } - private var hasUnreadRooms = false override fun getMenuRes() = R.menu.room_list diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt index 2cb28be998..86156bc4d4 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt @@ -51,7 +51,7 @@ class LoginActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - addFragment(LoginFragment(), R.id.simpleFragmentContainer) + addFragment(R.id.simpleFragmentContainer, LoginFragment::class.java) } // Get config extra @@ -62,7 +62,7 @@ class LoginActivity : VectorBaseActivity() { loginViewModel.navigationLiveData.observeEvent(this) { when (it) { - is Navigation.OpenSsoLoginFallback -> addFragmentToBackstack(LoginSsoFallbackFragment(), R.id.simpleFragmentContainer) + is Navigation.OpenSsoLoginFallback -> addFragmentToBackstack(R.id.simpleFragmentContainer, LoginSsoFallbackFragment::class.java) is Navigation.GoBack -> supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) } } 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 3da21aa1df..7da8a79ac8 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 @@ -26,8 +26,6 @@ import com.airbnb.mvrx.* import com.jakewharton.rxbinding3.view.focusChanges import com.jakewharton.rxbinding3.widget.textChanges import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent -import im.vector.riotx.core.error.ErrorFormatter import im.vector.riotx.core.extensions.setTextWithColoredPart import im.vector.riotx.core.extensions.showPassword import im.vector.riotx.core.platform.VectorBaseFragment @@ -43,20 +41,14 @@ import javax.inject.Inject * What can be improved: * - When filtering more (when entering new chars), we could filter on result we already have, during the new server request, to avoid empty screen effect */ -class LoginFragment : VectorBaseFragment() { +class LoginFragment @Inject constructor() : VectorBaseFragment() { private val viewModel: LoginViewModel by activityViewModel() private var passwordShown = false - @Inject lateinit var errorFormatter: ErrorFormatter - override fun getLayoutResId() = R.layout.fragment_login - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginSsoFallbackFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginSsoFallbackFragment.kt index cac981db84..9e0cd611d1 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginSsoFallbackFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginSsoFallbackFragment.kt @@ -35,17 +35,17 @@ import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.util.JsonDict import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.OnBackPressed import im.vector.riotx.core.platform.VectorBaseFragment import kotlinx.android.synthetic.main.fragment_login_sso_fallback.* import timber.log.Timber import java.net.URLDecoder +import javax.inject.Inject /** * Only login is supported for the moment */ -class LoginSsoFallbackFragment : VectorBaseFragment(), OnBackPressed { +class LoginSsoFallbackFragment @Inject constructor() : VectorBaseFragment(), OnBackPressed { private val viewModel: LoginViewModel by activityViewModel() @@ -62,10 +62,6 @@ class LoginSsoFallbackFragment : VectorBaseFragment(), OnBackPressed { override fun getLayoutResId() = R.layout.fragment_login_sso_fallback - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) 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 a4f443de1e..04fc99bbaa 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 @@ -24,12 +24,13 @@ import com.airbnb.epoxy.EpoxyRecyclerView import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.LiveEvent import javax.inject.Inject -class EmojiSearchResultFragment : VectorBaseFragment() { +class EmojiSearchResultFragment @Inject constructor( + private val epoxyController: EmojiSearchResultController +) : VectorBaseFragment() { override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler_epoxy @@ -37,12 +38,6 @@ class EmojiSearchResultFragment : VectorBaseFragment() { var sharedViewModel: EmojiChooserViewModel? = null - @Inject lateinit var epoxyController: EmojiSearchResultController - - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) 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 955713c0f8..7de3b1dc1e 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 @@ -28,7 +28,6 @@ import com.google.android.material.snackbar.Snackbar import com.jakewharton.rxbinding3.appcompat.queryTextChanges import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.error.ErrorFormatter import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.platform.VectorBaseFragment @@ -42,22 +41,18 @@ import javax.inject.Inject * What can be improved: * - When filtering more (when entering new chars), we could filter on result we already have, during the new server request, to avoid empty screen effect */ -class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback { +class PublicRoomsFragment @Inject constructor( + private val publicRoomsController: PublicRoomsController, + private val errorFormatter: ErrorFormatter +) : VectorBaseFragment(), PublicRoomsController.Callback { private val viewModel: RoomDirectoryViewModel by activityViewModel() private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel - @Inject lateinit var publicRoomsController: PublicRoomsController - @Inject lateinit var errorFormatter: ErrorFormatter - override fun getLayoutResId() = R.layout.fragment_public_rooms override fun getMenuRes() = R.menu.menu_room_directory - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActivity.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActivity.kt index b2dd13e59a..3bdcfa1c8d 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActivity.kt @@ -65,8 +65,8 @@ class RoomDirectoryActivity : VectorBaseActivity() { navigationViewModel.navigateTo.observeEvent(this) { navigation -> when (navigation) { is Navigation.Back -> onBackPressed() - is Navigation.CreateRoom -> addFragmentToBackstack(CreateRoomFragment(), R.id.simpleFragmentContainer) - is Navigation.ChangeProtocol -> addFragmentToBackstack(RoomDirectoryPickerFragment(), R.id.simpleFragmentContainer) + is Navigation.CreateRoom -> addFragmentToBackstack(R.id.simpleFragmentContainer, CreateRoomFragment::class.java) + is Navigation.ChangeProtocol -> addFragmentToBackstack(R.id.simpleFragmentContainer, RoomDirectoryPickerFragment::class.java) is Navigation.Close -> finish() } } @@ -79,7 +79,7 @@ class RoomDirectoryActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - addFragment(PublicRoomsFragment(), R.id.simpleFragmentContainer) + addFragment(R.id.simpleFragmentContainer, PublicRoomsFragment::class.java) } } diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt index 9a3e903954..3cbd033fda 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt @@ -23,7 +23,6 @@ import androidx.appcompat.widget.Toolbar import androidx.lifecycle.ViewModelProviders import com.airbnb.mvrx.viewModel import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.addFragment import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.platform.ToolbarConfigurable @@ -50,16 +49,11 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable { override fun initUiAndData() { if (isFirstCreation()) { - addFragment(CreateRoomFragment(), R.id.simpleFragmentContainer) - + addFragment(R.id.simpleFragmentContainer, CreateRoomFragment::class.java) createRoomViewModel.setName(intent?.getStringExtra(INITIAL_NAME) ?: "") } } - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryNavigationViewModel::class.java) 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 acea19b49a..c772d6d15d 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 @@ -24,7 +24,6 @@ import com.airbnb.mvrx.Success import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel @@ -32,20 +31,15 @@ import kotlinx.android.synthetic.main.fragment_create_room.* import timber.log.Timber import javax.inject.Inject -class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener { +class CreateRoomFragment @Inject constructor(private val createRoomController: CreateRoomController): VectorBaseFragment(), CreateRoomController.Listener { private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel private val viewModel: CreateRoomViewModel by activityViewModel() - @Inject lateinit var createRoomController: CreateRoomController override fun getLayoutResId() = R.layout.fragment_create_room override fun getMenuRes() = R.menu.vector_room_creation - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) vectorBaseActivity.setSupportActionBar(createRoomToolbar) 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 f338c71bbf..ef914f60ca 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 @@ -26,7 +26,6 @@ import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel @@ -37,15 +36,14 @@ import javax.inject.Inject // TODO Set title to R.string.select_room_directory // TODO Menu to add custom room directory (not done in RiotWeb so far...) -class RoomDirectoryPickerFragment : VectorBaseFragment(), RoomDirectoryPickerController.Callback { +class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerViewModelFactory: RoomDirectoryPickerViewModel.Factory, + private val roomDirectoryPickerController: RoomDirectoryPickerController +) : VectorBaseFragment(), RoomDirectoryPickerController.Callback { private val viewModel: RoomDirectoryViewModel by activityViewModel() private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel private val pickerViewModel: RoomDirectoryPickerViewModel by fragmentViewModel() - @Inject lateinit var roomDirectoryPickerViewModelFactory: RoomDirectoryPickerViewModel.Factory - @Inject lateinit var roomDirectoryPickerController: RoomDirectoryPickerController - override fun getLayoutResId() = R.layout.fragment_room_directory_picker override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -71,10 +69,6 @@ class RoomDirectoryPickerFragment : VectorBaseFragment(), RoomDirectoryPickerCon return super.onOptionsItemSelected(item) } - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java) diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt index e4fb122f7a..1bd138552e 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/roompreview/RoomPreviewActivity.kt @@ -67,9 +67,9 @@ class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable { if (args.worldReadable) { // TODO Room preview: Note: M does not recommend to use /events anymore, so for now we just display the room preview // TODO the same way if it was not world readable - addFragment(RoomPreviewNoPreviewFragment.newInstance(args), R.id.simpleFragmentContainer) + addFragment(R.id.simpleFragmentContainer, RoomPreviewNoPreviewFragment::class.java, args) } else { - addFragment(RoomPreviewNoPreviewFragment.newInstance(args), R.id.simpleFragmentContainer) + addFragment(R.id.simpleFragmentContainer, RoomPreviewNoPreviewFragment::class.java, args) } } } 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 e919b0096c..aff89e3b09 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 @@ -19,13 +19,11 @@ package im.vector.riotx.features.roomdirectory.roompreview import android.os.Bundle import android.view.View import androidx.core.view.isVisible -import androidx.fragment.app.Fragment import androidx.transition.TransitionManager import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.error.ErrorFormatter import im.vector.riotx.core.extensions.setTextOrHide import im.vector.riotx.core.platform.ButtonStateView @@ -38,24 +36,15 @@ import javax.inject.Inject /** * Note: this Fragment is also used for world readable room for the moment */ -class RoomPreviewNoPreviewFragment : VectorBaseFragment() { +class RoomPreviewNoPreviewFragment @Inject constructor( + private val errorFormatter: ErrorFormatter, + val roomPreviewViewModelFactory: RoomPreviewViewModel.Factory, + private val avatarRenderer: AvatarRenderer +) : VectorBaseFragment() { - companion object { - fun newInstance(arg: RoomPreviewData): Fragment { - return RoomPreviewNoPreviewFragment().apply { setArguments(arg) } - } - } - - @Inject lateinit var errorFormatter: ErrorFormatter - @Inject lateinit var roomPreviewViewModelFactory: RoomPreviewViewModel.Factory - @Inject lateinit var avatarRenderer: AvatarRenderer private val roomPreviewViewModel: RoomPreviewViewModel by fragmentViewModel() private val roomPreviewData: RoomPreviewData by args() - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setupToolbar(roomPreviewNoPreviewToolbar) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt index cd74dd7016..36536994d5 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt @@ -76,9 +76,9 @@ class VectorSettingsActivity : VectorBaseActivity(), override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean { val oFragment = when { VectorPreferences.SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY == pref.key -> - VectorSettingsNotificationsTroubleshootFragment.newInstance() + supportFragmentManager.fragmentFactory.instantiate(classLoader, VectorSettingsNotificationsTroubleshootFragment::class.java.name) VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY == pref.key -> - VectorSettingsAdvancedNotificationPreferenceFragment.newInstance() + supportFragmentManager.fragmentFactory.instantiate(classLoader, VectorSettingsAdvancedNotificationPreferenceFragment::class.java.name) else -> try { pref.fragment?.let { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt index 380e043ecf..a8328fae52 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt @@ -24,14 +24,15 @@ import androidx.core.content.edit import androidx.preference.Preference import androidx.preference.PreferenceManager import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.preference.BingRule import im.vector.riotx.core.preference.BingRulePreference import im.vector.riotx.core.preference.VectorPreference import im.vector.riotx.features.notifications.NotificationUtils import javax.inject.Inject -class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseFragment() { +class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor( + private val vectorPreferences: VectorPreferences +) : VectorSettingsBaseFragment() { // events listener /* TODO @@ -46,12 +47,6 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences - @Inject lateinit var vectorPreferences: VectorPreferences - - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun bindPref() { val callNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY)!! if (NotificationUtils.supportNotificationChannels()) { @@ -229,7 +224,5 @@ class VectorSettingsAdvancedNotificationPreferenceFragment : VectorSettingsBaseF VectorPreferences.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY to BingRule.RULE_ID_CALL, VectorPreferences.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY to BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS ) - - fun newInstance() = VectorSettingsAdvancedNotificationPreferenceFragment() } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt index a05ccb305d..6ce928c05d 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsHelpAboutFragment.kt @@ -23,24 +23,19 @@ import androidx.preference.Preference import com.google.android.gms.oss.licenses.OssLicensesMenuActivity import im.vector.matrix.android.api.Matrix import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.preference.VectorPreference import im.vector.riotx.core.utils.copyToClipboard import im.vector.riotx.core.utils.displayInWebView import im.vector.riotx.features.version.VersionProvider import javax.inject.Inject -class VectorSettingsHelpAboutFragment : VectorSettingsBaseFragment() { +class VectorSettingsHelpAboutFragment @Inject constructor( + private val versionProvider: VersionProvider +) : VectorSettingsBaseFragment() { override var titleRes = R.string.preference_root_help_about override val preferenceXmlRes = R.xml.vector_settings_help_about - @Inject lateinit var versionProvider: VersionProvider - - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun bindPref() { // preference to start the App info screen, to facilitate App permissions access findPreference(APP_INFO_LINK_PREFERENCE_KEY)!! diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt index cfb4c88259..b397cd1cf6 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt @@ -24,22 +24,21 @@ import im.vector.matrix.android.api.pushrules.RuleIds import im.vector.matrix.android.api.pushrules.RuleKind import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.preference.VectorSwitchPreference import im.vector.riotx.core.pushers.PushersManager import im.vector.riotx.push.fcm.FcmHelper import javax.inject.Inject // Referenced in vector_settings_preferences_root.xml -class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment() { +class VectorSettingsNotificationPreferenceFragment @Inject constructor( + private val pushManager: PushersManager, + private val activeSessionHolder: ActiveSessionHolder, + private val vectorPreferences: VectorPreferences +) : VectorSettingsBaseFragment() { override var titleRes: Int = R.string.settings_notifications override val preferenceXmlRes = R.xml.vector_settings_notifications - @Inject lateinit var pushManager: PushersManager - @Inject lateinit var activeSessionHolder: ActiveSessionHolder - @Inject lateinit var vectorPreferences: VectorPreferences - override fun bindPref() { findPreference(VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY)!!.let { pref -> val pushRuleService = session @@ -57,10 +56,6 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment( } } - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onResume() { super.onResume() activeSessionHolder.getSafeActiveSession()?.refreshPushers() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt index 5737425a3b..6f43114eb4 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt @@ -28,9 +28,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.transition.TransitionManager import butterknife.BindView -import im.vector.matrix.android.api.session.Session import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.rageshake.BugReporter @@ -39,7 +37,10 @@ import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest import im.vector.riotx.push.fcm.NotificationTroubleshootTestManagerFactory import javax.inject.Inject -class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { +class VectorSettingsNotificationsTroubleshootFragment @Inject constructor( + private val bugReporter: BugReporter, + private val testManagerFactory: NotificationTroubleshootTestManagerFactory +) : VectorBaseFragment() { @BindView(R.id.troubleshoot_test_recycler_view) lateinit var mRecyclerView: RecyclerView @@ -54,18 +55,11 @@ class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { private var testManager: NotificationTroubleshootTestManager? = null // members - @Inject lateinit var session: Session - @Inject lateinit var bugReporter: BugReporter - @Inject lateinit var testManagerFactory: NotificationTroubleshootTestManagerFactory override fun getLayoutResId() = R.layout.fragment_settings_notifications_troubleshoot private var interactionListener: VectorSettingsFragmentInteractionListener? = null - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -73,7 +67,7 @@ class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { mRecyclerView.layoutManager = layoutManager val dividerItemDecoration = DividerItemDecoration(mRecyclerView.context, - layoutManager.orientation) + layoutManager.orientation) mRecyclerView.addItemDecoration(dividerItemDecoration) mSummaryButton.setOnClickListener { @@ -88,7 +82,7 @@ class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { private fun startUI() { mSummaryDescription.text = getString(R.string.settings_troubleshoot_diagnostic_running_status, - 0, 0) + 0, 0) testManager = testManagerFactory.create(this) testManager?.statusListener = { troubleshootTestManager -> if (isAdded) { @@ -167,9 +161,4 @@ class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { interactionListener = context } } - - companion object { - // static constructor - fun newInstance() = VectorSettingsNotificationsTroubleshootFragment() - } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt index ab81e6937e..9c240ad093 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt @@ -25,14 +25,16 @@ import androidx.appcompat.app.AlertDialog import androidx.preference.Preference import androidx.preference.SwitchPreference import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.preference.VectorListPreference import im.vector.riotx.core.preference.VectorPreference import im.vector.riotx.features.configuration.VectorConfiguration import im.vector.riotx.features.themes.ThemeUtils import javax.inject.Inject -class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { +class VectorSettingsPreferencesFragment @Inject constructor( + private val vectorConfiguration: VectorConfiguration, + private val vectorPreferences: VectorPreferences +) : VectorSettingsBaseFragment() { override var titleRes = R.string.settings_preferences override val preferenceXmlRes = R.xml.vector_settings_preferences @@ -44,13 +46,6 @@ class VectorSettingsPreferencesFragment : VectorSettingsBaseFragment() { findPreference(VectorPreferences.SETTINGS_INTERFACE_TEXT_SIZE_KEY)!! } - @Inject lateinit var vectorConfiguration: VectorConfiguration - @Inject lateinit var vectorPreferences: VectorPreferences - - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun bindPref() { // user interface preferences setUserInterfacePreferences() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt index a78529f06c..b7ec443ea0 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -40,7 +40,6 @@ import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.model.rest.DeviceInfo import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.dialogs.ExportKeysDialog import im.vector.riotx.core.intent.ExternalIntentData import im.vector.riotx.core.intent.analyseIntent @@ -60,7 +59,9 @@ import java.util.Date import java.util.Locale import javax.inject.Inject -class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { +class VectorSettingsSecurityPrivacyFragment @Inject constructor( + private val vectorPreferences: VectorPreferences +) : VectorSettingsBaseFragment() { override var titleRes = R.string.settings_security_and_privacy override val preferenceXmlRes = R.xml.vector_settings_security_privacy @@ -128,12 +129,6 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { findPreference(VectorPreferences.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY)!! } - @Inject lateinit var vectorPreferences: VectorPreferences - - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun bindPref() { // Push target refreshPushersList() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt index c20ba2e248..ea23ba2583 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt @@ -24,7 +24,6 @@ import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R -import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.resources.StringProvider @@ -33,11 +32,12 @@ import kotlinx.android.synthetic.main.fragment_generic_recycler_epoxy.* import javax.inject.Inject // Referenced in vector_settings_notifications.xml -class PushGatewaysFragment : VectorBaseFragment() { +class PushGatewaysFragment @Inject constructor( + val pushGatewaysViewModelFactory: PushGatewaysViewModel.Factory +) : VectorBaseFragment() { override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler_epoxy - @Inject lateinit var pushGatewaysViewModelFactory: PushGatewaysViewModel.Factory private val viewModel: PushGatewaysViewModel by fragmentViewModel(PushGatewaysViewModel::class) private val epoxyController by lazy { PushGateWayController(StringProvider(requireContext().resources)) } @@ -46,10 +46,6 @@ class PushGatewaysFragment : VectorBaseFragment() { (activity as? VectorBaseActivity)?.supportActionBar?.setTitle(R.string.settings_notifications_targets) } - override fun injectWith(injector: ScreenComponent) { - injector.inject(this) - } - override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) val lmgr = LinearLayoutManager(context, RecyclerView.VERTICAL, false) diff --git a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt index 5e471cf78b..1ec020e1a0 100644 --- a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt @@ -42,9 +42,12 @@ class IncomingShareActivity : @Inject lateinit var sessionHolder: ActiveSessionHolder @Inject lateinit var incomingShareViewModelFactory: IncomingShareViewModel.Factory - private var roomListFragment: RoomListFragment? = null private lateinit var attachmentsHelper: AttachmentsHelper private val incomingShareViewModel: IncomingShareViewModel by viewModel() + private val roomListFragment: RoomListFragment? + get() { + return supportFragmentManager.findFragmentById(R.id.shareRoomListFragmentContainer) as? RoomListFragment + } override fun getLayoutRes(): Int { return R.layout.activity_incoming_share @@ -64,8 +67,7 @@ class IncomingShareActivity : } configureToolbar(incomingShareToolbar) if (isFirstCreation()) { - val loadingDetail = LoadingFragment.newInstance() - replaceFragment(loadingDetail, R.id.shareRoomListFragmentContainer) + replaceFragment(R.id.shareRoomListFragmentContainer, LoadingFragment::class.java) } attachmentsHelper = AttachmentsHelper.create(this, this).register() if (intent?.action == Intent.ACTION_SEND || intent?.action == Intent.ACTION_SEND_MULTIPLE) { @@ -96,8 +98,7 @@ class IncomingShareActivity : override fun onContentAttachmentsReady(attachments: List) { val roomListParams = RoomListParams(RoomListFragment.DisplayMode.SHARE, sharedData = SharedData.Attachments(attachments)) - roomListFragment = RoomListFragment.newInstance(roomListParams) - .also { replaceFragment(it, R.id.shareRoomListFragmentContainer) } + replaceFragment(R.id.shareRoomListFragmentContainer, RoomListFragment::class.java, roomListParams) } override fun onAttachmentsProcessFailed() { @@ -116,8 +117,7 @@ class IncomingShareActivity : false } else { val roomListParams = RoomListParams(RoomListFragment.DisplayMode.SHARE, sharedData = SharedData.Text(sharedText)) - roomListFragment = RoomListFragment.newInstance(roomListParams) - .also { replaceFragment(it, R.id.shareRoomListFragmentContainer) } + replaceFragment(R.id.shareRoomListFragmentContainer, RoomListFragment::class.java, roomListParams) true } }