diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentEnterpriseFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentEnterpriseFlowTest.kt new file mode 100644 index 0000000000..c7a955de0b --- /dev/null +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentEnterpriseFlowTest.kt @@ -0,0 +1,90 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: denbond7 + */ + +package com.flowcrypt.email.ui.fragment + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.doesNotExist +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.rules.activityScenarioRule +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.junit.annotations.FlowCryptTestSettings +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.activity.MainActivity +import com.flowcrypt.email.ui.base.BaseGmailApiTest +import com.flowcrypt.email.util.TestGeneralUtil +import okhttp3.mockwebserver.Dispatcher +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.RecordedRequest +import org.junit.Rule +import org.junit.Test +import org.junit.rules.RuleChain +import org.junit.rules.TestRule +import org.junit.runner.RunWith + +/** + * @author Denys Bondarenko + */ +@MediumTest +@RunWith(AndroidJUnit4::class) +@FlowCryptTestSettings(useCommonIdling = false) +class MainSettingsFragmentEnterpriseFlowTest : + BaseGmailApiTest(BASE_ACCOUNT_ENTITY.copy(useConversationMode = true)) { + override val activityScenarioRule = activityScenarioRule( + TestGeneralUtil.genIntentForNavigationComponent( + destinationId = R.id.mainSettingsFragment + ) + ) + + override val mockWebServerRule = + FlowCryptMockWebServerRule(TestConstants.MOCK_WEB_SERVER_PORT, object : Dispatcher() { + override fun dispatch(request: RecordedRequest): MockResponse { + return when { + else -> handleCommonAPICalls(request) + } + } + }) + + @get:Rule + var ruleChain: TestRule = RuleChain + .outerRule(RetryRule.DEFAULT) + .around(ClearAppSettingsRule()) + .around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS)) + .around(addAccountToDatabaseRule) + .around(addPrivateKeyToDatabaseRule) + .around(activityScenarioRule) + .around(ScreenshotTestRule()) + + @Test + fun testHiddenOrVisibleItems() { + //should be hidden as we have NO_PRV_BACKUP + onView(withText(getResString(R.string.backups))) + .check(doesNotExist()) + //should be hidden as we have RESTRICT_ANDROID_ATTACHMENT_HANDLING + onView(withText(getResString(R.string.general))) + .check(doesNotExist()) + + //should be visible + onView(withText(getResString(R.string.security_and_privacy))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.contacts))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.keys))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.attester))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.experimental))) + .check(matches(isDisplayed())) + } +} diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentNavigationToSubMenuFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentNavigationToSubMenuFlowTest.kt index 5e8dcf74ed..bf08b10cff 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentNavigationToSubMenuFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/MainSettingsFragmentNavigationToSubMenuFlowTest.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.fragment @@ -89,6 +89,24 @@ class MainSettingsFragmentNavigationToSubMenuFlowTest : BaseTest() { ) } + @Test + fun testHiddenOrVisibleItems() { + onView(withText(getResString(R.string.backups))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.security_and_privacy))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.contacts))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.keys))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.attester))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.general))) + .check(matches(isDisplayed())) + onView(withText(getResString(R.string.experimental))) + .check(matches(isDisplayed())) + } + private fun checkIsScreenDisplaying(screenName: String) { checkIsScreenDisplaying(screenName, screenName) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt index 0a6e0136c2..c1b13b5c94 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt @@ -55,11 +55,14 @@ class Constants { const val PREF_KEY_MESSAGES_NOTIFICATION_FILTER = "preferences_key_messages_notification_filter" const val PREF_KEY_MANAGE_NOTIFICATIONS = "preferences_key_manage_notifications" const val PREF_KEY_SECURITY_CHANGE_PASS_PHRASE = "preferences_key_security_change_pass_phrase" + const val PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW = + "preferences_key_attachments_disable_smart_mode_for_preview" const val PREF_KEY_LAST_ATT_ORDER_ID = "preferences_key_last_att_order_id" const val PREF_KEY_IS_CHECK_KEYS_NEEDED = "preferences_key_is_check_keys_needed" const val PREF_KEY_BACKUPS = "pref_key_backups" const val PREF_KEY_INSTALL_VERSION = "pref_key_install_version" const val PREF_KEY_SERVER_SETTINGS = "pref_key_server_settings" + const val PREF_KEY_GENERAL = "pref_key_general" /** * The max total size off all attachment which can be send via the app. diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt index 50389a5ed2..35af0ac35d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt @@ -59,6 +59,12 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() { return getFileDescriptor(getBytesForDocumentId(documentId)) } + override fun getDocumentType(documentId: String?): String { + return documentId?.let { + Cache.getInstance().get(documentId)?.type ?: super.getDocumentType(documentId) + } ?: super.getDocumentType(documentId) + } + private fun getBytesForDocumentId(documentId: String): ByteArray { val attachmentInfo = Cache.getInstance().get(documentId) return requireNotNull(attachmentInfo?.rawData) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt index d464d09bfd..a83ac90ffb 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt @@ -623,23 +623,6 @@ class AttachmentDownloadManagerService : LifecycleService() { val fileUri = resolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues) requireNotNull(fileUri) - - //we should check maybe a file is already exist. Then we will use the file name from the system - val cursor = - resolver.query(fileUri, arrayOf(MediaStore.DownloadColumns.DISPLAY_NAME), null, null, null) - cursor?.let { - if (it.moveToFirst()) { - val nameIndex = it.getColumnIndex(MediaStore.DownloadColumns.DISPLAY_NAME) - if (nameIndex != -1) { - val nameFromSystem = it.getString(nameIndex) - if (nameFromSystem != finalFileName) { - finalFileName = nameFromSystem - } - } - } - } - cursor?.close() - val srcInputStream = attFile.inputStream() val destOutputStream = resolver.openOutputStream(fileUri) ?: throw IllegalArgumentException("provided URI could not be opened") @@ -652,6 +635,23 @@ class AttachmentDownloadManagerService : LifecycleService() { put(MediaStore.Downloads.IS_PENDING, 0) }, null, null) + resolver.query( + fileUri, + arrayOf(MediaStore.DownloadColumns.DISPLAY_NAME), + null, + null, + null + ) + ?.use { cursor -> + //we should check maybe a file is already exist. + //Then we will use the file name from the system. + if (cursor.moveToFirst()) { + finalFileName = cursor.getString( + cursor.getColumnIndexOrThrow(MediaStore.DownloadColumns.DISPLAY_NAME) + ) + } + } + return fileUri } 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 1650de257b..fa5cb62476 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 @@ -39,6 +39,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.ViewModel import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.flowcrypt.email.Constants @@ -109,6 +110,7 @@ import com.flowcrypt.email.ui.adapter.recyclerview.itemdecoration.MarginItemDeco import com.flowcrypt.email.util.FileAndDirectoryUtils import com.flowcrypt.email.util.GeneralUtil import com.flowcrypt.email.util.LogsUtil +import com.flowcrypt.email.util.SharedPreferencesHelper import com.flowcrypt.email.util.UIUtil import com.flowcrypt.email.util.exception.DecryptionException import com.flowcrypt.email.util.exception.ExceptionUtil @@ -253,13 +255,17 @@ class CreateMessageFragment : BaseFragment(), attachmentActionListener = object : AttachmentsRecyclerViewAdapter.AttachmentActionListener { override fun onDownloadClick(attachmentInfo: AttachmentInfo) {} - override fun onAttachmentClick(attachmentInfo: AttachmentInfo) { - onPreviewClick(attachmentInfo) - } - override fun onPreviewClick(attachmentInfo: AttachmentInfo) { if (attachmentInfo.uri != null) { - val intent = GeneralUtil.genViewAttachmentIntent(attachmentInfo.uri, attachmentInfo) + val intent = GeneralUtil.genViewAttachmentIntent( + uri = attachmentInfo.uri, + attachmentInfo = attachmentInfo, + useCommonPattern = SharedPreferencesHelper.getBoolean( + sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()), + key = Constants.PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW, + defaultValue = false + ) + ) try { startActivity(intent) } catch (e: ActivityNotFoundException) { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSettingsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSettingsFragment.kt index 10e72e9d42..3cc315ab78 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSettingsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MainSettingsFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment @@ -95,6 +95,14 @@ class MainSettingsFragment : BasePreferenceFragment() { true } + findPreference(getString(R.string.pref_key_general)) + ?.setOnPreferenceClickListener { + navController?.navigate( + MainSettingsFragmentDirections.actionMainSettingsFragmentToGeneralSettingsFragment() + ) + true + } + findPreference(getString(R.string.pref_key_experimental)) ?.setOnPreferenceClickListener { navController?.navigate( @@ -110,8 +118,10 @@ class MainSettingsFragment : BasePreferenceFragment() { !(accountEntity?.hasClientConfigurationProperty(ClientConfiguration.ConfigurationProperty.NO_PRV_BACKUP) ?: false) - if (accountEntity?.useAPI == false) { - findPreference(Constants.PREF_KEY_SERVER_SETTINGS)?.isVisible = true - } + findPreference(Constants.PREF_KEY_SERVER_SETTINGS)?.isVisible = + accountEntity?.useAPI == false + + findPreference(Constants.PREF_KEY_GENERAL)?.isVisible = + accountEntity?.isHandlingAttachmentRestricted() == false } } 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 95247d2101..0e28553066 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 @@ -42,6 +42,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.lifecycleScope import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.flowcrypt.email.Constants @@ -131,6 +132,7 @@ import com.flowcrypt.email.ui.widget.EmailWebView import com.flowcrypt.email.ui.widget.TileDrawable import com.flowcrypt.email.util.DateTimeUtil import com.flowcrypt.email.util.GeneralUtil +import com.flowcrypt.email.util.SharedPreferencesHelper import com.flowcrypt.email.util.UIUtil import com.flowcrypt.email.util.exception.CommonConnectionException import com.flowcrypt.email.util.exception.GmailAPIException @@ -201,10 +203,6 @@ class MessageDetailsFragment : BaseFragment(), Pr } } - override fun onAttachmentClick(attachmentInfo: AttachmentInfo) { - onPreviewClick(attachmentInfo) - } - override fun onPreviewClick(attachmentInfo: AttachmentInfo) { if (attachmentInfo.uri != null) { if (attachmentInfo.isPossiblyEncrypted) { @@ -1828,7 +1826,15 @@ class MessageDetailsFragment : BaseFragment(), Pr useContentApp: Boolean = false ) { val intent = if (attachmentInfo.uri != null) { - GeneralUtil.genViewAttachmentIntent(requireNotNull(attachmentInfo.uri), attachmentInfo) + GeneralUtil.genViewAttachmentIntent( + uri = requireNotNull(attachmentInfo.uri), + attachmentInfo = attachmentInfo, + useCommonPattern = SharedPreferencesHelper.getBoolean( + sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()), + key = Constants.PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW, + defaultValue = false + ) + ) } else { toast(getString(R.string.preview_is_not_available)) return diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt index 7ce51bb9e3..47cd28c4ee 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt @@ -25,6 +25,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.ViewModel import androidx.navigation.NavDirections import androidx.navigation.fragment.navArgs +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.work.WorkManager import com.flowcrypt.email.Constants @@ -93,7 +94,9 @@ import com.flowcrypt.email.ui.activity.fragment.dialog.TwoWayDialogFragment import com.flowcrypt.email.ui.adapter.GmailApiLabelsListAdapter import com.flowcrypt.email.ui.adapter.MessagesInThreadListAdapter import com.flowcrypt.email.ui.adapter.recyclerview.itemdecoration.SkipFirstAndLastDividerItemDecoration +import com.flowcrypt.email.util.FileAndDirectoryUtils import com.flowcrypt.email.util.GeneralUtil +import com.flowcrypt.email.util.SharedPreferencesHelper import com.flowcrypt.email.util.exception.ThreadNotFoundException import com.google.api.client.googleapis.json.GoogleJsonResponseException import org.apache.commons.io.FilenameUtils @@ -593,6 +596,21 @@ class ThreadDetailsFragment : BaseFragment(), Prog } } + REQUEST_CODE_DOWNLOAD_FILE_AGAIN -> { + if (result == TwoWayDialogFragment.RESULT_OK) { + bundle.getBundle(TwoWayDialogFragment.KEY_REQUEST_INCOMING_BUNDLE) + ?.let { + processActionForMessageAndAttachmentBasedOnIncomingBundle(it) { attachmentInfo, message -> + processDownloadAttachment( + attachmentInfo = attachmentInfo, + message = message, + forcedDownload = true + ) + } + } + } + } + REQUEST_CODE_SHOW_TWO_WAY_DIALOG_FOR_DELETING_DRAFT -> if (result == TwoWayDialogFragment.RESULT_OK) { bundle.getBundle(TwoWayDialogFragment.KEY_REQUEST_INCOMING_BUNDLE)?.let { @@ -1276,7 +1294,15 @@ class ThreadDetailsFragment : BaseFragment(), Prog private fun previewAttachment(attachmentInfo: AttachmentInfo) { val intent = if (attachmentInfo.uri != null) { - GeneralUtil.genViewAttachmentIntent(requireNotNull(attachmentInfo.uri), attachmentInfo) + GeneralUtil.genViewAttachmentIntent( + uri = requireNotNull(attachmentInfo.uri), + attachmentInfo = attachmentInfo, + useCommonPattern = SharedPreferencesHelper.getBoolean( + sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()), + key = Constants.PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW, + defaultValue = false + ) + ) } else { toast(getString(R.string.preview_is_not_available)) return @@ -1303,7 +1329,8 @@ class ThreadDetailsFragment : BaseFragment(), Prog private fun processDownloadAttachment( attachmentInfo: AttachmentInfo, - message: MessagesInThreadListAdapter.Message + message: MessagesInThreadListAdapter.Message, + forcedDownload: Boolean = false ) { if ( checkAndShowNeedPassphraseDialogIfNeeded( @@ -1313,15 +1340,43 @@ class ThreadDetailsFragment : BaseFragment(), Prog ) ) return - downloadAttachment(attachmentInfo, message) + downloadAttachment( + attachmentInfo = attachmentInfo, + message = message, + forcedDownload = forcedDownload + ) } private fun downloadAttachment( attachmentInfo: AttachmentInfo, - message: MessagesInThreadListAdapter.Message + message: MessagesInThreadListAdapter.Message, + forcedDownload: Boolean = false ) { val documentId = EmbeddedAttachmentsProvider.Cache.getInstance().getDocumentId(attachmentInfo) + if (!forcedDownload && FileAndDirectoryUtils.Downloads.isFileAlreadyExist( + context = requireContext(), + fileName = attachmentInfo.getSafeName() + ) + ) { + showTwoWayDialog( + requestKey = REQUEST_KEY_TWO_WAY_DIALOG_BASE + args.messageEntityId.toString(), + requestCode = REQUEST_CODE_DOWNLOAD_FILE_AGAIN, + dialogTitle = "", + dialogMsg = getString( + R.string.file_already_exists_in_download, + attachmentInfo.getSafeName() + ), + positiveButtonTitle = getString(R.string.download), + negativeButtonTitle = getString(android.R.string.cancel), + bundle = Bundle().apply { + putLong(KEY_EXTRA_MESSAGE_ID, message.id) + putString(KEY_EXTRA_ATTACHMENT_ID, attachmentInfo.uniqueStringId) + } + ) + return + } + when { attachmentInfo.uri != null && documentId != null -> { requireContext().startService( @@ -1541,6 +1596,7 @@ class ThreadDetailsFragment : BaseFragment(), Prog private const val REQUEST_CODE_PROCESS_AND_REPLY = 1014 private const val REQUEST_CODE_PROCESS_AND_REPLY_ALL = 1015 private const val REQUEST_CODE_PROCESS_AND_FORWARD = 1016 + private const val REQUEST_CODE_DOWNLOAD_FILE_AGAIN = 1017 private const val CONTENT_MAX_ALLOWED_LENGTH = 50000 } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/GeneralSettingsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/GeneralSettingsFragment.kt new file mode 100644 index 0000000000..438c34c300 --- /dev/null +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/GeneralSettingsFragment.kt @@ -0,0 +1,28 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: denbond7 + */ + +package com.flowcrypt.email.ui.activity.fragment.preferences + +import android.os.Bundle +import android.view.View +import com.flowcrypt.email.R +import com.flowcrypt.email.extensions.androidx.fragment.app.supportActionBar +import com.flowcrypt.email.ui.activity.fragment.base.BasePreferenceFragment + +/** + * This class describes general settings. + * + * @author Denys Bondarenko + */ +open class GeneralSettingsFragment : BasePreferenceFragment() { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + supportActionBar?.title = getString(R.string.general) + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.preferences_general_settings, rootKey) + } +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/AttachmentsRecyclerViewAdapter.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/AttachmentsRecyclerViewAdapter.kt index 17a5fb57e1..14f0761f89 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/AttachmentsRecyclerViewAdapter.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/AttachmentsRecyclerViewAdapter.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.adapter @@ -76,10 +76,6 @@ class AttachmentsRecyclerViewAdapter( attachmentActionListener.onDeleteClick(attachmentInfo) } - itemView.setOnClickListener { - attachmentActionListener.onAttachmentClick(attachmentInfo) - } - val value = progressMap[attachmentInfo.uniqueStringId] if (value?.progressInPercentage in 0..99) { imageViewAttIcon.setImageResource(R.drawable.stat_sys_download_blue) @@ -103,7 +99,6 @@ class AttachmentsRecyclerViewAdapter( interface AttachmentActionListener { fun onDownloadClick(attachmentInfo: AttachmentInfo) - fun onAttachmentClick(attachmentInfo: AttachmentInfo) fun onPreviewClick(attachmentInfo: AttachmentInfo) fun onDeleteClick(attachmentInfo: AttachmentInfo) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MessagesInThreadListAdapter.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MessagesInThreadListAdapter.kt index 1e798405a1..c4cd513abc 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MessagesInThreadListAdapter.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MessagesInThreadListAdapter.kt @@ -418,8 +418,6 @@ class MessagesInThreadListAdapter( onMessageActionsListener.onAttachmentDownloadClick(attachmentInfo, message) } - override fun onAttachmentClick(attachmentInfo: AttachmentInfo) {} - override fun onPreviewClick(attachmentInfo: AttachmentInfo) { onMessageActionsListener.onAttachmentPreviewClick(attachmentInfo, message) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/util/FileAndDirectoryUtils.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/util/FileAndDirectoryUtils.kt index 8feadc797a..0e9a9ef05e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/FileAndDirectoryUtils.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/FileAndDirectoryUtils.kt @@ -1,10 +1,12 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.util +import android.content.Context +import android.provider.MediaStore import org.apache.commons.io.FilenameUtils import java.io.File import java.io.IOException @@ -17,6 +19,21 @@ import java.util.regex.Pattern * @author Denys Bondarenko */ class FileAndDirectoryUtils { + object Downloads { + fun isFileAlreadyExist(context: Context, fileName: String): Boolean { + return context.contentResolver.query( + MediaStore.Downloads.EXTERNAL_CONTENT_URI, + arrayOf( + MediaStore.Files.FileColumns._ID, + MediaStore.Files.FileColumns.DISPLAY_NAME + ), + MediaStore.Downloads.DISPLAY_NAME + " = ?", + arrayOf(fileName), + null + )?.use { it.moveToNext() } ?: false + } + } + companion object { /** * Cleans an input directory. diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt index 94423cc7c3..14ac170e4f 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt @@ -470,12 +470,26 @@ class GeneralUtil { } } - fun genViewAttachmentIntent(uri: Uri, attachmentInfo: AttachmentInfo) = - Intent() - .setAction(Intent.ACTION_VIEW) - .setDataAndType(uri, Intent.normalizeMimeType(attachmentInfo.type)) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fun genViewAttachmentIntent( + uri: Uri, + attachmentInfo: AttachmentInfo, + useCommonPattern: Boolean = false + ): Intent { + return Intent.createChooser( + Intent() + .setAction(Intent.ACTION_VIEW) + .setDataAndType( + uri, + if (useCommonPattern) { + "*/*" + } else { + Intent.normalizeMimeType(attachmentInfo.type) + } + ) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION), null + ) + } suspend fun getGoogleIdTokenSilently( context: Context, diff --git a/FlowCrypt/src/main/res/drawable/bg_att.xml b/FlowCrypt/src/main/res/drawable/bg_att.xml index 0f5250bced..7f837c60d9 100644 --- a/FlowCrypt/src/main/res/drawable/bg_att.xml +++ b/FlowCrypt/src/main/res/drawable/bg_att.xml @@ -1,10 +1,9 @@ - diff --git a/FlowCrypt/src/main/res/drawable/bg_att_decrypted.xml b/FlowCrypt/src/main/res/drawable/bg_att_decrypted.xml index e2cbd22a2d..a69f53d185 100644 --- a/FlowCrypt/src/main/res/drawable/bg_att_decrypted.xml +++ b/FlowCrypt/src/main/res/drawable/bg_att_decrypted.xml @@ -1,12 +1,10 @@ - - diff --git a/FlowCrypt/src/main/res/navigation/nav_graph.xml b/FlowCrypt/src/main/res/navigation/nav_graph.xml index 4257b24760..0ff33271e7 100644 --- a/FlowCrypt/src/main/res/navigation/nav_graph.xml +++ b/FlowCrypt/src/main/res/navigation/nav_graph.xml @@ -145,6 +145,9 @@ + + + Черновик Удалить черновик? Переписка удалена или перемещена + \'%1$s\' уже существует в Download. Хотите загрузить его снова? + Общиe + Отключить интеллектуальный режим для предварительного просмотра вложений Черновик Черновики(%1$d) diff --git a/FlowCrypt/src/main/res/values-uk/strings.xml b/FlowCrypt/src/main/res/values-uk/strings.xml index 0bf836de2d..d4c9af51fa 100644 --- a/FlowCrypt/src/main/res/values-uk/strings.xml +++ b/FlowCrypt/src/main/res/values-uk/strings.xml @@ -644,6 +644,9 @@ Чорновик Видалити чернетку? Бесіду видалено або переміщено + \'%1$s\' уже існує в Download. Бажаєте завантажити його знову? + Загальні + Вимкнути розумний режим для попереднього перегляду вкладень Чорновик Чорновики(%1$d) diff --git a/FlowCrypt/src/main/res/values/preferences.xml b/FlowCrypt/src/main/res/values/preferences.xml index fbe9270602..749c5c8cab 100644 --- a/FlowCrypt/src/main/res/values/preferences.xml +++ b/FlowCrypt/src/main/res/values/preferences.xml @@ -1,13 +1,15 @@ preferences_key_messages_notification_filter preferences_key_manage_notifications preferences_key_security_change_pass_phrase + preferences_key_attachments_disable_smart_mode_for_preview pref_key_backups + pref_key_general pref_key_server_settings pref_key_attester pref_key_legal diff --git a/FlowCrypt/src/main/res/values/strings.xml b/FlowCrypt/src/main/res/values/strings.xml index 846d2b6893..246e7ef2d6 100644 --- a/FlowCrypt/src/main/res/values/strings.xml +++ b/FlowCrypt/src/main/res/values/strings.xml @@ -653,6 +653,9 @@ Draft Delete draft? The thread was deleted or moved + \'%1$s\' already exists in Download. Would you like to download it again? + General + Disable smart mode for attachments preview Draft Drafts(%1$d) diff --git a/FlowCrypt/src/main/res/xml/preferences_general_settings.xml b/FlowCrypt/src/main/res/xml/preferences_general_settings.xml new file mode 100644 index 0000000000..5ad8f30e8e --- /dev/null +++ b/FlowCrypt/src/main/res/xml/preferences_general_settings.xml @@ -0,0 +1,19 @@ + + + + + + + + + + diff --git a/FlowCrypt/src/main/res/xml/preferences_main_settings.xml b/FlowCrypt/src/main/res/xml/preferences_main_settings.xml index cb89f03f39..75b0e640f2 100644 --- a/FlowCrypt/src/main/res/xml/preferences_main_settings.xml +++ b/FlowCrypt/src/main/res/xml/preferences_main_settings.xml @@ -1,6 +1,6 @@ + +