From 0e85a3d59f76fd3559d01e1618f6689fc94ccfa8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 18 Sep 2020 12:49:14 +0200 Subject: [PATCH 1/3] Add an advanced action to reset an account data entry (there is no API to completely delete it) --- CHANGES.md | 2 +- .../app/core/ui/list/GenericItemWithValue.kt | 4 +++ .../settings/devtools/AccountDataAction.kt | 23 +++++++++++++++++ .../devtools/AccountDataEpoxyController.kt | 7 +++++- .../settings/devtools/AccountDataFragment.kt | 19 ++++++++++++-- .../settings/devtools/AccountDataViewModel.kt | 25 +++++++++++++++---- vector/src/main/res/values/strings.xml | 2 ++ 7 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/settings/devtools/AccountDataAction.kt diff --git a/CHANGES.md b/CHANGES.md index fae13abeed..c2620d63ef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,7 +20,7 @@ Build 🧱: - Other changes: - - + - Add an advanced action to reset an account data entry Changes in Element 1.0.7 (2020-09-17) =================================================== diff --git a/vector/src/main/java/im/vector/app/core/ui/list/GenericItemWithValue.kt b/vector/src/main/java/im/vector/app/core/ui/list/GenericItemWithValue.kt index f9d32a9f1e..0e719a1cd2 100644 --- a/vector/src/main/java/im/vector/app/core/ui/list/GenericItemWithValue.kt +++ b/vector/src/main/java/im/vector/app/core/ui/list/GenericItemWithValue.kt @@ -56,6 +56,9 @@ abstract class GenericItemWithValue : VectorEpoxyModel + viewModel.handle(AccountDataAction.DeleteAccountData(data.type)) + } + .show() + .withColoredButton(DialogInterface.BUTTON_POSITIVE) + } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devtools/AccountDataViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devtools/AccountDataViewModel.kt index 4cac55cb84..af8d162f15 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devtools/AccountDataViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devtools/AccountDataViewModel.kt @@ -16,6 +16,7 @@ package im.vector.app.features.settings.devtools +import androidx.lifecycle.viewModelScope import com.airbnb.mvrx.Async import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.MvRxState @@ -24,11 +25,13 @@ import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject -import org.matrix.android.sdk.api.session.Session -import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent -import im.vector.app.core.platform.EmptyAction +import im.vector.app.core.extensions.exhaustive import im.vector.app.core.platform.EmptyViewEvents import im.vector.app.core.platform.VectorViewModel +import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent +import org.matrix.android.sdk.internal.util.awaitCallback import org.matrix.android.sdk.rx.rx data class AccountDataViewState( @@ -37,7 +40,7 @@ data class AccountDataViewState( class AccountDataViewModel @AssistedInject constructor(@Assisted initialState: AccountDataViewState, private val session: Session) - : VectorViewModel(initialState) { + : VectorViewModel(initialState) { init { session.rx().liveAccountData(emptySet()) @@ -46,7 +49,19 @@ class AccountDataViewModel @AssistedInject constructor(@Assisted initialState: A } } - override fun handle(action: EmptyAction) {} + override fun handle(action: AccountDataAction) { + when (action) { + is AccountDataAction.DeleteAccountData -> handleDeleteAccountData(action) + }.exhaustive + } + + private fun handleDeleteAccountData(action: AccountDataAction.DeleteAccountData) { + viewModelScope.launch { + awaitCallback { + session.updateAccountData(action.type, emptyMap(), it) + } + } + } @AssistedInject.Factory interface Factory { diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 167655f800..a32f3f6a4e 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2226,6 +2226,8 @@ Dev Tools Account Data + Delete the account data of type %1$s?\n\nUse with caution, it may lead to unexpected behavior. + %d vote %d votes From 4b66ffcd5b143310511f1f5315e50ac669d08cda Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 18 Sep 2020 15:00:36 +0200 Subject: [PATCH 2/3] Add "show password" in import Megolm keys dialog --- CHANGES.md | 2 +- .../VectorSettingsSecurityPrivacyFragment.kt | 11 ++++++ .../res/layout/dialog_import_e2e_keys.xml | 36 +++++++++++++++---- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2620d63ef..e6e0b540ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Improvements 🙌: - - + - Add "show password" in import Megolm keys dialog Bugfix 🐛: - diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt index 034fa617f0..ff824733ae 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -24,6 +24,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import android.widget.Button +import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat @@ -38,6 +39,7 @@ 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.queryExportKeys +import im.vector.app.core.extensions.showPassword import im.vector.app.core.intent.ExternalIntentData import im.vector.app.core.intent.analyseIntent import im.vector.app.core.intent.getFilenameFromUri @@ -458,6 +460,15 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( val passPhraseEditText = dialogLayout.findViewById(R.id.dialog_e2e_keys_passphrase_edit_text) val importButton = dialogLayout.findViewById