This commit is contained in:
lucky 2022-01-25 09:37:19 +03:00
parent c46c929ba6
commit 29612b5518
6 changed files with 22 additions and 29 deletions

View File

@ -1,25 +0,0 @@
package me.lucky.wasted
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
class AppNotificationManager(private val ctx: Context) {
companion object {
const val CHANNEL_DEFAULT_ID = "default"
}
private val manager = ctx.getSystemService(NotificationManager::class.java)
fun createNotificationChannels() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
manager?.createNotificationChannel(
NotificationChannel(
CHANNEL_DEFAULT_ID,
ctx.getString(R.string.notification_channel_default_name),
NotificationManager.IMPORTANCE_LOW,
)
)
}
}

View File

@ -45,7 +45,7 @@ class ForegroundService : Service() {
super.onStartCommand(intent, flags, startId)
startForeground(
NOTIFICATION_ID,
NotificationCompat.Builder(this, AppNotificationManager.CHANNEL_DEFAULT_ID)
NotificationCompat.Builder(this, NotificationManager.CHANNEL_DEFAULT_ID)
.setContentTitle(getString(R.string.foreground_service_notification_title))
.setSmallIcon(android.R.drawable.ic_delete)
.setPriority(NotificationCompat.PRIORITY_LOW)

View File

@ -56,7 +56,7 @@ open class MainActivity : AppCompatActivity() {
private fun init() {
prefs = Preferences(this)
admin = DeviceAdminManager(this)
AppNotificationManager(this).createNotificationChannels()
NotificationManager(this).createNotificationChannels()
if (prefs.code == "") prefs.code = makeCode()
updateCodeColorState()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) hideESIM()

View File

@ -0,0 +1,20 @@
package me.lucky.wasted
import android.content.Context
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
class NotificationManager(ctx: Context) {
companion object {
const val CHANNEL_DEFAULT_ID = "default"
}
private val manager = NotificationManagerCompat.from(ctx)
fun createNotificationChannels() {
manager.createNotificationChannel(NotificationChannelCompat.Builder(
CHANNEL_DEFAULT_ID,
NotificationManagerCompat.IMPORTANCE_LOW,
).build())
}
}

View File

@ -19,7 +19,6 @@
<string name="wipe_on_inactivity_switch">Стереть при неактивности</string>
<string name="wipe_on_inactivity_description">Стереть данные когда устройство не разблокируется N дней.</string>
<string name="wipe_on_inactivity_days">Дней</string>
<string name="notification_channel_default_name">Дефолт</string>
<string name="ok">OK</string>
<string name="wipe_job_description">Стереть данные при неактивности</string>
<string name="wipe_job_schedule_failed_popup">Не удалось запланировать сервис стирания данных</string>

View File

@ -19,7 +19,6 @@
<string name="wipe_on_inactivity_switch">Wipe on inactivity</string>
<string name="wipe_on_inactivity_description">Wipe a device when it was not unlocked for N days.</string>
<string name="wipe_on_inactivity_days">Days</string>
<string name="notification_channel_default_name">Default</string>
<string name="ok">OK</string>
<string name="wipe_job_description">Wipe a device on inactivity</string>
<string name="wipe_job_schedule_failed_popup">Failed to schedule a wipe job</string>