forked from upstream-mirrors/quik
Allow per-contact notification settings for pre-oreo
This commit is contained in:
@@ -76,7 +76,7 @@ class NotificationManager @Inject constructor(
|
||||
*/
|
||||
fun update(threadId: Long) {
|
||||
// If notifications are disabled, don't do anything
|
||||
if (!prefs.notifications.get()) {
|
||||
if (!prefs.notifications(threadId).get()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ class NotificationManager @Inject constructor(
|
||||
.setDeleteIntent(seenPI)
|
||||
.addAction(readAction)
|
||||
.setStyle(style)
|
||||
.setSound(Uri.parse(prefs.ringtone.get()))
|
||||
.setSound(Uri.parse(prefs.ringtone(threadId).get()))
|
||||
.setLights(Color.WHITE, 500, 2000)
|
||||
.setVibrate(if (prefs.vibration.get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
notification.addAction(getReplyAction(conversation.recipients[0]?.address.orEmpty(), threadId))
|
||||
@@ -154,9 +154,9 @@ class NotificationManager @Inject constructor(
|
||||
.setSmallIcon(R.drawable.ic_notification_failed)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(contentPI)
|
||||
.setSound(Uri.parse(prefs.ringtone.get()))
|
||||
.setSound(Uri.parse(prefs.ringtone(threadId).get()))
|
||||
.setLights(Color.WHITE, 500, 2000)
|
||||
.setVibrate(if (prefs.vibration.get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
|
||||
notificationManager.notify(threadId.toInt() + 50000, notification.build())
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
package common.util
|
||||
|
||||
import android.provider.Settings
|
||||
import com.f2prateek.rx.preferences2.Preference
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class Preferences @Inject constructor(rxPrefs: RxSharedPreferences) {
|
||||
class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences) {
|
||||
|
||||
companion object {
|
||||
const val NIGHT_MODE_OFF = 0
|
||||
@@ -39,12 +40,35 @@ class Preferences @Inject constructor(rxPrefs: RxSharedPreferences) {
|
||||
val nightStart = rxPrefs.getString("nightStart", "6:00 PM")
|
||||
val nightEnd = rxPrefs.getString("nightEnd", "6:00 AM")
|
||||
val autoEmoji = rxPrefs.getBoolean("autoEmoji", true)
|
||||
val notifications = rxPrefs.getBoolean("notifications", true)
|
||||
val vibration = rxPrefs.getBoolean("vibration", true)
|
||||
val ringtone = rxPrefs.getString("ringtone", Settings.System.DEFAULT_NOTIFICATION_URI.toString())
|
||||
val delivery = rxPrefs.getBoolean("delivery", false)
|
||||
val unicode = rxPrefs.getBoolean("unicode", false)
|
||||
val mms = rxPrefs.getBoolean("mms", true)
|
||||
val mmsSize = rxPrefs.getInteger("mmsSize", 100)
|
||||
|
||||
fun notifications(threadId: Long = 0): Preference<Boolean> {
|
||||
val default = rxPrefs.getBoolean("notifications", true)
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getBoolean("notifications_$threadId", default.get())
|
||||
}
|
||||
}
|
||||
|
||||
fun vibration(threadId: Long = 0): Preference<Boolean> {
|
||||
val default = rxPrefs.getBoolean("vibration", true)
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getBoolean("vibration$threadId", default.get())
|
||||
}
|
||||
}
|
||||
|
||||
fun ringtone(threadId: Long = 0): Preference<String> {
|
||||
val default = rxPrefs.getString("ringtone", Settings.System.DEFAULT_NOTIFICATION_URI.toString())
|
||||
|
||||
return when (threadId) {
|
||||
0L -> default
|
||||
else -> rxPrefs.getString("ringtone_$threadId", default.get())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package presentation.feature.conversationinfo
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
@@ -26,7 +25,6 @@ import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.extensions.setVisible
|
||||
import kotlinx.android.synthetic.main.conversation_info_activity.*
|
||||
import presentation.common.base.QkThemedActivity
|
||||
import javax.inject.Inject
|
||||
@@ -55,9 +53,6 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
|
||||
val supportsNotificationChannels = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
notifications.setVisible(supportsNotificationChannels)
|
||||
|
||||
recipients.layoutManager = LinearLayoutManager(this)
|
||||
recipients.adapter = recipientAdapter
|
||||
}
|
||||
|
||||
+18
-7
@@ -21,6 +21,7 @@ package presentation.feature.notificationprefs
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.f2prateek.rx.preferences2.Preference
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
@@ -32,19 +33,29 @@ import presentation.common.base.QkViewModel
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class NotificationPrefsViewModel(private val intent: Intent) : QkViewModel<NotificationPrefsView, NotificationPrefsState>(NotificationPrefsState()) {
|
||||
class NotificationPrefsViewModel(intent: Intent) : QkViewModel<NotificationPrefsView, NotificationPrefsState>(NotificationPrefsState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
private val threadId = intent.extras?.getLong("threadId") ?: 0L
|
||||
|
||||
private val notifications: Preference<Boolean>
|
||||
private val vibration: Preference<Boolean>
|
||||
private val ringtone: Preference<String>
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
disposables += prefs.notifications.asObservable()
|
||||
notifications = prefs.notifications(threadId)
|
||||
vibration = prefs.vibration(threadId)
|
||||
ringtone = prefs.ringtone(threadId)
|
||||
|
||||
disposables += notifications.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.vibration.asObservable()
|
||||
disposables += vibration.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(vibrationEnabled = enabled) } }
|
||||
}
|
||||
|
||||
@@ -57,16 +68,16 @@ class NotificationPrefsViewModel(private val intent: Intent) : QkViewModel<Notif
|
||||
Timber.v("Preference click: ${context.resources.getResourceName(it.id)}")
|
||||
|
||||
when (it.id) {
|
||||
R.id.notifications -> prefs.notifications.set(!prefs.notifications.get())
|
||||
R.id.notifications -> notifications.set(!notifications.get())
|
||||
|
||||
R.id.vibration -> prefs.vibration.set(!prefs.vibration.get())
|
||||
R.id.vibration -> vibration.set(!vibration.get())
|
||||
|
||||
R.id.ringtone -> view.showRingtonePicker(Uri.parse(prefs.ringtone.get()))
|
||||
R.id.ringtone -> view.showRingtonePicker(Uri.parse(ringtone.get()))
|
||||
}
|
||||
}
|
||||
|
||||
view.ringtoneSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { ringtone -> prefs.ringtone.set(ringtone) }
|
||||
.subscribe { ringtone -> this.ringtone.set(ringtone) }
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ data class SettingsState(
|
||||
val nightEnd: String = "",
|
||||
val autoEmojiEnabled: Boolean = true,
|
||||
val notificationsEnabled: Boolean = true,
|
||||
val vibrationEnabled: Boolean = true,
|
||||
val deliveryEnabled: Boolean = false,
|
||||
val splitSmsEnabled: Boolean = false,
|
||||
val stripUnicodeEnabled: Boolean = false,
|
||||
|
||||
@@ -70,12 +70,9 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
disposables += prefs.autoEmoji.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(autoEmojiEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.notifications.asObservable()
|
||||
disposables += prefs.notifications().asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.vibration.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(vibrationEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.delivery.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(deliveryEnabled = enabled) } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user