forked from upstream-mirrors/quik
Load parts during message sync
This commit is contained in:
@@ -21,17 +21,21 @@ package data.mapper
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.provider.Telephony
|
||||||
import android.provider.Telephony.*
|
import android.provider.Telephony.*
|
||||||
import com.google.android.mms.pdu_alt.PduHeaders
|
import com.google.android.mms.pdu_alt.PduHeaders
|
||||||
import common.util.Keys
|
import common.util.Keys
|
||||||
|
import common.util.extensions.map
|
||||||
import data.model.Message
|
import data.model.Message
|
||||||
|
import data.model.MmsPart
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CursorToMessage @Inject constructor(
|
class CursorToMessage @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val keys: Keys
|
private val keys: Keys,
|
||||||
|
private val cursorToPart: CursorToPart
|
||||||
) : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
|
) : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
|
||||||
|
|
||||||
override fun map(from: Pair<Cursor, MessageColumns>): Message {
|
override fun map(from: Pair<Cursor, MessageColumns>): Message {
|
||||||
@@ -78,7 +82,9 @@ class CursorToMessage @Inject constructor(
|
|||||||
mmsStatus = cursor.getInt(columnsMap.mmsStatus)
|
mmsStatus = cursor.getInt(columnsMap.mmsStatus)
|
||||||
subject = cursor.getString(columnsMap.mmsSubject) ?: ""
|
subject = cursor.getString(columnsMap.mmsSubject) ?: ""
|
||||||
textContentType = ""
|
textContentType = ""
|
||||||
attachmentType = Message.AttachmentType.NOT_LOADED
|
attachmentType = Message.AttachmentType.NOT_LOADED
|
||||||
|
|
||||||
|
parts.addAll(getMmsParts(contentId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +110,12 @@ class CursorToMessage @Inject constructor(
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getMmsParts(contentId: Long): List<MmsPart> {
|
||||||
|
return context.contentResolver.query(CursorToPart.CONTENT_URI, null,
|
||||||
|
"${Telephony.Mms.Part.MSG_ID} = ?", arrayOf(contentId.toString()), null)
|
||||||
|
.map { cursorToPart.map(it) }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val URI = Uri.parse("content://mms-sms/complete-conversations")
|
val URI = Uri.parse("content://mms-sms/complete-conversations")
|
||||||
val PROJECTION = arrayOf(
|
val PROJECTION = arrayOf(
|
||||||
|
|||||||
@@ -142,20 +142,6 @@ class MessageRepository @Inject constructor(
|
|||||||
.findAllSorted("date")
|
.findAllSorted("date")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadParts(id: Long) {
|
|
||||||
Realm.getDefaultInstance()?.use { realm ->
|
|
||||||
realm.where(Message::class.java).equalTo("id", id).findFirst()?.let { message ->
|
|
||||||
realm.executeTransaction {
|
|
||||||
val parts = realm.copyToRealmOrUpdate(context.contentResolver.query(CursorToPart.CONTENT_URI, null,
|
|
||||||
"${Telephony.Mms.Part.MSG_ID} = ?", arrayOf(message.contentId.toString()), null)
|
|
||||||
.map { cursorToPart.map(it) })
|
|
||||||
|
|
||||||
message.parts = RealmList<MmsPart>().apply { addAll(parts) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the list of messages which should be shown in the notification
|
* Retrieves the list of messages which should be shown in the notification
|
||||||
* for a given conversation
|
* for a given conversation
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of QKSMS.
|
|
||||||
*
|
|
||||||
* QKSMS 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.
|
|
||||||
*
|
|
||||||
* QKSMS 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package interactor
|
|
||||||
|
|
||||||
import data.repository.MessageRepository
|
|
||||||
import io.reactivex.Flowable
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class LoadMmsParts @Inject constructor(private val messageRepo: MessageRepository): Interactor<Long, Long>() {
|
|
||||||
|
|
||||||
override fun buildObservable(params: Long): Flowable<Long> {
|
|
||||||
return Flowable.just(params)
|
|
||||||
.doOnNext { messageId -> messageRepo.loadParts(messageId) }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -36,7 +36,6 @@ class ReceiveMms @Inject constructor(
|
|||||||
override fun buildObservable(params: Uri): Flowable<Conversation> {
|
override fun buildObservable(params: Uri): Flowable<Conversation> {
|
||||||
return Flowable.just(params)
|
return Flowable.just(params)
|
||||||
.flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message
|
.flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message
|
||||||
.doOnNext { message -> messageRepo.loadParts(message.id) } // Sync the message parts
|
|
||||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||||
.doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
.doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||||
.doOnNext { conversation -> notificationManager.update(conversation.id) } // Update the notification
|
.doOnNext { conversation -> notificationManager.update(conversation.id) } // Update the notification
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ class SyncMessage @Inject constructor(
|
|||||||
override fun buildObservable(params: Uri): Flowable<Message> {
|
override fun buildObservable(params: Uri): Flowable<Message> {
|
||||||
return Flowable.just(params)
|
return Flowable.just(params)
|
||||||
.flatMap { uri -> syncManager.syncMessage(uri) }
|
.flatMap { uri -> syncManager.syncMessage(uri) }
|
||||||
.doOnNext { message ->
|
|
||||||
if (message.isMms()) {
|
|
||||||
messageRepo.loadParts(message.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,6 @@ import common.util.extensions.setVisible
|
|||||||
import data.model.Contact
|
import data.model.Contact
|
||||||
import data.model.Message
|
import data.model.Message
|
||||||
import data.model.PhoneNumber
|
import data.model.PhoneNumber
|
||||||
import interactor.LoadMmsParts
|
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
@@ -48,8 +47,7 @@ import javax.inject.Inject
|
|||||||
class MessagesAdapter @Inject constructor(
|
class MessagesAdapter @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
private val dateFormatter: DateFormatter,
|
private val dateFormatter: DateFormatter)
|
||||||
private val loadMmsParts: LoadMmsParts)
|
|
||||||
: RealmRecyclerViewAdapter<Message, QkViewHolder>(null, true) {
|
: RealmRecyclerViewAdapter<Message, QkViewHolder>(null, true) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -102,11 +100,6 @@ class MessagesAdapter @Inject constructor(
|
|||||||
return QkViewHolder(view)
|
return QkViewHolder(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
|
||||||
super.onAttachedToRecyclerView(recyclerView)
|
|
||||||
disposables += loadMmsParts
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||||
super.onDetachedFromRecyclerView(recyclerView)
|
super.onDetachedFromRecyclerView(recyclerView)
|
||||||
disposables.clear()
|
disposables.clear()
|
||||||
@@ -138,12 +131,6 @@ class MessagesAdapter @Inject constructor(
|
|||||||
|
|
||||||
private fun bindMmsPreview(view: View, position: Int) {
|
private fun bindMmsPreview(view: View, position: Int) {
|
||||||
val message = getItem(position)!!
|
val message = getItem(position)!!
|
||||||
|
|
||||||
// If it's an MMS and the parts haven't been loaded, kick off a load
|
|
||||||
if (message.isMms() && message.parts.isEmpty()) {
|
|
||||||
loadMmsParts.execute(message.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
view.mmsPreview.parts = message.parts
|
view.mmsPreview.parts = message.parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user