From 3d31e3d75f1b94e06ab453bec59c588be22e06f0 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Mon, 28 Jun 2021 13:36:43 +0300 Subject: [PATCH 01/19] Renamed ChangePassPhraseActivity to ChangePassphraseOfImportedKeysFragment.| #1303 --- ...est.kt => ChangePassphraseOfImportedKeysFragmentTest.kt} | 4 ++-- FlowCrypt/src/main/AndroidManifest.xml | 2 +- ...ctivity.kt => ChangePassphraseOfImportedKeysFragment.kt} | 4 ++-- .../email/ui/activity/fragment/BackupKeysFragment.kt | 4 ++-- .../fragment/preferences/SecuritySettingsFragment.kt | 6 +++--- .../email/ui/notifications/SystemNotificationManager.kt | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) rename FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/{ChangePassPhraseActivityTest.kt => ChangePassphraseOfImportedKeysFragmentTest.kt} (95%) rename FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/{ChangePassPhraseActivity.kt => ChangePassphraseOfImportedKeysFragment.kt} (97%) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ChangePassPhraseActivityTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragmentTest.kt similarity index 95% rename from FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ChangePassPhraseActivityTest.kt rename to FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragmentTest.kt index 02ed4b6e20..04c6f7cdc3 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ChangePassPhraseActivityTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragmentTest.kt @@ -39,11 +39,11 @@ import org.junit.runner.RunWith */ @MediumTest @RunWith(AndroidJUnit4::class) -class ChangePassPhraseActivityTest : BasePassphraseActivityTest() { +class ChangePassphraseOfImportedKeysFragmentTest : BasePassphraseActivityTest() { private val addAccountToDatabaseRule = AddAccountToDatabaseRule() override val useIntents: Boolean = true - override val activityScenarioRule = activityScenarioRule() + override val activityScenarioRule = activityScenarioRule() @get:Rule var ruleChain: TestRule = RuleChain diff --git a/FlowCrypt/src/main/AndroidManifest.xml b/FlowCrypt/src/main/AndroidManifest.xml index 4f912dbff3..863b87b5c5 100644 --- a/FlowCrypt/src/main/AndroidManifest.xml +++ b/FlowCrypt/src/main/AndroidManifest.xml @@ -176,7 +176,7 @@ android:screenOrientation="portrait" /> when (resultCode) { FixNeedPassphraseIssueDialogFragment.RESULT_OK -> { - startActivity(ChangePassPhraseActivity.newIntent(context)) + startActivity(ChangePassphraseOfImportedKeysFragment.newIntent(context)) } } @@ -72,7 +72,7 @@ class SecuritySettingsFragment : BasePreferenceFragment(), Preference.OnPreferen logicType = FixNeedPassphraseIssueDialogFragment.LogicType.ALL ) } else { - startActivity(ChangePassPhraseActivity.newIntent(context)) + startActivity(ChangePassphraseOfImportedKeysFragment.newIntent(context)) } } true diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt index 11d50a6d1c..738bfe25af 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt @@ -14,7 +14,7 @@ import androidx.core.app.NotificationCompat import com.flowcrypt.email.BuildConfig import com.flowcrypt.email.R import com.flowcrypt.email.database.entity.AccountEntity -import com.flowcrypt.email.ui.activity.ChangePassPhraseActivity +import com.flowcrypt.email.ui.activity.ChangePassphraseOfImportedKeysFragment import com.flowcrypt.email.ui.activity.EmailManagerActivity /** @@ -42,7 +42,7 @@ class SystemNotificationManager(context: Context) : CustomNotificationManager(co val intent = if (account?.isRuleExist(AccountEntity.DomainRule.NO_PRV_BACKUP) == true) { Intent(context, EmailManagerActivity::class.java) } else { - ChangePassPhraseActivity.newIntent(context) + ChangePassphraseOfImportedKeysFragment.newIntent(context) } val pendingIntent = From fe3907e53fbc790d757baeccca4378aaa9ff972f Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Mon, 28 Jun 2021 14:29:03 +0300 Subject: [PATCH 02/19] wip| #1303 --- FlowCrypt/src/main/AndroidManifest.xml | 4 - .../ChangePassphraseOfImportedKeysFragment.kt | 97 ++++++------ .../activity/fragment/BackupKeysFragment.kt | 3 +- .../preferences/SecuritySettingsFragment.kt | 12 +- .../SystemNotificationManager.kt | 4 +- ...agment_apply_new_passphrase_first_step.xml | 141 ++++++++++++++++++ .../src/main/res/navigation/nav_graph.xml | 13 ++ 7 files changed, 220 insertions(+), 54 deletions(-) create mode 100644 FlowCrypt/src/main/res/layout/fragment_apply_new_passphrase_first_step.xml diff --git a/FlowCrypt/src/main/AndroidManifest.xml b/FlowCrypt/src/main/AndroidManifest.xml index 863b87b5c5..2fba9ff57e 100644 --- a/FlowCrypt/src/main/AndroidManifest.xml +++ b/FlowCrypt/src/main/AndroidManifest.xml @@ -175,10 +175,6 @@ android:label="@string/add_contact" android:screenOrientation="portrait" /> - - diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragment.kt index 8eadae0106..1c43481706 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/ChangePassphraseOfImportedKeysFragment.kt @@ -5,52 +5,63 @@ package com.flowcrypt.email.ui.activity -import android.app.Activity import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle +import android.view.LayoutInflater import android.view.View -import android.widget.Toast -import androidx.activity.viewModels +import android.view.ViewGroup +import androidx.fragment.app.viewModels import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result -import com.flowcrypt.email.database.entity.AccountEntity +import com.flowcrypt.email.databinding.FragmentApplyNewPassphraseFirstStepBinding import com.flowcrypt.email.extensions.decrementSafely import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.jetpack.viewmodel.LoadPrivateKeysViewModel import com.flowcrypt.email.jetpack.viewmodel.PrivateKeysViewModel -import com.flowcrypt.email.ui.activity.base.BasePassPhraseManagerActivity +import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment import com.flowcrypt.email.ui.notifications.SystemNotificationManager -import com.flowcrypt.email.util.UIUtil -import org.pgpainless.util.Passphrase /** - * This activity describes a logic of changing the pass phrase of all imported private keys of an active account. + * This fragment describes a logic of changing the passphrase of all imported private keys of + * an active account. * * @author Denis Bondarenko * Date: 05.08.2018 * Time: 20:15 * E-mail: DenBond7@gmail.com */ -class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { +class ChangePassphraseOfImportedKeysFragment : BaseFragment() { + private var binding: FragmentApplyNewPassphraseFirstStepBinding? = null private val loadPrivateKeysViewModel: LoadPrivateKeysViewModel by viewModels() private val privateKeysViewModel: PrivateKeysViewModel by viewModels() - override fun onConfirmPassPhraseSuccess() { - privateKeysViewModel.changePassphrase( - Passphrase.fromPassword(editTextKeyPassword.text.toString()) - ) + override val contentResourceId: Int = R.layout.fragment_apply_new_passphrase_first_step + + override fun onAttach(context: Context) { + super.onAttach(context) + SystemNotificationManager(context) + .cancel(SystemNotificationManager.NOTIFICATION_ID_PASSPHRASE_TOO_WEAK) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentApplyNewPassphraseFirstStepBinding.inflate(inflater, container, false) + return binding?.root } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - SystemNotificationManager(this).cancel(SystemNotificationManager.NOTIFICATION_ID_PASSPHRASE_TOO_WEAK) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + supportActionBar?.title = getString(R.string.security) setupLoadPrivateKeysViewModel() setupPrivateKeysViewModel() } - override fun onBackPressed() { + /*override fun onBackPressed() { if (isBackEnabled) { super.onBackPressed() } else { @@ -71,9 +82,9 @@ class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { else -> super.onClick(v) } - } + }*/ - override fun initViews() { + /*override fun initViews() { super.initViews() textViewFirstPasswordCheckTitle.setText(R.string.change_pass_phrase) @@ -82,22 +93,22 @@ class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { textViewSuccessTitle.setText(R.string.done) textViewSuccessSubTitle.setText(R.string.pass_phrase_changed) btnSuccess.setText(R.string.back) - } + }*/ private fun runBackupKeysActivity() { - isBackEnabled = true - Toast.makeText(this, R.string.back_up_updated_key, Toast.LENGTH_LONG).show() + //isBackEnabled = true + //Toast.makeText(this, R.string.back_up_updated_key, Toast.LENGTH_LONG).show() val intent = Intent(Intent.ACTION_VIEW, Uri.parse("flowcrypt://email.flowcrypt.com/settings/make_backup")) startActivity(intent) } private fun setupLoadPrivateKeysViewModel() { - loadPrivateKeysViewModel.privateKeysLiveData.observe(this, { + loadPrivateKeysViewModel.privateKeysLiveData.observe(viewLifecycleOwner, { it?.let { when (it.status) { Result.Status.LOADING -> { - countingIdlingResource.incrementSafely() + baseActivity.countingIdlingResource.incrementSafely() } Result.Status.SUCCESS -> { @@ -107,28 +118,28 @@ class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { } else { privateKeysViewModel.saveBackupsToInbox() } - countingIdlingResource.decrementSafely() + baseActivity.countingIdlingResource.decrementSafely() } Result.Status.ERROR, Result.Status.EXCEPTION -> { runBackupKeysActivity() - countingIdlingResource.decrementSafely() + baseActivity.countingIdlingResource.decrementSafely() } - else -> countingIdlingResource.decrementSafely() + else -> baseActivity.countingIdlingResource.decrementSafely() } } }) } private fun setupPrivateKeysViewModel() { - privateKeysViewModel.changePassphraseLiveData.observe(this, { + privateKeysViewModel.changePassphraseLiveData.observe(viewLifecycleOwner, { it?.let { - when (it.status) { + /*when (it.status) { Result.Status.LOADING -> { - countingIdlingResource.incrementSafely() - isBackEnabled = false - UIUtil.exchangeViewVisibility(true, layoutProgress, layoutContentView) + baseActivity.countingIdlingResource.incrementSafely() + //isBackEnabled = false + //UIUtil.exchangeViewVisibility(true, layoutProgress, layoutContentView) } Result.Status.SUCCESS -> { @@ -145,7 +156,7 @@ class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { } } - countingIdlingResource.decrementSafely() + baseActivity.countingIdlingResource.decrementSafely() } Result.Status.ERROR, Result.Status.EXCEPTION -> { @@ -154,19 +165,19 @@ class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { UIUtil.exchangeViewVisibility(false, layoutProgress, layoutContentView) showInfoSnackbar(rootView, it.exception?.message ?: getString(R.string.unknown_error)) - countingIdlingResource.decrementSafely() + baseActivity.countingIdlingResource.decrementSafely() } - else -> countingIdlingResource.decrementSafely() - } + else -> baseActivity.countingIdlingResource.decrementSafely() + }*/ } }) - privateKeysViewModel.saveBackupToInboxLiveData.observe(this, { + privateKeysViewModel.saveBackupToInboxLiveData.observe(viewLifecycleOwner, { it?.let { - when (it.status) { + /*when (it.status) { Result.Status.LOADING -> { - countingIdlingResource.incrementSafely() + baseActivity.countingIdlingResource.incrementSafely() } Result.Status.SUCCESS -> { @@ -174,18 +185,18 @@ class ChangePassphraseOfImportedKeysFragment : BasePassPhraseManagerActivity() { Toast.makeText(this, R.string.pass_phrase_changed, Toast.LENGTH_SHORT).show() setResult(Activity.RESULT_OK) - countingIdlingResource.decrementSafely() + baseActivity.countingIdlingResource.decrementSafely() finish() } Result.Status.ERROR, Result.Status.EXCEPTION -> { isBackEnabled = true runBackupKeysActivity() - countingIdlingResource.decrementSafely() + baseActivity.countingIdlingResource.decrementSafely() } - else -> countingIdlingResource.decrementSafely() - } + else -> baseActivity.countingIdlingResource.decrementSafely() + }*/ } }) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/BackupKeysFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/BackupKeysFragment.kt index c04274e3db..8f2684d72d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/BackupKeysFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/BackupKeysFragment.kt @@ -27,7 +27,6 @@ import com.flowcrypt.email.jetpack.viewmodel.BackupsViewModel import com.flowcrypt.email.jetpack.viewmodel.PrivateKeysViewModel import com.flowcrypt.email.security.KeysStorageImpl import com.flowcrypt.email.security.SecurityUtils -import com.flowcrypt.email.ui.activity.ChangePassphraseOfImportedKeysFragment import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment import com.flowcrypt.email.ui.activity.fragment.base.ProgressBehaviour import com.flowcrypt.email.ui.activity.fragment.dialog.FixNeedPassphraseIssueDialogFragment @@ -300,7 +299,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour { btnName = btnName, duration = Snackbar.LENGTH_LONG ) { - startActivityForResult(ChangePassphraseOfImportedKeysFragment.newIntent(requireContext()), 0) + //startActivityForResult(ChangePassphraseOfImportedKeysFragment.newIntent(requireContext()), 0) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/SecuritySettingsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/SecuritySettingsFragment.kt index 1e52115299..361ff7d43e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/SecuritySettingsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/SecuritySettingsFragment.kt @@ -12,9 +12,9 @@ import androidx.appcompat.app.AppCompatActivity import androidx.preference.Preference import com.flowcrypt.email.Constants import com.flowcrypt.email.R +import com.flowcrypt.email.extensions.navController import com.flowcrypt.email.extensions.showNeedPassphraseDialog import com.flowcrypt.email.security.KeysStorageImpl -import com.flowcrypt.email.ui.activity.ChangePassphraseOfImportedKeysFragment import com.flowcrypt.email.ui.activity.fragment.base.BasePreferenceFragment import com.flowcrypt.email.ui.activity.fragment.dialog.FixNeedPassphraseIssueDialogFragment import com.flowcrypt.email.util.UIUtil @@ -44,7 +44,10 @@ class SecuritySettingsFragment : BasePreferenceFragment(), Preference.OnPreferen when (requestCode) { REQUEST_CODE_SHOW_FIX_EMPTY_PASSPHRASE_DIALOG -> when (resultCode) { FixNeedPassphraseIssueDialogFragment.RESULT_OK -> { - startActivity(ChangePassphraseOfImportedKeysFragment.newIntent(context)) + navController?.navigate( + SecuritySettingsFragmentDirections + .actionSecuritySettingsFragmentToChangePassphraseOfImportedKeysFragment() + ) } } @@ -72,7 +75,10 @@ class SecuritySettingsFragment : BasePreferenceFragment(), Preference.OnPreferen logicType = FixNeedPassphraseIssueDialogFragment.LogicType.ALL ) } else { - startActivity(ChangePassphraseOfImportedKeysFragment.newIntent(context)) + navController?.navigate( + SecuritySettingsFragmentDirections + .actionSecuritySettingsFragmentToChangePassphraseOfImportedKeysFragment() + ) } } true diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt index 738bfe25af..4408f089ed 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/notifications/SystemNotificationManager.kt @@ -14,7 +14,6 @@ import androidx.core.app.NotificationCompat import com.flowcrypt.email.BuildConfig import com.flowcrypt.email.R import com.flowcrypt.email.database.entity.AccountEntity -import com.flowcrypt.email.ui.activity.ChangePassphraseOfImportedKeysFragment import com.flowcrypt.email.ui.activity.EmailManagerActivity /** @@ -42,7 +41,8 @@ class SystemNotificationManager(context: Context) : CustomNotificationManager(co val intent = if (account?.isRuleExist(AccountEntity.DomainRule.NO_PRV_BACKUP) == true) { Intent(context, EmailManagerActivity::class.java) } else { - ChangePassphraseOfImportedKeysFragment.newIntent(context) + Intent(context, EmailManagerActivity::class.java) + //ChangePassphraseOfImportedKeysFragment.newIntent(context) } val pendingIntent = diff --git a/FlowCrypt/src/main/res/layout/fragment_apply_new_passphrase_first_step.xml b/FlowCrypt/src/main/res/layout/fragment_apply_new_passphrase_first_step.xml new file mode 100644 index 0000000000..b49170ad76 --- /dev/null +++ b/FlowCrypt/src/main/res/layout/fragment_apply_new_passphrase_first_step.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + +