Skip to content

Commit

Permalink
Refactored code.| #2137
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed May 5, 2023
1 parent 81e727b commit 40e3b3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ data class AccountEntity constructor(
return clientConfiguration?.hasProperty(configurationProperty) ?: false
}

fun isHandlingAttachmentRestricted(): Boolean {
return hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
}

companion object {
const val TABLE_NAME = "accounts"
const val ACCOUNT_TYPE_GOOGLE = "com.google"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.flowcrypt.email.api.email.gmail.GmailApiHelper
import com.flowcrypt.email.api.email.model.AttachmentInfo
import com.flowcrypt.email.api.email.protocol.ImapProtocolUtil
import com.flowcrypt.email.api.email.protocol.OpenStoreHelper
import com.flowcrypt.email.api.retrofit.response.model.ClientConfiguration
import com.flowcrypt.email.database.FlowCryptRoomDatabase
import com.flowcrypt.email.database.entity.AccountEntity
import com.flowcrypt.email.extensions.android.content.getParcelableExtraViaExt
Expand Down Expand Up @@ -463,9 +462,7 @@ class AttachmentDownloadManagerService : Service() {
listener?.onAttDownloaded(
attInfo = att.copy(name = finalFileName),
uri = uri,
useContentApp = account.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
useContentApp = account.isHandlingAttachmentRestricted()
)
}

Expand All @@ -488,9 +485,7 @@ class AttachmentDownloadManagerService : Service() {
).use { inputStream ->
handleAttachmentInputStream(
inputStream = inputStream,
useContentApp = account.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
useContentApp = account.isHandlingAttachmentRestricted()
)
}
}
Expand All @@ -517,9 +512,7 @@ class AttachmentDownloadManagerService : Service() {
)?.inputStream?.let { inputStream ->
handleAttachmentInputStream(
inputStream = inputStream,
useContentApp = account.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
useContentApp = account.isHandlingAttachmentRestricted()
)
} ?: throw ManualHandledException(context.getString(R.string.attachment_not_found))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import com.flowcrypt.email.api.email.model.IncomingMessageInfo
import com.flowcrypt.email.api.email.model.LocalFolder
import com.flowcrypt.email.api.email.model.ServiceInfo
import com.flowcrypt.email.api.retrofit.response.base.Result
import com.flowcrypt.email.api.retrofit.response.model.ClientConfiguration
import com.flowcrypt.email.api.retrofit.response.model.DecryptErrorMsgBlock
import com.flowcrypt.email.api.retrofit.response.model.DecryptedAttMsgBlock
import com.flowcrypt.email.api.retrofit.response.model.MsgBlock
Expand Down Expand Up @@ -206,9 +205,7 @@ class MessageDetailsFragment : BaseFragment<FragmentMessageDetailsBinding>(), Pr
if (attachmentInfo.uri != null || attachmentInfo.rawData?.isNotEmpty() == true) {
previewAttachment(
attachmentInfo = attachmentInfo,
useContentApp = account?.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
) == true
useContentApp = account?.isHandlingAttachmentRestricted() == true
)
}
}
Expand All @@ -217,9 +214,7 @@ class MessageDetailsFragment : BaseFragment<FragmentMessageDetailsBinding>(), Pr
if (attachmentInfo.uri != null || attachmentInfo.rawData?.isNotEmpty() == true) {
previewAttachment(
attachmentInfo = attachmentInfo,
useContentApp = account?.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
) == true
useContentApp = account?.isHandlingAttachmentRestricted() == true
)
} else {
navController?.navigate(
Expand Down Expand Up @@ -1611,7 +1606,7 @@ class MessageDetailsFragment : BaseFragment<FragmentMessageDetailsBinding>(), Pr
if (attInfo.rawData?.isNotEmpty() == true) {
downloadInlinedAtt(attInfo)
} else {
if (account?.hasClientConfigurationProperty(ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING) == true) {
if (account?.isHandlingAttachmentRestricted() == true) {
navController?.navigate(
MessageDetailsFragmentDirections
.actionMessageDetailsFragmentToDownloadAttachmentDialogFragment(
Expand Down Expand Up @@ -1720,7 +1715,7 @@ class MessageDetailsFragment : BaseFragment<FragmentMessageDetailsBinding>(), Pr
previewAttachment(
attachmentInfo = it,
useContentApp =
account?.hasClientConfigurationProperty(ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING) == true
account?.isHandlingAttachmentRestricted() == true
)
}
}
Expand Down

0 comments on commit 40e3b3b

Please sign in to comment.