Added option to disable notification sounds (ref #6).

This commit is contained in:
Felix Ableitner 2015-06-23 22:41:40 +02:00
parent c4db86c5af
commit 71791c252f
4 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,8 @@
<resources translatable="false">
<string name="default_scan_interval">15</string>
<bool name="default_notification_sounds">true</bool>
<string name="default_max_connections">1000000</string>

View File

@ -66,6 +66,9 @@
<!-- Preference title -->
<string name="scan_interval_seconds">Scan Interval (seconds)</string>
<!-- Preference title -->
<string name="notification_sounds">Notification Sounds</string>
<!-- Preference title (debug only)-->
<string name="max_connections">Maximum Number of Connections</string>

View File

@ -13,6 +13,11 @@
android:inputType="number"
android:numeric="integer" />
<CheckBoxPreference
android:title="@string/notification_sounds"
android:key="notification_sounds"
android:defaultValue="@bool/default_notification_sounds" />
<EditTextPreference
android:title="@string/max_connections"
android:key="max_connections"

View File

@ -2,12 +2,13 @@ package com.nutomic.ensichat.util
import android.app.{Notification, NotificationManager, PendingIntent}
import android.content.{Context, Intent}
import android.preference.PreferenceManager
import android.support.v4.app.NotificationCompat
import com.nutomic.ensichat.R
import com.nutomic.ensichat.activities.MainActivity
import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener
import com.nutomic.ensichat.protocol.{Message, Crypto}
import com.nutomic.ensichat.protocol.body.Text
import com.nutomic.ensichat.protocol.{Crypto, Message}
/**
* Displays notifications for new messages.
@ -26,14 +27,27 @@ class NotificationHandler(context: Context) extends OnMessageReceivedListener {
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getString(R.string.notification_message))
.setContentText(text.text)
.setDefaults(Notification.DEFAULT_ALL)
.setDefaults(defaults())
.setContentIntent(pi)
.setAutoCancel(true)
.build()
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE)
.asInstanceOf[NotificationManager]
nm.notify(notificationIdNewMessage, notification)
case _ =>
}
/**
* Returns the default notification options that should be used.
*/
def defaults(): Int = {
val sp = PreferenceManager.getDefaultSharedPreferences(context)
val defaultSounds = context.getResources.getBoolean(R.bool.default_notification_sounds)
if (sp.getBoolean("notification_sounds", defaultSounds))
Notification.DEFAULT_ALL
else
Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS
}
}