mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 09:55:40 +03:00
Navigate to rename session screen from current session menu
This commit is contained in:
parent
bbc756136c
commit
540758d66b
6 changed files with 61 additions and 19 deletions
|
@ -145,6 +145,10 @@ class VectorSettingsDevicesFragment :
|
|||
private fun initCurrentSessionHeaderView() {
|
||||
views.deviceListHeaderCurrentSession.setOnMenuItemClickListener { menuItem ->
|
||||
when (menuItem.itemId) {
|
||||
R.id.currentSessionHeaderRename -> {
|
||||
navigateToRenameCurrentSession()
|
||||
true
|
||||
}
|
||||
R.id.currentSessionHeaderSignoutOtherSessions -> {
|
||||
confirmMultiSignoutOtherSessions()
|
||||
true
|
||||
|
@ -154,6 +158,16 @@ class VectorSettingsDevicesFragment :
|
|||
}
|
||||
}
|
||||
|
||||
private fun navigateToRenameCurrentSession() = withState(viewModel) { state ->
|
||||
val currentDeviceId = state.currentSessionCrossSigningInfo.deviceId
|
||||
if (currentDeviceId.isNotEmpty()) {
|
||||
viewNavigator.navigateToRenameSession(
|
||||
context = requireActivity(),
|
||||
deviceId = currentDeviceId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initCurrentSessionListView() {
|
||||
views.deviceListCurrentSession.viewVerifyButton.debouncedClicks {
|
||||
viewModel.handle(DevicesAction.VerifyCurrentSession)
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context
|
|||
import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType
|
||||
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsActivity
|
||||
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
|
||||
import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsDevicesViewNavigator @Inject constructor() {
|
||||
|
@ -38,4 +39,8 @@ class VectorSettingsDevicesViewNavigator @Inject constructor() {
|
|||
OtherSessionsActivity.newIntent(context, titleResourceId, defaultFilter, excludeCurrentDevice)
|
||||
)
|
||||
}
|
||||
|
||||
fun navigateToRenameSession(context: Context, deviceId: String) {
|
||||
context.startActivity(RenameSessionActivity.newIntent(context, deviceId))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Intent
|
|||
import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType
|
||||
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsActivity
|
||||
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
|
||||
import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity
|
||||
import im.vector.app.test.fakes.FakeContext
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
|
@ -43,6 +44,7 @@ class VectorSettingsDevicesViewNavigatorTest {
|
|||
fun setUp() {
|
||||
mockkObject(SessionOverviewActivity.Companion)
|
||||
mockkObject(OtherSessionsActivity.Companion)
|
||||
mockkObject(RenameSessionActivity.Companion)
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -52,26 +54,41 @@ class VectorSettingsDevicesViewNavigatorTest {
|
|||
|
||||
@Test
|
||||
fun `given a session id when navigating to overview then it starts the correct activity`() {
|
||||
// Given
|
||||
val intent = givenIntentForSessionOverview(A_SESSION_ID)
|
||||
context.givenStartActivity(intent)
|
||||
|
||||
// When
|
||||
vectorSettingsDevicesViewNavigator.navigateToSessionOverview(context.instance, A_SESSION_ID)
|
||||
|
||||
verify {
|
||||
context.instance.startActivity(intent)
|
||||
}
|
||||
// Then
|
||||
context.verifyStartActivity(intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given an intent when navigating to other sessions list then it starts the correct activity`() {
|
||||
// Given
|
||||
val intent = givenIntentForOtherSessions(A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true)
|
||||
context.givenStartActivity(intent)
|
||||
|
||||
// When
|
||||
vectorSettingsDevicesViewNavigator.navigateToOtherSessions(context.instance, A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true)
|
||||
|
||||
verify {
|
||||
context.instance.startActivity(intent)
|
||||
// Then
|
||||
context.verifyStartActivity(intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given an intent when navigating to rename session screen then it starts the correct activity`() {
|
||||
// Given
|
||||
val intent = givenIntentForRenameSession(A_SESSION_ID)
|
||||
context.givenStartActivity(intent)
|
||||
|
||||
// When
|
||||
vectorSettingsDevicesViewNavigator.navigateToRenameSession(context.instance, A_SESSION_ID)
|
||||
|
||||
// Then
|
||||
context.verifyStartActivity(intent)
|
||||
}
|
||||
|
||||
private fun givenIntentForSessionOverview(sessionId: String): Intent {
|
||||
|
@ -85,4 +102,10 @@ class VectorSettingsDevicesViewNavigatorTest {
|
|||
every { OtherSessionsActivity.newIntent(context.instance, titleResourceId, defaultFilter, excludeCurrentDevice) } returns intent
|
||||
return intent
|
||||
}
|
||||
|
||||
private fun givenIntentForRenameSession(sessionId: String): Intent {
|
||||
val intent = mockk<Intent>()
|
||||
every { RenameSessionActivity.newIntent(context.instance, sessionId) } returns intent
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import io.mockk.every
|
|||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
import io.mockk.unmockkAll
|
||||
import io.mockk.verify
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
@ -47,14 +46,15 @@ class OtherSessionsViewNavigatorTest {
|
|||
|
||||
@Test
|
||||
fun `given a device id when navigating to overview then it starts the correct activity`() {
|
||||
// Given
|
||||
val intent = givenIntentForDeviceOverview(A_DEVICE_ID)
|
||||
context.givenStartActivity(intent)
|
||||
|
||||
// When
|
||||
otherSessionsViewNavigator.navigateToSessionOverview(context.instance, A_DEVICE_ID)
|
||||
|
||||
verify {
|
||||
context.instance.startActivity(intent)
|
||||
}
|
||||
// Then
|
||||
context.verifyStartActivity(intent)
|
||||
}
|
||||
|
||||
private fun givenIntentForDeviceOverview(deviceId: String): Intent {
|
||||
|
|
|
@ -60,9 +60,7 @@ class SessionOverviewViewNavigatorTest {
|
|||
sessionOverviewViewNavigator.goToSessionDetails(context.instance, A_SESSION_ID)
|
||||
|
||||
// Then
|
||||
verify {
|
||||
context.instance.startActivity(intent)
|
||||
}
|
||||
context.verifyStartActivity(intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,9 +73,7 @@ class SessionOverviewViewNavigatorTest {
|
|||
sessionOverviewViewNavigator.goToRenameSession(context.instance, A_SESSION_ID)
|
||||
|
||||
// Then
|
||||
verify {
|
||||
context.instance.startActivity(intent)
|
||||
}
|
||||
context.verifyStartActivity(intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,9 +24,9 @@ import android.net.ConnectivityManager
|
|||
import android.net.Uri
|
||||
import android.os.ParcelFileDescriptor
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.justRun
|
||||
import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import io.mockk.verify
|
||||
import java.io.OutputStream
|
||||
|
||||
class FakeContext(
|
||||
|
@ -73,7 +73,11 @@ class FakeContext(
|
|||
}
|
||||
|
||||
fun givenStartActivity(intent: Intent) {
|
||||
every { instance.startActivity(intent) } just runs
|
||||
justRun { instance.startActivity(intent) }
|
||||
}
|
||||
|
||||
fun verifyStartActivity(intent: Intent) {
|
||||
verify { instance.startActivity(intent) }
|
||||
}
|
||||
|
||||
fun givenClipboardManager(): FakeClipboardManager {
|
||||
|
|
Loading…
Reference in a new issue