From ee87c253fec6433705c0660aa8cc40334b3d7b73 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 19 Jun 2019 19:40:59 +0200 Subject: [PATCH] Dagger: continue working on app side. Now compile but some DI are not branched yet. --- .../main/java/im/vector/matrix/rx/RxRoom.kt | 5 + .../vector/riotredesign/VectorApplication.kt | 3 + .../riotredesign/core/di/ScreenComponent.kt | 58 ++++++++ .../riotredesign/core/di/VectorComponent.kt | 6 + .../riotredesign/core/di/ViewModelModule.kt | 47 ++++--- .../core/platform/SimpleFragmentActivity.kt | 9 +- .../core/platform/VectorBaseActivity.kt | 14 +- .../core/platform/VectorBaseFragment.kt | 16 ++- .../core/services/EventStreamServiceX.kt | 14 +- .../KeysBackupRestoreFromKeyFragment.kt | 5 + ...KeysBackupRestoreFromPassphraseFragment.kt | 5 + .../KeysBackupRestoreSuccessFragment.kt | 5 + .../settings/KeysBackupManageActivity.kt | 5 +- .../settings/KeysBackupSettingsFragment.kt | 7 +- .../setup/KeysBackupSetupStep1Fragment.kt | 5 + .../setup/KeysBackupSetupStep2Fragment.kt | 5 + .../setup/KeysBackupSetupStep3Fragment.kt | 5 + .../SASVerificationIncomingFragment.kt | 5 + .../features/home/HomeActivity.kt | 8 +- .../features/home/HomeDetailFragment.kt | 5 + .../features/home/HomeDrawerFragment.kt | 7 +- .../features/home/HomeNavigator.kt | 3 + .../features/home/group/GroupListFragment.kt | 6 + .../home/room/detail/RoomDetailFragment.kt | 6 +- .../action/MessageActionsBottomSheet.kt | 6 +- .../timeline/action/MessageMenuFragment.kt | 19 ++- .../timeline/action/QuickReactionFragment.kt | 16 +-- ...=> VectorBaseBottomSheetDialogFragment.kt} | 20 ++- .../action/ViewReactionBottomSheet.kt | 12 +- .../timeline/action/ViewReactionViewModel.kt | 125 ++++++++---------- .../home/room/list/RoomListFragment.kt | 5 + .../features/navigation/DefaultNavigator.kt | 2 + .../reactions/EmojiReactionPickerActivity.kt | 8 +- .../roomdirectory/PublicRoomsController.kt | 3 +- .../roomdirectory/PublicRoomsFragment.kt | 5 + .../roomdirectory/RoomDirectoryModule.kt | 54 -------- .../createroom/CreateRoomController.kt | 3 +- .../createroom/CreateRoomFragment.kt | 18 ++- .../createroom/CreateRoomViewModel.kt | 18 ++- .../picker/RoomDirectoryPickerFragment.kt | 6 +- .../RoomPreviewNoPreviewFragment.kt | 6 +- .../settings/VectorSettingsActivity.kt | 9 +- ...sAdvancedNotificationPreferenceFragment.kt | 4 +- ...ttingsNotificationsTroubleshootFragment.kt | 6 +- .../VectorSettingsPreferencesFragment.kt | 42 +++--- .../main/res/layout/fragment_message_menu.xml | 5 + 46 files changed, 406 insertions(+), 240 deletions(-) rename vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/{BaseMvRxBottomSheetDialog.kt => VectorBaseBottomSheetDialogFragment.kt} (73%) delete mode 100644 vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryModule.kt create mode 100644 vector/src/main/res/layout/fragment_message_menu.xml diff --git a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt index c9dbbdd0..ec6e1203 100644 --- a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt +++ b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxRoom.kt @@ -17,6 +17,7 @@ package im.vector.matrix.rx import im.vector.matrix.android.api.session.room.Room +import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary import im.vector.matrix.android.api.session.room.model.RoomSummary import io.reactivex.Observable @@ -30,6 +31,10 @@ class RxRoom(private val room: Room) { return room.getRoomMemberIdsLive().asObservable() } + fun liveAnnotationSummary(eventId: String): Observable> { + return room.getEventSummaryLive(eventId).asObservable() + } + } fun Room.rx(): RxRoom { diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index ed57d347..f740bec0 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -31,6 +31,7 @@ import com.github.piasy.biv.BigImageViewer import com.github.piasy.biv.loader.glide.GlideImageLoader import com.jakewharton.threetenabp.AndroidThreeTen import im.vector.matrix.android.api.Matrix +import im.vector.riotredesign.core.di.DaggerVectorComponent import im.vector.riotredesign.core.di.HasInjector import im.vector.riotredesign.core.di.VectorComponent import im.vector.riotredesign.features.configuration.VectorConfiguration @@ -53,6 +54,8 @@ class VectorApplication : Application(), HasInjector { override fun onCreate() { super.onCreate() appContext = this + vectorComponent = DaggerVectorComponent.factory().create(this) + vectorComponent.inject(this) VectorUncaughtExceptionHandler.activate(this) // Log VectorFileLogger.init(this) 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 1f20979a..46320f4e 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 @@ -20,13 +20,32 @@ import androidx.appcompat.app.AppCompatActivity 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.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreFromKeyFragment +import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreSuccessFragment 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 +import im.vector.riotredesign.features.crypto.keysbackup.setup.KeysBackupSetupStep3Fragment +import im.vector.riotredesign.features.crypto.verification.SASVerificationIncomingFragment import im.vector.riotredesign.features.home.HomeActivity +import im.vector.riotredesign.features.home.HomeDetailFragment +import im.vector.riotredesign.features.home.HomeDrawerFragment import im.vector.riotredesign.features.home.HomeModule +import im.vector.riotredesign.features.home.group.GroupListFragment import im.vector.riotredesign.features.home.room.detail.RoomDetailFragment +import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageActionsBottomSheet +import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageMenuFragment +import im.vector.riotredesign.features.home.room.detail.timeline.action.QuickReactionFragment +import im.vector.riotredesign.features.home.room.detail.timeline.action.ViewReactionBottomSheet +import im.vector.riotredesign.features.home.room.list.RoomListFragment +import im.vector.riotredesign.features.reactions.EmojiReactionPickerActivity +import im.vector.riotredesign.features.roomdirectory.PublicRoomsFragment +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 @Component(dependencies = [VectorComponent::class], modules = [ViewModelModule::class, HomeModule::class]) @ScreenScope @@ -40,12 +59,51 @@ interface ScreenComponent { 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(viewReactionBottomSheet: ViewReactionBottomSheet) + + fun inject(messageMenuFragment: MessageMenuFragment) + + fun inject(vectorSettingsActivity: VectorSettingsActivity) + + fun inject(createRoomFragment: CreateRoomFragment) + + 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(sasVerificationIncomingFragment: SASVerificationIncomingFragment) + + fun inject(quickReactionFragment: QuickReactionFragment) + + fun inject(emojiReactionPickerActivity: EmojiReactionPickerActivity) + + @Component.Factory interface Factory { fun create(vectorComponent: VectorComponent, diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt b/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt index 6517c4b9..100716f6 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt @@ -22,9 +22,11 @@ import dagger.BindsInstance import dagger.Component import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.session.Session +import im.vector.riotredesign.VectorApplication import im.vector.riotredesign.features.configuration.VectorConfiguration import im.vector.riotredesign.features.crypto.keysrequest.KeyRequestHandler import im.vector.riotredesign.features.crypto.verification.IncomingVerificationRequestHandler +import im.vector.riotredesign.features.home.HomeNavigator import im.vector.riotredesign.features.home.HomeRoomListObservableStore import im.vector.riotredesign.features.home.group.SelectedGroupStore import im.vector.riotredesign.features.navigation.Navigator @@ -49,6 +51,8 @@ interface VectorComponent { fun navigator(): Navigator + fun homeNavigator(): HomeNavigator + fun homeRoomListObservableStore(): HomeRoomListObservableStore fun selectedGroupStore(): SelectedGroupStore @@ -57,6 +61,8 @@ interface VectorComponent { fun incomingKeyRequestHandler(): KeyRequestHandler + fun inject(vectorApplication: VectorApplication) + @Component.Factory interface Factory { fun create(@BindsInstance context: Context): VectorComponent diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/ViewModelModule.kt b/vector/src/main/java/im/vector/riotredesign/core/di/ViewModelModule.kt index c38608ff..34b3e150 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/ViewModelModule.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/ViewModelModule.kt @@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModelProvider import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap +import im.vector.riotredesign.core.platform.ConfigurationViewModel import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreFromKeyViewModel import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreFromPassphraseViewModel import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreSharedViewModel @@ -39,18 +40,15 @@ import im.vector.riotredesign.features.home.room.detail.RoomDetailViewModel import im.vector.riotredesign.features.home.room.detail.RoomDetailViewModel_AssistedFactory import im.vector.riotredesign.features.home.room.detail.composer.TextComposerViewModel import im.vector.riotredesign.features.home.room.detail.composer.TextComposerViewModel_AssistedFactory -import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageActionsViewModel -import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageActionsViewModel_AssistedFactory -import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageMenuViewModel -import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageMenuViewModel_AssistedFactory -import im.vector.riotredesign.features.home.room.detail.timeline.action.QuickReactionViewModel -import im.vector.riotredesign.features.home.room.detail.timeline.action.QuickReactionViewModel_AssistedFactory +import im.vector.riotredesign.features.home.room.detail.timeline.action.* import im.vector.riotredesign.features.home.room.list.RoomListViewModel import im.vector.riotredesign.features.home.room.list.RoomListViewModel_AssistedFactory import im.vector.riotredesign.features.reactions.EmojiChooserViewModel import im.vector.riotredesign.features.roomdirectory.RoomDirectoryNavigationViewModel import im.vector.riotredesign.features.roomdirectory.RoomDirectoryViewModel import im.vector.riotredesign.features.roomdirectory.RoomDirectoryViewModel_AssistedFactory +import im.vector.riotredesign.features.roomdirectory.createroom.CreateRoomViewModel +import im.vector.riotredesign.features.roomdirectory.createroom.CreateRoomViewModel_AssistedFactory import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerViewModel import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerViewModel_AssistedFactory import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewViewModel @@ -109,42 +107,53 @@ interface ViewModelModule { fun bindKeysBackupSetupSharedViewModel(viewModel: KeysBackupSetupSharedViewModel): ViewModel @Binds - fun bind_im_vector_riotredesign_features_home_HomeActivityViewModel(factory: HomeActivityViewModel_AssistedFactory): HomeActivityViewModel.Factory + @IntoMap + @ViewModelKey(ConfigurationViewModel::class) + fun bindConfigurationViewModel(viewModel: ConfigurationViewModel): ViewModel @Binds - fun bind_im_vector_riotredesign_features_home_room_detail_composer_TextComposerViewModel(factory: TextComposerViewModel_AssistedFactory): TextComposerViewModel.Factory + fun bindHomeActivityViewModelFactory(factory: HomeActivityViewModel_AssistedFactory): HomeActivityViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_room_detail_RoomDetailViewModel(factory: RoomDetailViewModel_AssistedFactory): RoomDetailViewModel.Factory + fun bindTextComposerViewModelFactory(factory: TextComposerViewModel_AssistedFactory): TextComposerViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_room_detail_timeline_action_QuickReactionViewModel(factory: QuickReactionViewModel_AssistedFactory): QuickReactionViewModel.Factory + fun bindRoomDetailViewModelFactory(factory: RoomDetailViewModel_AssistedFactory): RoomDetailViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_room_detail_timeline_action_MessageActionsViewModel(factory: MessageActionsViewModel_AssistedFactory): MessageActionsViewModel.Factory + fun bindQuickReactionViewModelFactory(factory: QuickReactionViewModel_AssistedFactory): QuickReactionViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_room_detail_timeline_action_MessageMenuViewModel(factory: MessageMenuViewModel_AssistedFactory): MessageMenuViewModel.Factory + fun bindMessageActionsViewModelFactory(factory: MessageActionsViewModel_AssistedFactory): MessageActionsViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_room_list_RoomListViewModel(factory: RoomListViewModel_AssistedFactory): RoomListViewModel.Factory + fun bindMessageMenuViewModelFactory(factory: MessageMenuViewModel_AssistedFactory): MessageMenuViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_group_GroupListViewModel(factory: GroupListViewModel_AssistedFactory): GroupListViewModel.Factory + fun bindRoomListViewModelFactory(factory: RoomListViewModel_AssistedFactory): RoomListViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_home_HomeDetailViewModel(factory: HomeDetailViewModel_AssistedFactory): HomeDetailViewModel.Factory + fun bindGroupListViewModelFactory(factory: GroupListViewModel_AssistedFactory): GroupListViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_crypto_keysbackup_settings_KeysBackupSettingsViewModel(factory: KeysBackupSettingsViewModel_AssistedFactory): KeysBackupSettingsViewModel.Factory + fun bindHomeDetailViewModelFactory(factory: HomeDetailViewModel_AssistedFactory): HomeDetailViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_roomdirectory_picker_RoomDirectoryPickerViewModel(factory: RoomDirectoryPickerViewModel_AssistedFactory): RoomDirectoryPickerViewModel.Factory + fun bindKeysBackupSettingsViewModelFactory(factory: KeysBackupSettingsViewModel_AssistedFactory): KeysBackupSettingsViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_roomdirectory_RoomDirectoryViewModel(factory: RoomDirectoryViewModel_AssistedFactory): RoomDirectoryViewModel.Factory + fun bindRoomDirectoryPickerViewModelFactory(factory: RoomDirectoryPickerViewModel_AssistedFactory): RoomDirectoryPickerViewModel.Factory @Binds - fun bind_im_vector_riotredesign_features_roomdirectory_roompreview_RoomPreviewViewModel(factory: RoomPreviewViewModel_AssistedFactory): RoomPreviewViewModel.Factory + fun bindRoomDirectoryViewModelFactory(factory: RoomDirectoryViewModel_AssistedFactory): RoomDirectoryViewModel.Factory + + @Binds + fun bindRoomPreviewViewModelFactory(factory: RoomPreviewViewModel_AssistedFactory): RoomPreviewViewModel.Factory + + @Binds + fun bindViewReactionViewModelFactory(factory: ViewReactionViewModel_AssistedFactory): ViewReactionViewModel.Factory + + @Binds + fun bindCreateRoomViewModelFactory(factory: CreateRoomViewModel_AssistedFactory): CreateRoomViewModel.Factory } \ No newline at end of file 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 2b891275..8c9bfbde 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 @@ -24,6 +24,7 @@ import androidx.core.view.isVisible import butterknife.BindView import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.hideKeyboard import kotlinx.android.synthetic.main.activity.* import javax.inject.Inject @@ -44,12 +45,10 @@ abstract class SimpleFragmentActivity : VectorBaseActivity() { @BindView(R.id.waiting_view_status_horizontal_progress) lateinit var waitingHorizontalProgress: ProgressBar - @Inject - lateinit var session: Session + @Inject lateinit var session: Session - override fun onCreate(savedInstanceState: Bundle?) { - injector().inject(this) - super.onCreate(savedInstanceState) + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) } override fun initUiAndData() { diff --git a/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseActivity.kt index 830ebcf6..7296b7d5 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseActivity.kt @@ -44,8 +44,10 @@ import com.bumptech.glide.util.Util import com.google.android.material.snackbar.Snackbar import im.vector.riotredesign.BuildConfig import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.DaggerScreenComponent import im.vector.riotredesign.core.di.HasInjector import im.vector.riotredesign.core.di.ScreenComponent +import im.vector.riotredesign.core.di.VectorComponent import im.vector.riotredesign.core.utils.toast import im.vector.riotredesign.features.configuration.VectorConfiguration import im.vector.riotredesign.features.rageshake.BugReportActivity @@ -78,7 +80,6 @@ abstract class VectorBaseActivity : BaseMvRxActivity(), HasInjector).injector() + } + /** * Force to render the activity in fullscreen */ diff --git a/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseFragment.kt b/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseFragment.kt index 137c680c..f1fa25f7 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/platform/VectorBaseFragment.kt @@ -16,6 +16,7 @@ package im.vector.riotredesign.core.platform +import android.content.Context import android.os.Bundle import android.os.Parcelable import android.view.LayoutInflater @@ -33,6 +34,7 @@ import butterknife.Unbinder import com.airbnb.mvrx.BaseMvRxFragment import com.airbnb.mvrx.MvRx import com.bumptech.glide.util.Util.assertMainThread +import im.vector.riotredesign.core.di.DaggerScreenComponent import im.vector.riotredesign.core.di.HasInjector import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.features.navigation.Navigator @@ -55,11 +57,22 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed, HasInject protected lateinit var viewModelFactory: ViewModelProvider.Factory protected lateinit var navigator: Navigator + private lateinit var screenComponent: ScreenComponent /* ========================================================================================== * Life cycle * ========================================================================================== */ + override fun onAttach(context: Context) { + screenComponent = DaggerScreenComponent.factory().create(vectorBaseActivity.getVectorComponent(), vectorBaseActivity) + super.onAttach(context) + navigator = vectorBaseActivity.getVectorComponent().navigator() + viewModelFactory = screenComponent.viewModelFactory() + injectWith(injector()) + } + + protected open fun injectWith(injector: ScreenComponent) = Unit + @CallSuper override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -78,7 +91,6 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed, HasInject @CallSuper override fun onResume() { super.onResume() - Timber.v("onResume Fragment ${this.javaClass.simpleName}") } @@ -101,7 +113,7 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed, HasInject } override fun injector(): ScreenComponent { - return vectorBaseActivity.injector() + return screenComponent } /* ========================================================================================== diff --git a/vector/src/main/java/im/vector/riotredesign/core/services/EventStreamServiceX.kt b/vector/src/main/java/im/vector/riotredesign/core/services/EventStreamServiceX.kt index 0f26887e..6c4b7043 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/services/EventStreamServiceX.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/services/EventStreamServiceX.kt @@ -30,6 +30,7 @@ import im.vector.riotredesign.features.notifications.NotifiableEventResolver import im.vector.riotredesign.features.notifications.NotificationUtils import timber.log.Timber import java.util.concurrent.TimeUnit +import javax.inject.Inject /** * A service in charge of controlling whether the event stream is running or not. @@ -41,7 +42,7 @@ class EventStreamServiceX : VectorService() { /** * Managed session (no multi session for Riot) */ - private val mSession by inject() + @Inject lateinit var session: Session /** * Set to true to simulate a push immediately when service is destroyed @@ -135,6 +136,11 @@ class EventStreamServiceX : VectorService() { STARTED } + override fun onCreate() { + //setup injector + super.onCreate() + } + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { // Cancel any previous worker cancelAnySimulatedPushSchedule() @@ -168,7 +174,7 @@ class EventStreamServiceX : VectorService() { } } - if (null == mSession) { + if (null == session) { Timber.e("onStartCommand : no sessions") myStopSelf() return START_NOT_STICKY @@ -334,7 +340,7 @@ class EventStreamServiceX : VectorService() { // TODO mPushManager = Matrix.getInstance(applicationContext)!!.pushManager mNotifiableEventResolver = NotifiableEventResolver(applicationContext) - monitorSession(mSession!!) + monitorSession(session!!) serviceState = if (forPush) { ServiceState.CATCHUP @@ -387,7 +393,7 @@ class EventStreamServiceX : VectorService() { } if (canCatchup) { - if (mSession != null) { + if (session != null) { // TODO session!!.catchupEventStream() } else { Timber.i("catchup no session") diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt index f104791f..0c2eb788 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt @@ -28,6 +28,7 @@ import butterknife.OnClick import butterknife.OnTextChanged import com.google.android.material.textfield.TextInputLayout import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.core.utils.startImportTextFromFileIntent import timber.log.Timber @@ -50,6 +51,10 @@ 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) diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt index 57ca3743..a0da69fb 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseFragment.kt @@ -33,6 +33,7 @@ import butterknife.OnClick import butterknife.OnTextChanged import com.google.android.material.textfield.TextInputLayout import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.showPassword import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreFromPassphraseViewModel @@ -66,6 +67,10 @@ class KeysBackupRestoreFromPassphraseFragment : VectorBaseFragment() { fun newInstance() = KeysBackupRestoreFromPassphraseFragment() } + 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/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt index 6b4cc8b7..def561ac 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreSuccessFragment.kt @@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModelProviders import butterknife.BindView import butterknife.OnClick import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.core.utils.LiveEvent @@ -36,6 +37,10 @@ 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/riotredesign/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt index bc83aaf9..273b32aa 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt @@ -23,7 +23,7 @@ import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Loading import com.airbnb.mvrx.viewModel import im.vector.riotredesign.R -import im.vector.riotredesign.core.extensions.injector +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.SimpleFragmentActivity import im.vector.riotredesign.core.platform.WaitingViewData import javax.inject.Inject @@ -43,9 +43,8 @@ class KeysBackupManageActivity : SimpleFragmentActivity() { private val viewModel: KeysBackupSettingsViewModel by viewModel() @Inject lateinit var keysBackupSettingsViewModelFactory: KeysBackupSettingsViewModel.Factory - override fun onCreate(savedInstanceState: Bundle?) { + override fun injectWith(injector: ScreenComponent) { injector.inject(this) - super.onCreate(savedInstanceState) } override fun initUiAndData() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt index 3a0239d0..72a97f37 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsFragment.kt @@ -21,7 +21,7 @@ import androidx.appcompat.app.AlertDialog import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.R -import im.vector.riotredesign.core.extensions.injector +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreActivity import im.vector.riotredesign.features.crypto.keysbackup.setup.KeysBackupSetupActivity @@ -40,9 +40,8 @@ class KeysBackupSettingsFragment : VectorBaseFragment(), @Inject lateinit var keysBackupSettingsRecyclerViewController: KeysBackupSettingsRecyclerViewController private val viewModel: KeysBackupSettingsViewModel by activityViewModel() - override fun onCreate(savedInstanceState: Bundle?) { - injector().inject(this) - super.onCreate(savedInstanceState) + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt index f90983f7..d1fe142a 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep1Fragment.kt @@ -25,6 +25,7 @@ import androidx.lifecycle.ViewModelProviders import butterknife.BindView import butterknife.OnClick import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.core.utils.LiveEvent @@ -45,6 +46,10 @@ 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/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt index 5267c22b..7d0ca797 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt @@ -31,6 +31,7 @@ import butterknife.OnTextChanged import com.google.android.material.textfield.TextInputLayout import com.nulabinc.zxcvbn.Zxcvbn import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.showPassword import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.core.ui.views.PasswordStrengthBar @@ -77,6 +78,10 @@ class KeysBackupSetupStep2Fragment : VectorBaseFragment() { private lateinit var viewModel: KeysBackupSetupSharedViewModel + 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/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt index 0a738bf5..bf44cac4 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt @@ -29,6 +29,7 @@ import butterknife.BindView import butterknife.OnClick import com.google.android.material.bottomsheet.BottomSheetDialog import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.files.addEntryToDownloadManager import im.vector.riotredesign.core.files.saveStringToFile import im.vector.riotredesign.core.platform.VectorBaseFragment @@ -54,6 +55,10 @@ class KeysBackupSetupStep3Fragment : VectorBaseFragment() { private lateinit var viewModel: KeysBackupSetupSharedViewModel + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) viewModel = activity?.run { diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/SASVerificationIncomingFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/SASVerificationIncomingFragment.kt index 9f893afc..b8549995 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/SASVerificationIncomingFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/SASVerificationIncomingFragment.kt @@ -24,6 +24,7 @@ import butterknife.BindView import butterknife.OnClick import im.vector.matrix.android.api.session.crypto.sas.IncomingSasVerificationTransaction import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.home.AvatarRenderer @@ -49,6 +50,10 @@ class SASVerificationIncomingFragment : VectorBaseFragment() { private lateinit var viewModel: SasVerificationViewModel + 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/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index fb5671d2..497d108b 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -31,6 +31,7 @@ import androidx.lifecycle.ViewModelProviders import com.airbnb.mvrx.viewModel import im.vector.matrix.android.api.Matrix import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.hideKeyboard import im.vector.riotredesign.core.extensions.observeEvent import im.vector.riotredesign.core.extensions.replaceFragment @@ -73,6 +74,10 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun getLayoutRes() = R.layout.activity_home + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) homeNavigator.activity = this @@ -103,9 +108,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { is Navigation.OpenDrawer -> drawerLayout.openDrawer(GravityCompat.START) } } - - incomingVerificationRequestHandler.ensureStarted() - keyRequestHandler.ensureStarted() } override fun onDestroy() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailFragment.kt index bb03f2cd..23eb943d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailFragment.kt @@ -32,6 +32,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.sync.SyncState import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.ToolbarConfigurable import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.core.ui.views.KeysBackupBanner @@ -74,6 +75,10 @@ class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate { return R.layout.fragment_home_detail } + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) currentDisplayMode = savedInstanceState?.getSerializable(CURRENT_DISPLAY_MODE) as? RoomListFragment.DisplayMode diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt index 49ee8f67..28b8cf20 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt @@ -19,6 +19,7 @@ package im.vector.riotredesign.features.home import android.os.Bundle import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.observeK import im.vector.riotredesign.core.extensions.replaceChildFragment import im.vector.riotredesign.core.platform.VectorBaseFragment @@ -39,6 +40,10 @@ class HomeDrawerFragment : 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) { @@ -62,4 +67,4 @@ class HomeDrawerFragment : VectorBaseFragment() { navigator.openDebug(requireActivity()) } } -} \ No newline at end of file +} diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt index bc3b7bfb..35031bd2 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt @@ -20,12 +20,15 @@ import androidx.core.view.GravityCompat import androidx.fragment.app.FragmentManager import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenScope import im.vector.riotredesign.core.extensions.replaceFragment import im.vector.riotredesign.features.navigation.Navigator import kotlinx.android.synthetic.main.activity_home.* import timber.log.Timber import javax.inject.Inject +import javax.inject.Singleton +@Singleton class HomeNavigator @Inject constructor() { var activity: HomeActivity? = null diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/group/GroupListFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/group/GroupListFragment.kt index 58715088..30f6d0d8 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/group/GroupListFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/group/GroupListFragment.kt @@ -16,12 +16,14 @@ package im.vector.riotredesign.features.home.group +import android.content.Context import android.os.Bundle import com.airbnb.mvrx.Incomplete import com.airbnb.mvrx.Success import com.airbnb.mvrx.fragmentViewModel import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.observeEvent import im.vector.riotredesign.core.platform.StateView import im.vector.riotredesign.core.platform.VectorBaseFragment @@ -45,6 +47,10 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback override fun getLayoutResId() = R.layout.fragment_group_list + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) groupController.callback = this diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt index 16124ccc..f2eeaa99 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt @@ -67,6 +67,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageVideoConte import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.user.model.User import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.dialogs.DialogListItem import im.vector.riotredesign.core.epoxy.LayoutManagerStateRestorer import im.vector.riotredesign.core.extensions.hideKeyboard @@ -189,8 +190,11 @@ class RoomDetailFragment : @BindView(R.id.composerLayout) lateinit var composerLayout: TextComposerView + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { - injector().inject(this) super.onActivityCreated(savedInstanceState) actionViewModel = ViewModelProviders.of(requireActivity()).get(ActionsHandler::class.java) setupToolbar(roomToolbar) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt index 9a321c24..d32e83a6 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt @@ -33,6 +33,7 @@ import com.airbnb.mvrx.withState import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.features.home.AvatarRenderer import im.vector.riotredesign.features.home.room.detail.timeline.item.MessageInformationData import kotlinx.android.synthetic.main.bottom_sheet_message_actions.* @@ -42,7 +43,7 @@ import javax.inject.Inject * Bottom sheet fragment that shows a message preview with list of contextual actions * (Includes fragments for quick reactions and list of actions) */ -class MessageActionsBottomSheet : BaseMvRxBottomSheetDialog() { +class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment() { @Inject lateinit var messageActionViewModelFactory: MessageActionsViewModel.Factory private val viewModel: MessageActionsViewModel by fragmentViewModel(MessageActionsViewModel::class) @@ -61,6 +62,9 @@ class MessageActionsBottomSheet : BaseMvRxBottomSheetDialog() { @BindView(R.id.bottom_sheet_message_preview_body) lateinit var messageBodyTextView: TextView + override fun injectWith(screenComponent: ScreenComponent) { + screenComponent.inject(this) + } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.bottom_sheet_message_actions, container, false) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt index 116c792c..a45df7e1 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuFragment.kt @@ -23,24 +23,31 @@ import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView -import com.airbnb.mvrx.BaseMvRxFragment import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent +import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.themes.ThemeUtils import javax.inject.Inject /** * Fragment showing the list of available contextual action for a given message. */ -class MessageMenuFragment : BaseMvRxFragment() { +class MessageMenuFragment : VectorBaseFragment() { @Inject lateinit var messageMenuViewModelFactory: MessageMenuViewModel.Factory private val viewModel: MessageMenuViewModel by fragmentViewModel(MessageMenuViewModel::class) private var addSeparators = false var interactionListener: InteractionListener? = null + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + + override fun getLayoutResId() = R.layout.fragment_message_menu + override fun invalidate() = withState(viewModel) { state -> val linearLayout = view as? LinearLayout @@ -68,14 +75,6 @@ class MessageMenuFragment : BaseMvRxFragment() { } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - //we just create programmatically - val contentView = LinearLayout(context) - contentView.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) - contentView.orientation = LinearLayout.VERTICAL - return contentView - } - private fun inflateActionView(action: SimpleAction, inflater: LayoutInflater, container: ViewGroup?): View? { return inflater.inflate(R.layout.adapter_item_action, container, false)?.apply { if (action.iconResId != null) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt index 96d7052c..cd58c9cf 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/QuickReactionFragment.kt @@ -17,26 +17,24 @@ package im.vector.riotredesign.features.home.room.detail.timeline.action import android.graphics.Typeface import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.transition.TransitionManager import butterknife.BindView -import butterknife.ButterKnife -import com.airbnb.mvrx.BaseMvRxFragment import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.EmojiCompatFontProvider import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent +import im.vector.riotredesign.core.platform.VectorBaseFragment import javax.inject.Inject /** * Quick Reaction Fragment (agree / like reactions) */ -class QuickReactionFragment : BaseMvRxFragment() { +class QuickReactionFragment : VectorBaseFragment() { private val viewModel: QuickReactionViewModel by fragmentViewModel(QuickReactionViewModel::class) @@ -60,10 +58,10 @@ class QuickReactionFragment : BaseMvRxFragment() { @Inject lateinit var fontProvider: EmojiCompatFontProvider @Inject lateinit var quickReactionViewModelFactory: QuickReactionViewModel.Factory - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = inflater.inflate(R.layout.adapter_item_action_quick_reaction, container, false) - ButterKnife.bind(this, view) - return view + override fun getLayoutResId() = R.layout.adapter_item_action_quick_reaction + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/VectorBaseBottomSheetDialogFragment.kt similarity index 73% rename from vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt rename to vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/VectorBaseBottomSheetDialogFragment.kt index c3a068be..54b518bc 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/BaseMvRxBottomSheetDialog.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/VectorBaseBottomSheetDialogFragment.kt @@ -15,24 +15,40 @@ */ package im.vector.riotredesign.features.home.room.detail.timeline.action +import android.content.Context import android.os.Bundle import android.os.Parcelable import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRxView import com.airbnb.mvrx.MvRxViewModelStore import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import im.vector.riotredesign.core.di.DaggerScreenComponent +import im.vector.riotredesign.core.di.ScreenComponent +import im.vector.riotredesign.core.platform.VectorBaseActivity import java.util.* /** * Add MvRx capabilities to bottomsheetdialog (like BaseMvRxFragment) */ -abstract class BaseMvRxBottomSheetDialog : BottomSheetDialogFragment(), MvRxView { +abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment(), MvRxView { override val mvrxViewModelStore by lazy { MvRxViewModelStore(viewModelStore) } private lateinit var mvrxPersistedViewId: String - + private lateinit var screenComponent: ScreenComponent final override val mvrxViewId: String by lazy { mvrxPersistedViewId } + val vectorBaseActivity: VectorBaseActivity by lazy { + activity as VectorBaseActivity + } + + override fun onAttach(context: Context) { + screenComponent = DaggerScreenComponent.factory().create(vectorBaseActivity.getVectorComponent(), vectorBaseActivity) + super.onAttach(context) + injectWith(screenComponent) + } + + protected open fun injectWith(screenComponent: ScreenComponent) = Unit + override fun onCreate(savedInstanceState: Bundle?) { mvrxViewModelStore.restoreViewModels(this, savedInstanceState) mvrxPersistedViewId = savedInstanceState?.getString(PERSISTED_VIEW_ID_KEY) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionBottomSheet.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionBottomSheet.kt index 308c68bf..9c9a58d1 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionBottomSheet.kt @@ -15,24 +15,30 @@ import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.EmojiCompatFontProvider import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.features.home.room.detail.timeline.item.MessageInformationData import kotlinx.android.synthetic.main.bottom_sheet_display_reactions.* -import org.koin.android.ext.android.inject +import javax.inject.Inject /** * Bottom sheet displaying list of reactions for a given event ordered by timestamp */ -class ViewReactionBottomSheet : BaseMvRxBottomSheetDialog() { +class ViewReactionBottomSheet : VectorBaseBottomSheetDialogFragment() { private val viewModel: ViewReactionViewModel by fragmentViewModel(ViewReactionViewModel::class) - private val emojiCompatFontProvider by inject() + @Inject lateinit var viewReactionViewModelFactory: ViewReactionViewModel.Factory + @Inject lateinit var emojiCompatFontProvider: EmojiCompatFontProvider @BindView(R.id.bottom_sheet_display_reactions_list) lateinit var epoxyRecyclerView: EpoxyRecyclerView private val epoxyController by lazy { ViewReactionsEpoxyController(emojiCompatFontProvider.typeface) } + override fun injectWith(screenComponent: ScreenComponent) { + screenComponent.inject(this) + } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.bottom_sheet_display_reactions, container, false) ButterKnife.bind(this, view) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionViewModel.kt index 88548865..27a85abb 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ViewReactionViewModel.kt @@ -1,20 +1,25 @@ package im.vector.riotredesign.features.home.room.detail.timeline.action -import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import com.airbnb.mvrx.* +import com.squareup.inject.assisted.Assisted +import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.session.Session +import im.vector.matrix.rx.RxRoom import im.vector.riotredesign.core.extensions.localDateTime import im.vector.riotredesign.core.platform.VectorViewModel import im.vector.riotredesign.features.home.room.detail.timeline.helper.TimelineDateFormatter -import org.koin.android.ext.android.get +import io.reactivex.Observable data class DisplayReactionsViewState( - val eventId: String = "", - val roomId: String = "", + val eventId: String, + val roomId: String, val mapReactionKeyToMemberList: Async> = Uninitialized) - : MvRxState + : MvRxState { + + constructor(args: TimelineEventFragmentArgs) : this(roomId = args.roomId, eventId = args.eventId) + +} data class ReactionInfo( val eventId: String, @@ -27,75 +32,59 @@ data class ReactionInfo( /** * Used to display the list of members that reacted to a given event */ -class ViewReactionViewModel(private val session: Session, - private val timelineDateFormatter: TimelineDateFormatter, - initialState: DisplayReactionsViewState) : VectorViewModel(initialState) { +class ViewReactionViewModel @AssistedInject constructor(@Assisted + initialState: DisplayReactionsViewState, + private val session: Session, + private val timelineDateFormatter: TimelineDateFormatter +) : VectorViewModel(initialState) { - init { - loadReaction() + private val roomId = initialState.roomId + private val eventId = initialState.eventId + private val room = session.getRoom(roomId) + ?: throw IllegalStateException("Shouldn't use this ViewModel without a room") + + @AssistedInject.Factory + interface Factory { + fun create(initialState: DisplayReactionsViewState): ViewReactionViewModel } - fun loadReaction() = withState { state -> - - try { - val room = session.getRoom(state.roomId) - val event = room?.getTimeLineEvent(state.eventId) - if (event == null) { - setState { copy(mapReactionKeyToMemberList = Fail(Throwable())) } - return@withState - } - var results = ArrayList() - event.annotations?.reactionsSummary?.forEach { sum -> - - sum.sourceEvents.mapNotNull { room.getTimeLineEvent(it) }.forEach { - val localDate = it.root.localDateTime() - results.add(ReactionInfo(it.root.eventId!!, sum.key, it.root.sender - ?: "", it.senderName, timelineDateFormatter.formatMessageHour(localDate))) - } - } - setState { - copy( - mapReactionKeyToMemberList = Success(results.sortedBy { it.timestamp }) - ) - } - } catch (t: Throwable) { - setState { - copy( - mapReactionKeyToMemberList = Fail(t) - ) - } - } - } - - companion object : MvRxViewModelFactory { - override fun initialState(viewModelContext: ViewModelContext): DisplayReactionsViewState? { - - val roomId = (viewModelContext.args as? TimelineEventFragmentArgs)?.roomId - ?: return null - val info = (viewModelContext.args as? TimelineEventFragmentArgs)?.informationData - ?: return null - return DisplayReactionsViewState(info.eventId, roomId) - } - override fun create(viewModelContext: ViewModelContext, state: DisplayReactionsViewState): ViewReactionViewModel? { - val session = viewModelContext.activity.get() - val eventId = (viewModelContext.args as TimelineEventFragmentArgs).eventId - val lifecycleOwner = (viewModelContext as FragmentViewModelContext).fragment() - val liveSummary = session.getRoom(state.roomId)?.getEventSummaryLive(eventId) - val viewReactionViewModel = ViewReactionViewModel(session, viewModelContext.activity.get(), state) - // This states observes the live summary - // When fragment context will be destroyed the observer will automatically removed - liveSummary?.observe(lifecycleOwner, Observer { - it?.firstOrNull()?.let { - viewReactionViewModel.loadReaction() - } - }) - - return viewReactionViewModel + val fragment: ViewReactionBottomSheet = (viewModelContext as FragmentViewModelContext).fragment() + return fragment.viewReactionViewModelFactory.create(state) } - + } + + + init { + observeEventAnnotationSummaries() + } + + private fun observeEventAnnotationSummaries() { + RxRoom(room) + .liveAnnotationSummary(eventId) + .flatMapSingle { summaries -> + Observable + .fromIterable(summaries) + .flatMapIterable { it.reactionsSummary } + .map { + val event = room.getTimeLineEvent(eventId) + ?: throw RuntimeException("Your eventId is not valid") + val localDate = event.root.localDateTime() + ReactionInfo( + event.root.eventId!!, + it.key, + event.root.sender ?: "", + event.senderName, + timelineDateFormatter.formatMessageHour(localDate) + ) + } + .toList() + } + .execute { + copy(mapReactionKeyToMemberList = it) + } } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomListFragment.kt index 06415a05..13f71e31 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomListFragment.kt @@ -32,6 +32,7 @@ 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.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.epoxy.LayoutManagerStateRestorer import im.vector.riotredesign.core.extensions.observeEvent import im.vector.riotredesign.core.platform.OnBackPressed @@ -71,6 +72,10 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback, O override fun getLayoutResId() = R.layout.fragment_room_list + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setupCreateRoomButton() diff --git a/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt index c13f8b84..9e8c33b9 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt @@ -28,7 +28,9 @@ import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity import im.vector.riotredesign.features.settings.VectorSettingsActivity import javax.inject.Inject +import javax.inject.Singleton +@Singleton class DefaultNavigator @Inject constructor() : Navigator { override fun openRoom(roomId: String, context: Context) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/reactions/EmojiReactionPickerActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/reactions/EmojiReactionPickerActivity.kt index 72d3b19f..5944c81d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/reactions/EmojiReactionPickerActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/reactions/EmojiReactionPickerActivity.kt @@ -30,9 +30,11 @@ import androidx.lifecycle.ViewModelProviders import com.google.android.material.tabs.TabLayout import im.vector.riotredesign.EmojiCompatFontProvider import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.extensions.observeEvent import im.vector.riotredesign.core.platform.VectorBaseActivity import kotlinx.android.synthetic.main.activity_emoji_reaction_picker.* +import javax.inject.Inject /** * @@ -54,7 +56,7 @@ class EmojiReactionPickerActivity : VectorBaseActivity(), EmojiCompatFontProvide override fun getTitleRes(): Int = R.string.title_activity_emoji_reaction_picker - lateinit var emojiCompatFontProvider: EmojiCompatFontProvider + @Inject lateinit var emojiCompatFontProvider: EmojiCompatFontProvider private var tabLayoutSelectionListener = object : TabLayout.BaseOnTabSelectedListener { override fun onTabReselected(p0: TabLayout.Tab) { @@ -69,6 +71,10 @@ class EmojiReactionPickerActivity : VectorBaseActivity(), EmojiCompatFontProvide } + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun initUiAndData() { configureToolbar(emojiPickerToolbar) emojiCompatFontProvider.let { diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt index 01309e9e..bf395868 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsController.kt @@ -28,8 +28,9 @@ import im.vector.riotredesign.core.epoxy.loadingItem import im.vector.riotredesign.core.epoxy.noResultItem import im.vector.riotredesign.core.error.ErrorFormatter import im.vector.riotredesign.core.resources.StringProvider +import javax.inject.Inject -class PublicRoomsController(private val stringProvider: StringProvider, +class PublicRoomsController @Inject constructor(private val stringProvider: StringProvider, private val errorFormatter: ErrorFormatter) : TypedEpoxyController() { var callback: Callback? = null diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt index 7f701af8..fbf6d68e 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/PublicRoomsFragment.kt @@ -28,6 +28,7 @@ import com.google.android.material.snackbar.Snackbar import com.jakewharton.rxbinding2.widget.RxTextView import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.error.ErrorFormatter import im.vector.riotredesign.core.extensions.observeEvent import im.vector.riotredesign.core.platform.VectorBaseFragment @@ -55,6 +56,10 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback 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/riotredesign/features/roomdirectory/RoomDirectoryModule.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryModule.kt deleted file mode 100644 index 2ac22864..00000000 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/RoomDirectoryModule.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.riotredesign.features.roomdirectory - -import im.vector.matrix.android.api.session.Session -import im.vector.riotredesign.features.roomdirectory.createroom.CreateRoomController -import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryListCreator -import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerController -import org.koin.dsl.module.module - -class RoomDirectoryModule { - - companion object { - const val ROOM_DIRECTORY_SCOPE = "ROOM_DIRECTORY_SCOPE" - } - - val definition = module(override = true) { - - scope(ROOM_DIRECTORY_SCOPE) { - RoomDirectoryPickerController(get(), get(), get()) - } - - scope(ROOM_DIRECTORY_SCOPE) { - RoomDirectoryListCreator(get(), get().sessionParams.credentials) - } - - scope(ROOM_DIRECTORY_SCOPE) { - PublicRoomsController(get(), get()) - } - - /* ========================================================================================== - * Create room - * ========================================================================================== */ - - scope(ROOM_DIRECTORY_SCOPE) { - CreateRoomController(get(), get()) - } - - } -} \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomController.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomController.kt index 6d925e08..abd78d96 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomController.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomController.kt @@ -28,8 +28,9 @@ import im.vector.riotredesign.core.error.ErrorFormatter import im.vector.riotredesign.core.resources.StringProvider import im.vector.riotredesign.features.form.formEditTextItem import im.vector.riotredesign.features.form.formSwitchItem +import javax.inject.Inject -class CreateRoomController(private val stringProvider: StringProvider, +class CreateRoomController @Inject constructor(private val stringProvider: StringProvider, private val errorFormatter: ErrorFormatter ) : TypedEpoxyController() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomFragment.kt index 96e7c60c..31eaabe2 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomFragment.kt @@ -24,36 +24,34 @@ import com.airbnb.mvrx.Success import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity -import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule import im.vector.riotredesign.features.roomdirectory.RoomDirectoryNavigationViewModel import kotlinx.android.synthetic.main.fragment_create_room.* -import org.koin.android.ext.android.inject -import org.koin.android.scope.ext.android.bindScope -import org.koin.android.scope.ext.android.getOrCreateScope import timber.log.Timber +import javax.inject.Inject class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener { private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel private val viewModel: CreateRoomViewModel by fragmentViewModel() - private val createRoomController: CreateRoomController by inject() + @Inject lateinit var createRoomController: CreateRoomController + @Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory 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) - bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE)) - vectorBaseActivity.setSupportActionBar(createRoomToolbar) - navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java) - setupRecyclerView() - createRoomClose.setOnClickListener { navigationViewModel.goTo(RoomDirectoryActivity.Navigation.Back) } diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomViewModel.kt index 3790381a..f928e20c 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/createroom/CreateRoomViewModel.kt @@ -17,24 +17,30 @@ package im.vector.riotredesign.features.roomdirectory.createroom import com.airbnb.mvrx.* +import com.squareup.inject.assisted.Assisted +import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.room.model.RoomDirectoryVisibility import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams import im.vector.matrix.android.api.session.room.model.create.CreateRoomPreset import im.vector.riotredesign.core.platform.VectorViewModel -import org.koin.android.ext.android.get -class CreateRoomViewModel(initialState: CreateRoomViewState, - private val session: Session) : VectorViewModel(initialState) { +class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: CreateRoomViewState, + private val session: Session +) : VectorViewModel(initialState) { + + @AssistedInject.Factory + interface Factory { + fun create(initialState: CreateRoomViewState): CreateRoomViewModel + } companion object : MvRxViewModelFactory { @JvmStatic override fun create(viewModelContext: ViewModelContext, state: CreateRoomViewState): CreateRoomViewModel? { - val currentSession = viewModelContext.activity.get() - - return CreateRoomViewModel(state, currentSession) + val fragment: CreateRoomFragment = (viewModelContext as FragmentViewModelContext).fragment() + return fragment.createRoomViewModelFactory.create(state) } } diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt index 38cf4a3d..bde76fd2 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt @@ -26,6 +26,7 @@ import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity import im.vector.riotredesign.features.roomdirectory.RoomDirectoryNavigationViewModel @@ -70,8 +71,11 @@ class RoomDirectoryPickerFragment : VectorBaseFragment(), RoomDirectoryPickerCon return super.onOptionsItemSelected(item) } + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { - injector().inject(this) super.onActivityCreated(savedInstanceState) navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java) setupRecyclerView() diff --git a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt index d1960614..d94503a1 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt @@ -24,6 +24,7 @@ import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.error.ErrorFormatter import im.vector.riotredesign.core.extensions.setTextOrHide import im.vector.riotredesign.core.platform.ButtonStateView @@ -49,8 +50,11 @@ class RoomPreviewNoPreviewFragment : VectorBaseFragment() { 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?) { - injector().inject(this) super.onActivityCreated(savedInstanceState) setupToolbar(roomPreviewNoPreviewToolbar) } diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsActivity.kt index 6208c75e..6ac278a7 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsActivity.kt @@ -23,9 +23,10 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseActivity import kotlinx.android.synthetic.main.activity_vector_settings.* -import org.koin.android.ext.android.inject +import javax.inject.Inject /** * Displays the client settings. @@ -43,7 +44,11 @@ class VectorSettingsActivity : VectorBaseActivity(), private var keyToHighlight: String? = null - private val session by inject() + @Inject lateinit var session: Session + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } override fun initUiAndData() { configureToolbar(settingsToolbar) diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt index eee04547..0bf93ce3 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt @@ -34,12 +34,12 @@ import im.vector.riotredesign.core.preference.BingRule import im.vector.riotredesign.core.preference.BingRulePreference import im.vector.riotredesign.features.notifications.NotificationUtils import im.vector.riotredesign.features.notifications.supportNotificationChannels -import org.koin.android.ext.android.inject +import javax.inject.Inject class VectorSettingsAdvancedNotificationPreferenceFragment : VectorPreferenceFragment() { // members - private val mSession by inject() + @Inject lateinit var session: Session private var mLoadingView: View? = null // events listener diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt index 0fb39fff..b176362a 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt @@ -37,7 +37,7 @@ import im.vector.riotredesign.features.rageshake.BugReporter import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest import im.vector.riotredesign.push.fcm.NotificationTroubleshootTestManagerFactory -import org.koin.android.ext.android.inject +import javax.inject.Inject class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { @@ -54,7 +54,7 @@ class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { private var testManager: NotificationTroubleshootTestManager? = null // members - private val mSession by inject() + @Inject lateinit var session: Session override fun getLayoutResId() = R.layout.fragment_settings_notifications_troubleshoot @@ -92,7 +92,7 @@ class VectorSettingsNotificationsTroubleshootFragment : VectorBaseFragment() { mSummaryDescription.text = getString(R.string.settings_troubleshoot_diagnostic_running_status, 0, 0) - testManager = NotificationTroubleshootTestManagerFactory.createTestManager(this, mSession) + testManager = NotificationTroubleshootTestManagerFactory.createTestManager(this, session) testManager?.statusListener = { troubleshootTestManager -> if (isAdded) { 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 e30f9bb7..1d2371c8 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 @@ -64,17 +64,18 @@ import im.vector.riotredesign.features.MainActivity import im.vector.riotredesign.features.configuration.VectorConfiguration import im.vector.riotredesign.features.crypto.keysbackup.settings.KeysBackupManageActivity import im.vector.riotredesign.features.themes.ThemeUtils -import org.koin.android.ext.android.inject import timber.log.Timber import java.lang.ref.WeakReference import java.text.DateFormat import java.text.SimpleDateFormat import java.util.* +import javax.inject.Inject class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { // members - private val mSession by inject() + @Inject lateinit var session: Session + @Inject lateinit var vectorConfiguration: VectorConfiguration // disable some updates if there is // TODO private val mNetworkListener = IMXNetworkEventListener { refreshDisplay() } @@ -111,7 +112,6 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // used to avoid requesting to enter the password for each deletion private var mAccountPassword: String = "" - private val vectorConfiguration by inject() // current publicised group list private var mPublicisedGroups: MutableSet? = null @@ -272,7 +272,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // Avatar mUserAvatarPreference.let { - it.setSession(mSession) + it.setSession(session) it.onPreferenceClickListener = Preference.OnPreferenceClickListener { onUpdateAvatarClick() false @@ -479,7 +479,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref val cryptoIsEnabledPref = findPreference(PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY) - if (mSession.isCryptoEnabled()) { + if (session.isCryptoEnabled()) { mLabsCategory.removePreference(useCryptoPref) cryptoIsEnabledPref.isEnabled = false @@ -489,7 +489,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref useCryptoPref.isChecked = false useCryptoPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValueAsVoid -> - if (TextUtils.isEmpty(mSession.sessionParams.credentials.deviceId)) { + if (TextUtils.isEmpty(session.sessionParams.credentials.deviceId)) { activity?.let { activity -> AlertDialog.Builder(activity) .setMessage(R.string.room_settings_labs_end_to_end_warnings) @@ -508,7 +508,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref } else { val newValue = newValueAsVoid as Boolean - if (mSession.isCryptoEnabled() != newValue) { + if (session.isCryptoEnabled() != newValue) { notImplemented() /* TODO displayLoadingView() @@ -575,15 +575,15 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // user account findPreference(PreferencesManager.SETTINGS_LOGGED_IN_PREFERENCE_KEY) - .summary = mSession.sessionParams.credentials.userId + .summary = session.sessionParams.credentials.userId // home server findPreference(PreferencesManager.SETTINGS_HOME_SERVER_PREFERENCE_KEY) - .summary = mSession.sessionParams.homeServerConnectionConfig.homeServerUri.toString() + .summary = session.sessionParams.homeServerConnectionConfig.homeServerUri.toString() // identity server findPreference(PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY) - .summary = mSession.sessionParams.homeServerConnectionConfig.identityServerUri.toString() + .summary = session.sessionParams.homeServerConnectionConfig.identityServerUri.toString() // Analytics @@ -641,7 +641,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // olm version findPreference(PreferencesManager.SETTINGS_OLM_VERSION_PREFERENCE_KEY) - .summary = mSession.getCryptoVersion(requireContext(), false) + .summary = session.getCryptoVersion(requireContext(), false) // copyright findPreference(PreferencesManager.SETTINGS_COPYRIGHT_PREFERENCE_KEY) @@ -2163,8 +2163,8 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref * @param aMyDeviceInfo the device info */ private fun refreshCryptographyPreference(aMyDeviceInfo: DeviceInfo?) { - val userId = mSession.sessionParams.credentials.userId - val deviceId = mSession.sessionParams.credentials.deviceId + val userId = session.sessionParams.credentials.userId + val deviceId = session.sessionParams.credentials.deviceId // device name if (null != aMyDeviceInfo) { @@ -2195,7 +2195,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // crypto section: device key (fingerprint) if (!TextUtils.isEmpty(deviceId) && !TextUtils.isEmpty(userId)) { - val deviceInfo = mSession.getDeviceInfo(userId, deviceId) + val deviceInfo = session.getDeviceInfo(userId, deviceId) if (null != deviceInfo && !TextUtils.isEmpty(deviceInfo.fingerprint())) { cryptoInfoTextPreference.summary = deviceInfo.getFingerprintHumanReadable() @@ -2211,10 +2211,10 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref sendToUnverifiedDevicesPref.isChecked = false - sendToUnverifiedDevicesPref.isChecked = mSession.getGlobalBlacklistUnverifiedDevices() + sendToUnverifiedDevicesPref.isChecked = session.getGlobalBlacklistUnverifiedDevices() sendToUnverifiedDevicesPref.onPreferenceClickListener = Preference.OnPreferenceClickListener { - mSession.setGlobalBlacklistUnverifiedDevices(sendToUnverifiedDevicesPref.isChecked) + session.setGlobalBlacklistUnverifiedDevices(sendToUnverifiedDevicesPref.isChecked) true } @@ -2258,7 +2258,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref * It can be any mobile device, as any browser. */ private fun refreshDevicesList() { - if (mSession.isCryptoEnabled() && !TextUtils.isEmpty(mSession.sessionParams.credentials.deviceId)) { + if (session.isCryptoEnabled() && !TextUtils.isEmpty(session.sessionParams.credentials.deviceId)) { // display a spinner while loading the devices list if (0 == mDevicesListSettingsCategory.preferenceCount) { activity?.let { @@ -2267,7 +2267,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref } } - mSession.getDevicesList(object : MatrixCallback { + session.getDevicesList(object : MatrixCallback { override fun onSuccess(data: DevicesListResponse) { if (!isAdded) { return @@ -2306,7 +2306,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref var preference: VectorPreference var typeFaceHighlight: Int var isNewList = true - val myDeviceId = mSession.sessionParams.credentials.deviceId + val myDeviceId = session.sessionParams.credentials.deviceId if (aDeviceInfoList.size == mDevicesNameList.size) { isNewList = !mDevicesNameList.containsAll(aDeviceInfoList) @@ -2412,7 +2412,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref .setPositiveButton(R.string.rename) { _, _ -> displayDeviceRenameDialog(aDeviceInfo) } // disable the deletion for our own device - if (!TextUtils.equals(mSession.getMyDevice()?.deviceId, aDeviceInfo.deviceId)) { + if (!TextUtils.equals(session.getMyDevice()?.deviceId, aDeviceInfo.deviceId)) { builder.setNegativeButton(R.string.delete) { _, _ -> displayDeviceDeletionDialog(aDeviceInfo) } } @@ -2449,7 +2449,7 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref val newName = input.text.toString() - mSession.setDeviceName(aDeviceInfoToRename.deviceId!!, newName, object : MatrixCallback { + session.setDeviceName(aDeviceInfoToRename.deviceId!!, newName, object : MatrixCallback { override fun onSuccess(data: Unit) { hideLoadingView() diff --git a/vector/src/main/res/layout/fragment_message_menu.xml b/vector/src/main/res/layout/fragment_message_menu.xml new file mode 100644 index 00000000..4538ac93 --- /dev/null +++ b/vector/src/main/res/layout/fragment_message_menu.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file