Dagger: everything should be injected ok now

This commit is contained in:
ganfra 2019-06-21 10:36:02 +02:00
parent 07fee8ed3d
commit 47968c9447
5 changed files with 25 additions and 6 deletions

View File

@ -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()

View File

@ -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 {

View File

@ -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() {

View File

@ -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)

View File

@ -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<String>()
@ -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() {