diff --git a/app/src/main/kotlin/org/fossify/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/calendar/activities/SettingsActivity.kt index c489a8932..7fb7afa09 100644 --- a/app/src/main/kotlin/org/fossify/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/calendar/activities/SettingsActivity.kt @@ -32,7 +32,6 @@ import java.util.Locale import kotlin.system.exitProcess class SettingsActivity : SimpleActivity() { - private val GET_RINGTONE_URI = 1 private val PICK_SETTINGS_IMPORT_SOURCE_INTENT = 2 private val PICK_EVENTS_IMPORT_SOURCE_INTENT = 3 private val PICK_EVENTS_EXPORT_FILE_INTENT = 4 @@ -80,8 +79,6 @@ class SettingsActivity : SimpleActivity() { setupMidnightSpanEvents() setupAllowCustomizeDayCount() setupStartWeekWithCurrentDay() - setupVibrate() - setupReminderSound() setupReminderAudioStream() setupUseSameSnooze() setupLoopReminders() @@ -146,15 +143,12 @@ class SettingsActivity : SimpleActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) - if (requestCode == GET_RINGTONE_URI && resultCode == RESULT_OK && resultData != null) { - val newAlarmSound = storeNewYourAlarmSound(resultData) - updateReminderSound(newAlarmSound) - } else if (requestCode == PICK_SETTINGS_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) { + if (requestCode == PICK_SETTINGS_IMPORT_SOURCE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) { val inputStream = contentResolver.openInputStream(resultData.data!!) parseFile(inputStream) - } else if (requestCode == PICK_EVENTS_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) { + } else if (requestCode == PICK_EVENTS_IMPORT_SOURCE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) { tryImportEventsFromFile(resultData.data!!) - } else if (requestCode == PICK_EVENTS_EXPORT_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) { + } else if (requestCode == PICK_EVENTS_EXPORT_FILE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) { val outputStream = contentResolver.openOutputStream(resultData.data!!) exportEventsTo(eventTypesToExport, outputStream) } @@ -477,40 +471,6 @@ class SettingsActivity : SimpleActivity() { } } - @Deprecated("Not used on Oreo+ devices") - private fun setupReminderSound() = binding.apply { - settingsReminderSoundHolder.beGoneIf(isOreoPlus()) - settingsReminderSound.text = config.reminderSoundTitle - - settingsReminderSoundHolder.setOnClickListener { - SelectAlarmSoundDialog( - this@SettingsActivity, - config.reminderSoundUri, - config.reminderAudioStream, - GET_RINGTONE_URI, - RingtoneManager.TYPE_NOTIFICATION, - false, - onAlarmPicked = { - if (it != null) { - updateReminderSound(it) - } - }, - onAlarmSoundDeleted = { - if (it.uri == config.reminderSoundUri) { - val defaultAlarm = getDefaultAlarmSound(RingtoneManager.TYPE_NOTIFICATION) - updateReminderSound(defaultAlarm) - } - }) - } - } - - @Deprecated("Not used on Oreo+ devices") - private fun updateReminderSound(alarmSound: AlarmSound) { - config.reminderSoundTitle = alarmSound.title - config.reminderSoundUri = alarmSound.uri - binding.settingsReminderSound.text = alarmSound.title - } - private fun setupReminderAudioStream() = binding.apply { settingsReminderAudioStream.text = getAudioStreamText() settingsReminderAudioStreamHolder.setOnClickListener { @@ -537,14 +497,6 @@ class SettingsActivity : SimpleActivity() { } ) - private fun setupVibrate() = binding.apply { - settingsVibrate.isChecked = config.vibrateOnReminder - settingsVibrateHolder.setOnClickListener { - settingsVibrate.toggle() - config.vibrateOnReminder = settingsVibrate.isChecked - } - } - private fun setupLoopReminders() = binding.apply { settingsLoopReminders.isChecked = config.loopReminders settingsLoopRemindersHolder.setOnClickListener { @@ -944,7 +896,6 @@ class SettingsActivity : SimpleActivity() { put(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, config.showMidnightSpanningEventsAtTop) put(ALLOW_CUSTOMIZE_DAY_COUNT, config.allowCustomizeDayCount) put(START_WEEK_WITH_CURRENT_DAY, config.startWeekWithCurrentDay) - put(VIBRATE, config.vibrateOnReminder) put(LAST_EVENT_REMINDER_MINUTES, config.lastEventReminderMinutes1) put(LAST_EVENT_REMINDER_MINUTES_2, config.lastEventReminderMinutes2) put(LAST_EVENT_REMINDER_MINUTES_3, config.lastEventReminderMinutes3) @@ -1054,7 +1005,6 @@ class SettingsActivity : SimpleActivity() { SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP -> config.showMidnightSpanningEventsAtTop = value.toBoolean() ALLOW_CUSTOMIZE_DAY_COUNT -> config.allowCustomizeDayCount = value.toBoolean() START_WEEK_WITH_CURRENT_DAY -> config.startWeekWithCurrentDay = value.toBoolean() - VIBRATE -> config.vibrateOnReminder = value.toBoolean() LAST_EVENT_REMINDER_MINUTES -> config.lastEventReminderMinutes1 = value.toInt() LAST_EVENT_REMINDER_MINUTES_2 -> config.lastEventReminderMinutes2 = value.toInt() LAST_EVENT_REMINDER_MINUTES_3 -> config.lastEventReminderMinutes3 = value.toInt() diff --git a/app/src/main/kotlin/org/fossify/calendar/extensions/Context.kt b/app/src/main/kotlin/org/fossify/calendar/extensions/Context.kt index 04c8c3966..d1df1a712 100644 --- a/app/src/main/kotlin/org/fossify/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/calendar/extensions/Context.kt @@ -1,7 +1,6 @@ package org.fossify.calendar.extensions import android.accounts.Account -import android.annotation.SuppressLint import android.app.AlarmManager import android.app.Notification import android.app.NotificationChannel @@ -19,6 +18,7 @@ import android.graphics.Bitmap import android.media.AudioAttributes import android.media.AudioManager import android.media.MediaScannerConnection +import android.media.RingtoneManager import android.net.Uri import android.os.Bundle import android.provider.CalendarContract @@ -26,7 +26,6 @@ import android.view.LayoutInflater import android.view.ViewGroup import android.widget.LinearLayout import androidx.core.app.NotificationCompat -import androidx.core.net.toUri import androidx.print.PrintHelper import org.fossify.calendar.R import org.fossify.calendar.activities.EventActivity @@ -96,7 +95,6 @@ import org.fossify.commons.extensions.formatSecondsToTimeString import org.fossify.commons.extensions.getContrastColor import org.fossify.commons.extensions.getDoesFilePathExist import org.fossify.commons.extensions.getMimeType -import org.fossify.commons.extensions.grantReadUriPermission import org.fossify.commons.extensions.hasProperStoredFirstParentUri import org.fossify.commons.extensions.removeBit import org.fossify.commons.extensions.showErrorToast @@ -107,7 +105,6 @@ import org.fossify.commons.helpers.FONT_SIZE_SMALL import org.fossify.commons.helpers.FRIDAY_BIT import org.fossify.commons.helpers.MONDAY_BIT import org.fossify.commons.helpers.SATURDAY_BIT -import org.fossify.commons.helpers.SILENT import org.fossify.commons.helpers.SUNDAY_BIT import org.fossify.commons.helpers.THURSDAY_BIT import org.fossify.commons.helpers.TUESDAY_BIT @@ -115,7 +112,6 @@ import org.fossify.commons.helpers.WEDNESDAY_BIT import org.fossify.commons.helpers.WEEK_SECONDS import org.fossify.commons.helpers.YEAR_SECONDS import org.fossify.commons.helpers.ensureBackgroundThread -import org.fossify.commons.helpers.isOreoPlus import org.fossify.commons.helpers.isRPlus import org.fossify.commons.helpers.isSPlus import org.fossify.commons.helpers.isTiramisuPlus @@ -446,31 +442,26 @@ fun Context.getUsageAttributeForStreamType(): Int { } } -@SuppressLint("NewApi") fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: String, publicVersion: Boolean = false): Notification? { - var soundUri = config.reminderSoundUri - if (soundUri == SILENT) { - soundUri = "" - } else { - grantReadUriPermission(soundUri) - } - val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - // create a new channel for every new sound uri as the new Android Oreo notification system is fundamentally broken - if (soundUri != config.lastSoundUri || config.lastVibrateOnReminder != config.vibrateOnReminder) { - if (!publicVersion) { - if (isOreoPlus()) { - val oldChannelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}" - notificationManager.deleteNotificationChannel(oldChannelId) - } - } - - config.lastVibrateOnReminder = config.vibrateOnReminder - config.lastReminderChannel = System.currentTimeMillis() - config.lastSoundUri = soundUri + // TODO: Properly migrate old notification channels to avoid nuking user customization + // use legacy channels for existing users, new stable channels for fresh installs + val newChannelId = "simple_calendar_${config.reminderAudioStream}_${event.eventType}" + val legacyChannelId = if (!config.notificationChannelsMigrated) { + val existingChannels = notificationManager.notificationChannels + existingChannels.find { channel -> + channel.id.startsWith("simple_calendar_") && + channel.id.endsWith("_${config.reminderAudioStream}_${event.eventType}") && + channel.id != newChannelId + }?.id + } else null + + val channelId = legacyChannelId ?: newChannelId + if (!config.notificationChannelsMigrated) { + config.notificationChannelsMigrated = true } - val channelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}" + val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) val audioAttributes = AudioAttributes.Builder() .setUsage(getUsageAttributeForStreamType()) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) @@ -482,8 +473,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: setBypassDnd(true) enableLights(true) lightColor = event.color - enableVibration(config.vibrateOnReminder) - setSound(soundUri.toUri(), audioAttributes) + setSound(soundUri, audioAttributes) try { notificationManager.createNotificationChannel(this) } catch (e: Exception) { @@ -517,11 +507,6 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: ) } - if (config.vibrateOnReminder) { - val vibrateArray = LongArray(2) { 500 } - builder.setVibrate(vibrateArray) - } - if (!publicVersion) { val notification = getNotification(pendingIntent, event, content, true) if (notification != null) { diff --git a/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt b/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt index 7d5a98012..e80940a29 100644 --- a/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt @@ -2,11 +2,8 @@ package org.fossify.calendar.helpers import android.content.Context import android.media.AudioManager -import android.media.RingtoneManager import org.fossify.calendar.R -import org.fossify.calendar.extensions.config import org.fossify.calendar.extensions.scheduleCalDAVSync -import org.fossify.commons.extensions.getDefaultAlarmTitle import org.fossify.commons.helpers.BaseConfig import org.fossify.commons.helpers.DAY_MINUTES import org.fossify.commons.helpers.YEAR_SECONDS @@ -37,29 +34,6 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(ALLOW_CUSTOMIZE_DAY_COUNT, true) set(allow) = prefs.edit().putBoolean(ALLOW_CUSTOMIZE_DAY_COUNT, allow).apply() - var vibrateOnReminder: Boolean - get() = prefs.getBoolean(VIBRATE, false) - set(vibrate) = prefs.edit().putBoolean(VIBRATE, vibrate).apply() - - @Deprecated("Not used on Oreo+ devices") - var reminderSoundUri: String - get() = prefs.getString(REMINDER_SOUND_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString())!! - set(reminderSoundUri) = prefs.edit().putString(REMINDER_SOUND_URI, reminderSoundUri).apply() - - @Deprecated("Not used on Oreo+ devices") - var reminderSoundTitle: String - get() = prefs.getString(REMINDER_SOUND_TITLE, context.getDefaultAlarmTitle(RingtoneManager.TYPE_NOTIFICATION))!! - set(reminderSoundTitle) = prefs.edit().putString(REMINDER_SOUND_TITLE, reminderSoundTitle).apply() - - @Deprecated("Not used on Oreo+ devices") - var lastSoundUri: String - get() = prefs.getString(LAST_SOUND_URI, "")!! - set(lastSoundUri) = prefs.edit().putString(LAST_SOUND_URI, lastSoundUri).apply() - - var lastReminderChannel: Long - get() = prefs.getLong(LAST_REMINDER_CHANNEL_ID, 0L) - set(lastReminderChannel) = prefs.edit().putLong(LAST_REMINDER_CHANNEL_ID, lastReminderChannel).apply() - var storedView: Int get() = prefs.getInt(VIEW, MONTHLY_VIEW) set(view) = prefs.edit().putInt(VIEW, view).apply() @@ -190,10 +164,6 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(PULL_TO_REFRESH, false) set(pullToRefresh) = prefs.edit().putBoolean(PULL_TO_REFRESH, pullToRefresh).apply() - var lastVibrateOnReminder: Boolean - get() = prefs.getBoolean(LAST_VIBRATE_ON_REMINDER, context.config.vibrateOnReminder) - set(lastVibrateOnReminder) = prefs.edit().putBoolean(LAST_VIBRATE_ON_REMINDER, lastVibrateOnReminder).apply() - var defaultStartTime: Int get() = prefs.getInt(DEFAULT_START_TIME, DEFAULT_START_TIME_NEXT_FULL_HOUR) set(defaultStartTime) = prefs.edit().putInt(DEFAULT_START_TIME, defaultStartTime).apply() @@ -266,6 +236,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(WAS_FILTERED_OUT_WARNING_SHOWN, false) set(wasFilteredOutWarningShown) = prefs.edit().putBoolean(WAS_FILTERED_OUT_WARNING_SHOWN, wasFilteredOutWarningShown).apply() + var notificationChannelsMigrated: Boolean + get() = prefs.getBoolean(NOTIFICATION_CHANNELS_MIGRATED, false) + set(notificationChannelsMigrated) = prefs.edit().putBoolean(NOTIFICATION_CHANNELS_MIGRATED, notificationChannelsMigrated).apply() + var autoBackupEventTypes: Set get() = prefs.getStringSet(AUTO_BACKUP_EVENT_TYPES, HashSet())!! set(autoBackupEventTypes) = prefs.edit().remove(AUTO_BACKUP_EVENT_TYPES).putStringSet(AUTO_BACKUP_EVENT_TYPES, autoBackupEventTypes).apply() diff --git a/app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt b/app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt index 2214d2898..5821bc1d7 100644 --- a/app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt @@ -90,9 +90,6 @@ const val START_WEEKLY_AT = "start_weekly_at" const val START_WEEK_WITH_CURRENT_DAY = "start_week_with_current_day" const val SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP = "show_midnight_spanning_events_at_top" const val ALLOW_CUSTOMIZE_DAY_COUNT = "allow_customise_day_count" -const val VIBRATE = "vibrate" -const val REMINDER_SOUND_URI = "reminder_sound_uri" -const val REMINDER_SOUND_TITLE = "reminder_sound_title" const val VIEW = "view" const val LAST_EVENT_REMINDER_MINUTES = "reminder_minutes" const val LAST_EVENT_REMINDER_MINUTES_2 = "reminder_minutes_2" @@ -112,15 +109,12 @@ const val SHOW_GRID = "show_grid" const val LOOP_REMINDERS = "loop_reminders" const val DIM_PAST_EVENTS = "dim_past_events" const val DIM_COMPLETED_TASKS = "dim_completed_tasks" -const val LAST_SOUND_URI = "last_sound_uri" -const val LAST_REMINDER_CHANNEL_ID = "last_reminder_channel_ID" const val REMINDER_AUDIO_STREAM = "reminder_audio_stream" const val USE_PREVIOUS_EVENT_REMINDERS = "use_previous_event_reminders" const val DEFAULT_REMINDER_1 = "default_reminder_1" const val DEFAULT_REMINDER_2 = "default_reminder_2" const val DEFAULT_REMINDER_3 = "default_reminder_3" const val PULL_TO_REFRESH = "pull_to_refresh" -const val LAST_VIBRATE_ON_REMINDER = "last_vibrate_on_reminder" const val DEFAULT_START_TIME = "default_start_time" const val DEFAULT_DURATION = "default_duration" const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id" @@ -140,6 +134,7 @@ const val HIGHLIGHT_WEEKENDS_COLOR = "highlight_weekends_color" const val LAST_USED_EVENT_SPAN = "last_used_event_span" const val ALLOW_CREATING_TASKS = "allow_creating_tasks" const val WAS_FILTERED_OUT_WARNING_SHOWN = "was_filtered_out_warning_shown" +const val NOTIFICATION_CHANNELS_MIGRATED = "notification_channels_migrated" const val AUTO_BACKUP = "auto_backup" const val AUTO_BACKUP_FOLDER = "auto_backup_folder" const val AUTO_BACKUP_FILENAME = "auto_backup_filename" diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index b8d550c26..bffb8b598 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -258,29 +258,6 @@ - - - - - - - - - - - - - -