Skip to content

Commit 5a74db3

Browse files
committed
chore: remove outdated in-app vibration option
See: #689
1 parent 9484647 commit 5a74db3

5 files changed

Lines changed: 26 additions & 160 deletions

File tree

app/src/main/kotlin/org/fossify/calendar/activities/SettingsActivity.kt

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import java.util.Locale
3232
import kotlin.system.exitProcess
3333

3434
class SettingsActivity : SimpleActivity() {
35-
private val GET_RINGTONE_URI = 1
3635
private val PICK_SETTINGS_IMPORT_SOURCE_INTENT = 2
3736
private val PICK_EVENTS_IMPORT_SOURCE_INTENT = 3
3837
private val PICK_EVENTS_EXPORT_FILE_INTENT = 4
@@ -80,8 +79,6 @@ class SettingsActivity : SimpleActivity() {
8079
setupMidnightSpanEvents()
8180
setupAllowCustomizeDayCount()
8281
setupStartWeekWithCurrentDay()
83-
setupVibrate()
84-
setupReminderSound()
8582
setupReminderAudioStream()
8683
setupUseSameSnooze()
8784
setupLoopReminders()
@@ -146,15 +143,12 @@ class SettingsActivity : SimpleActivity() {
146143

147144
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
148145
super.onActivityResult(requestCode, resultCode, resultData)
149-
if (requestCode == GET_RINGTONE_URI && resultCode == RESULT_OK && resultData != null) {
150-
val newAlarmSound = storeNewYourAlarmSound(resultData)
151-
updateReminderSound(newAlarmSound)
152-
} else if (requestCode == PICK_SETTINGS_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
146+
if (requestCode == PICK_SETTINGS_IMPORT_SOURCE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) {
153147
val inputStream = contentResolver.openInputStream(resultData.data!!)
154148
parseFile(inputStream)
155-
} else if (requestCode == PICK_EVENTS_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
149+
} else if (requestCode == PICK_EVENTS_IMPORT_SOURCE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) {
156150
tryImportEventsFromFile(resultData.data!!)
157-
} else if (requestCode == PICK_EVENTS_EXPORT_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
151+
} else if (requestCode == PICK_EVENTS_EXPORT_FILE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) {
158152
val outputStream = contentResolver.openOutputStream(resultData.data!!)
159153
exportEventsTo(eventTypesToExport, outputStream)
160154
}
@@ -477,40 +471,6 @@ class SettingsActivity : SimpleActivity() {
477471
}
478472
}
479473

480-
@Deprecated("Not used on Oreo+ devices")
481-
private fun setupReminderSound() = binding.apply {
482-
settingsReminderSoundHolder.beGoneIf(isOreoPlus())
483-
settingsReminderSound.text = config.reminderSoundTitle
484-
485-
settingsReminderSoundHolder.setOnClickListener {
486-
SelectAlarmSoundDialog(
487-
this@SettingsActivity,
488-
config.reminderSoundUri,
489-
config.reminderAudioStream,
490-
GET_RINGTONE_URI,
491-
RingtoneManager.TYPE_NOTIFICATION,
492-
false,
493-
onAlarmPicked = {
494-
if (it != null) {
495-
updateReminderSound(it)
496-
}
497-
},
498-
onAlarmSoundDeleted = {
499-
if (it.uri == config.reminderSoundUri) {
500-
val defaultAlarm = getDefaultAlarmSound(RingtoneManager.TYPE_NOTIFICATION)
501-
updateReminderSound(defaultAlarm)
502-
}
503-
})
504-
}
505-
}
506-
507-
@Deprecated("Not used on Oreo+ devices")
508-
private fun updateReminderSound(alarmSound: AlarmSound) {
509-
config.reminderSoundTitle = alarmSound.title
510-
config.reminderSoundUri = alarmSound.uri
511-
binding.settingsReminderSound.text = alarmSound.title
512-
}
513-
514474
private fun setupReminderAudioStream() = binding.apply {
515475
settingsReminderAudioStream.text = getAudioStreamText()
516476
settingsReminderAudioStreamHolder.setOnClickListener {
@@ -537,14 +497,6 @@ class SettingsActivity : SimpleActivity() {
537497
}
538498
)
539499

540-
private fun setupVibrate() = binding.apply {
541-
settingsVibrate.isChecked = config.vibrateOnReminder
542-
settingsVibrateHolder.setOnClickListener {
543-
settingsVibrate.toggle()
544-
config.vibrateOnReminder = settingsVibrate.isChecked
545-
}
546-
}
547-
548500
private fun setupLoopReminders() = binding.apply {
549501
settingsLoopReminders.isChecked = config.loopReminders
550502
settingsLoopRemindersHolder.setOnClickListener {
@@ -944,7 +896,6 @@ class SettingsActivity : SimpleActivity() {
944896
put(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, config.showMidnightSpanningEventsAtTop)
945897
put(ALLOW_CUSTOMIZE_DAY_COUNT, config.allowCustomizeDayCount)
946898
put(START_WEEK_WITH_CURRENT_DAY, config.startWeekWithCurrentDay)
947-
put(VIBRATE, config.vibrateOnReminder)
948899
put(LAST_EVENT_REMINDER_MINUTES, config.lastEventReminderMinutes1)
949900
put(LAST_EVENT_REMINDER_MINUTES_2, config.lastEventReminderMinutes2)
950901
put(LAST_EVENT_REMINDER_MINUTES_3, config.lastEventReminderMinutes3)
@@ -1054,7 +1005,6 @@ class SettingsActivity : SimpleActivity() {
10541005
SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP -> config.showMidnightSpanningEventsAtTop = value.toBoolean()
10551006
ALLOW_CUSTOMIZE_DAY_COUNT -> config.allowCustomizeDayCount = value.toBoolean()
10561007
START_WEEK_WITH_CURRENT_DAY -> config.startWeekWithCurrentDay = value.toBoolean()
1057-
VIBRATE -> config.vibrateOnReminder = value.toBoolean()
10581008
LAST_EVENT_REMINDER_MINUTES -> config.lastEventReminderMinutes1 = value.toInt()
10591009
LAST_EVENT_REMINDER_MINUTES_2 -> config.lastEventReminderMinutes2 = value.toInt()
10601010
LAST_EVENT_REMINDER_MINUTES_3 -> config.lastEventReminderMinutes3 = value.toInt()

app/src/main/kotlin/org/fossify/calendar/extensions/Context.kt

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.fossify.calendar.extensions
22

33
import android.accounts.Account
4-
import android.annotation.SuppressLint
54
import android.app.AlarmManager
65
import android.app.Notification
76
import android.app.NotificationChannel
@@ -19,14 +18,14 @@ import android.graphics.Bitmap
1918
import android.media.AudioAttributes
2019
import android.media.AudioManager
2120
import android.media.MediaScannerConnection
21+
import android.media.RingtoneManager
2222
import android.net.Uri
2323
import android.os.Bundle
2424
import android.provider.CalendarContract
2525
import android.view.LayoutInflater
2626
import android.view.ViewGroup
2727
import android.widget.LinearLayout
2828
import androidx.core.app.NotificationCompat
29-
import androidx.core.net.toUri
3029
import androidx.print.PrintHelper
3130
import org.fossify.calendar.R
3231
import org.fossify.calendar.activities.EventActivity
@@ -96,7 +95,6 @@ import org.fossify.commons.extensions.formatSecondsToTimeString
9695
import org.fossify.commons.extensions.getContrastColor
9796
import org.fossify.commons.extensions.getDoesFilePathExist
9897
import org.fossify.commons.extensions.getMimeType
99-
import org.fossify.commons.extensions.grantReadUriPermission
10098
import org.fossify.commons.extensions.hasProperStoredFirstParentUri
10199
import org.fossify.commons.extensions.removeBit
102100
import org.fossify.commons.extensions.showErrorToast
@@ -107,15 +105,13 @@ import org.fossify.commons.helpers.FONT_SIZE_SMALL
107105
import org.fossify.commons.helpers.FRIDAY_BIT
108106
import org.fossify.commons.helpers.MONDAY_BIT
109107
import org.fossify.commons.helpers.SATURDAY_BIT
110-
import org.fossify.commons.helpers.SILENT
111108
import org.fossify.commons.helpers.SUNDAY_BIT
112109
import org.fossify.commons.helpers.THURSDAY_BIT
113110
import org.fossify.commons.helpers.TUESDAY_BIT
114111
import org.fossify.commons.helpers.WEDNESDAY_BIT
115112
import org.fossify.commons.helpers.WEEK_SECONDS
116113
import org.fossify.commons.helpers.YEAR_SECONDS
117114
import org.fossify.commons.helpers.ensureBackgroundThread
118-
import org.fossify.commons.helpers.isOreoPlus
119115
import org.fossify.commons.helpers.isRPlus
120116
import org.fossify.commons.helpers.isSPlus
121117
import org.fossify.commons.helpers.isTiramisuPlus
@@ -446,31 +442,26 @@ fun Context.getUsageAttributeForStreamType(): Int {
446442
}
447443
}
448444

449-
@SuppressLint("NewApi")
450445
fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: String, publicVersion: Boolean = false): Notification? {
451-
var soundUri = config.reminderSoundUri
452-
if (soundUri == SILENT) {
453-
soundUri = ""
454-
} else {
455-
grantReadUriPermission(soundUri)
456-
}
457-
458446
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
459-
// create a new channel for every new sound uri as the new Android Oreo notification system is fundamentally broken
460-
if (soundUri != config.lastSoundUri || config.lastVibrateOnReminder != config.vibrateOnReminder) {
461-
if (!publicVersion) {
462-
if (isOreoPlus()) {
463-
val oldChannelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}"
464-
notificationManager.deleteNotificationChannel(oldChannelId)
465-
}
466-
}
467-
468-
config.lastVibrateOnReminder = config.vibrateOnReminder
469-
config.lastReminderChannel = System.currentTimeMillis()
470-
config.lastSoundUri = soundUri
447+
// TODO: Properly migrate old notification channels to avoid nuking user customization
448+
// use legacy channels for existing users, new stable channels for fresh installs
449+
val newChannelId = "simple_calendar_${config.reminderAudioStream}_${event.eventType}"
450+
val legacyChannelId = if (!config.notificationChannelsMigrated) {
451+
val existingChannels = notificationManager.notificationChannels
452+
existingChannels.find { channel ->
453+
channel.id.startsWith("simple_calendar_") &&
454+
channel.id.endsWith("_${config.reminderAudioStream}_${event.eventType}") &&
455+
channel.id != newChannelId
456+
}?.id
457+
} else null
458+
459+
val channelId = legacyChannelId ?: newChannelId
460+
if (!config.notificationChannelsMigrated) {
461+
config.notificationChannelsMigrated = true
471462
}
472463

473-
val channelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}"
464+
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
474465
val audioAttributes = AudioAttributes.Builder()
475466
.setUsage(getUsageAttributeForStreamType())
476467
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
@@ -482,8 +473,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
482473
setBypassDnd(true)
483474
enableLights(true)
484475
lightColor = event.color
485-
enableVibration(config.vibrateOnReminder)
486-
setSound(soundUri.toUri(), audioAttributes)
476+
setSound(soundUri, audioAttributes)
487477
try {
488478
notificationManager.createNotificationChannel(this)
489479
} catch (e: Exception) {
@@ -517,11 +507,6 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
517507
)
518508
}
519509

520-
if (config.vibrateOnReminder) {
521-
val vibrateArray = LongArray(2) { 500 }
522-
builder.setVibrate(vibrateArray)
523-
}
524-
525510
if (!publicVersion) {
526511
val notification = getNotification(pendingIntent, event, content, true)
527512
if (notification != null) {

app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package org.fossify.calendar.helpers
22

33
import android.content.Context
44
import android.media.AudioManager
5-
import android.media.RingtoneManager
65
import org.fossify.calendar.R
7-
import org.fossify.calendar.extensions.config
86
import org.fossify.calendar.extensions.scheduleCalDAVSync
9-
import org.fossify.commons.extensions.getDefaultAlarmTitle
107
import org.fossify.commons.helpers.BaseConfig
118
import org.fossify.commons.helpers.DAY_MINUTES
129
import org.fossify.commons.helpers.YEAR_SECONDS
@@ -37,29 +34,6 @@ class Config(context: Context) : BaseConfig(context) {
3734
get() = prefs.getBoolean(ALLOW_CUSTOMIZE_DAY_COUNT, true)
3835
set(allow) = prefs.edit().putBoolean(ALLOW_CUSTOMIZE_DAY_COUNT, allow).apply()
3936

40-
var vibrateOnReminder: Boolean
41-
get() = prefs.getBoolean(VIBRATE, false)
42-
set(vibrate) = prefs.edit().putBoolean(VIBRATE, vibrate).apply()
43-
44-
@Deprecated("Not used on Oreo+ devices")
45-
var reminderSoundUri: String
46-
get() = prefs.getString(REMINDER_SOUND_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString())!!
47-
set(reminderSoundUri) = prefs.edit().putString(REMINDER_SOUND_URI, reminderSoundUri).apply()
48-
49-
@Deprecated("Not used on Oreo+ devices")
50-
var reminderSoundTitle: String
51-
get() = prefs.getString(REMINDER_SOUND_TITLE, context.getDefaultAlarmTitle(RingtoneManager.TYPE_NOTIFICATION))!!
52-
set(reminderSoundTitle) = prefs.edit().putString(REMINDER_SOUND_TITLE, reminderSoundTitle).apply()
53-
54-
@Deprecated("Not used on Oreo+ devices")
55-
var lastSoundUri: String
56-
get() = prefs.getString(LAST_SOUND_URI, "")!!
57-
set(lastSoundUri) = prefs.edit().putString(LAST_SOUND_URI, lastSoundUri).apply()
58-
59-
var lastReminderChannel: Long
60-
get() = prefs.getLong(LAST_REMINDER_CHANNEL_ID, 0L)
61-
set(lastReminderChannel) = prefs.edit().putLong(LAST_REMINDER_CHANNEL_ID, lastReminderChannel).apply()
62-
6337
var storedView: Int
6438
get() = prefs.getInt(VIEW, MONTHLY_VIEW)
6539
set(view) = prefs.edit().putInt(VIEW, view).apply()
@@ -190,10 +164,6 @@ class Config(context: Context) : BaseConfig(context) {
190164
get() = prefs.getBoolean(PULL_TO_REFRESH, false)
191165
set(pullToRefresh) = prefs.edit().putBoolean(PULL_TO_REFRESH, pullToRefresh).apply()
192166

193-
var lastVibrateOnReminder: Boolean
194-
get() = prefs.getBoolean(LAST_VIBRATE_ON_REMINDER, context.config.vibrateOnReminder)
195-
set(lastVibrateOnReminder) = prefs.edit().putBoolean(LAST_VIBRATE_ON_REMINDER, lastVibrateOnReminder).apply()
196-
197167
var defaultStartTime: Int
198168
get() = prefs.getInt(DEFAULT_START_TIME, DEFAULT_START_TIME_NEXT_FULL_HOUR)
199169
set(defaultStartTime) = prefs.edit().putInt(DEFAULT_START_TIME, defaultStartTime).apply()
@@ -266,6 +236,10 @@ class Config(context: Context) : BaseConfig(context) {
266236
get() = prefs.getBoolean(WAS_FILTERED_OUT_WARNING_SHOWN, false)
267237
set(wasFilteredOutWarningShown) = prefs.edit().putBoolean(WAS_FILTERED_OUT_WARNING_SHOWN, wasFilteredOutWarningShown).apply()
268238

239+
var notificationChannelsMigrated: Boolean
240+
get() = prefs.getBoolean(NOTIFICATION_CHANNELS_MIGRATED, false)
241+
set(notificationChannelsMigrated) = prefs.edit().putBoolean(NOTIFICATION_CHANNELS_MIGRATED, notificationChannelsMigrated).apply()
242+
269243
var autoBackupEventTypes: Set<String>
270244
get() = prefs.getStringSet(AUTO_BACKUP_EVENT_TYPES, HashSet())!!
271245
set(autoBackupEventTypes) = prefs.edit().remove(AUTO_BACKUP_EVENT_TYPES).putStringSet(AUTO_BACKUP_EVENT_TYPES, autoBackupEventTypes).apply()

app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ const val START_WEEKLY_AT = "start_weekly_at"
9090
const val START_WEEK_WITH_CURRENT_DAY = "start_week_with_current_day"
9191
const val SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP = "show_midnight_spanning_events_at_top"
9292
const val ALLOW_CUSTOMIZE_DAY_COUNT = "allow_customise_day_count"
93-
const val VIBRATE = "vibrate"
94-
const val REMINDER_SOUND_URI = "reminder_sound_uri"
95-
const val REMINDER_SOUND_TITLE = "reminder_sound_title"
9693
const val VIEW = "view"
9794
const val LAST_EVENT_REMINDER_MINUTES = "reminder_minutes"
9895
const val LAST_EVENT_REMINDER_MINUTES_2 = "reminder_minutes_2"
@@ -112,15 +109,12 @@ const val SHOW_GRID = "show_grid"
112109
const val LOOP_REMINDERS = "loop_reminders"
113110
const val DIM_PAST_EVENTS = "dim_past_events"
114111
const val DIM_COMPLETED_TASKS = "dim_completed_tasks"
115-
const val LAST_SOUND_URI = "last_sound_uri"
116-
const val LAST_REMINDER_CHANNEL_ID = "last_reminder_channel_ID"
117112
const val REMINDER_AUDIO_STREAM = "reminder_audio_stream"
118113
const val USE_PREVIOUS_EVENT_REMINDERS = "use_previous_event_reminders"
119114
const val DEFAULT_REMINDER_1 = "default_reminder_1"
120115
const val DEFAULT_REMINDER_2 = "default_reminder_2"
121116
const val DEFAULT_REMINDER_3 = "default_reminder_3"
122117
const val PULL_TO_REFRESH = "pull_to_refresh"
123-
const val LAST_VIBRATE_ON_REMINDER = "last_vibrate_on_reminder"
124118
const val DEFAULT_START_TIME = "default_start_time"
125119
const val DEFAULT_DURATION = "default_duration"
126120
const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id"
@@ -140,6 +134,7 @@ const val HIGHLIGHT_WEEKENDS_COLOR = "highlight_weekends_color"
140134
const val LAST_USED_EVENT_SPAN = "last_used_event_span"
141135
const val ALLOW_CREATING_TASKS = "allow_creating_tasks"
142136
const val WAS_FILTERED_OUT_WARNING_SHOWN = "was_filtered_out_warning_shown"
137+
const val NOTIFICATION_CHANNELS_MIGRATED = "notification_channels_migrated"
143138
const val AUTO_BACKUP = "auto_backup"
144139
const val AUTO_BACKUP_FOLDER = "auto_backup_folder"
145140
const val AUTO_BACKUP_FILENAME = "auto_backup_filename"

app/src/main/res/layout/activity_settings.xml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -258,29 +258,6 @@
258258

259259
</RelativeLayout>
260260

261-
<RelativeLayout
262-
android:id="@+id/settings_reminder_sound_holder"
263-
style="@style/SettingsHolderTextViewStyle"
264-
android:layout_width="match_parent"
265-
android:layout_height="wrap_content">
266-
267-
<org.fossify.commons.views.MyTextView
268-
android:id="@+id/settings_reminder_sound_label"
269-
style="@style/SettingsTextLabelStyle"
270-
android:layout_width="wrap_content"
271-
android:layout_height="wrap_content"
272-
android:text="@string/reminder_sound" />
273-
274-
<org.fossify.commons.views.MyTextView
275-
android:id="@+id/settings_reminder_sound"
276-
style="@style/SettingsTextValueStyle"
277-
android:layout_width="match_parent"
278-
android:layout_height="wrap_content"
279-
android:layout_below="@+id/settings_reminder_sound_label"
280-
tools:text="Default" />
281-
282-
</RelativeLayout>
283-
284261
<RelativeLayout
285262
android:id="@+id/settings_reminder_audio_stream_holder"
286263
style="@style/SettingsHolderTextViewStyle"
@@ -304,21 +281,6 @@
304281

305282
</RelativeLayout>
306283

307-
<RelativeLayout
308-
android:id="@+id/settings_vibrate_holder"
309-
style="@style/SettingsHolderSwitchStyle"
310-
android:layout_width="match_parent"
311-
android:layout_height="wrap_content">
312-
313-
<org.fossify.commons.views.MyMaterialSwitch
314-
android:id="@+id/settings_vibrate"
315-
style="@style/SettingsSwitchStyle"
316-
android:layout_width="match_parent"
317-
android:layout_height="wrap_content"
318-
android:text="@string/vibrate" />
319-
320-
</RelativeLayout>
321-
322284
<RelativeLayout
323285
android:id="@+id/settings_loop_reminders_holder"
324286
style="@style/SettingsHolderSwitchStyle"

0 commit comments

Comments
 (0)