Toggle ip address on sessions overview screen.

This commit is contained in:
Onuray Sahin 2022-11-08 16:33:20 +03:00
parent b5e8375592
commit 0868869fe3
7 changed files with 39 additions and 0 deletions

View File

@ -76,6 +76,7 @@ class SessionInfoView @JvmOverloads constructor(
sessionInfoViewState.deviceFullInfo.isInactive,
sessionInfoViewState.deviceFullInfo.deviceInfo,
sessionInfoViewState.isLastSeenDetailsVisible,
sessionInfoViewState.isShowingIpAddress,
dateFormatter,
drawableProvider,
colorProvider,
@ -157,6 +158,7 @@ class SessionInfoView @JvmOverloads constructor(
isInactive: Boolean,
deviceInfo: DeviceInfo,
isLastSeenDetailsVisible: Boolean,
isShowingIpAddress: Boolean,
dateFormatter: VectorDateFormatter,
drawableProvider: DrawableProvider,
colorProvider: ColorProvider,
@ -187,6 +189,7 @@ class SessionInfoView @JvmOverloads constructor(
views.sessionInfoLastActivityTextView.isGone = true
}
views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible })
views.sessionInfoLastIPAddressTextView.isVisible = isShowingIpAddress
}
private fun renderDetailsButton(isDetailsButtonVisible: Boolean) {

View File

@ -25,4 +25,5 @@ data class SessionInfoViewState(
val isDetailsButtonVisible: Boolean = true,
val isLearnMoreLinkVisible: Boolean = false,
val isLastSeenDetailsVisible: Boolean = false,
val isShowingIpAddress: Boolean = false,
)

View File

@ -29,4 +29,5 @@ sealed class SessionOverviewAction : VectorViewModelAction {
val deviceId: String,
val enabled: Boolean,
) : SessionOverviewAction()
object ToggleIpAddressVisibility : SessionOverviewAction()
}

View File

@ -19,6 +19,7 @@ package im.vector.app.features.settings.devices.v2.overview
import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
@ -156,16 +157,34 @@ class SessionOverviewFragment :
override fun getMenuRes() = R.menu.menu_session_overview
override fun handlePrepareMenu(menu: Menu) {
withState(viewModel) { state ->
menu.findItem(R.id.sessionOverviewToggleIpAddress).title = if (state.isShowingIpAddress) {
getString(R.string.device_manager_other_sessions_hide_ip_address)
} else {
getString(R.string.device_manager_other_sessions_show_ip_address)
}
}
}
override fun handleMenuItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.sessionOverviewRename -> {
goToRenameSession()
true
}
R.id.sessionOverviewToggleIpAddress -> {
toggleIpAddressVisibility()
true
}
else -> false
}
}
private fun toggleIpAddressVisibility() {
viewModel.handle(SessionOverviewAction.ToggleIpAddressVisibility)
}
private fun goToRenameSession() = withState(viewModel) { state ->
viewNavigator.goToRenameSession(requireContext(), state.deviceId)
}
@ -206,6 +225,7 @@ class SessionOverviewFragment :
isDetailsButtonVisible = false,
isLearnMoreLinkVisible = deviceInfo.roomEncryptionTrustLevel != RoomEncryptionTrustLevel.Default,
isLastSeenDetailsVisible = !isCurrentSession,
isShowingIpAddress = viewState.isShowingIpAddress,
)
views.sessionOverviewInfo.render(infoViewState, dateFormatter, drawableProvider, colorProvider, stringProvider)
views.sessionOverviewInfo.onLearnMoreClickListener = {

View File

@ -113,6 +113,14 @@ class SessionOverviewViewModel @AssistedInject constructor(
is SessionOverviewAction.PasswordAuthDone -> handlePasswordAuthDone(action)
SessionOverviewAction.ReAuthCancelled -> handleReAuthCancelled()
is SessionOverviewAction.TogglePushNotifications -> handleTogglePusherAction(action)
SessionOverviewAction.ToggleIpAddressVisibility -> handleToggleIpAddressVisibility()
}
}
private fun handleToggleIpAddressVisibility() = withState { state ->
val isShowingIpAddress = state.isShowingIpAddress
setState {
copy(isShowingIpAddress = !isShowingIpAddress)
}
}

View File

@ -28,6 +28,7 @@ data class SessionOverviewViewState(
val deviceInfo: Async<DeviceFullInfo> = Uninitialized,
val isLoading: Boolean = false,
val notificationsStatus: NotificationsStatus = NotificationsStatus.NOT_SUPPORTED,
val isShowingIpAddress: Boolean = false,
) : MavericksState {
constructor(args: SessionOverviewArgs) : this(
deviceId = args.deviceId

View File

@ -4,6 +4,11 @@
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/sessionOverviewToggleIpAddress"
android:title="@string/device_manager_other_sessions_show_ip_address"
app:showAsAction="withText|never" />
<item
android:id="@+id/sessionOverviewRename"
android:title="@string/device_manager_session_rename"