Vibration pattern
This commit is contained in:
parent
4444c9de9c
commit
4ed73f6f98
6 changed files with 61 additions and 22776 deletions
|
@ -13,7 +13,7 @@ android {
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
|
|
||||||
versionCode 9
|
versionCode 9
|
||||||
versionName "1.2.2"
|
versionName "1.3.0"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.app.PendingIntent
|
||||||
import android.app.TaskStackBuilder
|
import android.app.TaskStackBuilder
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -16,7 +15,6 @@ import androidx.core.content.ContextCompat
|
||||||
import io.heckel.ntfy.R
|
import io.heckel.ntfy.R
|
||||||
import io.heckel.ntfy.data.Notification
|
import io.heckel.ntfy.data.Notification
|
||||||
import io.heckel.ntfy.data.Subscription
|
import io.heckel.ntfy.data.Subscription
|
||||||
import io.heckel.ntfy.util.topicShortUrl
|
|
||||||
import io.heckel.ntfy.ui.DetailActivity
|
import io.heckel.ntfy.ui.DetailActivity
|
||||||
import io.heckel.ntfy.ui.MainActivity
|
import io.heckel.ntfy.ui.MainActivity
|
||||||
import io.heckel.ntfy.util.formatMessage
|
import io.heckel.ntfy.util.formatMessage
|
||||||
|
@ -42,7 +40,7 @@ class NotificationService(val context: Context) {
|
||||||
val message = formatMessage(notification)
|
val message = formatMessage(notification)
|
||||||
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||||
val channelId = toChannelId(notification.priority)
|
val channelId = toChannelId(notification.priority)
|
||||||
var notificationBuilder = NotificationCompat.Builder(context, channelId)
|
val notificationBuilder = NotificationCompat.Builder(context, channelId)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setColor(ContextCompat.getColor(context, R.color.primaryColor))
|
.setColor(ContextCompat.getColor(context, R.color.primaryColor))
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
|
@ -52,20 +50,8 @@ class NotificationService(val context: Context) {
|
||||||
.setContentIntent(pendingIntent) // Click target for notification
|
.setContentIntent(pendingIntent) // Click target for notification
|
||||||
.setAutoCancel(true) // Cancel when notification is clicked
|
.setAutoCancel(true) // Cancel when notification is clicked
|
||||||
|
|
||||||
if (notification.priority == 4) {
|
|
||||||
notificationBuilder = notificationBuilder
|
|
||||||
.setVibrate(longArrayOf(500, 500, 500, 500, 500, 500))
|
|
||||||
.setLights(Color.YELLOW, 3000, 3000)
|
|
||||||
} else if (notification.priority == 5) {
|
|
||||||
notificationBuilder = notificationBuilder
|
|
||||||
.setVibrate(longArrayOf(1000, 500, 1000, 500, 1000, 500))
|
|
||||||
.setLights(Color.RED, 3000, 3000)
|
|
||||||
}
|
|
||||||
|
|
||||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
maybeCreateNotificationChannel(notificationManager, notification.priority)
|
||||||
createNotificationChannel(notificationManager, notification)
|
|
||||||
}
|
|
||||||
notificationManager.notify(notification.notificationId, notificationBuilder.build())
|
notificationManager.notify(notification.notificationId, notificationBuilder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,16 +63,46 @@ class NotificationService(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
fun createNotificationChannels() {
|
||||||
private fun createNotificationChannel(notificationManager: NotificationManager, notification: Notification) {
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
val channel = when (notification.priority) {
|
(1..5).forEach { priority -> maybeCreateNotificationChannel(notificationManager, priority) }
|
||||||
1 -> NotificationChannel(CHANNEL_ID_MIN, context.getString(R.string.channel_notifications_min_name), NotificationManager.IMPORTANCE_MIN)
|
}
|
||||||
2 -> NotificationChannel(CHANNEL_ID_LOW, context.getString(R.string.channel_notifications_low_name), NotificationManager.IMPORTANCE_LOW)
|
|
||||||
4 -> NotificationChannel(CHANNEL_ID_HIGH, context.getString(R.string.channel_notifications_high_name), NotificationManager.IMPORTANCE_HIGH)
|
private fun maybeCreateNotificationChannel(notificationManager: NotificationManager, priority: Int) {
|
||||||
5 -> NotificationChannel(CHANNEL_ID_MAX, context.getString(R.string.channel_notifications_max_name), NotificationManager.IMPORTANCE_MAX)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
else -> NotificationChannel(CHANNEL_ID_DEFAULT, context.getString(R.string.channel_notifications_default_name), NotificationManager.IMPORTANCE_DEFAULT)
|
// Note: To change a notification channel, you must delete the old one and create a new one!
|
||||||
|
|
||||||
|
val pause = 300L
|
||||||
|
val channel = when (priority) {
|
||||||
|
1 -> NotificationChannel(CHANNEL_ID_MIN, context.getString(R.string.channel_notifications_min_name), NotificationManager.IMPORTANCE_MIN)
|
||||||
|
2 -> NotificationChannel(CHANNEL_ID_LOW, context.getString(R.string.channel_notifications_low_name), NotificationManager.IMPORTANCE_LOW)
|
||||||
|
4 -> {
|
||||||
|
val channel = NotificationChannel(CHANNEL_ID_HIGH, context.getString(R.string.channel_notifications_high_name), NotificationManager.IMPORTANCE_HIGH)
|
||||||
|
channel.enableVibration(true)
|
||||||
|
channel.vibrationPattern = longArrayOf(
|
||||||
|
pause, 100, pause, 100, pause, 100,
|
||||||
|
pause, 2000
|
||||||
|
)
|
||||||
|
channel
|
||||||
|
}
|
||||||
|
5 -> {
|
||||||
|
val channel = NotificationChannel(CHANNEL_ID_MAX, context.getString(R.string.channel_notifications_max_name), NotificationManager.IMPORTANCE_MAX)
|
||||||
|
channel.enableLights(true)
|
||||||
|
channel.enableVibration(true)
|
||||||
|
channel.vibrationPattern = longArrayOf(
|
||||||
|
pause, 100, pause, 100, pause, 100,
|
||||||
|
pause, 2000,
|
||||||
|
pause, 100, pause, 100, pause, 100,
|
||||||
|
pause, 2000,
|
||||||
|
pause, 100, pause, 100, pause, 100,
|
||||||
|
pause, 2000
|
||||||
|
)
|
||||||
|
channel
|
||||||
|
}
|
||||||
|
else -> NotificationChannel(CHANNEL_ID_DEFAULT, context.getString(R.string.channel_notifications_default_name), NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
|
}
|
||||||
|
notificationManager.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
notificationManager.createNotificationChannel(channel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toChannelId(priority: Int): String {
|
private fun toChannelId(priority: Int): String {
|
||||||
|
|
|
@ -112,6 +112,9 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
subscriberManager?.refreshService(it)
|
subscriberManager?.refreshService(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create notification channels right away, so we can configure them immediately after installing the app
|
||||||
|
notifier!!.createNotificationChannels()
|
||||||
|
|
||||||
// Background things
|
// Background things
|
||||||
startPeriodicWorker()
|
startPeriodicWorker()
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
12
fastlane/metadata/android/en-US/changelog/9.txt
Normal file
12
fastlane/metadata/android/en-US/changelog/9.txt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
New features:
|
||||||
|
* Support for five priorities (via X-Priority, #24) mapped to Android priorities
|
||||||
|
* Support for notification title (via X-Title, #24)
|
||||||
|
* Support for tags and emojis (via X-Tags, #24)
|
||||||
|
|
||||||
|
Usability improvements:
|
||||||
|
* Support deep links for https://ntfy.sh/.. topics (#20)
|
||||||
|
* Add "clear all notifications" menu item (#21)
|
||||||
|
* Auto-complete for "use another server" feature (#13)
|
||||||
|
* Expanding notifications to read entire text (no ticket)
|
||||||
|
* Color "Permanently delete" buttons red (no ticket)
|
||||||
|
|
|
@ -12,6 +12,6 @@ Example:
|
||||||
$ curl -d "Your backup is done" ntfy.sh/mytopic
|
$ curl -d "Your backup is done" ntfy.sh/mytopic
|
||||||
|
|
||||||
Find more examples and usage instructions here:
|
Find more examples and usage instructions here:
|
||||||
⭐ Website: https://ntfy.sh
|
* Website: https://ntfy.sh
|
||||||
⭐ GitHub (server): https://github.com/binwiederhier/ntfy
|
* GitHub (server): https://github.com/binwiederhier/ntfy
|
||||||
⭐ GitHub (Android app): https://github.com/binwiederhier/ntfy-android
|
* GitHub (Android app): https://github.com/binwiederhier/ntfy-android
|
||||||
|
|
Loading…
Reference in a new issue