2020-04-16 15:44:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Proton Technologies AG
|
2020-08-06 15:55:16 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* This file is part of ProtonMail.
|
2020-08-06 15:55:16 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* ProtonMail is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-08-06 15:55:16 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* ProtonMail is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-08-06 15:55:16 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
package ch.protonmail.android.activities.messageDetails
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Context
|
2021-06-24 13:06:00 +00:00
|
|
|
import android.os.Build
|
2020-04-16 15:44:53 +00:00
|
|
|
import android.text.method.LinkMovementMethod
|
|
|
|
import android.text.util.Linkify
|
2020-08-06 15:55:16 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ScaleGestureDetector
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewConfiguration
|
|
|
|
import android.view.ViewGroup
|
2020-04-16 15:44:53 +00:00
|
|
|
import android.webkit.WebSettings
|
|
|
|
import android.webkit.WebView
|
|
|
|
import android.widget.LinearLayout
|
2021-05-27 08:11:54 +00:00
|
|
|
import android.widget.ProgressBar
|
2020-04-16 15:44:53 +00:00
|
|
|
import android.widget.TextView
|
2021-05-26 16:21:47 +00:00
|
|
|
import androidx.core.view.isVisible
|
2020-04-16 15:44:53 +00:00
|
|
|
import androidx.fragment.app.FragmentActivity
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import ch.protonmail.android.R
|
2021-05-26 16:21:47 +00:00
|
|
|
import ch.protonmail.android.activities.messageDetails.attachments.MessageDetailsAttachmentListAdapter
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.activities.messageDetails.body.MessageBodyScaleListener
|
|
|
|
import ch.protonmail.android.activities.messageDetails.body.MessageBodyTouchListener
|
|
|
|
import ch.protonmail.android.core.Constants
|
2021-05-31 15:26:45 +00:00
|
|
|
import ch.protonmail.android.core.UserManager
|
2021-05-26 16:21:47 +00:00
|
|
|
import ch.protonmail.android.data.local.model.Attachment
|
2021-04-08 16:01:09 +00:00
|
|
|
import ch.protonmail.android.data.local.model.Label
|
2021-03-18 09:46:25 +00:00
|
|
|
import ch.protonmail.android.data.local.model.Message
|
2021-04-29 06:03:25 +00:00
|
|
|
import ch.protonmail.android.details.presentation.MessageDetailsActivity
|
2021-05-13 13:18:53 +00:00
|
|
|
import ch.protonmail.android.ui.view.LabelChipUiModel
|
2020-08-06 15:55:16 +00:00
|
|
|
import ch.protonmail.android.utils.redirectToChrome
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.utils.ui.ExpandableRecyclerAdapter
|
|
|
|
import ch.protonmail.android.views.PMWebViewClient
|
|
|
|
import ch.protonmail.android.views.messageDetails.LoadContentButton
|
2021-06-03 16:00:53 +00:00
|
|
|
import ch.protonmail.android.views.messageDetails.MessageDetailsAttachmentsView
|
2021-03-31 14:57:26 +00:00
|
|
|
import kotlinx.android.synthetic.main.layout_message_details.view.*
|
|
|
|
import kotlinx.android.synthetic.main.layout_message_details_web_view.view.*
|
2021-06-04 16:38:41 +00:00
|
|
|
import org.apache.http.protocol.HTTP
|
2021-05-26 12:54:34 +00:00
|
|
|
import timber.log.Timber
|
2020-08-06 15:55:16 +00:00
|
|
|
import java.util.ArrayList
|
2020-04-16 15:44:53 +00:00
|
|
|
|
|
|
|
private const val TYPE_ITEM = 1001
|
|
|
|
private const val TYPE_HEADER = 1000
|
|
|
|
|
2021-05-26 12:54:34 +00:00
|
|
|
internal class MessageDetailsAdapter(
|
2021-03-31 14:57:26 +00:00
|
|
|
private val context: Context,
|
2021-05-21 14:58:27 +00:00
|
|
|
private var messages: List<Message>,
|
2021-04-08 16:01:09 +00:00
|
|
|
private val messageDetailsRecyclerView: RecyclerView,
|
2021-06-28 15:45:30 +00:00
|
|
|
private val onLoadEmbeddedImagesClicked: (Message) -> Unit,
|
|
|
|
private val onDisplayRemoteContentClicked: (Message) -> Unit,
|
2021-06-04 16:38:41 +00:00
|
|
|
private val userManager: UserManager,
|
2021-06-17 13:05:07 +00:00
|
|
|
private val onLoadMessageBody: (Message) -> Unit,
|
2021-06-15 14:00:11 +00:00
|
|
|
private val onAttachmentDownloadCallback: (Attachment) -> Unit
|
2021-03-31 14:57:26 +00:00
|
|
|
) : ExpandableRecyclerAdapter<MessageDetailsAdapter.MessageDetailsListItem>(context) {
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-07-06 20:39:32 +00:00
|
|
|
private var allLabelsList: List<Label>? = emptyList()
|
2021-05-13 13:18:53 +00:00
|
|
|
private var nonInclusiveLabelsList: List<LabelChipUiModel> = emptyList()
|
2020-04-16 15:44:53 +00:00
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
2021-03-31 14:57:26 +00:00
|
|
|
if (getItemViewType(position) == TYPE_HEADER) {
|
|
|
|
(holder as HeaderViewHolder).bind(
|
2021-05-26 16:21:47 +00:00
|
|
|
visibleItems!![position].message
|
2021-03-31 14:57:26 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
(holder as ItemViewHolder).bind(
|
|
|
|
position,
|
2021-06-04 16:38:41 +00:00
|
|
|
visibleItems!![position]
|
2021-03-31 14:57:26 +00:00
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
2021-03-31 14:57:26 +00:00
|
|
|
return if (viewType == TYPE_HEADER) {
|
|
|
|
HeaderViewHolder(
|
|
|
|
LayoutInflater.from(context).inflate(
|
|
|
|
R.layout.layout_message_details,
|
|
|
|
parent,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else {
|
2021-06-04 16:38:41 +00:00
|
|
|
val messageBodyProgress = ProgressBar(context)
|
|
|
|
val view = LayoutInflater.from(context).inflate(
|
|
|
|
R.layout.layout_message_details_web_view,
|
|
|
|
parent,
|
|
|
|
false
|
2021-03-31 14:57:26 +00:00
|
|
|
)
|
2021-06-04 16:38:41 +00:00
|
|
|
setupMessageWebView(messageBodyProgress, view)
|
|
|
|
ItemViewHolder(view)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
private fun setupMessageWebView(
|
|
|
|
messageBodyProgress: ProgressBar,
|
|
|
|
itemView: View
|
|
|
|
): WebView? {
|
|
|
|
val context = context as MessageDetailsActivity
|
|
|
|
// Looks like some devices are not able to create a WebView in some conditions.
|
|
|
|
// Show Toast and redirect to the proper page.
|
|
|
|
val webView = try {
|
|
|
|
WebView(context)
|
|
|
|
} catch (ignored: Throwable) {
|
|
|
|
(context as FragmentActivity).redirectToChrome()
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
val webViewClient = MessageDetailsPmWebViewClient(userManager, context, itemView)
|
|
|
|
configureWebView(webView, webViewClient)
|
|
|
|
setUpScrollListener(webView, itemView.messageWebViewContainer)
|
|
|
|
|
|
|
|
webView.invalidate()
|
|
|
|
context.registerForContextMenu(webView)
|
|
|
|
itemView.messageWebViewContainer.removeAllViews()
|
|
|
|
itemView.messageWebViewContainer.addView(webView)
|
|
|
|
itemView.messageWebViewContainer.addView(messageBodyProgress)
|
|
|
|
|
|
|
|
return webView
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:44:53 +00:00
|
|
|
class MessageDetailsListItem : ListItem {
|
2021-06-04 16:38:41 +00:00
|
|
|
|
|
|
|
var message: Message
|
|
|
|
var messageFormattedHtml: String? = null
|
|
|
|
var showLoadEmbeddedImagesButton: Boolean = false
|
2020-04-16 15:44:53 +00:00
|
|
|
|
|
|
|
constructor(messageData: Message) : super(TYPE_HEADER) {
|
|
|
|
message = messageData
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
constructor(message: Message, content: String?) : super(TYPE_ITEM) {
|
|
|
|
this.message = message
|
|
|
|
this.messageFormattedHtml = content
|
|
|
|
}
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:57:26 +00:00
|
|
|
inner class HeaderViewHolder(
|
|
|
|
view: View
|
|
|
|
) : ExpandableRecyclerAdapter<MessageDetailsListItem>.HeaderViewHolder(view) {
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
fun bind(message: Message) {
|
2021-05-27 08:11:54 +00:00
|
|
|
val messageDetailsHeaderView = itemView.headerView
|
2021-05-26 16:21:47 +00:00
|
|
|
messageDetailsHeaderView.bind(message, allLabelsList ?: listOf(), nonInclusiveLabelsList)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
open inner class ItemViewHolder(view: View) : ExpandableRecyclerAdapter<MessageDetailsListItem>.ViewHolder(view) {
|
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
fun bind(position: Int, listItem: MessageDetailsListItem) {
|
|
|
|
val message = listItem.message
|
2021-06-23 15:01:55 +00:00
|
|
|
Timber.v("Bind item: ${message.messageId}")
|
2021-05-26 16:21:47 +00:00
|
|
|
val attachmentsView = itemView.attachmentsView
|
|
|
|
attachmentsView.visibility = View.GONE
|
|
|
|
|
2021-05-27 08:11:54 +00:00
|
|
|
val expirationInfoView = itemView.expirationInfoView
|
2021-05-31 15:26:45 +00:00
|
|
|
val displayRemoteContentButton = itemView.displayRemoteContentButton
|
2021-06-24 15:16:39 +00:00
|
|
|
val loadEmbeddedImagesButton = itemView.loadEmbeddedImagesButton
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-04-08 16:01:09 +00:00
|
|
|
expirationInfoView.bind(message.expirationTime)
|
2021-03-31 14:57:26 +00:00
|
|
|
setUpSpamScoreView(message.spamScore, itemView.spamScoreView)
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
Timber.v("Load data for message: ${message.messageId} at position $position")
|
|
|
|
if (listItem.messageFormattedHtml == null) {
|
2021-06-17 13:05:07 +00:00
|
|
|
onLoadMessageBody(message)
|
2021-06-04 16:38:41 +00:00
|
|
|
}
|
2021-05-26 16:21:47 +00:00
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
val webView = itemView.messageWebViewContainer.getChildAt(0) as? WebView ?: return
|
|
|
|
val messageBodyProgress = itemView.messageWebViewContainer.getChildAt(1) as? ProgressBar ?: return
|
|
|
|
webView.loadDataWithBaseURL(
|
|
|
|
Constants.DUMMY_URL_PREFIX,
|
|
|
|
listItem.messageFormattedHtml ?: "",
|
|
|
|
"text/html",
|
|
|
|
HTTP.UTF_8,
|
|
|
|
""
|
|
|
|
)
|
2021-05-26 16:21:47 +00:00
|
|
|
|
2021-06-04 16:38:41 +00:00
|
|
|
listItem.messageFormattedHtml?.let {
|
2021-05-26 16:21:47 +00:00
|
|
|
messageBodyProgress.visibility = View.INVISIBLE
|
2021-06-04 16:38:41 +00:00
|
|
|
}
|
|
|
|
displayAttachmentInfo(listItem.message.attachments, attachmentsView)
|
2021-06-24 15:16:39 +00:00
|
|
|
loadEmbeddedImagesButton.isVisible = listItem.showLoadEmbeddedImagesButton
|
2021-06-04 16:38:41 +00:00
|
|
|
setUpViewDividers()
|
2021-05-26 16:21:47 +00:00
|
|
|
|
2021-06-24 15:16:39 +00:00
|
|
|
setupMessageContentActions(position, loadEmbeddedImagesButton, displayRemoteContentButton)
|
2021-05-26 16:21:47 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 15:26:45 +00:00
|
|
|
private fun setupMessageContentActions(
|
|
|
|
position: Int,
|
|
|
|
loadEmbeddedImagesContainer: LoadContentButton,
|
|
|
|
displayRemoteContentButton: LoadContentButton
|
|
|
|
) {
|
2021-06-25 16:02:44 +00:00
|
|
|
loadEmbeddedImagesContainer.setOnClickListener { view ->
|
|
|
|
view.visibility = View.GONE
|
|
|
|
// Once images were loaded for one message, we automatically load them for all the others, so:
|
|
|
|
// the 'load embedded images' button will be hidden for all messages
|
|
|
|
// the 'formatted html' gets reset so that messages which were already rendered without images
|
|
|
|
// go through the rendering again (through `onLoadMessageBody` callback) and load them
|
|
|
|
allItems.map {
|
|
|
|
it.showLoadEmbeddedImagesButton = false
|
|
|
|
it.messageFormattedHtml = null
|
|
|
|
}
|
2021-06-16 16:07:03 +00:00
|
|
|
val item = visibleItems!![position]
|
2021-06-28 15:45:30 +00:00
|
|
|
onLoadEmbeddedImagesClicked(item.message)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 15:26:45 +00:00
|
|
|
displayRemoteContentButton.setOnClickListener {
|
2021-05-31 10:05:12 +00:00
|
|
|
val item = visibleItems!![position]
|
2021-06-04 16:38:41 +00:00
|
|
|
val webView = itemView.messageWebViewContainer.getChildAt(0) as? WebView
|
2021-03-31 14:57:26 +00:00
|
|
|
// isInit will prevent clicking the button before the WebView is ready.
|
|
|
|
// WebView init can take a bit longer.
|
2021-06-04 16:38:41 +00:00
|
|
|
if (webView != null && webView.contentHeight > 0) {
|
2021-05-27 08:11:54 +00:00
|
|
|
itemView.displayRemoteContentButton.visibility = View.GONE
|
2021-06-04 16:38:41 +00:00
|
|
|
(webView.webViewClient as MessageDetailsPmWebViewClient).allowLoadingRemoteResources()
|
|
|
|
webView.reload()
|
2021-06-28 15:45:30 +00:00
|
|
|
onDisplayRemoteContentClicked(item.message)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-31 14:57:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 16:21:47 +00:00
|
|
|
private fun setUpViewDividers() {
|
2021-07-06 20:39:32 +00:00
|
|
|
val hideHeaderDivider = itemView.attachmentsView.visibility == View.GONE &&
|
|
|
|
itemView.expirationInfoView.visibility == View.VISIBLE
|
2021-06-03 10:13:44 +00:00
|
|
|
itemView.headerDividerView.isVisible = !hideHeaderDivider
|
2021-05-26 12:54:34 +00:00
|
|
|
|
2021-07-06 20:39:32 +00:00
|
|
|
val showAttachmentsDivider = itemView.attachmentsView.visibility == View.VISIBLE &&
|
|
|
|
itemView.expirationInfoView.visibility != View.VISIBLE
|
2021-05-26 16:21:47 +00:00
|
|
|
itemView.attachmentsDividerView.isVisible = showAttachmentsDivider
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 16:29:17 +00:00
|
|
|
fun showMessageDetails(
|
|
|
|
parsedBody: String?,
|
|
|
|
messageId: String,
|
|
|
|
showLoadEmbeddedImagesButton: Boolean,
|
|
|
|
attachments: List<Attachment>
|
|
|
|
) {
|
2021-06-28 12:56:36 +00:00
|
|
|
val item: MessageDetailsListItem? = visibleItems?.firstOrNull {
|
2021-06-04 16:38:41 +00:00
|
|
|
it.ItemType == TYPE_ITEM && it.message.messageId == messageId
|
|
|
|
}
|
2021-06-28 12:56:36 +00:00
|
|
|
item?.messageFormattedHtml = parsedBody
|
|
|
|
item?.showLoadEmbeddedImagesButton = showLoadEmbeddedImagesButton
|
|
|
|
item?.message?.setAttachmentList(attachments)
|
2021-06-04 16:38:41 +00:00
|
|
|
|
2021-06-28 12:56:36 +00:00
|
|
|
visibleItems?.indexOf(item)?.let { changedItemIndex ->
|
|
|
|
notifyItemChanged(changedItemIndex, item)
|
|
|
|
}
|
2021-06-04 16:38:41 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:58:27 +00:00
|
|
|
fun setMessageData(messageData: List<Message>) {
|
2021-06-23 15:01:55 +00:00
|
|
|
Timber.v("setMessageData size: ${messageData.size} ")
|
2021-05-21 14:58:27 +00:00
|
|
|
messages = messageData
|
2020-04-16 15:44:53 +00:00
|
|
|
val items = ArrayList<MessageDetailsListItem>()
|
2021-05-21 14:58:27 +00:00
|
|
|
messages.forEach { message ->
|
|
|
|
items.add(MessageDetailsListItem(message))
|
2021-06-04 16:38:41 +00:00
|
|
|
items.add(MessageDetailsListItem(message, message.decryptedHTML))
|
2021-05-21 14:58:27 +00:00
|
|
|
}
|
2020-04-16 15:44:53 +00:00
|
|
|
setItems(items)
|
|
|
|
}
|
|
|
|
|
2021-05-13 13:18:53 +00:00
|
|
|
fun setAllLabels(labels: List<Label>) {
|
|
|
|
allLabelsList = labels
|
|
|
|
}
|
|
|
|
|
|
|
|
fun setNonInclusiveLabels(labels: List<LabelChipUiModel>) {
|
|
|
|
nonInclusiveLabelsList = labels
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:44:53 +00:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
2021-05-27 08:11:54 +00:00
|
|
|
private fun setUpScrollListener(webView: WebView, directParent: LinearLayout) {
|
2021-03-31 14:57:26 +00:00
|
|
|
val mScaleDetector = ScaleGestureDetector(
|
|
|
|
context,
|
|
|
|
MessageBodyScaleListener(
|
2021-04-08 16:01:09 +00:00
|
|
|
messageDetailsRecyclerView,
|
2021-03-31 14:57:26 +00:00
|
|
|
webView,
|
|
|
|
directParent
|
|
|
|
)
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
|
|
|
|
val scaledTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
2021-04-08 16:01:09 +00:00
|
|
|
val touchListener = MessageBodyTouchListener(messageDetailsRecyclerView, mScaleDetector, scaledTouchSlop)
|
|
|
|
messageDetailsRecyclerView.setOnTouchListener(touchListener)
|
2020-04-16 15:44:53 +00:00
|
|
|
webView.setOnTouchListener(touchListener)
|
|
|
|
}
|
|
|
|
|
2021-07-06 20:39:32 +00:00
|
|
|
private fun displayAttachmentInfo(
|
|
|
|
attachments: List<Attachment>?,
|
|
|
|
attachmentsView: MessageDetailsAttachmentsView
|
|
|
|
) {
|
2021-05-27 08:11:54 +00:00
|
|
|
if (attachments == null) {
|
|
|
|
attachmentsView.visibility = View.GONE
|
|
|
|
return
|
|
|
|
}
|
2021-05-26 16:21:47 +00:00
|
|
|
val attachmentsCount = attachments.size
|
|
|
|
val totalAttachmentSize = attachments.map { it.fileSize }.sum()
|
|
|
|
|
|
|
|
val attachmentsListAdapter = MessageDetailsAttachmentListAdapter(
|
|
|
|
context,
|
2021-06-15 14:00:11 +00:00
|
|
|
onAttachmentDownloadCallback
|
2021-05-26 16:21:47 +00:00
|
|
|
)
|
|
|
|
attachmentsListAdapter.setList(attachments)
|
2021-05-27 08:11:54 +00:00
|
|
|
attachmentsView.bind(attachmentsCount, totalAttachmentSize, attachmentsListAdapter)
|
|
|
|
attachmentsView.isVisible = attachmentsCount > 0
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun configureWebView(webView: WebView, pmWebViewClient: PMWebViewClient) {
|
|
|
|
webView.isScrollbarFadingEnabled = false
|
|
|
|
webView.isVerticalScrollBarEnabled = false
|
|
|
|
webView.isHorizontalScrollBarEnabled = false
|
|
|
|
val webViewParams = LinearLayout.LayoutParams(
|
2021-03-31 14:57:26 +00:00
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
webViewParams.height = LinearLayout.LayoutParams.WRAP_CONTENT
|
|
|
|
webViewParams.setMargins(0, 0, 0, 0)
|
|
|
|
webView.layoutParams = webViewParams
|
|
|
|
webView.webViewClient = pmWebViewClient
|
2021-01-21 16:27:43 +00:00
|
|
|
webView.tag = "messageWebView"
|
2020-04-16 15:44:53 +00:00
|
|
|
val webSettings = webView.settings
|
2021-04-19 14:06:26 +00:00
|
|
|
webSettings.layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
2020-04-16 15:44:53 +00:00
|
|
|
webSettings.useWideViewPort = true
|
|
|
|
webSettings.loadWithOverviewMode = true
|
|
|
|
webSettings.allowFileAccess = false
|
|
|
|
webSettings.displayZoomControls = false
|
|
|
|
webSettings.setGeolocationEnabled(false)
|
|
|
|
webSettings.savePassword = false
|
|
|
|
webSettings.javaScriptEnabled = false
|
|
|
|
webSettings.setSupportZoom(true)
|
|
|
|
webSettings.builtInZoomControls = true
|
|
|
|
webSettings.pluginState = WebSettings.PluginState.OFF
|
|
|
|
webSettings.setNeedInitialFocus(false)
|
|
|
|
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH)
|
|
|
|
webSettings.cacheMode = WebSettings.LOAD_NO_CACHE
|
|
|
|
webSettings.setAppCacheEnabled(false)
|
|
|
|
webSettings.saveFormData = false
|
2021-05-13 13:03:35 +00:00
|
|
|
webView.setOnLongClickListener {
|
|
|
|
val messageBodyWebView = it as WebView
|
|
|
|
val result = messageBodyWebView.hitTestResult
|
|
|
|
if (result.type == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
|
|
|
|
(context as Activity).openContextMenu(messageBodyWebView)
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun setUpSpamScoreView(spamScore: Int, spamScoreView: TextView) {
|
|
|
|
val spamScoreVisibility: Int
|
|
|
|
if (listOf(100, 101, 102).contains(spamScore)) {
|
|
|
|
val spamScoreText = getSpamScoreText(spamScore)
|
|
|
|
spamScoreView.setText(spamScoreText)
|
|
|
|
Linkify.addLinks(spamScoreView, Linkify.ALL)
|
|
|
|
spamScoreView.movementMethod = LinkMovementMethod.getInstance()
|
|
|
|
spamScoreVisibility = View.VISIBLE
|
|
|
|
} else {
|
|
|
|
spamScoreVisibility = View.GONE
|
|
|
|
}
|
|
|
|
spamScoreView.visibility = spamScoreVisibility
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getSpamScoreText(spamScore: Int): Int {
|
|
|
|
return when (spamScore) {
|
|
|
|
100 -> R.string.spam_score_100
|
|
|
|
101 -> R.string.spam_score_101
|
|
|
|
102 -> R.string.spam_score_102
|
2021-05-13 13:03:35 +00:00
|
|
|
else -> throw IllegalArgumentException("Unknown spam score.")
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-31 15:26:45 +00:00
|
|
|
|
2021-06-23 15:01:55 +00:00
|
|
|
private class MessageDetailsPmWebViewClient(
|
|
|
|
private val userManager: UserManager,
|
2021-05-31 15:26:45 +00:00
|
|
|
activity: Activity,
|
|
|
|
private val itemView: View
|
|
|
|
) : PMWebViewClient(userManager, activity, false) {
|
|
|
|
|
|
|
|
override fun onPageFinished(view: WebView, url: String) {
|
2021-06-24 13:06:00 +00:00
|
|
|
// Do not display the 'displayRemoteContent' button when API is lower than 26 as in that case remote
|
|
|
|
// images will be loaded automatically for the reason mentioned below
|
|
|
|
if (amountOfRemoteResourcesBlocked() > 0 && !isAndroidAPILevelLowerThan26()) {
|
2021-05-31 15:26:45 +00:00
|
|
|
itemView.displayRemoteContentButton.isVisible = true
|
|
|
|
}
|
|
|
|
|
2021-06-24 13:06:00 +00:00
|
|
|
// When android API < 26 we automatically show remote images because the `getWebViewClient` method
|
|
|
|
// that we use to access the webView and load them later on was only introduced with API 26
|
|
|
|
val showRemoteImages = isAutoShowRemoteImages() || isAndroidAPILevelLowerThan26()
|
|
|
|
this.blockRemoteResources(!showRemoteImages)
|
2021-05-31 15:26:45 +00:00
|
|
|
|
|
|
|
super.onPageFinished(view, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun isAutoShowRemoteImages(): Boolean {
|
|
|
|
val mailSettings = userManager.getCurrentUserMailSettingsBlocking()
|
|
|
|
return mailSettings?.showImagesFrom?.includesRemote() ?: false
|
|
|
|
}
|
2021-06-24 13:06:00 +00:00
|
|
|
|
2021-06-25 15:23:33 +00:00
|
|
|
private fun isAndroidAPILevelLowerThan26() = Build.VERSION.SDK_INT < Build.VERSION_CODES.O
|
|
|
|
}
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|