From 975da6b59dfec63541615007dc1fa3df20038e2d Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Thu, 29 Jul 2021 15:07:05 +0300 Subject: [PATCH 01/14] Modified AccountEntity. Refactored code.| #1327 --- .../25.json | 47 +++--- .../ui/activity/SearchMessagesActivityTest.kt | 2 +- ...ndardReplyWithServiceInfoAndOneFileTest.kt | 2 +- .../flowcrypt/email/api/email/EmailUtil.kt | 9 +- .../email/api/email/gmail/GmailApiHelper.kt | 2 +- .../email/api/email/model/AuthCredentials.kt | 8 +- .../api/email/protocol/SmtpProtocolUtil.kt | 2 +- .../email/database/FlowCryptRoomDatabase.kt | 3 +- .../database/converters/OrgRulesConverter.kt | 43 ++++++ .../email/database/dao/AccountDao.kt | 10 +- .../email/database/entity/AccountEntity.kt | 140 +++++++----------- .../jetpack/viewmodel/AccountViewModel.kt | 2 +- .../jetpack/viewmodel/MessagesViewModel.kt | 16 +- .../workmanager/sync/BaseIdleWorker.kt | 2 +- .../sync/InboxIdleMsgsAddedWorker.kt | 2 +- .../workmanager/sync/InboxIdleSyncWorker.kt | 4 +- .../workmanager/sync/LoadContactsWorker.kt | 4 +- .../email/ui/activity/EmailManagerActivity.kt | 6 +- .../activity/fragment/MainSignInFragment.kt | 2 +- .../NotificationsSettingsFragment.kt | 2 +- 20 files changed, 158 insertions(+), 150 deletions(-) create mode 100644 FlowCrypt/src/main/java/com/flowcrypt/email/database/converters/OrgRulesConverter.kt diff --git a/FlowCrypt/schemas/com.flowcrypt.email.database.FlowCryptRoomDatabase/25.json b/FlowCrypt/schemas/com.flowcrypt.email.database.FlowCryptRoomDatabase/25.json index 0893da53a5..601d82fe28 100644 --- a/FlowCrypt/schemas/com.flowcrypt.email.database.FlowCryptRoomDatabase/25.json +++ b/FlowCrypt/schemas/com.flowcrypt.email.database.FlowCryptRoomDatabase/25.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 25, - "identityHash": "424a5613be14bb041d6a44a5f930b216", + "identityHash": "0195dbcce64e0e09b2d7b8f95d8b5f2c", "entities": [ { "tableName": "accounts_aliases", @@ -89,7 +89,7 @@ }, { "tableName": "accounts", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `email` TEXT NOT NULL, `account_type` TEXT DEFAULT NULL, `display_name` TEXT DEFAULT NULL, `given_name` TEXT DEFAULT NULL, `family_name` TEXT DEFAULT NULL, `photo_url` TEXT DEFAULT NULL, `is_enable` INTEGER DEFAULT 1, `is_active` INTEGER DEFAULT 0, `username` TEXT NOT NULL, `password` TEXT NOT NULL, `imap_server` TEXT NOT NULL, `imap_port` INTEGER DEFAULT 143, `imap_is_use_ssl_tls` INTEGER DEFAULT 0, `imap_is_use_starttls` INTEGER DEFAULT 0, `imap_auth_mechanisms` TEXT, `smtp_server` TEXT NOT NULL, `smtp_port` INTEGER DEFAULT 25, `smtp_is_use_ssl_tls` INTEGER DEFAULT 0, `smtp_is_use_starttls` INTEGER DEFAULT 0, `smtp_auth_mechanisms` TEXT, `smtp_is_use_custom_sign` INTEGER DEFAULT 0, `smtp_username` TEXT DEFAULT NULL, `smtp_password` TEXT DEFAULT NULL, `ic_contacts_loaded` INTEGER DEFAULT 0, `is_show_only_encrypted` INTEGER DEFAULT 0, `uuid` TEXT DEFAULT NULL, `domain_rules` TEXT DEFAULT NULL, `is_restore_access_required` INTEGER DEFAULT 0, `use_api` INTEGER NOT NULL DEFAULT 0)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `email` TEXT NOT NULL, `account_type` TEXT DEFAULT NULL, `display_name` TEXT DEFAULT NULL, `given_name` TEXT DEFAULT NULL, `family_name` TEXT DEFAULT NULL, `photo_url` TEXT DEFAULT NULL, `is_enabled` INTEGER DEFAULT 1, `is_active` INTEGER DEFAULT 0, `username` TEXT NOT NULL, `password` TEXT NOT NULL, `imap_server` TEXT NOT NULL, `imap_port` INTEGER DEFAULT 143, `imap_use_ssl_tls` INTEGER DEFAULT 0, `imap_use_starttls` INTEGER DEFAULT 0, `imap_auth_mechanisms` TEXT, `smtp_server` TEXT NOT NULL, `smtp_port` INTEGER DEFAULT 25, `smtp_use_ssl_tls` INTEGER DEFAULT 0, `smtp_use_starttls` INTEGER DEFAULT 0, `smtp_auth_mechanisms` TEXT, `smtp_use_custom_sign` INTEGER DEFAULT 0, `smtp_username` TEXT DEFAULT NULL, `smtp_password` TEXT DEFAULT NULL, `contacts_loaded` INTEGER DEFAULT 0, `show_only_encrypted` INTEGER DEFAULT 0, `uuid` TEXT DEFAULT NULL, `client_configuration` TEXT DEFAULT NULL, `use_api` INTEGER NOT NULL DEFAULT 0)", "fields": [ { "fieldPath": "id", @@ -140,7 +140,7 @@ }, { "fieldPath": "isEnabled", - "columnName": "is_enable", + "columnName": "is_enabled", "affinity": "INTEGER", "notNull": false, "defaultValue": "1" @@ -178,15 +178,15 @@ "defaultValue": "143" }, { - "fieldPath": "imapIsUseSslTls", - "columnName": "imap_is_use_ssl_tls", + "fieldPath": "imapUseSslTls", + "columnName": "imap_use_ssl_tls", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" }, { - "fieldPath": "imapIsUseStarttls", - "columnName": "imap_is_use_starttls", + "fieldPath": "imapUseStarttls", + "columnName": "imap_use_starttls", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" @@ -211,15 +211,15 @@ "defaultValue": "25" }, { - "fieldPath": "smtpIsUseSslTls", - "columnName": "smtp_is_use_ssl_tls", + "fieldPath": "smtpUseSslTls", + "columnName": "smtp_use_ssl_tls", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" }, { - "fieldPath": "smtpIsUseStarttls", - "columnName": "smtp_is_use_starttls", + "fieldPath": "smtpUseStarttls", + "columnName": "smtp_use_starttls", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" @@ -231,8 +231,8 @@ "notNull": false }, { - "fieldPath": "useCustomSignForSmtp", - "columnName": "smtp_is_use_custom_sign", + "fieldPath": "smtpUseCustomSign", + "columnName": "smtp_use_custom_sign", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" @@ -252,15 +252,15 @@ "defaultValue": "NULL" }, { - "fieldPath": "areContactsLoaded", - "columnName": "ic_contacts_loaded", + "fieldPath": "contactsLoaded", + "columnName": "contacts_loaded", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" }, { - "fieldPath": "isShowOnlyEncrypted", - "columnName": "is_show_only_encrypted", + "fieldPath": "showOnlyEncrypted", + "columnName": "show_only_encrypted", "affinity": "INTEGER", "notNull": false, "defaultValue": "0" @@ -273,19 +273,12 @@ "defaultValue": "NULL" }, { - "fieldPath": "domainRules", - "columnName": "domain_rules", + "fieldPath": "clientConfiguration", + "columnName": "client_configuration", "affinity": "TEXT", "notNull": false, "defaultValue": "NULL" }, - { - "fieldPath": "isRestoreAccessRequired", - "columnName": "is_restore_access_required", - "affinity": "INTEGER", - "notNull": false, - "defaultValue": "0" - }, { "fieldPath": "useAPI", "columnName": "use_api", @@ -994,7 +987,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '424a5613be14bb041d6a44a5f930b216')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0195dbcce64e0e09b2d7b8f95d8b5f2c')" ] } } \ No newline at end of file diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/SearchMessagesActivityTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/SearchMessagesActivityTest.kt index ad6ee97339..6ec2f66cd1 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/SearchMessagesActivityTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/SearchMessagesActivityTest.kt @@ -55,7 +55,7 @@ import org.junit.runner.RunWith class SearchMessagesActivityTest : BaseEmailListActivityTest() { private val accountRule = AddAccountToDatabaseRule( - AccountDaoManager.getDefaultAccountDao().copy(areContactsLoaded = true) + AccountDaoManager.getDefaultAccountDao().copy(contactsLoaded = true) ) override val activityScenarioRule = activityScenarioRule( diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/StandardReplyWithServiceInfoAndOneFileTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/StandardReplyWithServiceInfoAndOneFileTest.kt index 2010ba9e45..aa8bdb3bdf 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/StandardReplyWithServiceInfoAndOneFileTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/StandardReplyWithServiceInfoAndOneFileTest.kt @@ -58,7 +58,7 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class StandardReplyWithServiceInfoAndOneFileTest : BaseTest() { private val addAccountToDatabaseRule: AddAccountToDatabaseRule = AddAccountToDatabaseRule( - AccountDaoManager.getDefaultAccountDao().copy(areContactsLoaded = true) + AccountDaoManager.getDefaultAccountDao().copy(contactsLoaded = true) ) private val attachmentInfo = AttachmentInfo( name = "test.txt", diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt index 4e1791b903..48e079d542 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt @@ -59,7 +59,10 @@ import java.io.ByteArrayInputStream import java.io.IOException import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat -import java.util.* +import java.util.Date +import java.util.Locale +import java.util.Properties +import java.util.UUID import javax.activation.DataHandler import javax.mail.BodyPart import javax.mail.FetchProfile @@ -84,8 +87,6 @@ import javax.mail.search.SearchTerm import javax.mail.search.StringTerm import javax.mail.search.SubjectTerm import javax.mail.util.ByteArrayDataSource -import kotlin.collections.HashMap -import kotlin.collections.HashSet /** * @author Denis Bondarenko @@ -940,7 +941,7 @@ class EmailUtil { * @return A generated [SearchTerm]. */ fun generateSearchTerm(account: AccountEntity, localFolder: LocalFolder): SearchTerm { - val isEncryptedModeEnabled = account.isShowOnlyEncrypted + val isEncryptedModeEnabled = account.showOnlyEncrypted if (isEncryptedModeEnabled == true) { val searchTerm = genEncryptedMsgsSearchTerm(account) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailApiHelper.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailApiHelper.kt index 3f755c3c6d..24d40ce759 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailApiHelper.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailApiHelper.kt @@ -235,7 +235,7 @@ class GmailApiHelper { request.labelIds = listOf(localFolder.fullName) } - if (accountEntity.isShowOnlyEncrypted == true) { + if (accountEntity.showOnlyEncrypted == true) { request.q = (EmailUtil.genEncryptedMsgsSearchTerm(accountEntity) as? GmailRawSearchTerm)?.pattern } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/model/AuthCredentials.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/model/AuthCredentials.kt index 2983389c58..0518c5b118 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/model/AuthCredentials.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/model/AuthCredentials.kt @@ -99,17 +99,17 @@ data class AuthCredentials constructor( with(accountEntity) { var imapOpt: SecurityType.Option = SecurityType.Option.NONE - if (imapIsUseSslTls == true) { + if (imapUseSslTls == true) { imapOpt = SecurityType.Option.SSL_TLS - } else if (imapIsUseStarttls == true) { + } else if (imapUseStarttls == true) { imapOpt = SecurityType.Option.STARTLS } var smtpOpt: SecurityType.Option = SecurityType.Option.NONE - if (smtpIsUseSslTls == true) { + if (smtpUseSslTls == true) { smtpOpt = SecurityType.Option.SSL_TLS - } else if (smtpIsUseStarttls == true) { + } else if (smtpUseStarttls == true) { smtpOpt = SecurityType.Option.STARTLS } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/protocol/SmtpProtocolUtil.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/protocol/SmtpProtocolUtil.kt index 156aa67b26..bc851d112f 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/protocol/SmtpProtocolUtil.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/protocol/SmtpProtocolUtil.kt @@ -65,7 +65,7 @@ class SmtpProtocolUtil { val userName: String? var password: String? - if (accountEntity.useCustomSignForSmtp == true) { + if (accountEntity.smtpUseCustomSign == true) { userName = accountEntity.smtpUsername password = accountEntity.smtpPassword } else { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt index 4a55be82c1..bc17305986 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt @@ -16,6 +16,7 @@ import androidx.room.RoomDatabase import androidx.room.TypeConverters import androidx.sqlite.db.SupportSQLiteDatabase import com.flowcrypt.email.api.email.JavaEmailConstants +import com.flowcrypt.email.database.converters.OrgRulesConverter import com.flowcrypt.email.database.converters.PassphraseTypeConverter import com.flowcrypt.email.database.dao.AccountAliasesDao import com.flowcrypt.email.database.dao.AccountDao @@ -59,7 +60,7 @@ import org.pgpainless.key.OpenPgpV4Fingerprint ], version = FlowCryptRoomDatabase.DB_VERSION ) -@TypeConverters(PassphraseTypeConverter::class) +@TypeConverters(PassphraseTypeConverter::class, OrgRulesConverter::class) abstract class FlowCryptRoomDatabase : RoomDatabase() { abstract fun msgDao(): MessageDao diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/converters/OrgRulesConverter.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/converters/OrgRulesConverter.kt new file mode 100644 index 0000000000..d8c23d1bb1 --- /dev/null +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/converters/OrgRulesConverter.kt @@ -0,0 +1,43 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: DenBond7 + */ + +package com.flowcrypt.email.database.converters + +import androidx.room.TypeConverter +import com.flowcrypt.email.api.retrofit.response.model.OrgRules +import com.google.gson.GsonBuilder + +/** + * @author Denis Bondarenko + * Date: 7/29/21 + * Time: 2:19 PM + * E-mail: DenBond7@gmail.com + */ +class OrgRulesConverter { + private val gson = GsonBuilder() + .excludeFieldsWithoutExposeAnnotation() + .serializeNulls() + .create() + + @TypeConverter + fun fromOrgRules(orgRules: OrgRules?): String? { + return try { + orgRules?.let { gson.toJson(orgRules) } + } catch (e: Exception) { + e.printStackTrace() + null + } + } + + @TypeConverter + fun toOrgRules(orgRulesJson: String?): OrgRules? { + return try { + orgRulesJson?.let { gson.fromJson(it, OrgRules::class.java) } + } catch (e: Exception) { + e.printStackTrace() + null + } + } +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountDao.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountDao.kt index 5dad9ac6d8..027e1b0a2c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountDao.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountDao.kt @@ -186,13 +186,13 @@ abstract class AccountDao : BaseDao { smtpPassword = encryptedSmtpPassword, imapServer = authCredentials.imapServer.toLowerCase(Locale.US), imapPort = authCredentials.imapPort, - imapIsUseSslTls = authCredentials.imapOpt === SecurityType.Option.SSL_TLS, - imapIsUseStarttls = authCredentials.imapOpt === SecurityType.Option.STARTLS, + imapUseSslTls = authCredentials.imapOpt === SecurityType.Option.SSL_TLS, + imapUseStarttls = authCredentials.imapOpt === SecurityType.Option.STARTLS, smtpServer = authCredentials.smtpServer.toLowerCase(Locale.US), smtpPort = authCredentials.smtpPort, - smtpIsUseSslTls = authCredentials.smtpOpt === SecurityType.Option.SSL_TLS, - smtpIsUseStarttls = authCredentials.smtpOpt === SecurityType.Option.STARTLS, - useCustomSignForSmtp = authCredentials.hasCustomSignInForSmtp, + smtpUseSslTls = authCredentials.smtpOpt === SecurityType.Option.SSL_TLS, + smtpUseStarttls = authCredentials.smtpOpt === SecurityType.Option.STARTLS, + smtpUseCustomSign = authCredentials.hasCustomSignInForSmtp, smtpUsername = authCredentials.smtpSigInUsername ) ) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt index 61e1d1e9b4..8969a6bb09 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt @@ -44,53 +44,36 @@ data class AccountEntity constructor( @ColumnInfo(name = "given_name", defaultValue = "NULL") val givenName: String? = null, @ColumnInfo(name = "family_name", defaultValue = "NULL") val familyName: String? = null, @ColumnInfo(name = "photo_url", defaultValue = "NULL") val photoUrl: String? = null, - @ColumnInfo(name = "is_enable", defaultValue = "1") val isEnabled: Boolean? = true, + @ColumnInfo(name = "is_enabled", defaultValue = "1") val isEnabled: Boolean? = true, @ColumnInfo(name = "is_active", defaultValue = "0") val isActive: Boolean? = false, val username: String, val password: String, @ColumnInfo(name = "imap_server") val imapServer: String, @ColumnInfo(name = "imap_port", defaultValue = "143") val imapPort: Int? = 143, - @ColumnInfo( - name = "imap_is_use_ssl_tls", - defaultValue = "0" - ) val imapIsUseSslTls: Boolean? = false, - @ColumnInfo( - name = "imap_is_use_starttls", - defaultValue = "0" - ) val imapIsUseStarttls: Boolean? = false, + @ColumnInfo(name = "imap_use_ssl_tls", defaultValue = "0") val imapUseSslTls: Boolean? = false, + @ColumnInfo(name = "imap_use_starttls", defaultValue = "0") val imapUseStarttls: Boolean? = false, @ColumnInfo(name = "imap_auth_mechanisms") val imapAuthMechanisms: String? = null, @ColumnInfo(name = "smtp_server") val smtpServer: String, @ColumnInfo(name = "smtp_port", defaultValue = "25") val smtpPort: Int? = 25, - @ColumnInfo( - name = "smtp_is_use_ssl_tls", - defaultValue = "0" - ) val smtpIsUseSslTls: Boolean? = false, - @ColumnInfo( - name = "smtp_is_use_starttls", - defaultValue = "0" - ) val smtpIsUseStarttls: Boolean? = false, + @ColumnInfo(name = "smtp_use_ssl_tls", defaultValue = "0") val smtpUseSslTls: Boolean? = false, + @ColumnInfo(name = "smtp_use_starttls", defaultValue = "0") val smtpUseStarttls: Boolean? = false, @ColumnInfo(name = "smtp_auth_mechanisms") val smtpAuthMechanisms: String? = null, @ColumnInfo( - name = "smtp_is_use_custom_sign", + name = "smtp_use_custom_sign", defaultValue = "0" - ) val useCustomSignForSmtp: Boolean? = false, + ) val smtpUseCustomSign: Boolean? = false, @ColumnInfo(name = "smtp_username", defaultValue = "NULL") val smtpUsername: String? = null, @ColumnInfo(name = "smtp_password", defaultValue = "NULL") val smtpPassword: String? = null, + @ColumnInfo(name = "contacts_loaded", defaultValue = "0") val contactsLoaded: Boolean? = false, @ColumnInfo( - name = "ic_contacts_loaded", + name = "show_only_encrypted", defaultValue = "0" - ) val areContactsLoaded: Boolean? = false, - @ColumnInfo( - name = "is_show_only_encrypted", - defaultValue = "0" - ) val isShowOnlyEncrypted: Boolean? = false, + ) val showOnlyEncrypted: Boolean? = false, @ColumnInfo(defaultValue = "NULL") val uuid: String? = null, - @ColumnInfo(name = "domain_rules", defaultValue = "NULL") val domainRules: String? = null, - @Deprecated("Don't use this field. Should be removed in the next database upgrading") @ColumnInfo( - name = "is_restore_access_required", - defaultValue = "0" - ) val isRestoreAccessRequired: Boolean? = false, + name = "client_configuration", + defaultValue = "NULL" + ) val clientConfiguration: OrgRules? = null, @ColumnInfo(name = "use_api", defaultValue = "0") val useAPI: Boolean = false ) : Parcelable { @@ -103,8 +86,9 @@ data class AccountEntity constructor( val useOAuth2: Boolean get() = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2 == imapAuthMechanisms - constructor(googleSignInAccount: GoogleSignInAccount, uuid: String? = null, - domainRules: List? = null) : + constructor( + googleSignInAccount: GoogleSignInAccount, uuid: String? = null, orgRules: OrgRules? = null + ) : this( email = googleSignInAccount.email!!.toLowerCase(Locale.US), accountType = googleSignInAccount.account?.type?.toLowerCase(Locale.US), @@ -118,26 +102,25 @@ data class AccountEntity constructor( password = "", imapServer = GmailConstants.GMAIL_IMAP_SERVER, imapPort = GmailConstants.GMAIL_IMAP_PORT, - imapIsUseSslTls = true, - imapIsUseStarttls = false, + imapUseSslTls = true, + imapUseStarttls = false, imapAuthMechanisms = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2, smtpServer = GmailConstants.GMAIL_SMTP_SERVER, smtpPort = GmailConstants.GMAIL_SMTP_PORT, - smtpIsUseSslTls = true, - smtpIsUseStarttls = false, + smtpUseSslTls = true, + smtpUseStarttls = false, smtpAuthMechanisms = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2, - useCustomSignForSmtp = false, + smtpUseCustomSign = false, smtpUsername = null, smtpPassword = null, - areContactsLoaded = false, - isShowOnlyEncrypted = false, + contactsLoaded = false, + showOnlyEncrypted = false, uuid = uuid, - domainRules = domainRules?.joinToString(), - isRestoreAccessRequired = false, + clientConfiguration = orgRules, useAPI = FlavorSettings.isGMailAPIEnabled() ) - constructor(authCredentials: AuthCredentials, uuid: String? = null, domainRules: List? = null) : + constructor(authCredentials: AuthCredentials, uuid: String? = null, orgRules: OrgRules? = null) : this( email = authCredentials.email.toLowerCase(Locale.US), accountType = authCredentials.email.substring(authCredentials.email.indexOf('@') + 1) @@ -152,22 +135,21 @@ data class AccountEntity constructor( password = authCredentials.password, imapServer = authCredentials.imapServer.toLowerCase(Locale.US), imapPort = authCredentials.imapPort, - imapIsUseSslTls = authCredentials.imapOpt === SecurityType.Option.SSL_TLS, - imapIsUseStarttls = authCredentials.imapOpt === SecurityType.Option.STARTLS, + imapUseSslTls = authCredentials.imapOpt === SecurityType.Option.SSL_TLS, + imapUseStarttls = authCredentials.imapOpt === SecurityType.Option.STARTLS, imapAuthMechanisms = if (authCredentials.useOAuth2) JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2 else null, smtpServer = authCredentials.smtpServer.toLowerCase(Locale.US), smtpPort = authCredentials.smtpPort, - smtpIsUseSslTls = authCredentials.smtpOpt === SecurityType.Option.SSL_TLS, - smtpIsUseStarttls = authCredentials.smtpOpt === SecurityType.Option.STARTLS, + smtpUseSslTls = authCredentials.smtpOpt === SecurityType.Option.SSL_TLS, + smtpUseStarttls = authCredentials.smtpOpt === SecurityType.Option.STARTLS, smtpAuthMechanisms = if (authCredentials.useOAuth2) JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2 else null, - useCustomSignForSmtp = authCredentials.hasCustomSignInForSmtp, + smtpUseCustomSign = authCredentials.hasCustomSignInForSmtp, smtpUsername = authCredentials.smtpSigInUsername, smtpPassword = authCredentials.smtpSignInPassword, - areContactsLoaded = false, - isShowOnlyEncrypted = false, + contactsLoaded = false, + showOnlyEncrypted = false, uuid = uuid, - domainRules = domainRules?.joinToString(), - isRestoreAccessRequired = false, + clientConfiguration = orgRules, useAPI = false ) @@ -185,22 +167,21 @@ data class AccountEntity constructor( password = "", imapServer = "", imapPort = 0, - imapIsUseSslTls = true, - imapIsUseStarttls = false, + imapUseSslTls = true, + imapUseStarttls = false, imapAuthMechanisms = null, smtpServer = "", smtpPort = 0, - smtpIsUseSslTls = true, - smtpIsUseStarttls = false, + smtpUseSslTls = true, + smtpUseStarttls = false, smtpAuthMechanisms = "", - useCustomSignForSmtp = false, + smtpUseCustomSign = false, smtpUsername = null, smtpPassword = null, - areContactsLoaded = false, - isShowOnlyEncrypted = false, + contactsLoaded = false, + showOnlyEncrypted = false, uuid = null, - domainRules = null, - isRestoreAccessRequired = false, + clientConfiguration = null, useAPI = false ) @@ -232,26 +213,17 @@ data class AccountEntity constructor( source.readValue(Boolean::class.java.classLoader) as Boolean?, source.readValue(Boolean::class.java.classLoader) as Boolean?, source.readString(), - source.readString(), - source.readValue(Boolean::class.java.classLoader) as Boolean?, + source.readParcelable(OrgRules::class.java.classLoader), source.readValue(Boolean::class.java.classLoader) as Boolean ) - fun domainRulesList(): List { - return if (domainRules.isNullOrEmpty()) { - emptyList() - } else { - domainRules.split(",").map { it.trim() } - } - } - fun imapOpt(): SecurityType.Option { return when { - imapIsUseSslTls == true -> { + imapUseSslTls == true -> { SecurityType.Option.SSL_TLS } - imapIsUseStarttls == true -> { + imapUseStarttls == true -> { SecurityType.Option.STARTLS } @@ -261,11 +233,11 @@ data class AccountEntity constructor( fun smtpOpt(): SecurityType.Option { return when { - smtpIsUseSslTls == true -> { + smtpUseSslTls == true -> { SecurityType.Option.SSL_TLS } - smtpIsUseStarttls == true -> { + smtpUseStarttls == true -> { SecurityType.Option.STARTLS } @@ -274,8 +246,7 @@ data class AccountEntity constructor( } fun isRuleExist(domainRule: OrgRules.DomainRule): Boolean { - val rules = domainRulesList() - return domainRule.name in rules + return clientConfiguration?.hasRule(domainRule) ?: false } override fun describeContents() = 0 @@ -294,22 +265,21 @@ data class AccountEntity constructor( writeString(password) writeString(imapServer) writeValue(imapPort) - writeValue(imapIsUseSslTls) - writeValue(imapIsUseStarttls) + writeValue(imapUseSslTls) + writeValue(imapUseStarttls) writeString(imapAuthMechanisms) writeString(smtpServer) writeValue(smtpPort) - writeValue(smtpIsUseSslTls) - writeValue(smtpIsUseStarttls) + writeValue(smtpUseSslTls) + writeValue(smtpUseStarttls) writeString(smtpAuthMechanisms) - writeValue(useCustomSignForSmtp) + writeValue(smtpUseCustomSign) writeString(smtpUsername) writeString(smtpPassword) - writeValue(areContactsLoaded) - writeValue(isShowOnlyEncrypted) + writeValue(contactsLoaded) + writeValue(showOnlyEncrypted) writeString(uuid) - writeString(domainRules) - writeValue(isRestoreAccessRequired) + writeParcelable(clientConfiguration, flags) writeValue(useAPI) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountViewModel.kt index d5ec7a234a..b6128533dd 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountViewModel.kt @@ -79,7 +79,7 @@ open class AccountViewModel(application: Application) : RoomBasicViewModel(appli accountEntity.copy( id = existedAccount.id, uuid = existedAccount.uuid, - domainRules = existedAccount.domainRules + clientConfiguration = existedAccount.clientConfiguration ) ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt index 30ec989fbc..ee7f7e7a7e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt @@ -375,7 +375,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application else -> countOfAlreadyLoadedMsgs } - val isEncryptedModeEnabled = accountEntity.isShowOnlyEncrypted + val isEncryptedModeEnabled = accountEntity.showOnlyEncrypted var foundMsgs: Array = emptyArray() var msgsCount = 0 @@ -493,7 +493,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application val email = account.email val folder = localFolder.fullName - val isEncryptedModeEnabled = account.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = account.showOnlyEncrypted ?: false val msgEntities = MessageEntity.genMessageEntities( context = getApplication(), email = email, @@ -519,7 +519,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application val email = account.email val folder = localFolder.fullName - val isEncryptedModeEnabled = account.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = account.showOnlyEncrypted ?: false val msgEntities = MessageEntity.genMessageEntities( context = getApplication(), email = email, @@ -734,7 +734,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application remoteFolder: IMAPFolder, msgs: Array ) = withContext(Dispatchers.IO) { val email = account.email - val isEncryptedModeEnabled = account.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = account.showOnlyEncrypted ?: false val searchLabel = SearchMessagesActivity.SEARCH_FOLDER_NAME val msgEntities = MessageEntity.genMessageEntities( @@ -763,7 +763,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application val email = account.email val label = localFolder.fullName - val isEncryptedModeEnabled = account.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = account.showOnlyEncrypted ?: false val msgEntities = MessageEntity.genMessageEntities( context = getApplication(), email = email, @@ -844,7 +844,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application newestCachedUID.toLong() ) - val newMsgsAfterLastInLocalCache = if (accountEntity.isShowOnlyEncrypted == true) { + val newMsgsAfterLastInLocalCache = if (accountEntity.showOnlyEncrypted == true) { val foundMsgs = imapFolder.search(EmailUtil.genEncryptedMsgsSearchTerm(accountEntity)) val fetchProfile = FetchProfile() @@ -907,7 +907,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application val newCandidates = EmailUtil.genNewCandidates(msgsUIDs, remoteFolder, newMsgs) - val isEncryptedModeEnabled = accountEntity.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = accountEntity.showOnlyEncrypted ?: false val isNew = !GeneralUtil.isAppForegrounded() && folderType === FoldersManager.FolderType.INBOX val msgEntities = MessageEntity.genMessageEntities( @@ -960,7 +960,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application newCandidates.toList(), localFolder ) - val isEncryptedModeEnabled = accountEntity.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = accountEntity.showOnlyEncrypted ?: false val isNew = !GeneralUtil.isAppForegrounded() && folderType === FoldersManager.FolderType.INBOX diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/BaseIdleWorker.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/BaseIdleWorker.kt index 744fd3d0df..f578eb5499 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/BaseIdleWorker.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/BaseIdleWorker.kt @@ -87,7 +87,7 @@ abstract class BaseIdleWorker(context: Context, params: WorkerParameters) : if (newMsgs.isNotEmpty()) { EmailUtil.fetchMsgs(remoteFolder, newMsgs) val msgsEncryptionStates = - EmailUtil.getMsgsEncryptionInfo(accountEntity.isShowOnlyEncrypted, remoteFolder, newMsgs) + EmailUtil.getMsgsEncryptionInfo(accountEntity.showOnlyEncrypted, remoteFolder, newMsgs) val msgEntities = MessageEntity.genMessageEntities( context = applicationContext, email = accountEntity.email, diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleMsgsAddedWorker.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleMsgsAddedWorker.kt index 099b7b1941..b768a536dc 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleMsgsAddedWorker.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleMsgsAddedWorker.kt @@ -54,7 +54,7 @@ class InboxIdleMsgsAddedWorker(context: Context, params: WorkerParameters) : .getLastUIDOfMsgForLabelSuspend(accountEntity.email, folderFullName) ?: 0 val cachedUIDSet = roomDatabase.msgDao().getUIDsForLabel(accountEntity.email, folderFullName).toSet() - val newMsgs = if (accountEntity.isShowOnlyEncrypted == true) { + val newMsgs = if (accountEntity.showOnlyEncrypted == true) { val foundMsgs = remoteFolder.search(EmailUtil.genEncryptedMsgsSearchTerm(accountEntity)) val fetchProfile = FetchProfile().apply { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleSyncWorker.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleSyncWorker.kt index 8d0e5d102d..797d2d0ceb 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleSyncWorker.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/InboxIdleSyncWorker.kt @@ -63,7 +63,7 @@ open class InboxIdleSyncWorker(context: Context, params: WorkerParameters) : roomDatabase.msgDao().getMapOfUIDAndMsgFlagsSuspend(accountEntity.email, folderFullName) val cachedUIDSet = mapOfUIDAndMsgFlags.keys.toSet() - if (accountEntity.isShowOnlyEncrypted == true) { + if (accountEntity.showOnlyEncrypted == true) { val foundMsgs = remoteFolder.search(EmailUtil.genEncryptedMsgsSearchTerm(accountEntity)) val fetchProfile = FetchProfile().apply { add(UIDFolder.FetchProfileItem.UID) @@ -157,7 +157,7 @@ open class InboxIdleSyncWorker(context: Context, params: WorkerParameters) : newCandidates, localFolder ) - val isEncryptedModeEnabled = accountEntity.isShowOnlyEncrypted ?: false + val isEncryptedModeEnabled = accountEntity.showOnlyEncrypted ?: false val isNew = !GeneralUtil.isAppForegrounded() val msgEntities = MessageEntity.genMessageEntities( diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/LoadContactsWorker.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/LoadContactsWorker.kt index 2b22ee5bf4..a1e1977c9a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/LoadContactsWorker.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/sync/LoadContactsWorker.kt @@ -141,13 +141,13 @@ class LoadContactsWorker(context: Context, params: WorkerParameters) : account: AccountEntity, action: suspend () -> Array ) = withContext(Dispatchers.IO) { - if (account.areContactsLoaded == true) return@withContext + if (account.contactsLoaded == true) return@withContext val msgs = action.invoke() if (msgs.isNotEmpty()) { updateContacts(msgs) FlowCryptRoomDatabase.getDatabase(applicationContext).accountDao() - .updateAccountSuspend(account.copy(areContactsLoaded = true)) + .updateAccountSuspend(account.copy(contactsLoaded = true)) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt index bc2ebe0e8c..7feb789535 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt @@ -182,7 +182,7 @@ class EmailManagerActivity : BaseEmailListActivity(), super.onAccountInfoRefreshed(accountEntity) if (accountEntity != null) { actionsViewModel.checkAndAddActionsToQueue(accountEntity) - switchView?.isChecked = activeAccount?.isShowOnlyEncrypted ?: false + switchView?.isChecked = activeAccount?.showOnlyEncrypted ?: false invalidateOptionsMenu() navigationView?.getHeaderView(0)?.let { initUserProfileView(it) } } else { @@ -204,7 +204,7 @@ class EmailManagerActivity : BaseEmailListActivity(), val item = menu.findItem(R.id.menuSwitch) switchView = item.actionView.findViewById(R.id.switchShowOnlyEncryptedMessages) - switchView?.isChecked = activeAccount?.isShowOnlyEncrypted ?: false + switchView?.isChecked = activeAccount?.showOnlyEncrypted ?: false switchView?.setOnCheckedChangeListener { buttonView, isChecked -> lifecycleScope.launch { activeAccount?.let { @@ -213,7 +213,7 @@ class EmailManagerActivity : BaseEmailListActivity(), } FlowCryptRoomDatabase.getDatabase(this@EmailManagerActivity.applicationContext) - .accountDao().updateAccountSuspend(it.copy(isShowOnlyEncrypted = isChecked)) + .accountDao().updateAccountSuspend(it.copy(showOnlyEncrypted = isChecked)) onShowOnlyEncryptedMsgs(isChecked) 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 5d5bf7de0d..7250be8c9a 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 @@ -193,7 +193,7 @@ class MainSignInFragment : BaseSingInFragment() { } override fun getTempAccount(): AccountEntity? { - return googleSignInAccount?.let { AccountEntity(it, uuid, orgRules?.flags ?: emptyList()) } + return googleSignInAccount?.let { AccountEntity(it, uuid, orgRules) } } override fun returnResultOk() { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/NotificationsSettingsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/NotificationsSettingsFragment.kt index bfddea42ac..b092b8f1b2 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/NotificationsSettingsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/NotificationsSettingsFragment.kt @@ -73,7 +73,7 @@ open class NotificationsSettingsFragment : BasePreferenceFragment(), override fun onAccountInfoRefreshed(accountEntity: AccountEntity?) { if (accountEntity != null) { - val isEncryptedModeEnabled = accountEntity.isShowOnlyEncrypted + val isEncryptedModeEnabled = accountEntity.showOnlyEncrypted if (isEncryptedModeEnabled == true) { levels = arrayOf( From f19919f93fd8e50d1696721316e8b5c03257ec74 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Thu, 29 Jul 2021 12:03:17 +0300 Subject: [PATCH 02/14] Fixed names in GeneralUtil.hasInternetAccess().| #1327 --- .../java/com/flowcrypt/email/util/GeneralUtil.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 9ebb475b28..55623f90ba 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt @@ -87,11 +87,11 @@ class GeneralUtil { suspend fun hasInternetAccess(): Boolean = withContext(Dispatchers.IO) { val url = "https://www.google.com" - val connectionTimeoutInSeconds = 2000L + val connectionTimeoutInMilliseconds = 2000L val okHttpClient = OkHttpClient.Builder() - .connectTimeout(connectionTimeoutInSeconds, TimeUnit.MILLISECONDS) - .writeTimeout(connectionTimeoutInSeconds, TimeUnit.MILLISECONDS) - .readTimeout(connectionTimeoutInSeconds, TimeUnit.MILLISECONDS) + .connectTimeout(connectionTimeoutInMilliseconds, TimeUnit.MILLISECONDS) + .writeTimeout(connectionTimeoutInMilliseconds, TimeUnit.MILLISECONDS) + .readTimeout(connectionTimeoutInMilliseconds, TimeUnit.MILLISECONDS) .build() val retrofit = Retrofit.Builder() @@ -292,7 +292,7 @@ class GeneralUtil { } else { val fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()) MimeTypeMap.getSingleton() - .getMimeTypeFromExtension(fileExtension.toLowerCase(Locale.getDefault())) + .getMimeTypeFromExtension(fileExtension.lowercase(Locale.getDefault())) ?: Constants.MIME_TYPE_BINARY_DATA } } @@ -395,7 +395,7 @@ class GeneralUtil { context ?: return "en" return if (context.resources.configuration.locales.isEmpty) { "en" - } else context.resources.configuration.locales.get(0).language.toLowerCase(Locale.getDefault()) + } else context.resources.configuration.locales.get(0).language.lowercase(Locale.getDefault()) } } } From a7016f56224ddf821ef256709107093fb311bb47 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Thu, 29 Jul 2021 15:11:59 +0300 Subject: [PATCH 03/14] Fixed bug after previous commit.| #1327 --- .../src/main/java/com/flowcrypt/email/util/GeneralUtil.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 55623f90ba..a0e41c085a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt @@ -292,7 +292,7 @@ class GeneralUtil { } else { val fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()) MimeTypeMap.getSingleton() - .getMimeTypeFromExtension(fileExtension.lowercase(Locale.getDefault())) + .getMimeTypeFromExtension(fileExtension.toLowerCase(Locale.getDefault())) ?: Constants.MIME_TYPE_BINARY_DATA } } @@ -395,7 +395,7 @@ class GeneralUtil { context ?: return "en" return if (context.resources.configuration.locales.isEmpty) { "en" - } else context.resources.configuration.locales.get(0).language.lowercase(Locale.getDefault()) + } else context.resources.configuration.locales.get(0).language.toLowerCase(Locale.getDefault()) } } } From 8a941a078c66b2c3b1d53d169faa99215f3e91af Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Thu, 29 Jul 2021 17:05:31 +0300 Subject: [PATCH 04/14] Added restriction "forbid adding keys in settings -> keys".| #1327 --- .../fragment/PrivateKeysListFragment.kt | 132 +++++++++--------- .../adapter/PrivateKeysRecyclerViewAdapter.kt | 10 +- .../main/res/layout/fragment_private_keys.xml | 3 +- 3 files changed, 77 insertions(+), 68 deletions(-) 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 acd792e741..8ae622786f 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 @@ -6,12 +6,13 @@ package com.flowcrypt.email.ui.activity.fragment import android.app.Activity -import android.content.Context import android.content.Intent import android.os.Bundle +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.View +import android.view.ViewGroup import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode @@ -25,19 +26,23 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView 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.FragmentPrivateKeysBinding import com.flowcrypt.email.extensions.decrementSafely +import com.flowcrypt.email.extensions.gone import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.extensions.navController import com.flowcrypt.email.extensions.showTwoWayDialog +import com.flowcrypt.email.extensions.toast import com.flowcrypt.email.jetpack.viewmodel.PrivateKeysViewModel import com.flowcrypt.email.security.model.PgpKeyDetails import com.flowcrypt.email.ui.activity.ImportPrivateKeyActivity import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment +import com.flowcrypt.email.ui.activity.fragment.base.ListProgressBehaviour import com.flowcrypt.email.ui.activity.fragment.dialog.TwoWayDialogFragment import com.flowcrypt.email.ui.adapter.PrivateKeysRecyclerViewAdapter import com.flowcrypt.email.ui.adapter.selection.NodeKeyDetailsKeyProvider import com.flowcrypt.email.ui.adapter.selection.PrivateKeyItemDetailsLookup -import com.flowcrypt.email.util.UIUtil /** * This [Fragment] shows information about available private keys in the database. @@ -47,18 +52,12 @@ import com.flowcrypt.email.util.UIUtil * Time: 10:30 * E-mail: DenBond7@gmail.com */ -class PrivateKeysListFragment : BaseFragment(), View.OnClickListener, +class PrivateKeysListFragment : BaseFragment(), ListProgressBehaviour, PrivateKeysRecyclerViewAdapter.OnKeySelectedListener { + private var binding: FragmentPrivateKeysBinding? = null - private var progressBar: View? = null - private var emptyView: View? = null - private var content: View? = null - + private val recyclerViewAdapter = PrivateKeysRecyclerViewAdapter(this) private val privateKeysViewModel: PrivateKeysViewModel by viewModels() - private lateinit var recyclerViewAdapter: PrivateKeysRecyclerViewAdapter - - override val contentResourceId: Int = R.layout.fragment_private_keys - private var tracker: SelectionTracker? = null private var actionMode: ActionMode? = null private val selectionObserver = object : SelectionTracker.SelectionObserver() { @@ -83,15 +82,29 @@ class PrivateKeysListFragment : BaseFragment(), View.OnClickListener, } } - override fun onAttach(context: Context) { - super.onAttach(context) - recyclerViewAdapter = PrivateKeysRecyclerViewAdapter(context, this) + override val emptyView: View? + get() = binding?.emptyView + override val progressView: View? + get() = binding?.progressBar + override val contentView: View? + get() = binding?.groupContent + override val statusView: View? = null + + override val contentResourceId: Int = R.layout.fragment_private_keys + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentPrivateKeysBinding.inflate(inflater, container, false) + return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) supportActionBar?.setTitle(R.string.keys) - initViews(view) + initViews() setupPrivateKeysViewModel() } @@ -112,11 +125,7 @@ class PrivateKeysListFragment : BaseFragment(), View.OnClickListener, override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { REQUEST_CODE_START_IMPORT_KEY_ACTIVITY -> when (resultCode) { - Activity.RESULT_OK -> Toast.makeText( - context, - R.string.key_successfully_imported, - Toast.LENGTH_SHORT - ).show() + Activity.RESULT_OK -> toast(R.string.key_successfully_imported, Toast.LENGTH_SHORT) } REQUEST_CODE_DELETE_KEYS_DIALOG -> { @@ -136,24 +145,6 @@ class PrivateKeysListFragment : BaseFragment(), View.OnClickListener, } } - override fun onClick(v: View) { - when (v.id) { - R.id.floatActionButtonAddKey -> startActivityForResult( - ImportPrivateKeyActivity.getIntent( - context = requireContext(), - title = getString(R.string.import_private_key), - throwErrorIfDuplicateFoundEnabled = true, - cls = ImportPrivateKeyActivity::class.java, - isSubmittingPubKeysEnabled = false, - accountEntity = account, - isSyncEnabled = true, - skipImportedKeys = true - ), - REQUEST_CODE_START_IMPORT_KEY_ACTIVITY - ) - } - } - override fun onKeySelected(position: Int, pgpKeyDetails: PgpKeyDetails?) { if (tracker?.hasSelection() == true) { return @@ -167,59 +158,74 @@ class PrivateKeysListFragment : BaseFragment(), View.OnClickListener, } } + override fun onAccountInfoRefreshed(accountEntity: AccountEntity?) { + super.onAccountInfoRefreshed(accountEntity) + if (accountEntity?.clientConfiguration?.usesKeyManager() == true) { + binding?.floatActionButtonAddKey?.gone() + } + } + private fun setupPrivateKeysViewModel() { privateKeysViewModel.parseKeysResultLiveData.observe(viewLifecycleOwner, { when (it.status) { Result.Status.LOADING -> { + showProgress() baseActivity.countingIdlingResource.incrementSafely() - emptyView?.visibility = View.GONE - UIUtil.exchangeViewVisibility(true, progressBar, content) } Result.Status.SUCCESS -> { val detailsList = it.data ?: emptyList() + recyclerViewAdapter.swap(detailsList) if (detailsList.isEmpty()) { - recyclerViewAdapter.swap(emptyList()) - UIUtil.exchangeViewVisibility(true, emptyView, content) + showEmptyView() } else { - recyclerViewAdapter.swap(detailsList) - UIUtil.exchangeViewVisibility(false, progressBar, content) + showContent() } baseActivity.countingIdlingResource.decrementSafely() } Result.Status.EXCEPTION -> { - Toast.makeText(context, it.exception?.message, Toast.LENGTH_SHORT).show() + showContent() + toast(it.exception?.message, Toast.LENGTH_SHORT) baseActivity.countingIdlingResource.decrementSafely() } } }) } - private fun initViews(root: View) { - this.progressBar = root.findViewById(R.id.progressBar) - this.content = root.findViewById(R.id.groupContent) - this.emptyView = root.findViewById(R.id.emptyView) - - val recyclerView = root.findViewById(R.id.recyclerViewKeys) - recyclerView.setHasFixedSize(true) - val manager = LinearLayoutManager(context) - val decoration = DividerItemDecoration(recyclerView.context, manager.orientation) - val drawable = - ResourcesCompat.getDrawable(resources, R.drawable.divider_1dp_grey, requireContext().theme) - drawable?.let { decoration.setDrawable(drawable) } - recyclerView.addItemDecoration(decoration) - recyclerView.layoutManager = manager - recyclerView.adapter = recyclerViewAdapter + private fun initViews() { + binding?.recyclerViewKeys?.apply { + setHasFixedSize(true) + val manager = LinearLayoutManager(context) + val decoration = DividerItemDecoration(context, manager.orientation) + val drawable = + ResourcesCompat.getDrawable(resources, R.drawable.divider_1dp_grey, requireContext().theme) + drawable?.let { decoration.setDrawable(drawable) } + addItemDecoration(decoration) + layoutManager = manager + adapter = recyclerViewAdapter + } //setupSelectionTracker(recyclerView) if (recyclerViewAdapter.itemCount > 0) { - progressBar?.visibility = View.GONE + showContent() } - if (root.findViewById(R.id.floatActionButtonAddKey) != null) { - root.findViewById(R.id.floatActionButtonAddKey).setOnClickListener(this) + binding?.floatActionButtonAddKey?.setOnClickListener { + startActivityForResult( + ImportPrivateKeyActivity.getIntent( + context = requireContext(), + title = getString(R.string.import_private_key), + throwErrorIfDuplicateFoundEnabled = true, + cls = ImportPrivateKeyActivity::class.java, + isSubmittingPubKeysEnabled = false, + accountEntity = account, + isSyncEnabled = true, + skipImportedKeys = true + ), + REQUEST_CODE_START_IMPORT_KEY_ACTIVITY + ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/PrivateKeysRecyclerViewAdapter.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/PrivateKeysRecyclerViewAdapter.kt index 5ad00dff69..4aaf4600a1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/PrivateKeysRecyclerViewAdapter.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/PrivateKeysRecyclerViewAdapter.kt @@ -5,7 +5,6 @@ package com.flowcrypt.email.ui.adapter -import android.content.Context import android.text.format.DateFormat import android.view.LayoutInflater import android.view.View @@ -30,11 +29,10 @@ import java.util.Date * E-mail: DenBond7@gmail.com */ class PrivateKeysRecyclerViewAdapter( - context: Context, private val listener: OnKeySelectedListener?, val pgpKeyDetailsList: MutableList = mutableListOf() ) : RecyclerView.Adapter() { - private val dateFormat: java.text.DateFormat = DateFormat.getMediumDateFormat(context) + private var dateFormat: java.text.DateFormat? = null var tracker: SelectionTracker? = null override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -43,6 +41,10 @@ class PrivateKeysRecyclerViewAdapter( } override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { + if (dateFormat == null) { + dateFormat = DateFormat.getMediumDateFormat(viewHolder.itemView.context) + } + val nodeKeyDetails = pgpKeyDetailsList[position] tracker?.isSelected(nodeKeyDetails)?.let { viewHolder.setActivated(it) } val email = nodeKeyDetails.primaryPgpContact.email @@ -54,7 +56,7 @@ class PrivateKeysRecyclerViewAdapter( val timestamp = nodeKeyDetails.created if (timestamp != -1L) { - viewHolder.textViewCreationDate.text = dateFormat.format(Date(timestamp)) + viewHolder.textViewCreationDate.text = dateFormat?.format(Date(timestamp)) } else { viewHolder.textViewCreationDate.text = null } diff --git a/FlowCrypt/src/main/res/layout/fragment_private_keys.xml b/FlowCrypt/src/main/res/layout/fragment_private_keys.xml index ae520509ee..1b560d0fe1 100644 --- a/FlowCrypt/src/main/res/layout/fragment_private_keys.xml +++ b/FlowCrypt/src/main/res/layout/fragment_private_keys.xml @@ -8,7 +8,8 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearLayout" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:animateLayoutChanges="true"> Date: Thu, 29 Jul 2021 17:20:33 +0300 Subject: [PATCH 05/14] Migreated to use view binding in PrivateKeyDetailsFragment. Refactored code.| #1327 --- .../fragment/PrivateKeyDetailsFragment.kt | 177 ++++++++---------- .../layout/fragment_private_key_details.xml | 16 +- 2 files changed, 91 insertions(+), 102 deletions(-) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeyDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeyDetailsFragment.kt index fc43dcfcbf..6c15156e7c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeyDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/PrivateKeyDetailsFragment.kt @@ -14,13 +14,12 @@ import android.os.Bundle import android.provider.DocumentsContract import android.text.TextUtils import android.text.format.DateFormat +import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.widget.Button -import android.widget.EditText -import android.widget.TextView +import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels @@ -29,6 +28,7 @@ import com.flowcrypt.email.Constants import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result import com.flowcrypt.email.database.entity.KeyEntity +import com.flowcrypt.email.databinding.FragmentPrivateKeyDetailsBinding import com.flowcrypt.email.extensions.decrementSafely import com.flowcrypt.email.extensions.gone import com.flowcrypt.email.extensions.incrementSafely @@ -63,14 +63,8 @@ import java.util.* */ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { private val args by navArgs() + private var binding: FragmentPrivateKeyDetailsBinding? = null - private var tVFingerprint: TextView? = null - private var tVDate: TextView? = null - private var tVUsers: TextView? = null - private var tVPassPhraseVerification: TextView? = null - private var eTKeyPassword: EditText? = null - private var btnForgetPassphrase: Button? = null - private var gCheckPassphrase: View? = null private val privateKeysViewModel: PrivateKeysViewModel by viewModels() private val checkPrivateKeysViewModel: CheckPrivateKeysViewModel by viewModels() private val pgpKeyDetailsViewModel: PgpKeyDetailsViewModel by viewModels { @@ -78,11 +72,11 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { } override val progressView: View? - get() = view?.findViewById(R.id.progress) + get() = binding?.progress?.root override val contentView: View? - get() = view?.findViewById(R.id.content) + get() = binding?.content override val statusView: View? - get() = view?.findViewById(R.id.status) + get() = binding?.status?.root override val contentResourceId: Int = R.layout.fragment_private_key_details @@ -115,10 +109,19 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { } } + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentPrivateKeyDetailsBinding.inflate(inflater, container, false) + return binding?.root + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) supportActionBar?.setTitle(R.string.key_details) - initViews(view) + initViews() updateViews() setupPgpKeyDetailsViewModel() setupPrivateKeysViewModel() @@ -159,7 +162,7 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { uri = data.data!!, data = pgpKeyDetailsViewModel.getPgpKeyDetails()!!.publicKey ) - Toast.makeText(context, getString(R.string.saved), Toast.LENGTH_SHORT).show() + toast(R.string.saved, Toast.LENGTH_SHORT) } catch (e: Exception) { e.printStackTrace() var error = if (e.message.isNullOrEmpty()) e.javaClass.simpleName else e.message @@ -192,72 +195,21 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { } } - private fun initViews(view: View) { - tVFingerprint = view.findViewById(R.id.textViewFingerprint) - tVDate = view.findViewById(R.id.textViewDate) - tVUsers = view.findViewById(R.id.textViewUsers) - tVPassPhraseVerification = view.findViewById(R.id.tVPassPhraseVerification) - eTKeyPassword = view.findViewById(R.id.eTKeyPassword) - gCheckPassphrase = view.findViewById(R.id.gCheckPassphrase) - - initButtons(view) - } - - private fun updateViews() { - pgpKeyDetailsViewModel.getPgpKeyDetails()?.let { value -> - UIUtil.setHtmlTextToTextView( - getString( - R.string.template_fingerprint, - GeneralUtil.doSectionsInText(" ", value.fingerprint, 4) - ), tVFingerprint - ) - - tVDate?.text = getString( - R.string.template_date, - DateFormat.getMediumDateFormat(context).format(Date(value.created)) - ) - - tVUsers?.text = getString( - R.string.template_users, - TextUtils.join(", ", value.pgpContacts.map { it.email }) - ) - - val passPhrase = pgpKeyDetailsViewModel.getPassphrase() - val passPhraseType = pgpKeyDetailsViewModel.getPassphraseType() - if (passPhrase == null || passPhrase.isEmpty) { - handlePassphraseNotProvided() - return - } - - if (passPhraseType == KeyEntity.PassphraseType.RAM) { - btnForgetPassphrase?.visible() - } - } - } - - private fun handlePassphraseNotProvided() { - tVPassPhraseVerification?.setTextColor(UIUtil.getColor(requireContext(), R.color.red)) - tVPassPhraseVerification?.text = getString(R.string.pass_phrase_not_provided) - btnForgetPassphrase?.gone() - gCheckPassphrase?.visible() - } - - private fun initButtons(view: View) { - btnForgetPassphrase = view.findViewById(R.id.btnForgetPassphrase) - btnForgetPassphrase?.setOnClickListener { + private fun initViews() { + binding?.btnForgetPassphrase?.setOnClickListener { pgpKeyDetailsViewModel.forgetPassphrase() toast(getString(R.string.passphrase_purged_from_memory)) - eTKeyPassword?.text = null + binding?.eTKeyPassword?.text = null } - view.findViewById(R.id.btnUpdatePassphrase)?.setOnClickListener { - UIUtil.hideSoftInput(requireContext(), eTKeyPassword) - val typedText = eTKeyPassword?.text?.toString() + binding?.btnUpdatePassphrase?.setOnClickListener { + UIUtil.hideSoftInput(requireContext(), binding?.eTKeyPassword) + val typedText = binding?.eTKeyPassword?.text?.toString() if (typedText.isNullOrEmpty()) { - showInfoSnackbar(eTKeyPassword, getString(R.string.passphrase_must_be_non_empty)) + showInfoSnackbar(binding?.eTKeyPassword, getString(R.string.passphrase_must_be_non_empty)) } else { snackBar?.dismiss() - eTKeyPassword?.let { + binding?.eTKeyPassword?.let { val passPhrase = Passphrase.fromPassword(typedText) val pgpKeyDetails = pgpKeyDetailsViewModel.getPgpKeyDetails() ?: return@let checkPrivateKeysViewModel.checkKeys( @@ -270,7 +222,7 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { } } - view.findViewById(R.id.btnShowPubKey)?.setOnClickListener { + binding?.btnShowPubKey?.setOnClickListener { val dialogFragment = InfoDialogFragment.newInstance( dialogTitle = "", dialogMsg = pgpKeyDetailsViewModel.getPgpKeyDetails()!!.publicKey @@ -278,25 +230,60 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { dialogFragment.show(parentFragmentManager, InfoDialogFragment::class.java.simpleName) } - view.findViewById(R.id.btnCopyToClipboard)?.setOnClickListener { - val clipboard = - requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - clipboard.setPrimaryClip( - ClipData.newPlainText( - "pubKey", - pgpKeyDetailsViewModel.getPgpKeyDetails()?.publicKey - ) + binding?.btnCopyToClipboard?.setOnClickListener { + val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager + clipboard?.setPrimaryClip( + ClipData.newPlainText("pubKey", pgpKeyDetailsViewModel.getPgpKeyDetails()?.publicKey) ) - Toast.makeText(context, getString(R.string.copied), Toast.LENGTH_SHORT).show() + toast(R.string.copied, Toast.LENGTH_SHORT) } - view.findViewById(R.id.btnSaveToFile)?.setOnClickListener { + binding?.btnSaveToFile?.setOnClickListener { chooseDest() } - view.findViewById(R.id.btnShowPrKey)?.setOnClickListener { + binding?.btnShowPrKey?.setOnClickListener { toast(getString(R.string.see_backups_to_save_your_private_keys), Toast.LENGTH_SHORT) } } + private fun updateViews() { + pgpKeyDetailsViewModel.getPgpKeyDetails()?.let { value -> + UIUtil.setHtmlTextToTextView( + getString( + R.string.template_fingerprint, + GeneralUtil.doSectionsInText(" ", value.fingerprint, 4) + ), binding?.tVFingerprint + ) + + binding?.tVDate?.text = getString( + R.string.template_date, + DateFormat.getMediumDateFormat(context).format(Date(value.created)) + ) + + binding?.tVUsers?.text = getString( + R.string.template_users, + TextUtils.join(", ", value.pgpContacts.map { it.email }) + ) + + val passPhrase = pgpKeyDetailsViewModel.getPassphrase() + val passPhraseType = pgpKeyDetailsViewModel.getPassphraseType() + if (passPhrase == null || passPhrase.isEmpty) { + handlePassphraseNotProvided() + return + } + + if (passPhraseType == KeyEntity.PassphraseType.RAM) { + binding?.btnForgetPassphrase?.visible() + } + } + } + + private fun handlePassphraseNotProvided() { + binding?.tVPassPhraseVerification?.setTextColor(UIUtil.getColor(requireContext(), R.color.red)) + binding?.tVPassPhraseVerification?.text = getString(R.string.pass_phrase_not_provided) + binding?.btnForgetPassphrase?.gone() + binding?.gCheckPassphrase?.visible() + } + private fun chooseDest() { val intent = Intent(Intent.ACTION_CREATE_DOCUMENT) intent.addCategory(Intent.CATEGORY_OPENABLE) @@ -382,11 +369,11 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { Result.Status.SUCCESS -> { val checkResult = it.data?.firstOrNull() - var verificationMsg: String? + val verificationMsg: String? if (checkResult != null) { if (checkResult.pgpKeyDetails.isPrivate) { if (checkResult.e == null) { - tVPassPhraseVerification?.setTextColor( + binding?.tVPassPhraseVerification?.setTextColor( UIUtil.getColor(requireContext(), R.color.colorPrimaryLight) ) verificationMsg = getString(R.string.stored_pass_phrase_matched) @@ -397,17 +384,17 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { Passphrase.fromPassword(checkResult.passphrase) ) } - btnForgetPassphrase?.visible() - gCheckPassphrase?.gone() + binding?.btnForgetPassphrase?.visible() + binding?.gCheckPassphrase?.gone() } } else { if (pgpKeyDetailsViewModel.getPassphraseType() == KeyEntity.PassphraseType.RAM) { - eTKeyPassword?.requestFocus() + binding?.eTKeyPassword?.requestFocus() toast(R.string.password_is_incorrect) verificationMsg = getString(R.string.pass_phrase_not_provided) } else { verificationMsg = getString(R.string.stored_pass_phrase_mismatch) - tVPassPhraseVerification?.setTextColor( + binding?.tVPassPhraseVerification?.setTextColor( UIUtil.getColor(requireContext(), R.color.red) ) } @@ -415,10 +402,12 @@ class PrivateKeyDetailsFragment : BaseFragment(), ProgressBehaviour { } else verificationMsg = getString(R.string.not_private_key) } else { verificationMsg = getString(R.string.could_not_check_pass_phrase) - tVPassPhraseVerification?.setTextColor(UIUtil.getColor(requireContext(), R.color.red)) + binding?.tVPassPhraseVerification?.setTextColor( + UIUtil.getColor(requireContext(), R.color.red) + ) } - tVPassPhraseVerification?.text = verificationMsg + binding?.tVPassPhraseVerification?.text = verificationMsg baseActivity.countingIdlingResource.decrementSafely() } diff --git a/FlowCrypt/src/main/res/layout/fragment_private_key_details.xml b/FlowCrypt/src/main/res/layout/fragment_private_key_details.xml index 98cbc59724..6120388043 100644 --- a/FlowCrypt/src/main/res/layout/fragment_private_key_details.xml +++ b/FlowCrypt/src/main/res/layout/fragment_private_key_details.xml @@ -27,7 +27,7 @@ android:animateLayoutChanges="true"> + app:layout_constraintTop_toBottomOf="@+id/tVHeader" />