Merge pull request #7239 from vector-im/feature/bma/arch_fixes

Feature/bma/arch fixes
This commit is contained in:
Benoit Marty 2022-10-18 11:47:12 +02:00 committed by GitHub
commit f3309692a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 88 additions and 139 deletions

View File

@ -26,7 +26,6 @@ import androidx.core.app.Person
import androidx.core.content.getSystemService
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.time.Clock
@ -59,11 +58,7 @@ class DebugMenuActivity : VectorBaseActivity<ActivityDebugMenuBinding>() {
override fun getBinding() = ActivityDebugMenuBinding.inflate(layoutInflater)
@Inject
lateinit var activeSessionHolder: ActiveSessionHolder
@Inject
lateinit var clock: Clock
@Inject lateinit var clock: Clock
private lateinit var buffer: ByteArray

View File

@ -56,6 +56,7 @@ import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.ActivityEntryPoint
import im.vector.app.core.dialogs.DialogLocker
import im.vector.app.core.dialogs.UnrecognizedCertificateDialog
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.error.fatalError
import im.vector.app.core.extensions.observeEvent
import im.vector.app.core.extensions.observeNotNull
@ -105,7 +106,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
protected var analyticsScreenName: MobileScreen.ScreenName? = null
protected lateinit var analyticsTracker: AnalyticsTracker
@Inject lateinit var analyticsTracker: AnalyticsTracker
/* ==========================================================================================
* View
@ -149,27 +150,23 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
* ========================================================================================== */
private lateinit var configurationViewModel: ConfigurationViewModel
private lateinit var sessionListener: SessionListener
protected lateinit var bugReporter: BugReporter
private lateinit var pinLocker: PinLocker
@Inject lateinit var sessionListener: SessionListener
@Inject lateinit var bugReporter: BugReporter
@Inject lateinit var pinLocker: PinLocker
@Inject lateinit var rageShake: RageShake
@Inject lateinit var buildMeta: BuildMeta
@Inject lateinit var fontScalePreferences: FontScalePreferences
@Inject lateinit var vectorLocale: VectorLocaleProvider
@Inject lateinit var vectorFeatures: VectorFeatures
@Inject lateinit var navigator: Navigator
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var errorFormatter: ErrorFormatter
// For debug only
@Inject lateinit var debugReceiver: DebugReceiver
@Inject
lateinit var vectorFeatures: VectorFeatures
lateinit var navigator: Navigator
private set
private lateinit var activeSessionHolder: ActiveSessionHolder
private lateinit var vectorPreferences: VectorPreferences
// Filter for multiple invalid token error
private var mainActivityStarted = false
@ -205,7 +202,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
@CallSuper
override fun onCreate(savedInstanceState: Bundle?) {
Timber.i("onCreate Activity ${javaClass.simpleName}")
val singletonEntryPoint = singletonEntryPoint()
val activityEntryPoint = EntryPointAccessors.fromActivity(this, ActivityEntryPoint::class.java)
ThemeUtils.setActivityTheme(this, getOtherThemes())
viewModelFactory = activityEntryPoint.viewModelFactory()
@ -213,12 +209,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
addOnMultiWindowModeChangedListener(onMultiWindowModeChangedListener)
setupMenu()
configurationViewModel = viewModelProvider.get(ConfigurationViewModel::class.java)
bugReporter = singletonEntryPoint.bugReporter()
pinLocker = singletonEntryPoint.pinLocker()
analyticsTracker = singletonEntryPoint.analyticsTracker()
navigator = singletonEntryPoint.navigator()
activeSessionHolder = singletonEntryPoint.activeSessionHolder()
vectorPreferences = singletonEntryPoint.vectorPreferences()
configurationViewModel.activityRestarter.observe(this) {
if (!it.hasBeenHandled) {
// Recreate the Activity because configuration has changed
@ -230,7 +220,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
navigator.openPinCode(this, pinStartForActivityResult, PinMode.AUTH)
}
}
sessionListener = singletonEntryPoint.sessionListener()
sessionListener.globalErrorLiveData.observeEvent(this) {
handleGlobalError(it)
}

View File

@ -30,8 +30,6 @@ import com.bumptech.glide.Glide
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.extensions.vectorStore
import im.vector.app.core.platform.VectorBaseActivity
@ -42,13 +40,11 @@ import im.vector.app.features.analytics.plan.ViewRoom
import im.vector.app.features.home.HomeActivity
import im.vector.app.features.home.ShortcutsHandler
import im.vector.app.features.notifications.NotificationDrawerManager
import im.vector.app.features.pin.PinLocker
import im.vector.app.features.pin.UnlockedActivity
import im.vector.app.features.pin.lockscreen.crypto.LockScreenKeyRepository
import im.vector.app.features.pin.lockscreen.pincode.PinCodeHelper
import im.vector.app.features.popup.PopupAlertManager
import im.vector.app.features.session.VectorSessionStore
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.signout.hard.SignedOutActivity
import im.vector.app.features.start.StartAppAction
import im.vector.app.features.start.StartAppAndroidService
@ -131,13 +127,9 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
private lateinit var args: MainActivityArgs
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
@Inject lateinit var sessionHolder: ActiveSessionHolder
@Inject lateinit var errorFormatter: ErrorFormatter
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var uiStateRepository: UiStateRepository
@Inject lateinit var shortcutsHandler: ShortcutsHandler
@Inject lateinit var pinCodeHelper: PinCodeHelper
@Inject lateinit var pinLocker: PinLocker
@Inject lateinit var popupAlertManager: PopupAlertManager
@Inject lateinit var vectorAnalytics: VectorAnalytics
@Inject lateinit var lockScreenKeyRepository: LockScreenKeyRepository
@ -232,7 +224,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
}
private fun doCleanUp() {
val session = sessionHolder.getSafeActiveSession()
val session = activeSessionHolder.getSafeActiveSession()
if (session == null) {
startNextActivityAndFinish()
return
@ -244,7 +236,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
lifecycleScope.launch {
// Just do the local cleanup
Timber.w("Account deactivated, start app")
sessionHolder.clearActiveSession()
activeSessionHolder.clearActiveSession()
doLocalCleanup(clearPreferences = true, onboardingStore)
startNextActivityAndFinish()
}
@ -258,7 +250,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
return@launch
}
Timber.w("SIGN_OUT: success, start app")
sessionHolder.clearActiveSession()
activeSessionHolder.clearActiveSession()
doLocalCleanup(clearPreferences = true, onboardingStore)
startNextActivityAndFinish()
}
@ -330,10 +322,10 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
args.isUserLoggedOut ->
// the homeserver has invalidated the token (password changed, device deleted, other security reasons)
SignedOutActivity.newIntent(this)
sessionHolder.hasActiveSession() ->
activeSessionHolder.hasActiveSession() ->
// We have a session.
// Check it can be opened
if (sessionHolder.getActiveSession().isOpenable) {
if (activeSessionHolder.getActiveSession().isOpenable) {
HomeActivity.newIntent(this, firstStartMainActivity = false, existingSession = true)
} else {
// The token is still invalid

View File

@ -23,7 +23,6 @@ import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.app.features.call.webrtc.WebRtcCallManager
@ -39,7 +38,6 @@ class PstnDialActivity : SimpleFragmentActivity() {
@Inject lateinit var callManager: WebRtcCallManager
@Inject lateinit var directRoomHelper: DirectRoomHelper
@Inject lateinit var session: Session
@Inject lateinit var errorFormatter: ErrorFormatter
private var progress: AppCompatDialog? = null

View File

@ -25,12 +25,10 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityCallTransferBinding
import im.vector.lib.core.utils.compat.getParcelableCompat
import kotlinx.parcelize.Parcelize
import javax.inject.Inject
@Parcelize
data class CallTransferArgs(val callId: String) : Parcelable
@ -40,8 +38,6 @@ private const val USER_LIST_FRAGMENT_TAG = "USER_LIST_FRAGMENT_TAG"
@AndroidEntryPoint
class CallTransferActivity : VectorBaseActivity<ActivityCallTransferBinding>() {
@Inject lateinit var errorFormatter: ErrorFormatter
private lateinit var sectionsPagerAdapter: CallTransferPagerAdapter
private val callTransferViewModel: CallTransferViewModel by viewModel()

View File

@ -32,7 +32,6 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.extensions.addFragmentToBackstack
import im.vector.app.core.platform.SimpleFragmentActivity
@ -58,7 +57,6 @@ import kotlinx.coroutines.flow.onEach
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure
import java.net.HttpURLConnection
import javax.inject.Inject
@AndroidEntryPoint
class CreateDirectRoomActivity : SimpleFragmentActivity() {
@ -67,7 +65,6 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
private val qrViewModel: QrCodeScannerViewModel by viewModel()
private lateinit var sharedActionViewModel: UserListSharedActionViewModel
@Inject lateinit var errorFormatter: ErrorFormatter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View File

@ -22,7 +22,6 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.addFragmentToBackstack
import im.vector.app.core.extensions.observeEvent
import im.vector.app.core.extensions.registerStartForActivityResult
@ -32,7 +31,6 @@ import im.vector.app.features.crypto.quads.SharedSecureStorageActivity
import im.vector.app.features.workers.signout.ServerBackupStatusAction
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME
import javax.inject.Inject
@AndroidEntryPoint
class KeysBackupRestoreActivity : SimpleFragmentActivity() {
@ -56,8 +54,6 @@ class KeysBackupRestoreActivity : SimpleFragmentActivity() {
super.onBackPressed()
}
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
override fun initUiAndData() {
super.initUiAndData()
viewModel = viewModelProvider.get(KeysBackupRestoreSharedViewModel::class.java)

View File

@ -25,7 +25,6 @@ import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.dialogs.ExportKeysDialog
import im.vector.app.core.extensions.observeEvent
import im.vector.app.core.extensions.queryExportKeys
@ -45,7 +44,6 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() {
private lateinit var viewModel: KeysBackupSetupSharedViewModel
@Inject lateinit var keysExporter: KeysExporter
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
private val session by lazy {
activeSessionHolder.getActiveSession()

View File

@ -30,13 +30,11 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.features.crypto.recover.SetupMode
import kotlinx.parcelize.Parcelize
import javax.inject.Inject
import kotlin.reflect.KClass
@AndroidEntryPoint
@ -54,7 +52,6 @@ class SharedSecureStorageActivity :
) : Parcelable
private val viewModel: SharedSecureStorageViewModel by viewModel()
@Inject lateinit var errorFormatter: ErrorFormatter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View File

@ -37,7 +37,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.SpaceStateHandler
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.replaceFragment
@ -77,7 +76,6 @@ import im.vector.app.features.popup.PopupAlertManager
import im.vector.app.features.popup.VerificationVectorAlert
import im.vector.app.features.rageshake.ReportType
import im.vector.app.features.rageshake.VectorUncaughtExceptionHandler
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.VectorSettingsActivity
import im.vector.app.features.spaces.SpaceCreationActivity
import im.vector.app.features.spaces.SpacePreviewActivity
@ -129,11 +127,9 @@ class HomeActivity :
private val serverBackupStatusViewModel: ServerBackupStatusViewModel by viewModel()
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
@Inject lateinit var pushersManager: PushersManager
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var popupAlertManager: PopupAlertManager
@Inject lateinit var shortcutsHandler: ShortcutsHandler
@Inject lateinit var permalinkHandler: PermalinkHandler

View File

@ -32,6 +32,7 @@ import im.vector.app.core.resources.BuildMeta
import im.vector.app.core.utils.startSharePlainTextIntent
import im.vector.app.databinding.FragmentHomeDrawerBinding
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.permalink.PermalinkFactory
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.VectorSettingsActivity
import im.vector.app.features.spaces.SpaceListFragment
@ -49,6 +50,7 @@ class HomeDrawerFragment :
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var avatarRenderer: AvatarRenderer
@Inject lateinit var buildMeta: BuildMeta
@Inject lateinit var permalinkFactory: PermalinkFactory
private lateinit var sharedActionViewModel: HomeSharedActionViewModel
@ -101,7 +103,7 @@ class HomeDrawerFragment :
}
views.homeDrawerInviteFriendButton.debouncedClicks {
session.permalinkService().createPermalink(sharedActionViewModel.session.myUserId)?.let { permalink ->
permalinkFactory.createPermalinkOfCurrentUser()?.let { permalink ->
analyticsTracker.screen(MobileScreen(screenName = MobileScreen.ScreenName.InviteFriends))
val text = getString(R.string.invite_friends_text, permalink)

View File

@ -61,7 +61,6 @@ import im.vector.app.features.workers.signout.ServerBackupStatusAction
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject
@ -80,7 +79,6 @@ class NewHomeDetailFragment :
@Inject lateinit var callManager: WebRtcCallManager
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var spaceStateHandler: SpaceStateHandler
@Inject lateinit var session: Session
@Inject lateinit var buildMeta: BuildMeta
private val viewModel: HomeDetailViewModel by fragmentViewModel()

View File

@ -168,6 +168,7 @@ import im.vector.app.features.media.VideoContentRenderer
import im.vector.app.features.notifications.NotificationDrawerManager
import im.vector.app.features.notifications.NotificationUtils
import im.vector.app.features.permalink.NavigationInterceptor
import im.vector.app.features.permalink.PermalinkFactory
import im.vector.app.features.permalink.PermalinkHandler
import im.vector.app.features.poll.PollMode
import im.vector.app.features.reactions.EmojiReactionPickerActivity
@ -247,6 +248,7 @@ class TimelineFragment :
@Inject lateinit var clock: Clock
@Inject lateinit var vectorFeatures: VectorFeatures
@Inject lateinit var galleryOrCameraDialogHelperFactory: GalleryOrCameraDialogHelperFactory
@Inject lateinit var permalinkFactory: PermalinkFactory
companion object {
const val MAX_TYPING_MESSAGE_USERS_COUNT = 4
@ -867,7 +869,7 @@ class TimelineFragment :
}
R.id.menu_thread_timeline_copy_link -> {
getRootThreadEventId()?.let {
val permalink = session.permalinkService().createPermalink(timelineArgs.roomId, it)
val permalink = permalinkFactory.createPermalink(timelineArgs.roomId, it)
copyToClipboard(requireContext(), permalink, false)
showSnackWithMessage(getString(R.string.copied_to_clipboard))
}
@ -879,7 +881,7 @@ class TimelineFragment :
}
R.id.menu_thread_timeline_share -> {
getRootThreadEventId()?.let {
val permalink = session.permalinkService().createPermalink(timelineArgs.roomId, it)
val permalink = permalinkFactory.createPermalink(timelineArgs.roomId, it)
shareText(requireContext(), permalink)
}
true
@ -1788,7 +1790,7 @@ class TimelineFragment :
}
}
is EventSharedAction.CopyPermalink -> {
val permalink = session.permalinkService().createPermalink(timelineArgs.roomId, action.eventId)
val permalink = permalinkFactory.createPermalink(timelineArgs.roomId, action.eventId)
copyToClipboard(requireContext(), permalink, false)
showSnackWithMessage(getString(R.string.copied_to_clipboard))
}

View File

@ -40,8 +40,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class ThreadsActivity : VectorBaseActivity<ActivityThreadsBinding>() {
@Inject
lateinit var avatarRenderer: AvatarRenderer
@Inject lateinit var avatarRenderer: AvatarRenderer
// private val roomThreadDetailFragment: RoomThreadDetailFragment?
// get() {

View File

@ -27,7 +27,6 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.extensions.addFragmentToBackstack
import im.vector.app.core.platform.SimpleFragmentActivity
@ -47,7 +46,6 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.failure.Failure
import java.net.HttpURLConnection
import javax.inject.Inject
@Parcelize
data class InviteUsersToRoomArgs(val roomId: String) : Parcelable
@ -57,7 +55,6 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
private val viewModel: InviteUsersToRoomViewModel by viewModel()
private lateinit var sharedActionViewModel: UserListSharedActionViewModel
@Inject lateinit var errorFormatter: ErrorFormatter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View File

@ -24,8 +24,6 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.utils.toast
@ -46,8 +44,6 @@ import javax.inject.Inject
@AndroidEntryPoint
class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
@Inject lateinit var sessionHolder: ActiveSessionHolder
@Inject lateinit var errorFormatter: ErrorFormatter
@Inject lateinit var permalinkHandler: PermalinkHandler
private val startAppViewModel: StartAppViewModel by viewModel()
@ -103,7 +99,7 @@ class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
}
private fun handleConfigUrl(uri: Uri) {
if (sessionHolder.hasActiveSession()) {
if (activeSessionHolder.hasActiveSession()) {
displayAlreadyLoginPopup(uri)
} else {
// user is not yet logged in, this is the nominal case
@ -114,7 +110,7 @@ class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
private fun handleSupportedHostUrl() {
// If we are not logged in, open login screen.
// In the future, we might want to relaunch the process after login.
if (!sessionHolder.hasActiveSession()) {
if (!activeSessionHolder.hasActiveSession()) {
startLoginActivity()
return
}
@ -152,7 +148,7 @@ class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
}
private fun safeSignout(uri: Uri) {
val session = sessionHolder.getSafeActiveSession()
val session = activeSessionHolder.getSafeActiveSession()
if (session == null) {
// Should not happen
startLoginActivity(uri)
@ -161,7 +157,7 @@ class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
try {
session.signOutService().signOut(true)
Timber.d("## displayAlreadyLoginPopup(): logout succeeded")
sessionHolder.clearActiveSession()
activeSessionHolder.clearActiveSession()
startLoginActivity(uri)
} catch (failure: Throwable) {
displayError(failure)

View File

@ -69,14 +69,9 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt
val sharedTransitionName: String?
) : Parcelable
@Inject
lateinit var sessionHolder: ActiveSessionHolder
@Inject
lateinit var dataSourceFactory: AttachmentProviderFactory
@Inject
lateinit var imageContentRenderer: ImageContentRenderer
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var dataSourceFactory: AttachmentProviderFactory
@Inject lateinit var imageContentRenderer: ImageContentRenderer
private val viewModel: VectorAttachmentViewerViewModel by viewModel()
private val errorFormatter by lazy(LazyThreadSafetyMode.NONE) { singletonEntryPoint().errorFormatter() }
@ -128,7 +123,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt
}
}
val session = sessionHolder.getSafeActiveSession() ?: return Unit.also { finish() }
val session = activeSessionHolder.getSafeActiveSession() ?: return Unit.also { finish() }
val room = args.roomId?.let { session.getRoom(it) }

View File

@ -670,6 +670,7 @@ class OnboardingViewModel @AssistedInject constructor(
val homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities()
val capabilityOverrides = vectorOverrides.forceHomeserverCapabilities?.firstOrNull()
state.personalizationState.copy(
userId = session.myUserId,
displayName = state.registrationState.selectedMatrixId?.let { MatrixPatterns.extractUserNameFromId(it) },
supportsChangingDisplayName = capabilityOverrides?.canChangeDisplayName ?: homeServerCapabilities.canChangeDisplayName,
supportsChangingProfilePicture = capabilityOverrides?.canChangeAvatar ?: homeServerCapabilities.canChangeAvatar

View File

@ -80,10 +80,11 @@ data class SelectedHomeserverState(
@Parcelize
data class PersonalizationState(
val userId: String = "",
val supportsChangingDisplayName: Boolean = false,
val supportsChangingProfilePicture: Boolean = false,
val displayName: String? = null,
val selectedPictureUri: Uri? = null
val selectedPictureUri: Uri? = null,
) : Parcelable {
fun supportsPersonalization() = supportsChangingDisplayName || supportsChangingProfilePicture

View File

@ -26,21 +26,17 @@ import androidx.core.view.isVisible
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.animations.play
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.utils.isAnimationEnabled
import im.vector.app.core.utils.styleMatchingText
import im.vector.app.databinding.FragmentFtueAccountCreatedBinding
import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.onboarding.OnboardingViewEvents
import im.vector.app.features.onboarding.OnboardingViewState
import javax.inject.Inject
@AndroidEntryPoint
class FtueAuthAccountCreatedFragment :
AbstractFtueAuthFragment<FragmentFtueAccountCreatedBinding>() {
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
private var hasPlayedConfetti = false
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueAccountCreatedBinding {
@ -53,15 +49,15 @@ class FtueAuthAccountCreatedFragment :
}
private fun setupViews() {
val userId = activeSessionHolder.getActiveSession().myUserId
val subtitle = getString(R.string.ftue_account_created_subtitle, userId).toSpannable().styleMatchingText(userId, Typeface.BOLD)
views.accountCreatedSubtitle.text = subtitle
views.accountCreatedPersonalize.debouncedClicks { viewModel.handle(OnboardingAction.PersonalizeProfile) }
views.accountCreatedTakeMeHome.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnTakeMeHome)) }
views.accountCreatedTakeMeHomeCta.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnTakeMeHome)) }
}
override fun updateWithState(state: OnboardingViewState) {
val userId = state.personalizationState.userId
val subtitle = getString(R.string.ftue_account_created_subtitle, userId).toSpannable().styleMatchingText(userId, Typeface.BOLD)
views.accountCreatedSubtitle.text = subtitle
val canPersonalize = state.personalizationState.supportsPersonalization()
views.personalizeButtonGroup.isVisible = canPersonalize
views.takeMeHomeButtonGroup.isVisible = !canPersonalize

View File

@ -26,7 +26,6 @@ import androidx.core.view.isInvisible
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelperFactory
import im.vector.app.databinding.FragmentFtueProfilePictureBinding
@ -42,7 +41,6 @@ class FtueAuthChooseProfilePictureFragment :
AbstractFtueAuthFragment<FragmentFtueProfilePictureBinding>(),
GalleryOrCameraDialogHelper.Listener {
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var galleryOrCameraDialogHelperFactory: GalleryOrCameraDialogHelperFactory
@Inject lateinit var avatarRenderer: AvatarRenderer
@ -85,10 +83,9 @@ class FtueAuthChooseProfilePictureFragment :
views.profilePictureSubmit.isEnabled = hasSetPicture
views.changeProfilePictureIcon.setImageResource(if (hasSetPicture) R.drawable.ic_edit else R.drawable.ic_camera_plain)
val session = activeSessionHolder.getActiveSession()
val matrixItem = MatrixItem.UserItem(
id = session.myUserId,
displayName = state.personalizationState.displayName ?: ""
id = state.personalizationState.userId,
displayName = state.personalizationState.displayName.orEmpty()
)
avatarRenderer.render(matrixItem, localUri = state.personalizationState.selectedPictureUri, imageView = views.profilePictureView)
}

View File

@ -0,0 +1,39 @@
/*
* Copyright 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.permalink
import org.matrix.android.sdk.api.session.Session
import javax.inject.Inject
/**
* Contains synchronous methods to create permalinks from the Session.
*/
class PermalinkFactory @Inject constructor(
private val session: Session,
) {
fun createPermalinkOfCurrentUser(): String? {
return createPermalink(session.myUserId)
}
fun createPermalink(id: String): String? {
return session.permalinkService().createPermalink(id)
}
fun createPermalink(roomId: String, eventId: String): String {
return session.permalinkService().createPermalink(roomId, eventId)
}
}

View File

@ -37,12 +37,12 @@ import im.vector.app.core.utils.toast
import im.vector.app.databinding.FragmentPublicRoomsBinding
import im.vector.app.features.analytics.plan.ViewRoom
import im.vector.app.features.permalink.NavigationInterceptor
import im.vector.app.features.permalink.PermalinkFactory
import im.vector.app.features.permalink.PermalinkHandler
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
import reactivecircus.flowbinding.appcompat.queryTextChanges
import timber.log.Timber
@ -60,7 +60,7 @@ class PublicRoomsFragment :
@Inject lateinit var publicRoomsController: PublicRoomsController
@Inject lateinit var permalinkHandler: PermalinkHandler
@Inject lateinit var session: Session
@Inject lateinit var permalinkFactory: PermalinkFactory
private val viewModel: RoomDirectoryViewModel by activityViewModel()
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
@ -128,7 +128,7 @@ class PublicRoomsFragment :
override fun onUnknownRoomClicked(roomIdOrAlias: String) {
viewLifecycleOwner.lifecycleScope.launch {
val permalink = session.permalinkService().createPermalink(roomIdOrAlias)
val permalink = permalinkFactory.createPermalink(roomIdOrAlias)
val isHandled = permalinkHandler
.launch(requireActivity(), permalink, object : NavigationInterceptor {
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean {

View File

@ -69,8 +69,7 @@ class RoomProfileActivity :
private val requireActiveMembershipViewModel: RequireActiveMembershipViewModel by viewModel()
@Inject
lateinit var roomDetailPendingActionStore: RoomDetailPendingActionStore
@Inject lateinit var roomDetailPendingActionStore: RoomDetailPendingActionStore
override fun getBinding(): ActivitySimpleBinding {
return ActivitySimpleBinding.inflate(layoutInflater)

View File

@ -29,7 +29,6 @@ import com.airbnb.mvrx.viewModel
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.toMvRxBundle
@ -44,7 +43,6 @@ import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRul
import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRuleChooseRestrictedState
import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRuleChooseRestrictedViewModel
import im.vector.lib.core.utils.compat.getParcelableCompat
import javax.inject.Inject
@AndroidEntryPoint
class RoomJoinRuleActivity : VectorBaseActivity<ActivitySimpleBinding>() {
@ -53,9 +51,6 @@ class RoomJoinRuleActivity : VectorBaseActivity<ActivitySimpleBinding>() {
private lateinit var roomProfileArgs: RoomProfileArgs
@Inject
lateinit var errorFormatter: ErrorFormatter
val viewModel: RoomJoinRuleChooseRestrictedViewModel by viewModel()
override fun initUiAndData() {

View File

@ -63,8 +63,6 @@ class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>
@Inject lateinit var session: Session
@Inject lateinit var vectorPreferences: VectorPreferences
override fun initUiAndData() {
setupToolbar(views.settingsToolbar)
.allowBack()

View File

@ -20,22 +20,18 @@ import android.content.Intent
import android.os.Bundle
import com.airbnb.mvrx.viewModel
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleBinding
import im.vector.app.features.MainActivity
import im.vector.app.features.start.StartAppViewModel
import javax.inject.Inject
@AndroidEntryPoint
class IncomingShareActivity : VectorBaseActivity<ActivitySimpleBinding>() {
private val startAppViewModel: StartAppViewModel by viewModel()
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
private val launcher = registerStartForActivityResult {
if (it.resultCode == RESULT_OK) {
handleAppStarted()

View File

@ -25,7 +25,6 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.features.MainActivity
import im.vector.app.features.MainActivityArgs
@ -45,7 +44,6 @@ class SoftLogoutActivity : LoginActivity() {
private val softLogoutViewModel: SoftLogoutViewModel by viewModel()
@Inject lateinit var session: Session
@Inject lateinit var errorFormatter: ErrorFormatter
override fun initUiAndData() {
super.initUiAndData()

View File

@ -29,7 +29,6 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.extensions.setTextOrHide
@ -37,16 +36,13 @@ import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleLoadingBinding
import im.vector.app.features.spaces.SpaceBottomSheetSettingsArgs
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
import javax.inject.Inject
@AndroidEntryPoint
class SpaceLeaveAdvancedActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>() {
override fun getBinding(): ActivitySimpleLoadingBinding = ActivitySimpleLoadingBinding.inflate(layoutInflater)
val leaveViewModel: SpaceLeaveAdvancedViewModel by viewModel()
@Inject lateinit var errorFormatter: ErrorFormatter
private val leaveViewModel: SpaceLeaveAdvancedViewModel by viewModel()
override fun showWaitingView(text: String?) {
hideKeyboard()

View File

@ -22,18 +22,14 @@ import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
import org.matrix.android.sdk.api.session.terms.TermsService
import javax.inject.Inject
@AndroidEntryPoint
class ReviewTermsActivity : SimpleFragmentActivity() {
@Inject lateinit var errorFormatter: ErrorFormatter
private val reviewTermsViewModel: ReviewTermsViewModel by viewModel()
override fun initUiAndData() {

View File

@ -21,12 +21,10 @@ import android.content.Intent
import android.webkit.WebChromeClient
import android.webkit.WebView
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityVectorWebViewBinding
import im.vector.lib.core.utils.compat.getSerializableCompat
import org.matrix.android.sdk.api.session.Session
import javax.inject.Inject
/**
* This class is responsible for managing a WebView
@ -39,7 +37,6 @@ class VectorWebViewActivity : VectorBaseActivity<ActivityVectorWebViewBinding>()
override fun getBinding() = ActivityVectorWebViewBinding.inflate(layoutInflater)
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
val session: Session by lazy {
activeSessionHolder.getActiveSession()
}

View File

@ -39,7 +39,6 @@ import im.vector.app.R
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityWidgetBinding
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionBottomSheet
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewEvents
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewModel
@ -48,7 +47,6 @@ import im.vector.lib.core.utils.compat.getSerializableCompat
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.Content
import java.io.Serializable
import javax.inject.Inject
@AndroidEntryPoint
class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>() {
@ -83,8 +81,6 @@ class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>() {
private val viewModel: WidgetViewModel by viewModel()
private val permissionViewModel: RoomWidgetPermissionViewModel by viewModel()
@Inject lateinit var vectorPreferences: VectorPreferences
override fun getBinding() = ActivityWidgetBinding.inflate(layoutInflater)
override fun getTitleRes() = R.string.room_widget_activity_title

View File

@ -687,7 +687,7 @@ class OnboardingViewModelTest {
.assertStatesChanges(
initialState,
{ copy(isLoading = true) },
{ copy(isLoading = false, personalizationState = A_HOMESERVER_CAPABILITIES.toPersonalisationState(A_USERNAME)) }
{ copy(isLoading = false, personalizationState = A_HOMESERVER_CAPABILITIES.toPersonalisationState("@fake:server.fake", A_USERNAME)) }
)
.assertEvents(OnboardingViewEvents.OnAccountCreated)
.finish()
@ -1196,7 +1196,8 @@ class OnboardingViewModelTest {
}
}
private fun HomeServerCapabilities.toPersonalisationState(displayName: String? = null) = PersonalizationState(
private fun HomeServerCapabilities.toPersonalisationState(userId: String, displayName: String? = null) = PersonalizationState(
userId = userId,
supportsChangingDisplayName = canChangeDisplayName,
supportsChangingProfilePicture = canChangeAvatar,
displayName = displayName,