forked from upstream-mirrors/quik
add expedited worker getForegroundInfo()/notification for android platform versions older than 12
This commit is contained in:
@@ -25,6 +25,7 @@ import androidx.work.WorkerFactory
|
||||
import androidx.work.WorkerParameters
|
||||
import dev.octoshrimpy.quik.interactor.ReceiveMms
|
||||
import dev.octoshrimpy.quik.interactor.ReceiveSms
|
||||
import dev.octoshrimpy.quik.manager.NotificationManager
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -32,6 +33,7 @@ class InjectionWorkerFactory @Inject constructor(
|
||||
private val receiveSms: ReceiveSms,
|
||||
private val receiveMms: ReceiveMms,
|
||||
private val scheduledMessageRepository: ScheduledMessageRepository,
|
||||
private val notificationManager: NotificationManager,
|
||||
) : WorkerFactory() {
|
||||
override fun createWorker(
|
||||
appContext: Context,
|
||||
@@ -47,10 +49,14 @@ class InjectionWorkerFactory @Inject constructor(
|
||||
when (instance) {
|
||||
is HousekeepingWorker ->
|
||||
instance.scheduledMessageRepository = scheduledMessageRepository
|
||||
is ReceiveSmsWorker ->
|
||||
is ReceiveSmsWorker -> {
|
||||
instance.receiveSms = receiveSms
|
||||
is ReceiveMmsWorker ->
|
||||
instance.notificationManager = notificationManager
|
||||
}
|
||||
is ReceiveMmsWorker -> {
|
||||
instance.receiveMms = receiveMms
|
||||
instance.notificationManager = notificationManager
|
||||
}
|
||||
}
|
||||
|
||||
return instance
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
package dev.octoshrimpy.quik.worker
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.ForegroundInfo
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import dev.octoshrimpy.quik.interactor.ReceiveMms
|
||||
import dev.octoshrimpy.quik.manager.NotificationManager
|
||||
import dev.octoshrimpy.quik.receiver.MmsReceivedReceiver
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@@ -37,11 +39,11 @@ class ReceiveMmsWorker(appContext: Context, workerParams: WorkerParameters)
|
||||
}
|
||||
|
||||
@Inject lateinit var receiveMms: ReceiveMms
|
||||
@Inject lateinit var notificationManager: NotificationManager
|
||||
|
||||
override fun doWork(): Result {
|
||||
Timber.v("started")
|
||||
|
||||
|
||||
MmsReceivedReceiver.onReceiveWorker(
|
||||
applicationContext,
|
||||
inputData.getInt(INPUT_DATA_SUBSCRIPTION_ID, -1),
|
||||
@@ -57,4 +59,9 @@ class ReceiveMmsWorker(appContext: Context, workerParams: WorkerParameters)
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
override fun getForegroundInfo() = ForegroundInfo(
|
||||
0,
|
||||
notificationManager.getForegroundNotificationForWorkersOnOlderAndroids()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
package dev.octoshrimpy.quik.worker
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.ForegroundInfo
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import dev.octoshrimpy.quik.interactor.ReceiveSms
|
||||
import dev.octoshrimpy.quik.manager.NotificationManager
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -32,6 +34,7 @@ class ReceiveSmsWorker(appContext: Context, workerParams: WorkerParameters)
|
||||
}
|
||||
|
||||
@Inject lateinit var receiveSms: ReceiveSms
|
||||
@Inject lateinit var notificationManager: NotificationManager
|
||||
|
||||
override fun doWork(): Result {
|
||||
Timber.v("started")
|
||||
@@ -50,4 +53,9 @@ class ReceiveSmsWorker(appContext: Context, workerParams: WorkerParameters)
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
override fun getForegroundInfo() = ForegroundInfo(
|
||||
0,
|
||||
notificationManager.getForegroundNotificationForWorkersOnOlderAndroids()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,13 @@
|
||||
*/
|
||||
package dev.octoshrimpy.quik.manager
|
||||
|
||||
import android.app.Notification
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
||||
interface NotificationManager {
|
||||
|
||||
fun getForegroundNotificationForWorkersOnOlderAndroids(): Notification
|
||||
|
||||
fun update(threadId: Long)
|
||||
|
||||
fun notifyFailed(threadId: Long)
|
||||
|
||||
@@ -90,6 +90,18 @@ class NotificationManagerImpl @Inject constructor(
|
||||
createNotificationChannel()
|
||||
}
|
||||
|
||||
override fun getForegroundNotificationForWorkersOnOlderAndroids() =
|
||||
NotificationCompat.Builder(context, DEFAULT_CHANNEL_ID)
|
||||
.setContentTitle(context.getString(R.string.notification_foreground_worker_text))
|
||||
.setShowWhen(false)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setColor(colors.theme().theme)
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||
.setOngoing(true)
|
||||
.build()
|
||||
|
||||
/**
|
||||
* Updates the notification for a particular conversation
|
||||
*/
|
||||
|
||||
@@ -487,6 +487,7 @@
|
||||
</plurals>
|
||||
<string name="notification_message_failed_title">Message not sent</string>
|
||||
<string name="notification_message_failed_text">The message to %s failed to send</string>
|
||||
<string name="notification_foreground_worker_text">Receiving message</string>
|
||||
|
||||
<string-array name="night_modes">
|
||||
<item>System</item>
|
||||
|
||||
Reference in New Issue
Block a user