Merge pull request #6408 from thundernest/message_list_widget_threads

Fix opening messages in a thread from the message list widget
This commit is contained in:
cketti 2022-10-19 18:30:14 +02:00 committed by GitHub
commit eaa88f3c47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 41 deletions

View file

@ -384,10 +384,6 @@ public class LocalMessage extends MimeMessage {
return mFolder;
}
public String getUri() {
return "k9mail://messages/" + getAccount().getAccountNumber() + "/" + getFolder().getDatabaseId() + "/" + getUid();
}
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException {
if (headerNeedsUpdating) {

View file

@ -421,26 +421,9 @@ open class MessageList :
private fun decodeExtrasToLaunchData(intent: Intent): LaunchData {
val action = intent.action
val data = intent.data
val queryString = intent.getStringExtra(SearchManager.QUERY)
if (action == Intent.ACTION_VIEW && data != null && data.pathSegments.size >= 3) {
val segmentList = data.pathSegments
val accountId = segmentList[0]
for (account in preferences.accounts) {
if (account.accountNumber.toString() == accountId) {
val folderId = segmentList[1].toLong()
val messageUid = segmentList[2]
val messageReference = MessageReference(account.uuid, folderId, messageUid)
return LaunchData(
search = messageReference.toLocalSearch(),
messageReference = messageReference,
messageViewOnly = true
)
}
}
} else if (action == ACTION_SHORTCUT) {
if (action == ACTION_SHORTCUT) {
// Handle shortcut intents
val specialFolder = intent.getStringExtra(EXTRA_SPECIAL_FOLDER)
if (SearchAccount.UNIFIED_INBOX == specialFolder) {
@ -489,7 +472,8 @@ open class MessageList :
return LaunchData(
search = search,
messageReference = messageReference
messageReference = messageReference,
messageViewOnly = intent.getBooleanExtra(EXTRA_MESSAGE_VIEW_ONLY, false)
)
}
} else if (intent.hasExtra(EXTRA_SEARCH)) {
@ -1419,6 +1403,7 @@ open class MessageList :
private const val EXTRA_ACCOUNT = "account_uuid"
private const val EXTRA_MESSAGE_REFERENCE = "message_reference"
private const val EXTRA_MESSAGE_VIEW_ONLY = "message_view_only"
// used for remote search
const val EXTRA_SEARCH_ACCOUNT = "com.fsck.k9.search_account"
@ -1521,21 +1506,38 @@ open class MessageList :
fun actionDisplayMessageIntent(
context: Context,
messageReference: MessageReference,
openInUnifiedInbox: Boolean = false
openInUnifiedInbox: Boolean = false,
messageViewOnly: Boolean = false
): Intent {
return actionDisplayMessageTemplateIntent(context, openInUnifiedInbox, messageViewOnly).apply {
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
}
}
fun actionDisplayMessageTemplateIntent(
context: Context,
openInUnifiedInbox: Boolean,
messageViewOnly: Boolean
): Intent {
return Intent(context, MessageList::class.java).apply {
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
if (openInUnifiedInbox) {
val search = SearchAccount.createUnifiedInboxAccount().relatedSearch
putExtra(EXTRA_SEARCH, ParcelableUtil.marshall(search))
}
putExtra(EXTRA_MESSAGE_VIEW_ONLY, messageViewOnly)
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}
fun actionDisplayMessageTemplateFillIntent(messageReference: MessageReference): Intent {
return Intent().apply {
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
}
}
@JvmStatic
fun launch(context: Context) {
val intent = Intent(context, MessageList::class.java).apply {

View file

@ -1,6 +1,6 @@
package app.k9mail.ui.widget.list
import android.net.Uri
import com.fsck.k9.controller.MessageReference
internal data class MessageListItem(
val displayName: String,
@ -9,8 +9,9 @@ internal data class MessageListItem(
val preview: String,
val isRead: Boolean,
val hasAttachments: Boolean,
val uri: Uri,
val threadCount: Int,
val accountColor: Int,
val messageReference: MessageReference,
val uniqueId: Long,
val sortSubject: String?,

View file

@ -1,7 +1,7 @@
package app.k9mail.ui.widget.list
import android.net.Uri
import com.fsck.k9.Account
import com.fsck.k9.controller.MessageReference
import com.fsck.k9.helper.MessageHelper
import com.fsck.k9.mailstore.MessageDetailsAccessor
import com.fsck.k9.mailstore.MessageMapper
@ -28,7 +28,6 @@ internal class MessageListItemMapper(
} else {
messageHelper.getSenderDisplayName(displayAddress).toString()
}
val uri = Uri.parse("k9mail://messages/${account.accountNumber}/${message.folderId}/${message.messageServerId}")
return MessageListItem(
displayName = displayName,
@ -37,8 +36,9 @@ internal class MessageListItemMapper(
preview = previewText,
isRead = message.isRead,
hasAttachments = message.hasAttachments,
uri = uri,
threadCount = message.threadCount,
accountColor = account.chipColor,
messageReference = MessageReference(account.uuid, message.folderId, message.messageServerId),
uniqueId = uniqueId,
sortSubject = message.subject,
sortMessageDate = message.messageDate,

View file

@ -1,7 +1,6 @@
package app.k9mail.ui.widget.list
import android.content.Context
import android.content.Intent
import android.graphics.Typeface
import android.text.SpannableString
import android.text.style.StyleSpan
@ -11,6 +10,7 @@ import android.widget.RemoteViewsService.RemoteViewsFactory
import androidx.core.content.ContextCompat
import com.fsck.k9.Account.SortType
import com.fsck.k9.K9
import com.fsck.k9.activity.MessageList
import com.fsck.k9.search.LocalSearch
import com.fsck.k9.search.SearchAccount
import org.koin.core.component.KoinComponent
@ -75,6 +75,13 @@ internal class MessageListRemoteViewFactory(private val context: Context) : Remo
remoteView.setTextViewText(R.id.mail_date, item.displayDate)
remoteView.setTextViewText(R.id.mail_preview, item.preview)
if (item.threadCount > 1) {
remoteView.setTextViewText(R.id.thread_count, item.threadCount.toString())
remoteView.setInt(R.id.thread_count, "setVisibility", View.VISIBLE)
} else {
remoteView.setInt(R.id.thread_count, "setVisibility", View.GONE)
}
val textColor = getTextColor(item)
remoteView.setTextColor(R.id.sender, textColor)
remoteView.setTextColor(R.id.mail_subject, textColor)
@ -87,10 +94,7 @@ internal class MessageListRemoteViewFactory(private val context: Context) : Remo
remoteView.setInt(R.id.attachment, "setVisibility", View.GONE)
}
val intent = Intent().apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
data = item.uri
}
val intent = MessageList.actionDisplayMessageTemplateFillIntent(item.messageReference)
remoteView.setOnClickFillInIntent(R.id.mail_list_item, intent)
remoteView.setInt(R.id.chip, "setBackgroundColor", item.accountColor)

View file

@ -45,10 +45,13 @@ open class MessageListWidgetProvider : AppWidgetProvider() {
}
private fun viewActionTemplatePendingIntent(context: Context): PendingIntent {
val intent = Intent(context, MessageList::class.java).apply {
action = Intent.ACTION_VIEW
}
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_MUTABLE)
val intent = MessageList.actionDisplayMessageTemplateIntent(
context,
openInUnifiedInbox = true,
messageViewOnly = true
)
return PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_MUTABLE)
}
private fun viewUnifiedInboxPendingIntent(context: Context): PendingIntent {

View file

@ -39,6 +39,21 @@
android:visibility="gone"
tools:visibility="visible" />
<TextView
android:id="@+id/thread_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/attachment"
android:layout_marginStart="4dp"
android:maxLines="1"
android:paddingRight="4dip"
android:paddingBottom="1dip"
android:paddingLeft="4dip"
android:textSize="16sp"
android:textColor="?android:attr/colorBackground"
android:background="@drawable/thread_count_box_light"
tools:text="3" />
<TextView
android:id="@+id/sender"
android:layout_width="wrap_content"
@ -46,7 +61,7 @@
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="start"
android:layout_toStartOf="@id/attachment"
android:layout_toStartOf="@id/thread_count"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"