Update notification enhancement

This commit is contained in:
Koitharu
2020-04-02 20:39:15 +03:00
parent 3f31bd5ad1
commit 4c3dbe1643
4 changed files with 31 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -80,8 +81,18 @@ class AppUpdateService : BaseService() {
PendingIntent.FLAG_CANCEL_CURRENT
)
)
builder.addAction(
R.drawable.ic_download, getString(R.string.download),
PendingIntent.getActivity(
this,
NOTIFICATION_ID + 1,
Intent(Intent.ACTION_VIEW, Uri.parse(newVersion.apkUrl)),
PendingIntent.FLAG_CANCEL_CURRENT
)
)
builder.setSmallIcon(R.drawable.ic_stat_update)
builder.setAutoCancel(true)
builder.setColor(ContextCompat.getColor(this, R.color.blue_primary_dark))
builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
manager.notify(NOTIFICATION_ID, builder.build())
}
@@ -92,8 +103,12 @@ class AppUpdateService : BaseService() {
private const val CHANNEL_ID = "update"
private val PERIOD = TimeUnit.HOURS.toMillis(6)
fun start(context: Context) =
context.startService(Intent(context, AppUpdateService::class.java))
fun start(context: Context) {
try {
context.startService(Intent(context, AppUpdateService::class.java))
} catch (_: IllegalStateException) {
}
}
fun startIfRequired(context: Context) {
val settings = AppSettings(context)

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M13,5V11H14.17L12,13.17L9.83,11H11V5H13M15,3H9V9H5L12,16L19,9H15V3M19,18H5V20H19V18Z" />
</vector>

View File

@@ -115,4 +115,5 @@
<string name="enabled_d_from_d">Включено %1$d из %2$d</string>
<string name="new_chapters">Новые главы</string>
<string name="show_notification_new_chapters">Уведомлять об обновлении манги, которую Вы читаете</string>
<string name="download">Загрузить</string>
</resources>

View File

@@ -116,4 +116,5 @@
<string name="enabled_d_from_d">Enabled %1$d from %2$d</string>
<string name="new_chapters">New chapters</string>
<string name="show_notification_new_chapters">Notify about updates of manga you are reading</string>
<string name="download">Download</string>
</resources>