Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e2f4b926 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Add block/archive notification actions, and block swipe action

Closes #1575, closes #943
parent 853acaa4
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -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" }
    }

+52 −0
Original line number Diff line number Diff line
/*
 * 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() }
    }

}
+40 −0
Original line number Diff line number Diff line
/*
 * 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() }
    }

}
 No newline at end of file
+10 −7
Original line number Diff line number Diff line
@@ -52,10 +52,12 @@ class Preferences @Inject constructor(
        const val NOTIFICATION_PREVIEWS_NONE = 2

        const val NOTIFICATION_ACTION_NONE = 0
        const val NOTIFICATION_ACTION_READ = 1
        const val NOTIFICATION_ACTION_REPLY = 2
        const val NOTIFICATION_ACTION_CALL = 3
        const val NOTIFICATION_ACTION_DELETE = 4
        const val NOTIFICATION_ACTION_ARCHIVE = 1
        const val NOTIFICATION_ACTION_DELETE = 2
        const val NOTIFICATION_ACTION_BLOCK = 3
        const val NOTIFICATION_ACTION_CALL = 4
        const val NOTIFICATION_ACTION_READ = 5
        const val NOTIFICATION_ACTION_REPLY = 6

        const val SEND_DELAY_NONE = 0
        const val SEND_DELAY_SHORT = 1
@@ -65,9 +67,10 @@ class Preferences @Inject constructor(
        const val SWIPE_ACTION_NONE = 0
        const val SWIPE_ACTION_ARCHIVE = 1
        const val SWIPE_ACTION_DELETE = 2
        const val SWIPE_ACTION_CALL = 3
        const val SWIPE_ACTION_READ = 4
        const val SWIPE_ACTION_UNREAD = 5
        const val SWIPE_ACTION_BLOCK = 3
        const val SWIPE_ACTION_CALL = 4
        const val SWIPE_ACTION_READ = 5
        const val SWIPE_ACTION_UNREAD = 6

        const val BLOCKING_MANAGER_QKSMS = 0
        const val BLOCKING_MANAGER_CC = 1
+2 −0
Original line number Diff line number Diff line
@@ -149,6 +149,8 @@
        <receiver
            android:name=".receiver.MmsReceivedReceiver"
            android:taskAffinity="com.klinker.android.messaging.MMS_RECEIVED" />
        <receiver android:name=".receiver.MarkArchivedReceiver" />
        <receiver android:name=".receiver.BlockThreadReceiver" />
        <receiver android:name=".receiver.MarkSeenReceiver" />
        <receiver android:name=".receiver.MarkReadReceiver" />
        <receiver android:name=".receiver.RemoteMessagingReceiver" />
Loading