diff --git a/app/src/main/java/com/github/tmo1/sms_ie/CustomPreferences.kt b/app/src/main/java/com/github/tmo1/sms_ie/CustomPreferences.kt index 51e3b8a..3e417a9 100644 --- a/app/src/main/java/com/github/tmo1/sms_ie/CustomPreferences.kt +++ b/app/src/main/java/com/github/tmo1/sms_ie/CustomPreferences.kt @@ -37,7 +37,7 @@ class TimePickerPreference(context: Context, attrs: AttributeSet?) : DialogPrefe fun persistMinutesFromMidnight(minutesFromMidnight: Int) { super.persistInt(minutesFromMidnight) notifyChanged() - updateExportWork(context) + updateExportWork(context, true) } override fun onSetInitialValue(defaultValue: Any?) { diff --git a/app/src/main/java/com/github/tmo1/sms_ie/ExportWorker.kt b/app/src/main/java/com/github/tmo1/sms_ie/ExportWorker.kt index 909a75a..481b8b3 100644 --- a/app/src/main/java/com/github/tmo1/sms_ie/ExportWorker.kt +++ b/app/src/main/java/com/github/tmo1/sms_ie/ExportWorker.kt @@ -168,14 +168,16 @@ class ExportWorker(appContext: Context, workerParams: WorkerParameters) : } } } - updateExportWork(context) + updateExportWork(context, false) //FIXME: as written, this always returns success, since the work is launched asynchronously and these lines execute immediately upon coroutine launch return result } } -fun updateExportWork(context: Context) { - WorkManager.getInstance(context).cancelAllWorkByTag(EXPORT_WORK_TAG) +fun updateExportWork(context: Context, cancel: Boolean) { + if (cancel) { + WorkManager.getInstance(context).cancelAllWorkByTag(EXPORT_WORK_TAG) + } val prefs = PreferenceManager.getDefaultSharedPreferences(context) if (prefs.getBoolean("schedule_export", false)) { // https://stackoverflow.com/questions/4389500/how-can-i-find-the-amount-of-seconds-passed-from-the-midnight-with-java diff --git a/app/src/main/java/com/github/tmo1/sms_ie/SettingsActivity.kt b/app/src/main/java/com/github/tmo1/sms_ie/SettingsActivity.kt index d5d7699..fb40b84 100644 --- a/app/src/main/java/com/github/tmo1/sms_ie/SettingsActivity.kt +++ b/app/src/main/java/com/github/tmo1/sms_ie/SettingsActivity.kt @@ -139,7 +139,7 @@ class SettingsActivity : AppCompatActivity() { // https://stackoverflow.com/questions/66449883/kotlin-onsharedpreferencechangelistener val prefListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPrefs, key -> if (key == "schedule_export") { - context?.let { updateExportWork(it) } + context?.let { updateExportWork(it, true) } if (SDK_INT >= 33 && sharedPrefs.getBoolean(key, false)) { context?.let { if (ContextCompat.checkSelfPermission(