SoftLogout: adapt wording depending if all keys are backed up or not

This commit is contained in:
Benoit Marty 2019-12-12 17:39:21 +01:00
parent b9e8da1fbb
commit efc1f38f8c
8 changed files with 41 additions and 15 deletions

View File

@ -19,6 +19,7 @@ package im.vector.riotx.core.extensions
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ProcessLifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner
import im.vector.matrix.android.api.session.Session 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.FilterService import im.vector.matrix.android.api.session.sync.FilterService
import im.vector.riotx.features.notifications.PushRuleTriggerListener import im.vector.riotx.features.notifications.PushRuleTriggerListener
import im.vector.riotx.features.session.SessionListener import im.vector.riotx.features.session.SessionListener
@ -40,3 +41,11 @@ fun Session.configureAndStart(pushRuleTriggerListener: PushRuleTriggerListener,
// @Inject lateinit var incomingVerificationRequestHandler: IncomingVerificationRequestHandler // @Inject lateinit var incomingVerificationRequestHandler: IncomingVerificationRequestHandler
// @Inject lateinit var keyRequestHandler: KeyRequestHandler // @Inject lateinit var keyRequestHandler: KeyRequestHandler
} }
/**
* Tell is the session has unsaved e2e keys in the backup
*/
fun Session.hasUnsavedKeys(): Boolean {
return inboundGroupSessionsCount(false) > 0
&& getKeysBackupService().state != KeysBackupState.ReadyToBackUp
}

View File

