Try mvrx mock/launcher on RoomProfileFragment #2
This commit is contained in:
parent
05d8f1b355
commit
ace01876dd
|
@ -86,7 +86,6 @@ class DebugMenuActivity : VectorBaseActivity<ActivityDebugMenuBinding>() {
|
||||||
private fun setupViews() {
|
private fun setupViews() {
|
||||||
|
|
||||||
views.debugMock.setOnClickListener {
|
views.debugMock.setOnClickListener {
|
||||||
MavericksLauncherMockActivity.activityToShowMock = VectorLauncherMockActivity::class
|
|
||||||
MavericksLauncherActivity.show(this)
|
MavericksLauncherActivity.show(this)
|
||||||
}
|
}
|
||||||
views.debugFeatures.setOnClickListener { startActivity(Intent(this, DebugFeaturesSettingsActivity::class.java)) }
|
views.debugFeatures.setOnClickListener { startActivity(Intent(this, DebugFeaturesSettingsActivity::class.java)) }
|
||||||
|
|
|
@ -37,6 +37,7 @@ import com.airbnb.epoxy.Carousel
|
||||||
import com.airbnb.epoxy.EpoxyAsyncUtil
|
import com.airbnb.epoxy.EpoxyAsyncUtil
|
||||||
import com.airbnb.epoxy.EpoxyController
|
import com.airbnb.epoxy.EpoxyController
|
||||||
import com.airbnb.mvrx.Mavericks
|
import com.airbnb.mvrx.Mavericks
|
||||||
|
import com.airbnb.mvrx.launcher.MavericksLauncherMockActivity
|
||||||
import com.airbnb.mvrx.mocking.MavericksMock
|
import com.airbnb.mvrx.mocking.MavericksMock
|
||||||
import com.airbnb.mvrx.mocking.MockableMavericks
|
import com.airbnb.mvrx.mocking.MockableMavericks
|
||||||
import com.facebook.stetho.Stetho
|
import com.facebook.stetho.Stetho
|
||||||
|
@ -55,6 +56,7 @@ import im.vector.app.core.resources.BuildMeta
|
||||||
import im.vector.app.features.analytics.VectorAnalytics
|
import im.vector.app.features.analytics.VectorAnalytics
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.configuration.VectorConfiguration
|
import im.vector.app.features.configuration.VectorConfiguration
|
||||||
|
import im.vector.app.features.debug.VectorLauncherMockActivity
|
||||||
import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog
|
import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog
|
||||||
import im.vector.app.features.invite.InvitesAcceptor
|
import im.vector.app.features.invite.InvitesAcceptor
|
||||||
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
||||||
|
@ -149,6 +151,7 @@ class VectorApplication :
|
||||||
logInfo()
|
logInfo()
|
||||||
LazyThreeTen.init(this)
|
LazyThreeTen.init(this)
|
||||||
MockableMavericks.initialize(mocksEnabled = buildMeta.isDebug, debugMode = false, applicationContext = applicationContext)
|
MockableMavericks.initialize(mocksEnabled = buildMeta.isDebug, debugMode = false, applicationContext = applicationContext)
|
||||||
|
MavericksLauncherMockActivity.activityToShowMock = VectorLauncherMockActivity::class
|
||||||
//Mavericks.initialize(debugMode = false)
|
//Mavericks.initialize(debugMode = false)
|
||||||
|
|
||||||
configureEpoxy()
|
configureEpoxy()
|
||||||
|
|
|
@ -22,6 +22,7 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
@ -58,7 +59,7 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
@Assisted private val initialState: RoomProfileViewState,
|
@Assisted private val initialState: RoomProfileViewState,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val shortcutCreator: ShortcutCreator,
|
private val shortcutCreator: ShortcutCreator,
|
||||||
private val session: Session,
|
sessionHolder: ActiveSessionHolder,
|
||||||
private val analyticsTracker: AnalyticsTracker
|
private val analyticsTracker: AnalyticsTracker
|
||||||
) : VectorViewModel<RoomProfileViewState, RoomProfileAction, RoomProfileViewEvents>(initialState) {
|
) : VectorViewModel<RoomProfileViewState, RoomProfileAction, RoomProfileViewEvents>(initialState) {
|
||||||
|
|
||||||
|
@ -69,7 +70,9 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
companion object : MavericksViewModelFactory<RoomProfileViewModel, RoomProfileViewState> by hiltMavericksViewModelFactory()
|
companion object : MavericksViewModelFactory<RoomProfileViewModel, RoomProfileViewState> by hiltMavericksViewModelFactory()
|
||||||
|
|
||||||
private val room = session.getRoom(initialState.roomId)
|
private val session = sessionHolder.getSafeActiveSession()
|
||||||
|
private val room = session?.getRoom(initialState.roomId)
|
||||||
|
private val myUserId = session?.myUserId ?: ""
|
||||||
|
|
||||||
init {
|
init {
|
||||||
room?.also { room ->
|
room?.also { room ->
|
||||||
|
@ -87,7 +90,7 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
powerLevelsContentLive
|
powerLevelsContentLive
|
||||||
.onEach {
|
.onEach {
|
||||||
val powerLevelsHelper = PowerLevelsHelper(it)
|
val powerLevelsHelper = PowerLevelsHelper(it)
|
||||||
val canUpdateRoomState = powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_ENCRYPTION)
|
val canUpdateRoomState = powerLevelsHelper.isUserAllowedToSend(myUserId, true, EventType.STATE_ROOM_ENCRYPTION)
|
||||||
setState {
|
setState {
|
||||||
copy(canUpdateRoomState = canUpdateRoomState)
|
copy(canUpdateRoomState = canUpdateRoomState)
|
||||||
}
|
}
|
||||||
|
@ -104,7 +107,7 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
// This is a shortcut, we should do the next lines elsewhere, but keep it like that for the moment.
|
// This is a shortcut, we should do the next lines elsewhere, but keep it like that for the moment.
|
||||||
recommendedRoomVersion = flowRoom.room.roomVersionService().getRecommendedVersion(),
|
recommendedRoomVersion = flowRoom.room.roomVersionService().getRecommendedVersion(),
|
||||||
isUsingUnstableRoomVersion = flowRoom.room.roomVersionService().isUsingUnstableRoomVersion(),
|
isUsingUnstableRoomVersion = flowRoom.room.roomVersionService().isUsingUnstableRoomVersion(),
|
||||||
canUpgradeRoom = flowRoom.room.roomVersionService().userMayUpgradeRoom(session.myUserId),
|
canUpgradeRoom = flowRoom.room.roomVersionService().userMayUpgradeRoom(myUserId),
|
||||||
isTombstoned = flowRoom.room.getStateEvent(EventType.STATE_ROOM_TOMBSTONE, QueryStringValue.IsEmpty) != null
|
isTombstoned = flowRoom.room.getStateEvent(EventType.STATE_ROOM_TOMBSTONE, QueryStringValue.IsEmpty) != null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -131,21 +134,22 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
val powerLevelsHelper = PowerLevelsHelper(it)
|
val powerLevelsHelper = PowerLevelsHelper(it)
|
||||||
val permissions = RoomProfileViewState.ActionPermissions(
|
val permissions = RoomProfileViewState.ActionPermissions(
|
||||||
canEnableEncryption = powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_ENCRYPTION)
|
canEnableEncryption = powerLevelsHelper.isUserAllowedToSend(myUserId, true, EventType.STATE_ROOM_ENCRYPTION)
|
||||||
)
|
)
|
||||||
copy(actionPermissions = permissions)
|
copy(actionPermissions = permissions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(action: RoomProfileAction) {
|
override fun handle(action: RoomProfileAction) {
|
||||||
val room = this.room ?: return
|
val session = this.session ?: throw IllegalStateException("Action with no active session")
|
||||||
|
val room = this.room ?: throw IllegalStateException("Action with unknown room")
|
||||||
when (action) {
|
when (action) {
|
||||||
is RoomProfileAction.EnableEncryption -> handleEnableEncryption(room)
|
is RoomProfileAction.EnableEncryption -> handleEnableEncryption(room)
|
||||||
RoomProfileAction.LeaveRoom -> handleLeaveRoom(room)
|
RoomProfileAction.LeaveRoom -> handleLeaveRoom(session, room)
|
||||||
is RoomProfileAction.ChangeRoomNotificationState -> handleChangeNotificationMode(room, action)
|
is RoomProfileAction.ChangeRoomNotificationState -> handleChangeNotificationMode(room, action)
|
||||||
is RoomProfileAction.ShareRoomProfile -> handleShareRoomProfile()
|
is RoomProfileAction.ShareRoomProfile -> handleShareRoomProfile(session)
|
||||||
RoomProfileAction.CreateShortcut -> handleCreateShortcut()
|
RoomProfileAction.CreateShortcut -> handleCreateShortcut()
|
||||||
RoomProfileAction.RestoreEncryptionState -> restoreEncryptionState(room)
|
RoomProfileAction.RestoreEncryptionState -> restoreEncryptionState(session, room)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +194,7 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLeaveRoom(room: Room) {
|
private fun handleLeaveRoom(session: Session, room: Room) {
|
||||||
_viewEvents.post(RoomProfileViewEvents.Loading(stringProvider.getString(R.string.room_profile_leaving_room)))
|
_viewEvents.post(RoomProfileViewEvents.Loading(stringProvider.getString(R.string.room_profile_leaving_room)))
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
|
@ -209,14 +213,14 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleShareRoomProfile() {
|
private fun handleShareRoomProfile(session: Session) {
|
||||||
session.permalinkService().createRoomPermalink(initialState.roomId)
|
session.permalinkService().createRoomPermalink(initialState.roomId)
|
||||||
?.let { permalink ->
|
?.let { permalink ->
|
||||||
_viewEvents.post(RoomProfileViewEvents.ShareRoomProfile(permalink))
|
_viewEvents.post(RoomProfileViewEvents.ShareRoomProfile(permalink))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restoreEncryptionState(room: Room) {
|
private fun restoreEncryptionState(session: Session, room: Room) {
|
||||||
_viewEvents.post(RoomProfileViewEvents.Loading())
|
_viewEvents.post(RoomProfileViewEvents.Loading())
|
||||||
session.coroutineScope.launch {
|
session.coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue