forked from upstream-mirrors/quik
Add block/archive notification actions, and block swipe action
Closes #1575, closes #943
This commit is contained in:
@@ -36,7 +36,7 @@ class QkRealmMigration @Inject constructor(
|
||||
) : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SchemaVersion: Long = 9
|
||||
const val SchemaVersion: Long = 10
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@@ -193,6 +193,36 @@ class QkRealmMigration @Inject constructor(
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 9L) {
|
||||
val migrateNotificationAction = { pref: Int ->
|
||||
when (pref) {
|
||||
1 -> Preferences.NOTIFICATION_ACTION_READ
|
||||
2 -> Preferences.NOTIFICATION_ACTION_REPLY
|
||||
3 -> Preferences.NOTIFICATION_ACTION_CALL
|
||||
4 -> Preferences.NOTIFICATION_ACTION_DELETE
|
||||
else -> pref
|
||||
}
|
||||
}
|
||||
|
||||
val migrateSwipeAction = { pref: Int ->
|
||||
when (pref) {
|
||||
2 -> Preferences.SWIPE_ACTION_DELETE
|
||||
3 -> Preferences.SWIPE_ACTION_CALL
|
||||
4 -> Preferences.SWIPE_ACTION_READ
|
||||
5 -> Preferences.SWIPE_ACTION_UNREAD
|
||||
else -> pref
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.notifAction1.isSet) prefs.notifAction1.set(migrateNotificationAction(prefs.notifAction1.get()))
|
||||
if (prefs.notifAction2.isSet) prefs.notifAction2.set(migrateNotificationAction(prefs.notifAction2.get()))
|
||||
if (prefs.notifAction3.isSet) prefs.notifAction3.set(migrateNotificationAction(prefs.notifAction3.get()))
|
||||
if (prefs.swipeLeft.isSet) prefs.swipeLeft.set(migrateSwipeAction(prefs.swipeLeft.get()))
|
||||
if (prefs.swipeRight.isSet) prefs.swipeRight.set(migrateSwipeAction(prefs.swipeRight.get()))
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
check(version >= newVersion) { "Migration missing from v$oldVersion to v$newVersion" }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.blocking.BlockingClient
|
||||
import com.moez.QKSMS.interactor.MarkBlocked
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import dagger.android.AndroidInjection
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockThreadReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var blockingClient: BlockingClient
|
||||
@Inject lateinit var conversationRepo: ConversationRepository
|
||||
@Inject lateinit var markBlocked: MarkBlocked
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val pendingResult = goAsync()
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
val conversation = conversationRepo.getConversation(threadId)!!
|
||||
val blockingManager = prefs.blockingManager.get()
|
||||
|
||||
blockingClient
|
||||
.block(conversation.recipients.map { it.address })
|
||||
.andThen(markBlocked.buildObservable(MarkBlocked.Params(listOf(threadId), blockingManager, null)))
|
||||
.subscribe { pendingResult.finish() }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.MarkArchived
|
||||
import dagger.android.AndroidInjection
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkArchivedReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var markArchived: MarkArchived
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val pendingResult = goAsync()
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
markArchived.execute(listOf(threadId)) { pendingResult.finish() }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user