From 1afabb69c11469f5b5e798024e686a3bb49f8fe0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sat, 11 Jul 2020 13:13:08 +0200 Subject: [PATCH] Cleanup pref --- .../features/settings/VectorPreferences.kt | 2 - .../VectorSettingsSecurityPrivacyFragment.kt | 50 +++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index b485e337a9..9d08a9f62f 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -72,8 +72,6 @@ class VectorPreferences @Inject constructor(private val context: Context) { const val SETTINGS_ALLOW_INTEGRATIONS_KEY = "SETTINGS_ALLOW_INTEGRATIONS_KEY" const val SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY = "SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY" const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY" - const val SETTINGS_CRYPTOGRAPHY_MANAGE_4S_CATEGORY_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_4S_CATEGORY_KEY" - const val SETTINGS_SECURE_BACKUP_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_BACKUP_RECOVERY_PREFERENCE_KEY" // const val SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY = "SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY" // user diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt index 858b5eee76..7d524b76de 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -111,10 +111,10 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } private val secureBackupCategory by lazy { - findPreference(VectorPreferences.SETTINGS_CRYPTOGRAPHY_MANAGE_4S_CATEGORY_KEY) + findPreference("SETTINGS_CRYPTOGRAPHY_MANAGE_4S_CATEGORY_KEY")!! } private val secureBackupPreference by lazy { - findPreference(VectorPreferences.SETTINGS_SECURE_BACKUP_RECOVERY_PREFERENCE_KEY) + findPreference("SETTINGS_SECURE_BACKUP_RECOVERY_PREFERENCE_KEY")!! } // private val secureBackupResetPreference by lazy { // findPreference(VectorPreferences.SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY) @@ -129,30 +129,30 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } private fun refresh4SSection(state: SecretsSynchronisationInfo) { - secureBackupCategory?.isVisible = false + secureBackupCategory.isVisible = false // it's a lot of if / else if / else // But it's not yet clear how to manage all cases if (!state.isCrossSigningEnabled) { // There is not cross signing, so we can remove the section } else { - secureBackupCategory?.isVisible = true + secureBackupCategory.isVisible = true if (!state.isBackupSetup) { if (state.isCrossSigningEnabled && state.allPrivateKeysKnown) { // You can setup recovery! - secureBackupCategory?.isVisible = true - secureBackupPreference?.isVisible = true - secureBackupPreference?.title = getString(R.string.settings_secure_backup_setup) - secureBackupPreference?.isEnabled = true - secureBackupPreference?.onPreferenceClickListener = Preference.OnPreferenceClickListener { + secureBackupCategory.isVisible = true + secureBackupPreference.isVisible = true + secureBackupPreference.title = getString(R.string.settings_secure_backup_setup) + secureBackupPreference.isEnabled = true + secureBackupPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { BootstrapBottomSheet.show(parentFragmentManager, initCrossSigningOnly = false, forceReset4S = false) true } } else { // just hide all, you can't setup from here // you should synchronize to get gossips - secureBackupCategory?.isVisible = false + secureBackupCategory.isVisible = false } return } @@ -164,38 +164,38 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( if (!state.megolmBackupAvailable || state.megolmSecretKnown) { // Only option here is to create a new backup if you want? // aka reset - secureBackupCategory?.isVisible = true - secureBackupPreference?.isVisible = true - secureBackupPreference?.title = getString(R.string.settings_secure_backup_reset) - secureBackupPreference?.onPreferenceClickListener = Preference.OnPreferenceClickListener { + secureBackupCategory.isVisible = true + secureBackupPreference.isVisible = true + secureBackupPreference.title = getString(R.string.settings_secure_backup_reset) + secureBackupPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { BootstrapBottomSheet.show(parentFragmentManager, initCrossSigningOnly = false, forceReset4S = true) true } } else if (!state.megolmSecretKnown) { // megolm backup is available but we don't have key // you could try to synchronize to get missing megolm key ? - secureBackupCategory?.isVisible = true - secureBackupPreference?.isVisible = true - secureBackupPreference?.title = getString(R.string.settings_secure_backup_enter_to_setup) - secureBackupPreference?.isEnabled = true - secureBackupPreference?.onPreferenceClickListener = Preference.OnPreferenceClickListener { + secureBackupCategory.isVisible = true + secureBackupPreference.isVisible = true + secureBackupPreference.title = getString(R.string.settings_secure_backup_enter_to_setup) + secureBackupPreference.isEnabled = true + secureBackupPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { (requireActivity() as? VectorBaseActivity)?.let { it.navigator.requestSelfSessionVerification(it) } true } } else { - secureBackupCategory?.isVisible = false + secureBackupCategory.isVisible = false } return } else { // there is a backup, but this session is not trusted, or is missing some secrets // you should enter passphrase to get them or verify against another session - secureBackupCategory?.isVisible = true - secureBackupPreference?.isVisible = true - secureBackupPreference?.title = getString(R.string.settings_secure_backup_enter_to_setup) - secureBackupPreference?.isEnabled = true - secureBackupPreference?.onPreferenceClickListener = Preference.OnPreferenceClickListener { + secureBackupCategory.isVisible = true + secureBackupPreference.isVisible = true + secureBackupPreference.title = getString(R.string.settings_secure_backup_enter_to_setup) + secureBackupPreference.isEnabled = true + secureBackupPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { (requireActivity() as? VectorBaseActivity)?.let { it.navigator.requestSelfSessionVerification(it) }