Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Delete action for notification #1275

Merged
merged 1 commit into from Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,41 @@
/*
* 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 com.moez.QKSMS.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.moez.QKSMS.interactor.DeleteMessages
import dagger.android.AndroidInjection
import javax.inject.Inject

class DeleteMessagesReceiver : BroadcastReceiver() {

@Inject lateinit var deleteMessages: DeleteMessages

override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)

val pendingResult = goAsync()
val threadId = intent.getLongExtra("threadId", 0)
val messageIds = intent.getLongArrayExtra("messageIds")
deleteMessages.execute(DeleteMessages.Params(messageIds.toList(), threadId)) { pendingResult.finish() }
}

}
Expand Up @@ -18,6 +18,7 @@
*/
package com.moez.QKSMS.interactor

import com.moez.QKSMS.manager.NotificationManager
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.repository.MessageRepository
import io.reactivex.Flowable
Expand All @@ -26,6 +27,7 @@ import javax.inject.Inject
class DeleteMessages @Inject constructor(
private val conversationRepo: ConversationRepository,
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager,
private val updateBadge: UpdateBadge
) : Interactor<DeleteMessages.Params>() {

Expand All @@ -35,6 +37,7 @@ class DeleteMessages @Inject constructor(
return Flowable.just(params.messageIds.toLongArray())
.doOnNext { messageIds -> messageRepo.deleteMessages(*messageIds) } // Delete the messages
.doOnNext { params.threadId?.let { conversationRepo.updateConversations(it) } } // Update the conversation
.doOnNext { params.threadId?.let { notificationManager.update(it) } }
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
}

Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/AndroidManifest.xml
Expand Up @@ -104,6 +104,7 @@
<action android:name="android.provider.action.DEFAULT_SMS_PACKAGE_CHANGED" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.DeleteMessagesReceiver" />
<receiver
android:name=".receiver.SmsReceiver"
android:permission="android.permission.BROADCAST_SMS">
Expand Down
Expand Up @@ -38,8 +38,10 @@ import com.moez.QKSMS.common.util.extensions.dpToPx
import com.moez.QKSMS.extensions.isImage
import com.moez.QKSMS.feature.compose.ComposeActivity
import com.moez.QKSMS.feature.qkreply.QkReplyActivity
import com.moez.QKSMS.interactor.DeleteMessages
import com.moez.QKSMS.manager.PermissionManager
import com.moez.QKSMS.mapper.CursorToPartImpl
import com.moez.QKSMS.receiver.DeleteMessagesReceiver
import com.moez.QKSMS.receiver.MarkReadReceiver
import com.moez.QKSMS.receiver.MarkSeenReceiver
import com.moez.QKSMS.receiver.RemoteMessagingReceiver
Expand Down Expand Up @@ -230,6 +232,14 @@ class NotificationManagerImpl @Inject constructor(
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_CALL).build()
}

Preferences.NOTIFICATION_ACTION_DELETE -> {
val messageIds = messages.map { it.id }.toLongArray()
val intent = Intent(context, DeleteMessagesReceiver::class.java).putExtra("threadId", threadId).putExtra("messageIds", messageIds)
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 60000, intent, PendingIntent.FLAG_UPDATE_CURRENT)
NotificationCompat.Action.Builder(R.drawable.ic_delete_white_24dp, actionLabels[action], pi)
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_DELETE).build()
}

