feat: Update notification locale on locale change

This commit is contained in:
Myzel394 2023-08-06 15:32:54 +02:00
parent 3afc6a4053
commit 2439f42f42
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
6 changed files with 65 additions and 22 deletions

View File

@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
android:name=".RunningApp"
android:name=".UpdateSettingsApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
@ -29,6 +29,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".receivers.LocalChangeReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service android:name=".services.RecorderService" android:foregroundServiceType="microphone" />
</application>

View File

@ -0,0 +1,22 @@
package app.myzel394.alibi
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.annotation.RequiresApi
object NotificationHelper {
@RequiresApi(Build.VERSION_CODES.O)
fun createChannels(context: Context) {
val channel = NotificationChannel(
"recorder",
context.resources.getString(R.string.notificationChannels_recorder_name),
android.app.NotificationManager.IMPORTANCE_LOW,
)
channel.description = context.resources.getString(R.string.notificationChannels_recorder_description)
val notificationManager = context.getSystemService(NotificationManager::class.java)
notificationManager.createNotificationChannel(channel)
}
}

View File

@ -1,21 +0,0 @@
package app.myzel394.alibi
import android.app.Application
import android.app.NotificationChannel
import android.os.Build
class RunningApp: Application() {
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"recorder",
"Recorder",
android.app.NotificationManager.IMPORTANCE_LOW,
)
val notificationManager = getSystemService(android.app.NotificationManager::class.java)
notificationManager.createNotificationChannel(channel)
}
}
}

View File

@ -0,0 +1,16 @@
package app.myzel394.alibi
import android.app.Application
import android.app.NotificationChannel
import android.os.Build
import androidx.compose.ui.res.stringResource
class UpdateSettingsApp: Application() {
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationHelper.createChannels(this)
}
}
}

View File

@ -0,0 +1,15 @@
package app.myzel394.alibi.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import app.myzel394.alibi.NotificationHelper
class LocalChangeReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, p1: Intent?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationHelper.createChannels(context!!)
}
}
}

View File

@ -11,6 +11,9 @@
<string name="form_error_value_notInRange">Please enter a number between <xliff:g name="min">%s</xliff:g> and <xliff:g name="max">%s</xliff:g></string>
<string name="form_error_value_mustBeGreaterThan">Please enter a number greater than <xliff:g name="min">%s</xliff:g></string>
<string name="notificationChannels_recorder_name">Recorder</string>
<string name="notificationChannels_recorder_description">Shows the current recording status</string>
<string name="ui_permissions_request_title">Permission denied</string>
<string name="ui_permissions_request_message">Please grant the permission to continue. You will be redirected to the app settings to grant the permission there.</string>