Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Grouping isn't going to stay for long on Oreo
Browse files Browse the repository at this point in the history
  • Loading branch information
quarck committed Sep 20, 2018
1 parent 7ef3754 commit 73c52f8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/com/github/quarck/calnotify/Settings.kt
Expand Up @@ -20,6 +20,7 @@
package com.github.quarck.calnotify

import android.content.Context
import android.os.Build
import com.github.quarck.calnotify.prefs.PreferenceUtils
import com.github.quarck.calnotify.utils.PersistentStorageBase
import com.github.quarck.calnotify.utils.toIntOrNull
Expand Down Expand Up @@ -263,6 +264,9 @@ class Settings(context: Context) : PersistentStorageBase(context) {
get() = getBoolean(GROUP_NOTIFICAITONS, true)
set(value) = setBoolean(GROUP_NOTIFICAITONS, value)

val allowMuteAndAlarm: Boolean
get() = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) || !postGroupNotification

var showSnoozeButton: Boolean
get() = getBoolean(SHOW_SNOOZE_BUTTON, false)
set(value) = setBoolean(SHOW_SNOOZE_BUTTON, value)
Expand All @@ -272,7 +276,7 @@ class Settings(context: Context) : PersistentStorageBase(context) {
notificationSwipeBehavior = notificationSwipeBehavior,
groupNotificationSwipeBehavior = groupNotificationSwipeBehavior,
postGroupNotification = postGroupNotification,
enableNotificationMute = remindersEnabled,
enableNotificationMute = remindersEnabled && allowMuteAndAlarm,
appendEmptyAction = notificationAddEmptyAction,
useAlarmStream = notificationUseAlarmStream,
forwardReminersToPebble = forwardReminersToPebble,
Expand Down Expand Up @@ -338,7 +342,7 @@ class Settings(context: Context) : PersistentStorageBase(context) {

private const val NOTIFICATION_SWIPE_BEHAVIOR = "notification_swipe_behavior"
private const val GROUP_NOTIFICATION_SWIPE_BEHAVIOR = "group_notification_swipe_behavior"
private const val GROUP_NOTIFICAITONS = "group_notifications"
private const val GROUP_NOTIFICAITONS = "group_notifications_001"

private const val SHOW_SNOOZE_BUTTON = "show_snooze_btn_0001"

Expand Down
Expand Up @@ -107,7 +107,8 @@ class EventNotificationManager : EventNotificationManagerInterface {
snoozePresetsNotFiltered = settings.snoozePresets,
soundState = NotificationChannelManager.SoundState.Silent,
isReminder = false,
snooze0Time = settings.firstNonNegativeSnoozeTime
snooze0Time = settings.firstNonNegativeSnoozeTime,
settings = settings
)

context.notificationManager.cancel(Consts.NOTIFICATION_ID_REMINDER)
Expand Down Expand Up @@ -447,7 +448,7 @@ class EventNotificationManager : EventNotificationManagerInterface {
else
soundState

val channel = NotificationChannelManager.createNotificationChannel(context, activeSoundState, isReminder)
val channel = NotificationChannelManager.createNotificationChannel(context, activeSoundState, isReminder, settings)

val notificationStyle = NotificationCompat.InboxStyle()

Expand Down Expand Up @@ -637,7 +638,8 @@ class EventNotificationManager : EventNotificationManagerInterface {
isReminder = ntf.isReminder,
alertOnlyOnce = ntf.alertOnlyOnce,
soundState = ntf.soundState,
snooze0Time = snooze0time
snooze0Time = snooze0time,
settings = settings
)

}
Expand Down Expand Up @@ -693,7 +695,7 @@ class EventNotificationManager : EventNotificationManagerInterface {

val channel = NotificationChannelManager.createNotificationChannel(ctx,
NotificationChannelManager.SoundState.Silent,
false)
false, settings)

val notificationBehavior = settings.groupNotificationSwipeBehavior

Expand Down Expand Up @@ -765,7 +767,8 @@ class EventNotificationManager : EventNotificationManagerInterface {
isReminder: Boolean,
alertOnlyOnce: Boolean,
soundState: NotificationChannelManager.SoundState,
snooze0Time: Long
snooze0Time: Long,
settings: Settings
) {
val notificationManager = ctx.notificationManager

Expand Down Expand Up @@ -830,7 +833,8 @@ class EventNotificationManager : EventNotificationManagerInterface {
val channel = NotificationChannelManager.createNotificationChannel(
ctx,
soundState = activeSoundState,
isReminder = isReminder
isReminder = isReminder,
settings = settings
)

val notificationBehavior = notificationSettings.notificationSwipeBehavior
Expand Down Expand Up @@ -886,7 +890,7 @@ class EventNotificationManager : EventNotificationManagerInterface {

val extender = NotificationCompat.WearableExtender()

if ((notificationSettings.enableNotificationMute || event.isMuted) && !event.isTask) {
if ((notificationSettings.enableNotificationMute || event.isMuted) && !event.isTask && settings.allowMuteAndAlarm) {
// build and append

val muteTogglePendingIntent =
Expand Down
Expand Up @@ -31,6 +31,7 @@ import android.os.Build
import android.support.v4.app.NotificationCompat
import com.github.quarck.calnotify.Consts
import com.github.quarck.calnotify.R
import com.github.quarck.calnotify.Settings
import com.github.quarck.calnotify.logs.DevLog
import com.github.quarck.calnotify.utils.notificationManager

Expand Down Expand Up @@ -408,12 +409,21 @@ object NotificationChannelManager {
fun createNotificationChannel(
context: Context,
soundState: SoundState,
isReminder: Boolean
isReminder: Boolean,
settings: Settings

): NotificationChannelAttributes {

val allowedSoundState =
if (settings.allowMuteAndAlarm)
soundState
else
SoundState.Normal

return if (!isReminder)
createNotificationChannelForSoundState(context, soundState)
createNotificationChannelForSoundState(context, allowedSoundState)
else
createReminderNotificationChannelForSoundState(context, soundState)
createReminderNotificationChannelForSoundState(context, allowedSoundState)
}

// fun createNotificationChannelForRealAlarms(
Expand Down Expand Up @@ -463,7 +473,7 @@ object NotificationChannelManager {
fun launchSystemSettingForChannel(context: Context, soundState: SoundState, isReminder: Boolean) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = createNotificationChannel(context, soundState, isReminder)
val channel = createNotificationChannel(context, soundState, isReminder, Settings(context))
val intent = Intent(android.provider.Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
intent.putExtra(android.provider.Settings.EXTRA_APP_PACKAGE, context.packageName)
intent.putExtra(android.provider.Settings.EXTRA_CHANNEL_ID, channel.channelId)
Expand Down
Expand Up @@ -120,6 +120,11 @@ class NotificationSettingsActivity : AppCompatActivity(){
initial (settings.postGroupNotification)
onChange { settings.postGroupNotification = it }
depending {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
red_notice(R.string.group_notifications_android_oreo_gore)
}

groupNotificationBehavior(settings.groupNotificationSwipeBehavior) {
settings.groupNotificationSwipeBehavior = it
}
Expand All @@ -142,9 +147,11 @@ class NotificationSettingsActivity : AppCompatActivity(){
onChange{ settings.notificationAddEmptyAction = it }
}

switch(R.string.use_alarm_stream, R.string.use_alarm_stream_summary) {
initial(settings.notificationUseAlarmStream)
onChange{settings.notificationUseAlarmStream = it}
if (settings.allowMuteAndAlarm) {
switch(R.string.use_alarm_stream, R.string.use_alarm_stream_summary) {
initial(settings.notificationUseAlarmStream)
onChange { settings.notificationUseAlarmStream = it }
}
}
}
}
Expand Down
Expand Up @@ -41,6 +41,10 @@ class QuietHoursSettingsActivity : AppCompatActivity() {

depending {

if (!settings.allowMuteAndAlarm) {
red_notice(R.string.group_notifications_android_oreo_gore)
}

timeOfDay(
R.string.quiet_time_from,
settings.quietHoursFrom) {
Expand Down
Expand Up @@ -230,6 +230,8 @@ open class EditEventActivity : AppCompatActivity() {
private lateinit var taskTagButton: TextView
private lateinit var alarmTagButton: TextView

private var muteAndAlarmAllowed: Boolean = true

private lateinit var eventTitleLayout: RelativeLayout
private lateinit var tagsLayout: LinearLayout

Expand Down Expand Up @@ -376,6 +378,8 @@ open class EditEventActivity : AppCompatActivity() {
// settings
settings = Settings(this)

muteAndAlarmAllowed = settings.allowMuteAndAlarm

taskTagButton = find<TextView?>(R.id.add_event_task_tag) ?: throw Exception("Can't find add_event_task_tag")
muteTagButton = find<TextView?>(R.id.add_event_mute_tag) ?: throw Exception("Can't find add_event_mute_tag")
alarmTagButton = find<TextView?>(R.id.add_event_alarm_tag) ?: throw Exception("Can't find add_event_alarm_tag")
Expand Down Expand Up @@ -669,8 +673,8 @@ open class EditEventActivity : AppCompatActivity() {

if (updateLayouts) {
taskTagButton.visibility = View.VISIBLE
muteTagButton.visibility = View.VISIBLE
alarmTagButton.visibility = View.VISIBLE
muteTagButton.visibility = if (muteAndAlarmAllowed) View.VISIBLE else View.GONE
alarmTagButton.visibility = if (muteAndAlarmAllowed) View.VISIBLE else View.GONE
}

val selectedColor = ContextCompat.getColor(this, R.color.event_selected_tag_color)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -593,5 +593,7 @@

<string name="pre_oreo_notification_channels_explanation">Attention pre-Oreo users:\n\nThis app is running in compatibility mode on your device\n\nMultiple users has requested F-Droid build to be installable on pre-Oreo devices, thus this change was made. But sound / vibration / LED control are all now migrated to notification channel settings which are absent on pre-Oreo devices, so you would not be able to control these. To get these settings back - please revert to an older version (Google Play will serve older version for pre-Oreo devices, or ask me directly).</string>

<string name="group_notifications_android_oreo_gore">WARNING:\n\nEnabling notifications grouping on Oreo+ would disable/limit functionality related to event muting, #alarm tag handling and quiet hours\n\nThis is due to unexpected/unreliable behavior of system notifications when grouping notifications from different channels (muted and #alarm notifications has to be posted into a separate from main channels)</string>

</resources>

0 comments on commit 73c52f8

Please sign in to comment.