From 432f71ee95a43dccd6149ba518bc32dbbe553d7b Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Fri, 12 Jan 2018 15:52:19 -0500 Subject: [PATCH] Sync MMS once sent --- qksms/src/main/java/common/di/AppComponent.kt | 1 + .../src/main/java/common/util/SyncManager.kt | 13 ++++++- qksms/src/main/java/interactor/MarkMmsSent.kt | 34 +++++++++++++++++++ .../presentation/receiver/MmsSentReceiver.kt | 22 +++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 qksms/src/main/java/interactor/MarkMmsSent.kt diff --git a/qksms/src/main/java/common/di/AppComponent.kt b/qksms/src/main/java/common/di/AppComponent.kt index e1778eb0..818dc8c2 100644 --- a/qksms/src/main/java/common/di/AppComponent.kt +++ b/qksms/src/main/java/common/di/AppComponent.kt @@ -52,6 +52,7 @@ interface AppComponent { fun inject(receiver: MarkSeenReceiver) fun inject(receiver: MarkReadReceiver) fun inject(receiver: MmsReceivedReceiver) + fun inject(receiver: MmsSentReceiver) fun inject(receiver: RemoteMessagingReceiver) fun inject(view: AvatarView) diff --git a/qksms/src/main/java/common/util/SyncManager.kt b/qksms/src/main/java/common/util/SyncManager.kt index 87e2e468..7215e26b 100644 --- a/qksms/src/main/java/common/util/SyncManager.kt +++ b/qksms/src/main/java/common/util/SyncManager.kt @@ -20,6 +20,7 @@ package common.util import android.content.Context import android.net.Uri +import android.provider.Telephony import common.util.extensions.asFlowable import common.util.extensions.insertOrUpdate import common.util.extensions.map @@ -106,7 +107,17 @@ class SyncManager @Inject constructor( } fun syncMessage(uri: Uri): Flowable { - val cursor = context.contentResolver.query(uri, null, null, null, null) + val id = uri.lastPathSegment + val isMms = uri.toString().contains("mms") + + // The uri might be something like content://mms/inbox/id + // The box might change though, so we should just use the mms/id uri + val stableUri = when(isMms) { + true -> Uri.withAppendedPath(Telephony.Mms.CONTENT_URI, id) + false -> Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, id) + } + + val cursor = context.contentResolver.query(stableUri, null, null, null, null) val columnsMap = CursorToMessage.MessageColumns(cursor) // Map the cursor to a message diff --git a/qksms/src/main/java/interactor/MarkMmsSent.kt b/qksms/src/main/java/interactor/MarkMmsSent.kt new file mode 100644 index 00000000..bf675839 --- /dev/null +++ b/qksms/src/main/java/interactor/MarkMmsSent.kt @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package interactor + +import android.net.Uri +import common.util.SyncManager +import data.model.Message +import io.reactivex.Flowable +import javax.inject.Inject + +class MarkMmsSent @Inject constructor(private val syncManager: SyncManager) : Interactor() { + + override fun buildObservable(params: Uri): Flowable { + return Flowable.just(params) + .flatMap { uri -> syncManager.syncMessage(uri) } + } + +} \ No newline at end of file diff --git a/qksms/src/main/java/presentation/receiver/MmsSentReceiver.kt b/qksms/src/main/java/presentation/receiver/MmsSentReceiver.kt index 32d9ee80..4a109772 100644 --- a/qksms/src/main/java/presentation/receiver/MmsSentReceiver.kt +++ b/qksms/src/main/java/presentation/receiver/MmsSentReceiver.kt @@ -18,6 +18,26 @@ */ package presentation.receiver +import android.content.Context +import android.content.Intent +import android.net.Uri import com.klinker.android.send_message.MmsSentReceiver +import common.di.appComponent +import interactor.MarkMmsSent +import javax.inject.Inject -class MmsSentReceiver : MmsSentReceiver() \ No newline at end of file +class MmsSentReceiver : MmsSentReceiver() { + + @Inject lateinit var markMmsSent: MarkMmsSent + + override fun onReceive(context: Context, intent: Intent) { + super.onReceive(context, intent) + appComponent.inject(this) + + Uri.parse(intent.getStringExtra("content_uri"))?.let { uri -> + val pendingResult = goAsync() + markMmsSent.execute(uri) { pendingResult.finish() } + } + } + +} \ No newline at end of file