Commit 603411a2 authored by Christophe Henry's avatar Christophe Henry

Fix notification not being collapsed by default

parent e3d47d60
......@@ -68,7 +68,7 @@ class FreshRSSApplication : Application() {
val database get() = application.database
val context: Context get() = application.applicationContext
val notificationManager: NotificationManagerCompat
get() = NotificationManagerCompat.from(FreshRSSApplication.application)
get() = NotificationManagerCompat.from(application)
val stateSharedPreferences: SharedPreferences
get() = context.getSharedPreferences("STATE", Context.MODE_PRIVATE)
......
......@@ -6,7 +6,7 @@ import android.content.Intent
import android.os.Binder
import androidx.core.app.NotificationCompat
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.utils.NotificationChanels
import fr.chenry.android.freshrss.utils.NotificationChannels
import fr.chenry.android.freshrss.utils.NotificationHelper
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.all
......@@ -18,10 +18,14 @@ class RefresherService : Service() {
private val refreshNotification =
createNotification(R.string.notification_refresh_title, R.string.notification_refresh_description)
.setCategory(Notification.CATEGORY_PROGRESS)
.setProgress(0, 0, true)
.setSmallIcon(R.drawable.ic_rss_feed_black_24dp)
.build()
private val failNotification =
createNotification(R.string.notification_refresh_failed_title, R.string.notification_refresh_failed_description)
.setCategory(Notification.CATEGORY_ERROR)
.setSmallIcon(R.drawable.ic_rss_feed_red_24dp)
.build()
override fun onBind(intent: Intent) = RefresherBinder()
......@@ -29,7 +33,8 @@ class RefresherService : Service() {
fun refresh(): Promise<Unit, Exception> {
if (Store.refreshingPromise.value != null) return Store.refreshingPromise.value!!
this.startForeground(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification)
FreshRSSApplication.notificationManager
.notify(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification)
Store.ensureToken()
......@@ -51,23 +56,20 @@ class RefresherService : Service() {
FreshRSSApplication
.notificationManager
.notify(NotificationHelper.FAIL_REFRESH_NOTIFICATION, failNotification)
}.alwaysUi {
FreshRSSApplication.notificationManager.cancel(NotificationHelper.ONGOING_REFRESH_NOTIFICATION)
}
.alwaysUi { stopForeground(true) }
return promise
}
private fun createNotification(title: Int, text: Int) = NotificationCompat
.Builder(FreshRSSApplication.application, NotificationChanels.REFRESH.channelId)
.setSmallIcon(R.drawable.ic_rss_feed_black_24dp)
.setStyle(
NotificationCompat
.BigTextStyle()
.setSummaryText(FreshRSSApplication.getStringR(title))
.bigText(FreshRSSApplication.getStringR(text)))
.setPriority(NotificationCompat.PRIORITY_LOW)
.Builder(FreshRSSApplication.application, NotificationChannels.REFRESH.channelId)
.setContentTitle(FreshRSSApplication.getStringR(title))
.setContentText(FreshRSSApplication.getStringR(text))
.setPriority(NotificationCompat.PRIORITY_MIN)
.setOngoing(true)
.setShowWhen(false)
.setContentInfo(FreshRSSApplication.getStringR(title))
inner class RefresherBinder : Binder() {
val service: RefresherService get() = this@RefresherService
......
......@@ -4,18 +4,15 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationManagerCompat
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.R
object NotificationHelper {
const val ONGOING_REFRESH_NOTIFICATION = 1
const val FAIL_REFRESH_NOTIFICATION = 2
fun cancel(id: Int) = NotificationManagerCompat.from(FreshRSSApplication.application).cancel(id)
}
enum class NotificationChanels(nameResourceId: Int, descriptionResourceId: Int, importance: Int? = null) {
enum class NotificationChannels(nameResourceId: Int, descriptionResourceId: Int, importance: Int? = null) {
REFRESH(R.string.notification_channel_refresh_title, R.string.notification_channel_refresh_description);
val channelId: String get() = this.name
......@@ -25,11 +22,11 @@ enum class NotificationChanels(nameResourceId: Int, descriptionResourceId: Int,
FreshRSSApplication.application.getSystemService(Context.NOTIFICATION_SERVICE).apply {
this as NotificationManager
val n = FreshRSSApplication.getStringR(nameResourceId)
val i = importance ?: NotificationManager.IMPORTANCE_LOW
NotificationChannel(channelId, n, i).let {
it.description = FreshRSSApplication.getStringR(descriptionResourceId)
createNotificationChannel(it)
}
val i = importance ?: NotificationManager.IMPORTANCE_MIN
NotificationChannel(channelId, n, i).apply {
description = FreshRSSApplication.getStringR(descriptionResourceId)
setSound(null, null)
}.apply(::createNotificationChannel)
}
}
}
......
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#E53935"
android:pathData="M6.18,17.82m-2.18,0a2.18,2.18 0,1 1,4.36 0a2.18,2.18 0,1 1,-4.36 0" />
<path
android:fillColor="#E53935"
android:pathData="M4,4.44v2.83c7.03,0 12.73,5.7 12.73,12.73h2.83c0,-8.59 -6.97,-15.56 -15.56,-15.56zM4,10.1v2.83c3.9,0 7.07,3.17 7.07,7.07h2.83c0,-5.47 -4.43,-9.9 -9.9,-9.9z" />
</vector>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment