diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoKeyAvailableFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoKeyAvailableFlowTest.kt new file mode 100644 index 0000000000..a029aa13bc --- /dev/null +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoKeyAvailableFlowTest.kt @@ -0,0 +1,143 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: DenBond7 + */ + +package com.flowcrypt.email.ui + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.replaceText +import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.hasTextColor +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import com.flowcrypt.email.R +import com.flowcrypt.email.TestConstants +import com.flowcrypt.email.extensions.kotlin.asInternetAddress +import com.flowcrypt.email.junit.annotations.FlowCryptTestSettings +import com.flowcrypt.email.rules.AddPrivateKeyToDatabaseRule +import com.flowcrypt.email.rules.ClearAppSettingsRule +import com.flowcrypt.email.rules.FlowCryptMockWebServerRule +import com.flowcrypt.email.rules.GrantPermissionRuleChooser +import com.flowcrypt.email.rules.RetryRule +import com.flowcrypt.email.rules.ScreenshotTestRule +import com.flowcrypt.email.ui.base.BaseComposeScreenTest +import com.flowcrypt.email.util.PrivateKeysManager +import com.flowcrypt.email.util.TestGeneralUtil +import okhttp3.mockwebserver.Dispatcher +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.RecordedRequest +import org.hamcrest.CoreMatchers.not +import org.junit.ClassRule +import org.junit.Rule +import org.junit.Test +import org.junit.rules.RuleChain +import org.junit.rules.TestRule +import org.junit.runner.RunWith +import java.net.HttpURLConnection + +/** + * @author Denys Bondarenko + */ +@MediumTest +@RunWith(AndroidJUnit4::class) +@FlowCryptTestSettings(useCommonIdling = false) +class ComposeScreenNoKeyAvailableFlowTest : BaseComposeScreenTest() { + private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule( + keyPath = "pgp/denbond7@flowcrypt.test_prv_strong_primary.asc" + ) + + private val pgpKeyDetails = + PrivateKeysManager.getPgpKeyDetailsFromAssets("pgp/default@flowcrypt.test_fisrtKey_prv_strong.asc") + + @get:Rule + var ruleChain: TestRule = RuleChain + .outerRule(RetryRule.DEFAULT) + .around(ClearAppSettingsRule()) + .around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS)) + .around(addAccountToDatabaseRule) + .around(addPrivateKeyToDatabaseRule) + .around(activeActivityRule) + .around(ScreenshotTestRule()) + + @Test + fun testImportKey() { + activeActivityRule?.launch(intent) + registerAllIdlingResources() + fillInAllFields( + to = setOf( + requireNotNull(TestConstants.RECIPIENT_WITH_PUBLIC_KEY_ON_ATTESTER.asInternetAddress()) + ) + ) + + //check that editTextFrom has gray text color. It means a sender doesn't have a private key + onView(withId(R.id.editTextFrom)) + .check(matches(isDisplayed())) + .check(matches(hasTextColor(R.color.gray))) + + onView(withId(R.id.menuActionSend)) + .check(matches(isDisplayed())) + .perform(click()) + + isDialogWithTextDisplayed( + decorView, + getResString(R.string.no_key_available, addAccountToDatabaseRule.account.email) + ) + + addTextToClipboard("private key", requireNotNull(pgpKeyDetails.privateKey)) + onView(withText(R.string.import_private_key)) + .check(matches(isDisplayed())) + .perform(click()) + + Thread.sleep(1000) + onView(withText(R.string.load_from_clipboard)) + .check(matches(isDisplayed())) + .perform(click()) + + onView(withId(R.id.editTextKeyPassword)) + .perform( + replaceText(TestConstants.DEFAULT_STRONG_PASSWORD), + closeSoftKeyboard() + ) + onView(withId(R.id.buttonPositiveAction)) + .perform(scrollTo(), click()) + + waitForObjectWithText(addAccountToDatabaseRule.account.email, 5000) + + //check that editTextFrom doesn't have gray text color. It means a sender has a private key. + onView(withId(R.id.editTextFrom)) + .check(matches(isDisplayed())) + .check(matches(not(hasTextColor(R.color.gray)))) + } + + companion object { + @get:ClassRule + @JvmStatic + val mockWebServerRule = FlowCryptMockWebServerRule(TestConstants.MOCK_WEB_SERVER_PORT, + object : Dispatcher() { + override fun dispatch(request: RecordedRequest): MockResponse { + if (request.path?.startsWith("/attester/pub", ignoreCase = true) == true) { + val lastSegment = request.requestUrl?.pathSegments?.lastOrNull() + + when { + TestConstants.RECIPIENT_WITH_PUBLIC_KEY_ON_ATTESTER.equals( + lastSegment, true + ) -> { + return MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody(TestGeneralUtil.readResourceAsString("3.txt")) + } + } + } + + return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) + } + }) + } +} diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoSuitablePrivateKeysFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoSuitablePrivateKeysFlowTest.kt index 335942509d..c35bafcbdb 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoSuitablePrivateKeysFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenNoSuitablePrivateKeysFlowTest.kt @@ -30,6 +30,7 @@ import com.flowcrypt.email.util.GeneralUtil import com.flowcrypt.email.util.PrivateKeysManager import com.flowcrypt.email.util.TestGeneralUtil import com.flowcrypt.email.util.UIUtil +import com.flowcrypt.email.util.exception.NoKeyAvailableException import okhttp3.mockwebserver.Dispatcher import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest @@ -78,12 +79,15 @@ class ComposeScreenNoSuitablePrivateKeysFlowTest : BaseComposeScreenTest() { .check(matches(isDisplayed())) .perform(click()) - val exception = Assert.assertThrows(IllegalStateException::class.java) { + val exception = Assert.assertThrows(NoKeyAvailableException::class.java) { SecurityUtils.getSenderPublicKeys(getTargetContext(), addAccountToDatabaseRule.account.email) } assertEquals( - "There are no usable for encryption keys for " + addPrivateKeyToDatabaseRule.pgpKeyRingDetails.getPrimaryInternetAddress(), + getResString( + R.string.no_key_available_for_your_email_account, + getResString(R.string.support_email) + ), exception.message ) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/LifecycleOwnerExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/LifecycleOwnerExt.kt index 962951711f..460cfe0df7 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/LifecycleOwnerExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/LifecycleOwnerExt.kt @@ -12,8 +12,10 @@ import androidx.lifecycle.LifecycleOwner import androidx.navigation.NavController import androidx.navigation.NavDirections import com.flowcrypt.email.R +import com.flowcrypt.email.model.DialogItem import com.flowcrypt.email.model.Screenshot import com.flowcrypt.email.ui.activity.fragment.FeedbackFragmentArgs +import com.flowcrypt.email.ui.activity.fragment.dialog.ActionsDialogFragmentArgs import com.flowcrypt.email.ui.activity.fragment.dialog.FixNeedPassphraseIssueDialogFragment import com.flowcrypt.email.ui.activity.fragment.dialog.FixNeedPassphraseIssueDialogFragmentArgs import com.flowcrypt.email.ui.activity.fragment.dialog.InfoDialogFragmentArgs @@ -160,3 +162,23 @@ fun LifecycleOwner.showFeedbackFragment( navController?.navigate(navDirections) } } + +fun LifecycleOwner.showActionDialogFragment( + navController: NavController?, + requestKey: String, + dialogTitle: String? = null, + isCancelable: Boolean = true, + items: List +) { + showDialogFragment(navController) { + return@showDialogFragment object : NavDirections { + override val actionId = R.id.actions_dialog_graph + override val arguments = ActionsDialogFragmentArgs( + requestKey = requestKey, + dialogTitle = dialogTitle, + isCancelable = isCancelable, + items = items.toTypedArray() + ).toBundle() + } + } +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/model/DialogItem.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/model/DialogItem.kt index f9fd9b3687..8f8d63d219 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/model/DialogItem.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/model/DialogItem.kt @@ -14,7 +14,10 @@ import kotlinx.parcelize.Parcelize * @author Denys Bondarenko */ @Parcelize -data class DialogItem constructor( +data class DialogItem( + /** + * It should be an image 32*32 + */ val iconResourceId: Int = 0, val title: String = "", val id: Int = 0 diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt index 521c6dd888..2e0f4d26e5 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt @@ -151,7 +151,7 @@ class SecurityUtils { val matchingKeyRingInfoList = keysStorage.getPGPSecretKeyRingsByUserId(senderEmail) .map { KeyRingInfo(it) }.filter { it.usableForEncryption } if (matchingKeyRingInfoList.isEmpty()) { - throw IllegalStateException("There are no usable for encryption keys for $senderEmail") + throw NoKeyAvailableException(context = context, email = senderEmail) } return matchingKeyRingInfoList.map { PGPPublicKeyRing(it.publicKeys).armor() } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AddOtherAccountFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AddOtherAccountFragment.kt index fc9221a721..7b3fb6202f 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AddOtherAccountFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AddOtherAccountFragment.kt @@ -18,6 +18,7 @@ import android.widget.ArrayAdapter import android.widget.Toast import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.setFragmentResultListener +import androidx.navigation.NavDirections import androidx.preference.PreferenceManager import com.flowcrypt.email.Constants import com.flowcrypt.email.R @@ -357,15 +358,17 @@ class AddOtherAccountFragment : BaseSingInFragment(), ProgressBe duration = Snackbar.LENGTH_LONG ) { navController?.navigate( - BackupKeysFragmentDirections - .actionBackupKeysFragmentToCheckPassphraseStrengthFragment( + object : NavDirections { + override val actionId = R.id.pass_phrase_strength_graph + override val arguments = CheckPassphraseStrengthFragmentArgs( popBackStackIdIfSuccess = R.id.backupKeysFragment, title = getString(R.string.change_pass_phrase), lostPassphraseTitle = getString(R.string.loss_of_this_pass_phrase_cannot_be_recovered) - ) + ).toBundle() + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt index 464dde6534..b8b142e645 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt @@ -38,6 +38,7 @@ import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.ViewModel +import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -66,6 +67,7 @@ import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.extensions.launchAndRepeatWithViewLifecycle import com.flowcrypt.email.extensions.navController import com.flowcrypt.email.extensions.org.bouncycastle.openpgp.toPgpKeyRingDetails +import com.flowcrypt.email.extensions.showActionDialogFragment import com.flowcrypt.email.extensions.showChoosePublicKeyDialogFragment import com.flowcrypt.email.extensions.showInfoDialog import com.flowcrypt.email.extensions.showKeyboard @@ -80,11 +82,14 @@ import com.flowcrypt.email.jetpack.viewmodel.ComposeMsgViewModel import com.flowcrypt.email.jetpack.viewmodel.DraftViewModel import com.flowcrypt.email.jetpack.viewmodel.RecipientsAutoCompleteViewModel import com.flowcrypt.email.jetpack.viewmodel.RecipientsViewModel +import com.flowcrypt.email.model.DialogItem import com.flowcrypt.email.model.MessageEncryptionType import com.flowcrypt.email.model.MessageType import com.flowcrypt.email.security.KeysStorageImpl +import com.flowcrypt.email.security.model.PgpKeyRingDetails import com.flowcrypt.email.security.pgp.PgpDecryptAndOrVerify import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment +import com.flowcrypt.email.ui.activity.fragment.dialog.ActionsDialogFragment import com.flowcrypt.email.ui.activity.fragment.dialog.ChoosePublicKeyDialogFragment import com.flowcrypt.email.ui.activity.fragment.dialog.CreateOutgoingMessageDialogFragment import com.flowcrypt.email.ui.activity.fragment.dialog.NoPgpFoundDialogFragment @@ -98,6 +103,7 @@ import com.flowcrypt.email.util.GeneralUtil import com.flowcrypt.email.util.UIUtil import com.flowcrypt.email.util.exception.DecryptionException import com.flowcrypt.email.util.exception.ExceptionUtil +import com.flowcrypt.email.util.exception.NoKeyAvailableException import com.google.android.flexbox.FlexDirection import com.google.android.flexbox.FlexboxLayoutManager import com.google.android.flexbox.JustifyContent @@ -323,6 +329,8 @@ class CreateMessageFragment : BaseFragment(), subscribeToAddMissingRecipientPublicKey() subscribeToFixNeedPassphraseIssueDialogFragment() subscribeToNoPgpFoundDialogFragment() + subscribeToActionsDialogFragment() + subscribeToImportingAdditionalPrivateKeys() subscribeToChoosePublicKeyDialogFragment() subscribeToCreateOutgoingMessageDialogFragment() @@ -1108,7 +1116,22 @@ class CreateMessageFragment : BaseFragment(), private fun setupPrivateKeysViewModel() { KeysStorageImpl.getInstance(requireContext()).secretKeyRingsLiveData - .observe(viewLifecycleOwner) { updateFromAddressAdapter(it) } + .observe(viewLifecycleOwner) { + updateFromAddressAdapter(it) + if (composeMsgViewModel.msgEncryptionType == MessageEncryptionType.ENCRYPTED) { + val from = binding?.editTextFrom?.text?.toString() ?: return@observe + val position = fromAddressesAdapter?.getPosition(from) ?: return@observe + binding?.editTextFrom?.setTextColor( + if (fromAddressesAdapter?.isEnabled(position) == true) { + originalColor + } else { + UIUtil.getColor(requireContext(), R.color.gray) + } + ) + } else { + binding?.editTextFrom?.setTextColor(originalColor) + } + } } private fun updateFromAddressAdapter(list: List) { @@ -1346,7 +1369,30 @@ class CreateMessageFragment : BaseFragment(), } Result.Status.EXCEPTION -> { - showInfoDialog(dialogMsg = getString(R.string.could_not_save_draft, it.exceptionMsg)) + when (it.exception) { + is NoKeyAvailableException -> { + val email = it.exception.alias ?: it.exception.email + val text = getString(R.string.no_key_available, email) + + if (fromAddressesAdapter?.hasPrvKey(email) != true) { + showSnackbar( + msgText = text, + btnName = getString(R.string.fix), + duration = Snackbar.LENGTH_LONG + ) { + fixNoKeyAvailableIssue(text) + } + } + } + + else -> showInfoDialog( + dialogMsg = getString( + R.string.could_not_save_draft, + it.exceptionMsg + ) + ) + } + countingIdlingResource?.decrementSafely(this@CreateMessageFragment) } @@ -1408,7 +1454,11 @@ class CreateMessageFragment : BaseFragment(), binding?.spinnerFrom?.selectedItemPosition ?: Spinner.INVALID_POSITION ) == false ) { - showInfoSnackbar(msgText = getString(R.string.no_key_available)) + val email = fromAddressesAdapter?.getItem( + binding?.spinnerFrom?.selectedItemPosition ?: Spinner.INVALID_POSITION + ) ?: "" + val text = getString(R.string.no_key_available, email) + fixNoKeyAvailableIssue(text) return false } @@ -1603,6 +1653,45 @@ class CreateMessageFragment : BaseFragment(), } } + private fun subscribeToActionsDialogFragment() { + setFragmentResultListener(REQUEST_KEY_FIX_NO_PRIVATE_KEY_AVAILABLE) { _, bundle -> + val item = bundle.getParcelableViaExt( + ActionsDialogFragment.KEY_REQUEST_RESULT + ) ?: return@setFragmentResultListener + + when (item.id) { + RESULT_CODE_IMPORT_PRIVATE_KEY -> { + account?.let { accountEntity -> + navController?.navigate( + object : NavDirections { + override val actionId = R.id.import_additional_private_keys_graph + override val arguments = ImportAdditionalPrivateKeysFragmentArgs( + requestKey = REQUEST_KEY_IMPORT_PRIVATE_KEY, + accountEntity = accountEntity + ).toBundle() + } + ) + } + } + + RESULT_CODE_ADD_USER_ID_TO_EXISTING_PRIVATE_KEY -> { + //todo-denbond7 need to add realization in a separate PR + } + } + } + } + + private fun subscribeToImportingAdditionalPrivateKeys() { + setFragmentResultListener(REQUEST_KEY_IMPORT_PRIVATE_KEY) { _, bundle -> + val keys = bundle.getParcelableArrayListViaExt( + ImportAdditionalPrivateKeysFragment.KEY_IMPORTED_PRIVATE_KEYS + ) + if (keys?.isNotEmpty() == true) { + toast(R.string.key_successfully_imported) + } + } + } + private fun subscribeToChoosePublicKeyDialogFragment() { setFragmentResultListener(REQUEST_KEY_CHOOSE_PUBLIC_KEY) { _, bundle -> val keyList = bundle.getParcelableArrayListViaExt( @@ -1766,6 +1855,27 @@ class CreateMessageFragment : BaseFragment(), } } + private fun fixNoKeyAvailableIssue(text: String) { + showActionDialogFragment( + navController, + requestKey = REQUEST_KEY_FIX_NO_PRIVATE_KEY_AVAILABLE, + dialogTitle = text, + isCancelable = true, + items = listOf( + DialogItem( + iconResourceId = R.drawable.ic_import_user_public_key, + title = getString(R.string.import_private_key), + id = RESULT_CODE_IMPORT_PRIVATE_KEY + ), + DialogItem( + iconResourceId = R.drawable.ic_edit_key_add_user_id, + title = getString(R.string.add_email_to_existing_key), + id = RESULT_CODE_ADD_USER_ID_TO_EXISTING_PRIVATE_KEY + ) + ) + ) + } + companion object { private val TAG = CreateMessageFragment::class.java.simpleName @@ -1801,5 +1911,18 @@ class CreateMessageFragment : BaseFragment(), private val REQUEST_KEY_CREATE_OUTGOING_MESSAGE = GeneralUtil.generateUniqueExtraKey( "REQUEST_KEY_CREATE_OUTGOING_MESSAGE", CreateMessageFragment::class.java ) + + private val REQUEST_KEY_FIX_NO_PRIVATE_KEY_AVAILABLE = GeneralUtil.generateUniqueExtraKey( + "REQUEST_KEY_FIX_NO_PRIVATE_KEY_AVAILABLE", + CreateMessageFragment::class.java + ) + + private val REQUEST_KEY_IMPORT_PRIVATE_KEY = GeneralUtil.generateUniqueExtraKey( + "REQUEST_KEY_IMPORT_PRIVATE_KEY", + CreateMessageFragment::class.java + ) + + private const val RESULT_CODE_IMPORT_PRIVATE_KEY = 1 + private const val RESULT_CODE_ADD_USER_ID_TO_EXISTING_PRIVATE_KEY = 2 } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportAdditionalPrivateKeysFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportAdditionalPrivateKeysFragment.kt index 5d014d7d61..75c70f3c3d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportAdditionalPrivateKeysFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportAdditionalPrivateKeysFragment.kt @@ -14,6 +14,7 @@ import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.viewModels +import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result @@ -169,8 +170,9 @@ class ImportAdditionalPrivateKeysFragment : binding?.buttonImportBackup?.setOnClickListener { importSourceType = KeyImportDetails.SourceType.EMAIL navController?.navigate( - ImportAdditionalPrivateKeysFragmentDirections - .actionImportAdditionalPrivateKeysFragmentToCheckKeysFragment( + object : NavDirections { + override val actionId = R.id.check_keys_graph + override val arguments = CheckKeysFragmentArgs( requestKey = REQUEST_KEY_CHECK_PRIVATE_KEYS, privateKeys = keys.toTypedArray(), initSubTitlePlurals = R.plurals.found_backup_of_your_account_key, @@ -178,7 +180,8 @@ class ImportAdditionalPrivateKeysFragment : positiveBtnTitle = getString(R.string.continue_), negativeBtnTitle = getString(R.string.choose_another_key), skipImportedKeys = true - ) + ).toBundle() + } ) } } @@ -286,11 +289,13 @@ class ImportAdditionalPrivateKeysFragment : when (requestCode) { REQUEST_CODE_PROTECT_KEY_WITH_PASS_PHRASE -> if (result == TwoWayDialogFragment.RESULT_OK) { navController?.navigate( - ImportAdditionalPrivateKeysFragmentDirections - .actionImportAdditionalPrivateKeysFragmentToCheckPassphraseStrengthFragment( + object : NavDirections { + override val actionId = R.id.pass_phrase_strength_graph + override val arguments = CheckPassphraseStrengthFragmentArgs( popBackStackIdIfSuccess = R.id.importAdditionalPrivateKeysFragment, title = getString(R.string.set_up_flow_crypt, getString(R.string.app_name)) - ) + ).toBundle() + } ) } } @@ -375,8 +380,9 @@ class ImportAdditionalPrivateKeysFragment : } navController?.navigate( - ImportAdditionalPrivateKeysFragmentDirections - .actionImportAdditionalPrivateKeysFragmentToCheckKeysFragment( + object : NavDirections { + override val actionId = R.id.check_keys_graph + override val arguments = CheckKeysFragmentArgs( requestKey = REQUEST_KEY_CHECK_PRIVATE_KEYS, privateKeys = filteredKeys.toTypedArray(), subTitle = title, @@ -385,7 +391,8 @@ class ImportAdditionalPrivateKeysFragment : negativeBtnTitle = getString(R.string.choose_another_key), initSubTitlePlurals = 0, skipImportedKeys = true - ) + ).toBundle() + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt index b5790822a8..f6978a445c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt @@ -13,6 +13,7 @@ import android.view.ViewGroup import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResultListener +import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R import com.flowcrypt.email.databinding.FragmentImportPrivateKeysDuringSetupBinding @@ -91,8 +92,9 @@ class ImportPrivateKeysDuringSetupFragment : } navController?.navigate( - ImportPrivateKeysDuringSetupFragmentDirections - .actionImportPrivateKeysDuringSetupFragmentToCheckKeysFragment( + object : NavDirections { + override val actionId = R.id.check_keys_graph + override val arguments = CheckKeysFragmentArgs( requestKey = REQUEST_KEY_CHECK_PRIVATE_KEYS, privateKeys = keys.toTypedArray(), subTitle = title, @@ -101,7 +103,8 @@ class ImportPrivateKeysDuringSetupFragment : negativeBtnTitle = getString(R.string.choose_another_key), initSubTitlePlurals = 0, skipImportedKeys = true - ) + ).toBundle() + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSignInFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSignInFragment.kt index 89ba552508..0a99f77bd1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSignInFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSignInFragment.kt @@ -17,6 +17,7 @@ import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.viewModels +import androidx.navigation.NavDirections import com.flowcrypt.email.BuildConfig import com.flowcrypt.email.Constants import com.flowcrypt.email.NavGraphDirections @@ -536,15 +537,17 @@ class MainSignInFragment : BaseSingInFragment() { } } else { navController?.navigate( - MainSignInFragmentDirections - .actionMainSignInFragmentToCheckKeysFragment( + object : NavDirections { + override val actionId = R.id.check_keys_graph + override val arguments = CheckKeysFragmentArgs( requestKey = REQUEST_KEY_CHECK_PRIVATE_KEYS, privateKeys = keyDetailsList.toTypedArray(), sourceType = KeyImportDetails.SourceType.EMAIL, positiveBtnTitle = getString(R.string.continue_), negativeBtnTitle = getString(R.string.use_another_account), initSubTitlePlurals = R.plurals.found_backup_of_your_account_key - ) + ).toBundle() + } ) } } @@ -733,11 +736,13 @@ class MainSignInFragment : BaseSingInFragment() { importCandidates.clear() importCandidates.addAll(it?.data?.pgpKeyRingDetailsList ?: emptyList()) navController?.navigate( - MainSignInFragmentDirections - .actionMainSignInFragmentToCheckPassphraseStrengthFragment( + object : NavDirections { + override val actionId = R.id.pass_phrase_strength_graph + override val arguments = CheckPassphraseStrengthFragmentArgs( popBackStackIdIfSuccess = R.id.mainSignInFragment, title = getString(R.string.set_up_flow_crypt, getString(R.string.app_name)) - ) + ).toBundle() + } ) ekmViewModel.ekmLiveData.value = Result.none() countingIdlingResource?.decrementSafely(this@MainSignInFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt index b59c30d3d1..ef751cdc35 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt @@ -46,6 +46,7 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.ViewModel import androidx.lifecycle.lifecycleScope +import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -1476,11 +1477,13 @@ class MessageDetailsFragment : BaseFragment(), Pr buttonImportPrivateKey?.setOnClickListener { account?.let { accountEntity -> navController?.navigate( - MessageDetailsFragmentDirections - .actionMessageDetailsFragmentToImportAdditionalPrivateKeysFragment( + object : NavDirections { + override val actionId = R.id.import_additional_private_keys_graph + override val arguments = ImportAdditionalPrivateKeysFragmentArgs( requestKey = REQUEST_KEY_IMPORT_ADDITIONAL_PRIVATE_KEYS, accountEntity = accountEntity - ) + ).toBundle() + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeysListFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeysListFragment.kt index 15c6cc598e..9ad01cf4f8 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeysListFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeysListFragment.kt @@ -13,6 +13,7 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.viewModels +import androidx.navigation.NavDirections import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.flowcrypt.email.R @@ -132,11 +133,13 @@ class PrivateKeysListFragment : BaseFragment(), List binding?.floatActionButtonAddKey?.setOnClickListener { account?.let { accountEntity -> navController?.navigate( - PrivateKeysListFragmentDirections - .actionPrivateKeysListFragmentToImportAdditionalPrivateKeysFragment( + object : NavDirections { + override val actionId = R.id.import_additional_private_keys_graph + override val arguments = ImportAdditionalPrivateKeysFragmentArgs( requestKey = REQUEST_KEY_IMPORT_ADDITIONAL_PRIVATE_KEYS, accountEntity = accountEntity - ) + ).toBundle() + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/UpdatePrivateKeyFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/UpdatePrivateKeyFragment.kt index c4d130b905..d4762e1376 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/UpdatePrivateKeyFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/UpdatePrivateKeyFragment.kt @@ -14,6 +14,7 @@ import android.widget.Toast import androidx.core.widget.addTextChangedListener import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.viewModels +import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result @@ -143,8 +144,9 @@ class UpdatePrivateKeyFragment : BaseImportKeyFragment() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + isCancelable = args.isCancelable + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return AlertDialog.Builder(activity).apply { + setTitle(args.dialogTitle) + setAdapter( + DialogItemAdapter( + requireContext(), + args.items.toList() + ) + ) { _: DialogInterface, which: Int -> + navController?.navigateUp() + setFragmentResult( + args.requestKey, + bundleOf( + KEY_REQUEST_RESULT to args.items[which] + ) + ) + } + }.create() + } + + companion object { + val KEY_REQUEST_RESULT = GeneralUtil.generateUniqueExtraKey( + "KEY_REQUEST_RESULT", ActionsDialogFragment::class.java + ) + } +} \ No newline at end of file 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 51eafdbbae..47075d0eaa 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 @@ -8,6 +8,7 @@ package com.flowcrypt.email.ui.activity.fragment.preferences import android.os.Bundle import android.view.View import androidx.fragment.app.setFragmentResultListener +import androidx.navigation.NavDirections import androidx.preference.Preference import com.flowcrypt.email.Constants import com.flowcrypt.email.R @@ -17,6 +18,7 @@ import com.flowcrypt.email.extensions.showInfoDialog import com.flowcrypt.email.extensions.showNeedPassphraseDialog import com.flowcrypt.email.extensions.supportActionBar import com.flowcrypt.email.security.KeysStorageImpl +import com.flowcrypt.email.ui.activity.fragment.CheckPassphraseStrengthFragmentArgs import com.flowcrypt.email.ui.activity.fragment.RecheckProvidedPassphraseFragment import com.flowcrypt.email.ui.activity.fragment.base.BasePreferenceFragment import com.flowcrypt.email.ui.activity.fragment.dialog.FixNeedPassphraseIssueDialogFragment @@ -100,12 +102,14 @@ class SecuritySettingsFragment : BasePreferenceFragment(), Preference.OnPreferen private fun navigateToCheckPassphraseStrengthFragment() { navController?.navigate( - SecuritySettingsFragmentDirections - .actionSecuritySettingsFragmentToCheckPassphraseStrengthFragment( + object : NavDirections { + override val actionId = R.id.pass_phrase_strength_graph + override val arguments = CheckPassphraseStrengthFragmentArgs( popBackStackIdIfSuccess = R.id.securitySettingsFragment, title = getString(R.string.change_pass_phrase), lostPassphraseTitle = getString(R.string.loss_of_this_pass_phrase_cannot_be_recovered) - ) + ).toBundle() + } ) } diff --git a/FlowCrypt/src/main/res/drawable/ic_edit_key_add_user_id.xml b/FlowCrypt/src/main/res/drawable/ic_edit_key_add_user_id.xml new file mode 100644 index 0000000000..bd9f7509e8 --- /dev/null +++ b/FlowCrypt/src/main/res/drawable/ic_edit_key_add_user_id.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/FlowCrypt/src/main/res/navigation/actions_dialog_graph.xml b/FlowCrypt/src/main/res/navigation/actions_dialog_graph.xml new file mode 100644 index 0000000000..83427de220 --- /dev/null +++ b/FlowCrypt/src/main/res/navigation/actions_dialog_graph.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + diff --git a/FlowCrypt/src/main/res/navigation/check_keys_graph.xml b/FlowCrypt/src/main/res/navigation/check_keys_graph.xml new file mode 100644 index 0000000000..796f3256e5 --- /dev/null +++ b/FlowCrypt/src/main/res/navigation/check_keys_graph.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + diff --git a/FlowCrypt/src/main/res/navigation/create_msg_graph.xml b/FlowCrypt/src/main/res/navigation/create_msg_graph.xml index 86ff22d1fa..0c61e50b4f 100644 --- a/FlowCrypt/src/main/res/navigation/create_msg_graph.xml +++ b/FlowCrypt/src/main/res/navigation/create_msg_graph.xml @@ -16,6 +16,10 @@ + + + + + + + + + + + + diff --git a/FlowCrypt/src/main/res/navigation/nav_graph.xml b/FlowCrypt/src/main/res/navigation/nav_graph.xml index 44aa90e48c..89d83e2537 100644 --- a/FlowCrypt/src/main/res/navigation/nav_graph.xml +++ b/FlowCrypt/src/main/res/navigation/nav_graph.xml @@ -16,6 +16,9 @@ + + + - - @@ -45,9 +42,6 @@ - @@ -142,9 +136,6 @@ - - - - - - - - - - - - - - - - - @@ -418,9 +363,6 @@ android:name="com.flowcrypt.email.ui.activity.fragment.BackupKeysFragment" android:label="@string/backup_options" tools:layout="@layout/fragment_backup_keys"> - @@ -480,47 +422,6 @@ app:argType="string" /> - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FlowCrypt/src/main/res/values-ru/strings.xml b/FlowCrypt/src/main/res/values-ru/strings.xml index 1b37158b2f..b36a6021c2 100644 --- a/FlowCrypt/src/main/res/values-ru/strings.xml +++ b/FlowCrypt/src/main/res/values-ru/strings.xml @@ -280,7 +280,7 @@ Уведомления об ошибках Нет открытых ключей Нет сообщения с этим вложением - Нет ключа для Вашей учетной записи электронной почты + Нет ключа для Вашей учетной записи электронной почты %1$s Сохранено Скопировано Еще не реализовано, см. «Резервные копии», чтобы сохранить закрытый ключ в файл. @@ -610,6 +610,7 @@ Алгоритм: %1$s Информация о ключе Предварительный просмотр недоступен + Добавить адрес электронной почты к существующему ключу Для Вашей защиты и безопасности данных в настоящее время осталось только %1$d попытка, после чего следует 5-минутный период восстановления. Для Вашей защиты и безопасности данных в настоящее время осталось только %1$d попытки, после чего следует 5-минутный период восстановления. diff --git a/FlowCrypt/src/main/res/values-uk/strings.xml b/FlowCrypt/src/main/res/values-uk/strings.xml index 1ada5e0fb8..09d27a87f6 100644 --- a/FlowCrypt/src/main/res/values-uk/strings.xml +++ b/FlowCrypt/src/main/res/values-uk/strings.xml @@ -281,7 +281,7 @@ Сповіщення про помилки Немає відкритих ключів Немає повідомлення з цим вкладенням - Немає ключа для Вашого облікового запису електронної пошти + Немає ключа для Вашого облікового запису електронної пошти %1$s Збережено Скопійовано Ще не реалізовано, див. «Резервні копії», щоб зберегти закритий ключ у файл. @@ -611,6 +611,7 @@ Алгоритм: %1$s Інформація про ключ Попередній перегляд недоступний + Додати електронну адресу до існуючого ключа Для Вашого захисту та безпеки даних наразі залишилася лише %1$d спроба, а потім 5-хвилинний період відновлення. Для Вашого захисту та безпеки даних наразі залишилася лише %1$d спроби, а потім 5-хвилинний період відновлення. diff --git a/FlowCrypt/src/main/res/values/strings.xml b/FlowCrypt/src/main/res/values/strings.xml index 102a22bde3..bf5a26eb6a 100644 --- a/FlowCrypt/src/main/res/values/strings.xml +++ b/FlowCrypt/src/main/res/values/strings.xml @@ -295,7 +295,7 @@ Not implemented yet, see \"Backups\" to save your private key to file Copied Saved - No key available for your email account + No key available for your email account %1$s Not saved because the file already exists No message with this attachment The attachment not found @@ -632,4 +632,5 @@ notification for foreground services, a user can erase all passphrases stored in RAM at any time. The preview is not available + Add email to existing key