@ -22,6 +22,7 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.autofill.HintConstants import androidx.autofill.HintConstants
import androidx.core.view.isVisible
import butterknife.OnClick import butterknife.OnClick
import com.airbnb.mvrx.* import com.airbnb.mvrx.*
import com.jakewharton.rxbinding3.widget.textChanges import com.jakewharton.rxbinding3.widget.textChanges
@ -75,12 +76,18 @@ class SoftLogoutFragment @Inject constructor(
} }
@OnClick(R.id.softLogoutClearDataSubmit) @OnClick(R.id.softLogoutClearDataSubmit)
fun clearData() { fun clearData() = withState(softLogoutViewModel) { state ->
cleanupUi() cleanupUi()
val messageResId = if (state.hasUnsavedKeys) {
R.string.soft_logout_clear_data_dialog_content
} else {
R.string.soft_logout_clear_data_dialog_e2e_warning_content
}
AlertDialog.Builder(requireActivity()) AlertDialog.Builder(requireActivity())
.setTitle(R.string.soft_logout_clear_data_dialog_title) .setTitle(R.string.soft_logout_clear_data_dialog_title)
.setMessage(R.string.soft_logout_clear_data_dialog_content) .setMessage(messageResId)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.soft_logout_clear_data_submit) { _, _ -> .setPositiveButton(R.string.soft_logout_clear_data_submit) { _, _ ->
MainActivity.restartApp(requireActivity(), MainActivityArgs( MainActivity.restartApp(requireActivity(), MainActivityArgs(
@ -103,6 +110,8 @@ class SoftLogoutFragment @Inject constructor(
state.homeServerUrl, state.homeServerUrl,
state.userDisplayName, state.userDisplayName,
state.userId) state.userId)
softLogoutE2eWarningNotice.isVisible = state.hasUnsavedKeys
} }
private fun setupSubmitButton() { private fun setupSubmitButton() {

View File

@ -23,6 +23,7 @@ import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.core.extensions.hasUnsavedKeys
import im.vector.riotx.core.extensions.toReducedUrl import im.vector.riotx.core.extensions.toReducedUrl
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
@ -48,7 +49,8 @@ class SoftLogoutViewModel @AssistedInject constructor(
return SoftLogoutViewState( return SoftLogoutViewState(
homeServerUrl = activity.session.sessionParams.homeServerConnectionConfig.homeServerUri.toString().toReducedUrl(), homeServerUrl = activity.session.sessionParams.homeServerConnectionConfig.homeServerUri.toString().toReducedUrl(),
userId = userId, userId = userId,
userDisplayName = activity.session.getUser(userId)?.displayName ?: userId userDisplayName = activity.session.getUser(userId)?.displayName ?: userId,
hasUnsavedKeys = activity.session.hasUnsavedKeys()
) )
} }

View File

@ -25,7 +25,8 @@ data class SoftLogoutViewState(
val asyncLoginAction: Async<Unit> = Uninitialized, val asyncLoginAction: Async<Unit> = Uninitialized,
val homeServerUrl: String, val homeServerUrl: String,
val userId: String, val userId: String,
val userDisplayName: String val userDisplayName: String,
val hasUnsavedKeys: Boolean
) : MvRxState { ) : MvRxState {
fun isLoading(): Boolean { fun isLoading(): Boolean {

View File

@ -21,6 +21,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.core.extensions.hasUnsavedKeys
import im.vector.riotx.core.extensions.vectorComponent import im.vector.riotx.core.extensions.vectorComponent
import im.vector.riotx.features.MainActivity import im.vector.riotx.features.MainActivity
import im.vector.riotx.features.MainActivityArgs import im.vector.riotx.features.MainActivityArgs
@ -32,7 +33,8 @@ class SignOutUiWorker(private val activity: FragmentActivity) {
fun perform(context: Context) { fun perform(context: Context) {
activeSessionHolder = context.vectorComponent().activeSessionHolder() activeSessionHolder = context.vectorComponent().activeSessionHolder()
val session = activeSessionHolder.getActiveSession() val session = activeSessionHolder.getActiveSession()
if (SignOutViewModel.doYouNeedToBeDisplayed(session)) { if (session.hasUnsavedKeys()) {
// The backup check on logout flow has to be displayed if there are keys in the store, and the keys backup state is not Ready
val signOutDialog = SignOutBottomSheetDialogFragment.newInstance() val signOutDialog = SignOutBottomSheetDialogFragment.newInstance()
signOutDialog.onSignOut = Runnable { signOutDialog.onSignOut = Runnable {
doSignOut() doSignOut()

View File

@ -71,14 +71,4 @@ class SignOutViewModel @Inject constructor(private val session: Session) : ViewM
session.getKeysBackupService().checkAndStartKeysBackup() session.getKeysBackupService().checkAndStartKeysBackup()
} }
} }
companion object {
/**
* The backup check on logout flow has to be displayed if there are keys in the store, and the keys backup state is not Ready
*/
fun doYouNeedToBeDisplayed(session: Session): Boolean {
return session.inboundGroupSessionsCount(false) > 0
&& session.getKeysBackupService().state != KeysBackupState.ReadyToBackUp
}
}
} }

View File

@ -43,6 +43,17 @@
android:textAppearance="@style/TextAppearance.Vector.Login.Text" android:textAppearance="@style/TextAppearance.Vector.Login.Text"
tools:text="@string/soft_logout_signin_notice" /> tools:text="@string/soft_logout_signin_notice" />
<TextView
android:id="@+id/softLogoutE2eWarningNotice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="start"
android:text="@string/soft_logout_signin_e2e_warning_notice"
android:textAppearance="@style/TextAppearance.Vector.Login.Text"
android:visibility="gone"
tools:visibility="visible" />
<FrameLayout <FrameLayout
android:id="@+id/softLogoutPasswordContainer" android:id="@+id/softLogoutPasswordContainer"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -148,6 +148,7 @@
<string name="soft_logout_signin_title">Sign in</string> <string name="soft_logout_signin_title">Sign in</string>
<!-- Replacement: homeserver url, user display name and userId --> <!-- Replacement: homeserver url, user display name and userId -->
<string name="soft_logout_signin_notice">Your homeserver (%1$s) admin has signed you out of your account %2$s (%3$s).</string> <string name="soft_logout_signin_notice">Your homeserver (%1$s) admin has signed you out of your account %2$s (%3$s).</string>
<string name="soft_logout_signin_e2e_warning_notice">Sign in to recover encryption keys stored exclusively on this device. You need them to read all of your secure messages on any device.</string>
<string name="soft_logout_signin_submit">Sign in</string> <string name="soft_logout_signin_submit">Sign in</string>
<string name="soft_logout_signin_password_hint">Password</string> <string name="soft_logout_signin_password_hint">Password</string>
<string name="soft_logout_clear_data_title">Clear personal data</string> <string name="soft_logout_clear_data_title">Clear personal data</string>
@ -156,6 +157,7 @@
<string name="soft_logout_clear_data_dialog_title">Clear data</string> <string name="soft_logout_clear_data_dialog_title">Clear data</string>
<string name="soft_logout_clear_data_dialog_content">Clear all data currently stored on this device?\nSign in again to access your account data and messages.</string> <string name="soft_logout_clear_data_dialog_content">Clear all data currently stored on this device?\nSign in again to access your account data and messages.</string>
<string name="soft_logout_clear_data_dialog_e2e_warning_content">Youll lose access to secure messages unless you sign in to recover your encryption keys.</string>
<string name="soft_logout_clear_data_dialog_submit">Clear data</string> <string name="soft_logout_clear_data_dialog_submit">Clear data</string>
</resources> </resources>