else -> null
}
}
Expand Down
Expand Up @@ -22,6 +22,7 @@ import com.moez.QKSMS.feature.widget.WidgetProvider
import com.moez.QKSMS.injection.scope.ActivityScope
import com.moez.QKSMS.receiver.BootReceiver
import com.moez.QKSMS.receiver.DefaultSmsChangedReceiver
import com.moez.QKSMS.receiver.DeleteMessagesReceiver
import com.moez.QKSMS.receiver.MarkReadReceiver
import com.moez.QKSMS.receiver.MarkSeenReceiver
import com.moez.QKSMS.receiver.MmsReceivedReceiver
Expand Down Expand Up @@ -50,6 +51,10 @@ abstract class BroadcastReceiverBuilderModule {
@ContributesAndroidInjector()
abstract fun bindDefaultSmsChangedReceiver(): DefaultSmsChangedReceiver

@ActivityScope
@ContributesAndroidInjector()
abstract fun bindDeleteMessagesReceiver(): DeleteMessagesReceiver

@ActivityScope
@ContributesAndroidInjector()
abstract fun bindMarkReadReceiver(): MarkReadReceiver
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ar/strings.xml
Expand Up @@ -255,6 +255,7 @@
<item>علّمها مقروءة</item>
<item>الرد</item>
<item>اتصال</item>
<item>حذف</item>
</string-array>
<string name="button_cancel">إلغاء</string>
<string name="button_delete">حذف</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-bn/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">বাতিল করুন</string>
<string name="button_delete">মুছে ফেলুন</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-cs/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Přečteno</item>
<item>Odpovědět</item>
<item>Volat</item>
<item>Smazat</item>
</string-array>
<string name="button_cancel">Zrušit</string>
<string name="button_delete">Odstranit</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-da/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Markér som læst</item>
<item>Besvar</item>
<item>Ring op</item>
<item>Slet</item>
</string-array>
<string name="button_cancel">Annullér</string>
<string name="button_delete">Slet</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-de/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Als gelesen markieren</item>
<item>Antworten</item>
<item>Anrufen</item>
<item>Löschen</item>
</string-array>
<string name="button_cancel">Abbrechen</string>
<string name="button_delete">Löschen</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-es/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Eliminar</item>
</string-array>
<string name="button_cancel">Cancelar</string>
<string name="button_delete">Eliminar</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-fa/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">کنسل</string>
<string name="button_delete">حذف</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-fi/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Merkitse luetuksi</item>
<item>Vastaa</item>
<item>Soita</item>
<item>Poista</item>
</string-array>
<string name="button_cancel">Peruuta</string>
<string name="button_delete">Poista</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-fr/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Marquer comme lu</item>
<item>Répondre</item>
<item>Appeler</item>
<item>Supprimer</item>
</string-array>
<string name="button_cancel">Annuler</string>
<string name="button_delete">Supprimer</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-hi/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-hr/strings.xml
Expand Up @@ -251,6 +251,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Odustani</string>
<string name="button_delete">Izbriši</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-hu/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-in/strings.xml
Expand Up @@ -249,6 +249,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Batal</string>
<string name="button_delete">Hapus</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-it/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Segna come letto</item>
<item>Rispondi</item>
<item>Chiama</item>
<item>Elimina</item>
</string-array>
<string name="button_cancel">Annulla</string>
<string name="button_delete">Elimina</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-iw/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ja/strings.xml
Expand Up @@ -249,6 +249,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">キャンセル</string>
<string name="button_delete">削除</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ko/strings.xml
Expand Up @@ -249,6 +249,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-lt/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Atšaukti</string>
<string name="button_delete">Ištrinti</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ne/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-nl/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Markeren als gelezen</item>
<item>Beantwoorden</item>
<item>Bellen</item>
<item>Verwijderen</item>
</string-array>
<string name="button_cancel">Annuleren</string>
<string name="button_delete">Verwijderen</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-no/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-pl/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Oznacz jako przeczytane</item>
<item>Odpowiedz</item>
<item>Zadzwoń</item>
<item>Usuń</item>
</string-array>
<string name="button_cancel">Anuluj</string>
<string name="button_delete">Usuń</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-pt-rBR/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Marcar como lida</item>
<item>Responder</item>
<item>Ligar</item>
<item>Apagar</item>
</string-array>
<string name="button_cancel">Cancelar</string>
<string name="button_delete">Apagar</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-pt/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Marcar como lida</item>
<item>Responder</item>
<item>Ligar</item>
<item>Apagar</item>
</string-array>
<string name="button_cancel">Cancelar</string>
<string name="button_delete">Apagar</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ro/strings.xml
Expand Up @@ -251,6 +251,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ru/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Отметить непрочитанным</item>
<item>Ответить</item>
<item>Позвонить</item>
<item>Удалить</item>
</string-array>
<string name="button_cancel">Отмена</string>
<string name="button_delete">Удалить</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-sk/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-sr/strings.xml
Expand Up @@ -251,6 +251,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-sv/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Svara</item>
<item>Ring</item>
<item>Radera</item>
</string-array>
<string name="button_cancel">Avbryt</string>
<string name="button_delete">Radera</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-th/strings.xml
Expand Up @@ -249,6 +249,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">ยกเลิก</string>
<string name="button_delete">ลบ</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-tl/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-tr/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Okundu olarak işaretle</item>
<item>Yanıtla</item>
<item>Ara</item>
<item>Sil</item>
</string-array>
<string name="button_cancel">İptal</string>
<string name="button_delete">Sil</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-uk/strings.xml
Expand Up @@ -252,6 +252,7 @@
<item>Позначити як прочитане</item>
<item>Відповісти</item>
<item>Зателефонувати</item>
<item>Видалити</item>
</string-array>
<string name="button_cancel">Скасувати</string>
<string name="button_delete">Видалити</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-ur/strings.xml
Expand Up @@ -250,6 +250,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values-vi/strings.xml
Expand Up @@ -249,6 +249,7 @@
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_cancel">Hủy</string>
<string name="button_delete">Xóa</string>
Expand Down