Skip to content

Commit

Permalink
Create all notification channels in startup so that they are created …
Browse files Browse the repository at this point in the history
…for sure
  • Loading branch information
tuomas2 committed Jun 21, 2023
1 parent 0072cba commit fb30f13
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 60 deletions.
54 changes: 45 additions & 9 deletions app/src/main/java/net/bible/android/BibleApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ import net.bible.android.control.event.ToastEvent
import net.bible.android.control.report.BugReport
import net.bible.android.view.activity.base.ErrorActivity
import net.bible.android.view.util.locale.LocaleHelper
import net.bible.service.cloudsync.SYNC_NOTIFICATION_CHANNEL
import net.bible.service.common.BuildVariant
import net.bible.service.common.CommonUtils
import net.bible.service.device.ProgressNotificationManager
import net.bible.service.device.ProgressNotificationManager.Companion.PROGRESS_NOTIFICATION_CHANNEL
import net.bible.service.device.speak.SPEAK_NOTIFICATIONS_CHANNEL
import net.bible.service.sword.SwordDocumentFacade
import net.bible.service.sword.SwordEnvironmentInitialisation
import net.bible.service.sword.mybible.myBibleBible
Expand Down Expand Up @@ -152,6 +155,7 @@ open class BibleApplication : Application() {
// various initialisations required every time at app startup

localeOverrideAtStartUp = LocaleHelper.getOverrideLanguage(this)
createChannels()
}

var sqliteVersion = ""
Expand Down Expand Up @@ -275,15 +279,6 @@ open class BibleApplication : Application() {
if(BuildVariant.Appearance.isDiscrete) return

val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
ERROR_NOTIFICATION_CHANNEL,
getString(R.string.error_notification_channel_name), NotificationManager.IMPORTANCE_HIGH
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(channel)
}

val intent = Intent(this, ErrorActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
Expand All @@ -308,6 +303,47 @@ open class BibleApplication : Application() {
notificationManager.notify(GENERIC_NOTIFICATION_ID, notification)
}

fun createChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (BuildVariant.Appearance.isDiscrete) {
CommonUtils.createDiscreteNotificationChannel()
} else {
val errorChannel = NotificationChannel(
ERROR_NOTIFICATION_CHANNEL,
getString(R.string.error_notification_channel_name), NotificationManager.IMPORTANCE_HIGH
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(errorChannel)

val speakChannel = NotificationChannel(
SPEAK_NOTIFICATIONS_CHANNEL,
getString(R.string.notification_channel_tts_status), NotificationManager.IMPORTANCE_LOW
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(speakChannel)

val syncChannel = NotificationChannel(
SYNC_NOTIFICATION_CHANNEL,
getString(R.string.cloud_sync_title), NotificationManager.IMPORTANCE_NONE
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(syncChannel)

val progressChannel = NotificationChannel(
PROGRESS_NOTIFICATION_CHANNEL,
getString(R.string.notification_channel_progress_status), NotificationManager.IMPORTANCE_LOW
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(progressChannel)
}
}
}

companion object {
// this was moved from the MainBibleActivity and has always been called this
private const val saveStateTag = "MainBibleActivity"
Expand Down
18 changes: 1 addition & 17 deletions app/src/main/java/net/bible/service/cloudsync/SyncService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package net.bible.service.cloudsync

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
Expand All @@ -37,7 +35,7 @@ import net.bible.service.common.CALC_NOTIFICATION_CHANNEL
import net.bible.service.common.CommonUtils

private const val SYNC_NOTIFICATION_ID=2
private const val SYNC_NOTIFICATION_CHANNEL="sync-notifications"
const val SYNC_NOTIFICATION_CHANNEL="sync-notifications"
private const val WAKELOCK_TAG = "andbible:sync-wakelock"

class SyncService: Service() {
Expand Down Expand Up @@ -71,20 +69,6 @@ class SyncService: Service() {
throw RuntimeException("Wakelock already held, double-synchronize")
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(BuildVariant.Appearance.isDiscrete) {
CommonUtils.createDiscreteNotificationChannel()
} else {
val channel = NotificationChannel(
SYNC_NOTIFICATION_CHANNEL,
getString(R.string.cloud_sync_title), NotificationManager.IMPORTANCE_NONE
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(channel)
}
}

val builder = NotificationCompat.Builder(
this,
if(BuildVariant.Appearance.isDiscrete) CALC_NOTIFICATION_CHANNEL else SYNC_NOTIFICATION_CHANNEL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,6 @@ class ProgressNotificationManager {
fun initialise() {
Log.i(TAG, "Initializing")
notificationManager = BibleApplication.application.getSystemService(Application.NOTIFICATION_SERVICE) as NotificationManager
val app = BibleApplication.application

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (BuildVariant.Appearance.isDiscrete) {
CommonUtils.createDiscreteNotificationChannel()
} else {
val channel = NotificationChannel(
PROGRESS_NOTIFICATION_CHANNEL,
app.getString(R.string.notification_channel_progress_status), NotificationManager.IMPORTANCE_LOW
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(channel)
}
}


workListener = object : WorkListener {

override fun workProgressed(ev: WorkEvent) = synchronized(this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import net.bible.service.device.speak.event.SpeakProgressEvent
import java.util.*
import javax.inject.Inject

const val SPEAK_NOTIFICATIONS_CHANNEL="speak-notifications"

@ActivityScope
class TextToSpeechNotificationManager {
companion object {
Expand All @@ -58,8 +60,6 @@ class TextToSpeechNotificationManager {
private const val ACTION_FAST_FORWARD="action_fast_forward"
private const val ACTION_STOP="action_stop"

private const val SPEAK_NOTIFICATIONS_CHANNEL="speak-notifications"

private const val TTS_NOTIFICATION_ID=1

private const val WAKELOCK_TAG = "andbible:speak-wakelock"
Expand Down Expand Up @@ -211,21 +211,6 @@ class TextToSpeechNotificationManager {
app.registerReceiver(headsetReceiver, IntentFilter(Intent.ACTION_HEADSET_PLUG))

ABEventBus.register(this)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(BuildVariant.Appearance.isDiscrete) {
CommonUtils.createDiscreteNotificationChannel()
} else {
val channel = NotificationChannel(
SPEAK_NOTIFICATIONS_CHANNEL,
getString(R.string.notification_channel_tts_status), NotificationManager.IMPORTANCE_LOW
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
}
notificationManager.createNotificationChannel(channel)
}
}

}

fun destroy() {
Expand Down

0 comments on commit fb30f13

Please sign in to comment.