#1124 - Fix notification sound not being saved if set to None

This commit is contained in:
Moez Bhatti
2018-05-28 02:24:30 -04:00
parent e717e6e98a
commit b05e9b0518
5 changed files with 17 additions and 8 deletions
@@ -108,6 +108,11 @@ class NotificationManagerImpl @Inject constructor(
val readPI = PendingIntent.getBroadcast(context, threadId.toInt() + 30000, readIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val readAction = NotificationCompat.Action(R.drawable.ic_check_white_24dp, context.getString(R.string.notification_read), readPI)
// We can't store a null preference, so map it to a null Uri if the pref string is empty
val ringtone = prefs.ringtone(threadId).get()
.takeIf { it.isNotEmpty() }
?.let(Uri::parse)
val notification = NotificationCompat.Builder(context, getChannelIdForNotification(threadId))
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setColor(colors.theme(threadId).theme)
@@ -118,7 +123,7 @@ class NotificationManagerImpl @Inject constructor(
.setContentIntent(contentPI)
.setDeleteIntent(seenPI)
.addAction(readAction)
.setSound(Uri.parse(prefs.ringtone(threadId).get()))
.setSound(ringtone)
.setLights(Color.WHITE, 500, 2000)
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
@@ -96,7 +96,7 @@ class NotificationPrefsActivity : QkThemedActivity(), NotificationPrefsView {
override fun showPreviewModeDialog() = previewModeDialog.show(this)
override fun showRingtonePicker(default: Uri) {
override fun showRingtonePicker(default: Uri?) {
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
@@ -109,7 +109,7 @@ class NotificationPrefsActivity : QkThemedActivity(), NotificationPrefsView {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 123 && resultCode == Activity.RESULT_OK) {
val uri: Uri? = data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
uri?.let { ringtoneSelectedIntent.onNext(uri.toString()) }
ringtoneSelectedIntent.onNext(uri?.toString() ?: "")
}
}
@@ -31,5 +31,5 @@ interface NotificationPrefsView : QkView<NotificationPrefsState> {
val ringtoneSelectedIntent: Observable<String>
fun showPreviewModeDialog()
fun showRingtonePicker(default: Uri)
fun showRingtonePicker(default: Uri?)
}
@@ -22,7 +22,6 @@ import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
import androidx.net.toUri
import com.f2prateek.rx.preferences2.Preference
import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope
@@ -77,8 +76,12 @@ class NotificationPrefsViewModel @Inject constructor(
.subscribe { enabled -> newState { it.copy(vibrationEnabled = enabled) } }
disposables += ringtone.asObservable()
.map { uri -> uri.toUri() }
.map { uri -> RingtoneManager.getRingtone(context, uri).getTitle(context) }
.map { uriString ->
uriString.takeIf { it.isNotEmpty() }
?.let(Uri::parse)
?.let { uri -> RingtoneManager.getRingtone(context, uri) }?.getTitle(context)
?: context.getString(R.string.settings_ringtone_none)
}
.subscribe { title -> newState { it.copy(ringtoneName = title) } }
disposables += prefs.qkreply.asObservable()
@@ -103,7 +106,7 @@ class NotificationPrefsViewModel @Inject constructor(
R.id.vibration -> vibration.set(!vibration.get())
R.id.ringtone -> view.showRingtonePicker(Uri.parse(ringtone.get()))
R.id.ringtone -> view.showRingtonePicker(ringtone.get().takeIf { it.isNotEmpty() }?.let(Uri::parse))
R.id.qkreply -> prefs.qkreply.set(!prefs.qkreply.get())