From 47968c944784ad8c1f91aa1ea37afea12f43bff9 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 21 Jun 2019 10:36:02 +0200 Subject: [PATCH] Dagger: everything should be injected ok now --- .../android/internal/session/DefaultSession.kt | 5 +++-- .../vector/riotredesign/core/di/ScreenComponent.kt | 14 +++++++++++--- .../core/platform/SimpleFragmentActivity.kt | 2 +- .../roomdirectory/RoomDirectoryActivity.kt | 5 +++++ .../settings/VectorSettingsPreferencesFragment.kt | 5 +++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 0d0d0821..5e3f34f2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -43,6 +43,7 @@ import javax.inject.Inject @SessionScope internal class DefaultSession @Inject constructor(override val sessionParams: SessionParams, + private val liveEntityObservers: Set<@JvmSuppressWildcards LiveEntityObserver>, private val monarchy: Monarchy, private val sessionListeners: SessionListeners, private val roomService: RoomService, @@ -76,7 +77,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se if (!monarchy.isMonarchyThreadOpen) { monarchy.openManually() } - //liveEntityObservers.forEach { it.start() } + liveEntityObservers.forEach { it.start() } } @MainThread @@ -95,7 +96,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se override fun close() { assertMainThread() assert(isOpen) - //liveEntityObservers.forEach { it.dispose() } + liveEntityObservers.forEach { it.dispose() } cryptoService.close() if (monarchy.isMonarchyThreadOpen) { monarchy.closeManually() diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt index 1c28b8ef..90194074 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt @@ -21,10 +21,11 @@ import androidx.lifecycle.ViewModelProvider import dagger.BindsInstance import dagger.Component import im.vector.fragments.keysbackup.restore.KeysBackupRestoreFromPassphraseFragment -import im.vector.riotredesign.core.platform.SimpleFragmentActivity +import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.features.MainActivity import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreFromKeyFragment import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreSuccessFragment +import im.vector.riotredesign.features.crypto.keysbackup.settings.KeysBackupManageActivity import im.vector.riotredesign.features.crypto.keysbackup.settings.KeysBackupSettingsFragment import im.vector.riotredesign.features.crypto.keysbackup.setup.KeysBackupSetupStep1Fragment import im.vector.riotredesign.features.crypto.keysbackup.setup.KeysBackupSetupStep2Fragment @@ -44,18 +45,20 @@ import im.vector.riotredesign.features.home.room.list.RoomListFragment import im.vector.riotredesign.features.login.LoginActivity import im.vector.riotredesign.features.reactions.EmojiReactionPickerActivity import im.vector.riotredesign.features.roomdirectory.PublicRoomsFragment +import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity import im.vector.riotredesign.features.roomdirectory.createroom.CreateRoomFragment import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerFragment import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewNoPreviewFragment import im.vector.riotredesign.features.settings.VectorSettingsActivity +import im.vector.riotredesign.features.settings.VectorSettingsPreferencesFragment @Component(dependencies = [VectorComponent::class], modules = [ViewModelModule::class, HomeModule::class]) @ScreenScope interface ScreenComponent { - fun viewModelFactory(): ViewModelProvider.Factory + fun session(): Session - fun inject(activity: SimpleFragmentActivity) + fun viewModelFactory(): ViewModelProvider.Factory fun inject(activity: HomeActivity) @@ -85,6 +88,8 @@ interface ScreenComponent { fun inject(createRoomFragment: CreateRoomFragment) + fun inject(keysBackupManageActivity: KeysBackupManageActivity) + fun inject(keysBackupRestoreFromKeyFragment: KeysBackupRestoreFromKeyFragment) fun inject(keysBackupRestoreFromPassphraseFragment: KeysBackupRestoreFromPassphraseFragment) @@ -109,6 +114,9 @@ interface ScreenComponent { fun inject(mainActivity: MainActivity) + fun inject(vectorSettingsPreferencesFragment: VectorSettingsPreferencesFragment) + + fun inject(roomDirectoryActivity: RoomDirectoryActivity) @Component.Factory interface Factory { diff --git a/vector/src/main/java/im/vector/riotredesign/core/platform/SimpleFragmentActivity.kt b/vector/src/main/java/im/vector/riotredesign/core/platform/SimpleFragmentActivity.kt index 8c9bfbde..b02b2cb8 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/platform/SimpleFragmentActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/platform/SimpleFragmentActivity.kt @@ -48,7 +48,7 @@ abstract class SimpleFragmentActivity : VectorBaseActivity() { @Inject lateinit var session: Session override fun injectWith(injector: ScreenComponent) { - injector.inject(this) + session = injector.session() } override fun initUiAndData() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryActivity.kt index 64853b8d..1b99b5a1 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryActivity.kt @@ -19,6 +19,7 @@ package im.vector.riotredesign.features.roomdirectory import android.os.Bundle import androidx.lifecycle.ViewModelProviders import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.addFragment import im.vector.riotredesign.core.extensions.addFragmentToBackstack import im.vector.riotredesign.core.extensions.observeEvent @@ -43,6 +44,10 @@ class RoomDirectoryActivity : VectorBaseActivity() { override fun getLayoutRes() = R.layout.activity_simple + 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/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt index 1d2371c8..aa067cc5 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt @@ -50,6 +50,7 @@ import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.internal.crypto.model.rest.DeviceInfo import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.DaggerScreenComponent import im.vector.riotredesign.core.dialogs.ExportKeysDialog import im.vector.riotredesign.core.extensions.showPassword import im.vector.riotredesign.core.extensions.withArgs @@ -96,6 +97,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // TODO } // TODO } + private var mLoadingView: View? = null private var mDisplayedEmails = ArrayList() @@ -809,10 +811,13 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref } override fun onAttach(context: Context) { + val screenComponent = DaggerScreenComponent.factory().create(vectorActivity.getVectorComponent(), vectorActivity) super.onAttach(context) + screenComponent.inject(this) if (context is VectorSettingsFragmentInteractionListener) { interactionListener = context } + } override fun onDetach() {