reschedule wipe job on days change

This commit is contained in:
lucky 2022-01-15 15:00:58 +03:00
parent 0b5933ef28
commit 6bf789e31b
4 changed files with 12 additions and 9 deletions

View File

@ -101,7 +101,7 @@
<service <service
android:name=".WipeJobService" android:name=".WipeJobService"
android:exported="true" android:exported="true"
android:description="@string/wipe_job_service_description" android:description="@string/wipe_job_description"
android:permission="android.permission.BIND_JOB_SERVICE"> android:permission="android.permission.BIND_JOB_SERVICE">
</service> </service>

View File

@ -1,5 +1,6 @@
package me.lucky.wasted package me.lucky.wasted
import android.app.job.JobScheduler
import android.content.ComponentName import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
@ -109,7 +110,7 @@ open class MainActivity : AppCompatActivity() {
wipeOnInactivitySwitch.setOnCheckedChangeListener { _, isChecked -> wipeOnInactivitySwitch.setOnCheckedChangeListener { _, isChecked ->
if (!setWipeOnInactivityComponentsState(prefs.isServiceEnabled && isChecked)) { if (!setWipeOnInactivityComponentsState(prefs.isServiceEnabled && isChecked)) {
wipeOnInactivitySwitch.isChecked = false wipeOnInactivitySwitch.isChecked = false
showWipeJobServiceStartFailedPopup() showWipeJobScheduleFailedPopup()
return@setOnCheckedChangeListener return@setOnCheckedChangeListener
} }
prefs.isWipeOnInactivity = isChecked prefs.isWipeOnInactivity = isChecked
@ -184,6 +185,8 @@ open class MainActivity : AppCompatActivity() {
} }
.setPositiveButton(R.string.ok) { _, _ -> .setPositiveButton(R.string.ok) { _, _ ->
prefs.wipeOnInactivityDays = days prefs.wipeOnInactivityDays = days
if (prefs.isServiceEnabled && job.schedule() == JobScheduler.RESULT_FAILURE)
showWipeJobScheduleFailedPopup()
} }
.show() .show()
} }
@ -197,7 +200,7 @@ open class MainActivity : AppCompatActivity() {
private fun setOn() { private fun setOn() {
if (!setWipeOnInactivityComponentsState(prefs.isWipeOnInactivity)) { if (!setWipeOnInactivityComponentsState(prefs.isWipeOnInactivity)) {
binding.toggle.isChecked = false binding.toggle.isChecked = false
showWipeJobServiceStartFailedPopup() showWipeJobScheduleFailedPopup()
return return
} }
prefs.isServiceEnabled = true prefs.isServiceEnabled = true
@ -220,10 +223,10 @@ open class MainActivity : AppCompatActivity() {
updateCodeColorState() updateCodeColorState()
} }
private fun showWipeJobServiceStartFailedPopup() { private fun showWipeJobScheduleFailedPopup() {
Snackbar.make( Snackbar.make(
binding.toggle, binding.toggle,
R.string.wipe_job_service_start_failed_popup, R.string.wipe_job_schedule_failed_popup,
Snackbar.LENGTH_LONG, Snackbar.LENGTH_LONG,
).show() ).show()
} }

View File

@ -20,8 +20,8 @@
<string name="wipe_on_inactivity_days">Дней</string> <string name="wipe_on_inactivity_days">Дней</string>
<string name="notification_channel_default_name">Дефолт</string> <string name="notification_channel_default_name">Дефолт</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="wipe_job_service_description">Стереть данные при неактивности</string> <string name="wipe_job_description">Стереть данные при неактивности</string>
<string name="wipe_job_service_start_failed_popup">Не удалось запустить сервис стирания данных</string> <string name="wipe_job_schedule_failed_popup">Не удалось запланировать сервис стирания данных</string>
<string name="unlock_service_description">Получать события разблокировки</string> <string name="unlock_service_description">Получать события разблокировки</string>
<string name="unlock_service_notification_title">Служба Разблокировки</string> <string name="unlock_service_notification_title">Служба Разблокировки</string>
<string name="dialog_confirm_panic_title">Подтвердите</string> <string name="dialog_confirm_panic_title">Подтвердите</string>

View File

@ -20,8 +20,8 @@
<string name="wipe_on_inactivity_days">Days</string> <string name="wipe_on_inactivity_days">Days</string>
<string name="notification_channel_default_name">Default</string> <string name="notification_channel_default_name">Default</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="wipe_job_service_description">Wipe a device on inactivity</string> <string name="wipe_job_description">Wipe a device on inactivity</string>
<string name="wipe_job_service_start_failed_popup">Failed to start a wipe service</string> <string name="wipe_job_schedule_failed_popup">Failed to schedule a wipe service</string>
<string name="unlock_service_description">Receive unlock events</string> <string name="unlock_service_description">Receive unlock events</string>
<string name="unlock_service_notification_title">Unlock Service</string> <string name="unlock_service_notification_title">Unlock Service</string>
<string name="dialog_confirm_panic_title">Confirm</string> <string name="dialog_confirm_panic_title">Confirm</string>