mirror of
https://github.com/lone-cloud/prism-android
synced 2026-06-03 19:54:44 -07:00
Change notification channels ID
This commit is contained in:
parent
ac22124244
commit
733570bb50
3 changed files with 46 additions and 2 deletions
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.unifiedpush.distributor.sunup
|
||||||
|
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import org.unifiedpush.distributor.MigrationFactory
|
||||||
|
|
||||||
|
class Migrations(context: Context) : MigrationFactory(context, AppStore.PREF_NAME) {
|
||||||
|
|
||||||
|
override val migrations = listOf(
|
||||||
|
Migration000201
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration from 0.x.x to 0.2.1
|
||||||
|
*/
|
||||||
|
object Migration000201 : Migration {
|
||||||
|
override val version = 201
|
||||||
|
override fun run(context: Context) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
removeOldOsNotificationChannel(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration to remove old notifications channel, they will be recreated
|
||||||
|
* once needed. We used app_name as a prefix, but this can be buggy with
|
||||||
|
* debug env.
|
||||||
|
*/
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
fun removeOldOsNotificationChannel(context: Context) {
|
||||||
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
val oldPrefix = context.getString(R.string.app_name)
|
||||||
|
notificationManager.notificationChannels.forEach {
|
||||||
|
if (it.id.startsWith(oldPrefix)) {
|
||||||
|
notificationManager.deleteNotificationChannel(it.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.unifiedpush.distributor.sunup.EventBus
|
import org.unifiedpush.distributor.sunup.EventBus
|
||||||
|
import org.unifiedpush.distributor.sunup.Migrations
|
||||||
import org.unifiedpush.distributor.sunup.activities.ui.MainUi
|
import org.unifiedpush.distributor.sunup.activities.ui.MainUi
|
||||||
import org.unifiedpush.distributor.sunup.activities.ui.theme.AppTheme
|
import org.unifiedpush.distributor.sunup.activities.ui.theme.AppTheme
|
||||||
import org.unifiedpush.distributor.sunup.services.RestartWorker
|
import org.unifiedpush.distributor.sunup.services.RestartWorker
|
||||||
|
|
@ -22,6 +23,7 @@ class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
RestartWorker.startPeriodic(this)
|
RestartWorker.startPeriodic(this)
|
||||||
|
Migrations(this).run()
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val viewModel =
|
val viewModel =
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class MainNotificationData(
|
||||||
|
|
||||||
private val Context.warningChannelData: AppNotification.ChannelData
|
private val Context.warningChannelData: AppNotification.ChannelData
|
||||||
get() = AppNotification.ChannelData(
|
get() = AppNotification.ChannelData(
|
||||||
"${this.getString(R.string.app_name)}.Warning",
|
"Warning",
|
||||||
this.getString(LibR.string.warning),
|
this.getString(LibR.string.warning),
|
||||||
NotificationManager.IMPORTANCE_HIGH,
|
NotificationManager.IMPORTANCE_HIGH,
|
||||||
this.resources.getString(LibR.string.warning_notif_description).format(this.getString(R.string.app_name))
|
this.resources.getString(LibR.string.warning_notif_description).format(this.getString(R.string.app_name))
|
||||||
|
|
@ -71,7 +71,7 @@ class ForegroundNotification(context: Context) : AppNotification(
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
ChannelData(
|
ChannelData(
|
||||||
"${context.getString(R.string.app_name)}.Listener",
|
"Foreground",
|
||||||
context.getString(LibR.string.foreground_service),
|
context.getString(LibR.string.foreground_service),
|
||||||
NotificationManager.IMPORTANCE_LOW,
|
NotificationManager.IMPORTANCE_LOW,
|
||||||
context.getString(LibR.string.foreground_notif_description)
|
context.getString(LibR.string.foreground_notif_description)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue