From 7a65ae3ea76bfc64cee9abc2c21df0261c7ccf3d Mon Sep 17 00:00:00 2001 From: plum7x Date: Sun, 23 Jul 2023 15:06:08 +0200 Subject: [PATCH 1/5] Translated using Weblate (Chinese (Traditional)) Currently translated at 100.0% (447 of 447 strings) Co-authored-by: plum7x Translate-URL: https://hosted.weblate.org/projects/kotatsu/strings/zh_Hant/ Translation: Kotatsu/Strings --- app/src/main/res/values-zh-rTW/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0f4a767ec..126299d23 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -64,7 +64,7 @@ 選擇 ZIP 或 CBZ 檔案。 您可以在閱讀漫畫時建立書籤 您將會收到您正在閱讀的漫畫的更新通知 - 一些设备有不同的系统行为,这可能会破坏后台任务。 + 一些裝置有不同的系統行為,這可能會破壞背景任務。 輸入密碼以啟動應用程式 在啟動 Kotatsu 時要求密碼 此漫畫沒有章節 @@ -75,7 +75,7 @@ 密碼必須是 4 個字元以上 不支援在 %s 上登錄 \"%s\" 已從本機儲存區中刪除 - 典籍兩次返回鍵以退出應用程式 + 點擊兩次返回鍵以退出應用程式 啟用漫畫來源以閱讀線上漫畫 永久清除所有閱讀歷史紀錄\? 從裝置中永久刪除 \"%s\"\? -- 2.54.0 From 0c37265a5bbdcc5a8c61e5cc6ec4243dd49b0de2 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 22 Jul 2023 14:31:15 +0300 Subject: [PATCH 2/5] Update parsers --- app/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 437bcdef7..d468f00b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { //TODO: update as soon as sources becomes available //noinspection OldTargetApi targetSdkVersion 33 - versionCode 565 - versionName '5.3.8' + versionCode 566 + versionName '5.3.9' generatedDensities = [] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -81,7 +81,7 @@ afterEvaluate { } dependencies { //noinspection GradleDependency - implementation('com.github.KotatsuApp:kotatsu-parsers:69e0a531df') { + implementation('com.github.KotatsuApp:kotatsu-parsers:42cc0430f8') { exclude group: 'org.json', module: 'json' } @@ -138,8 +138,8 @@ dependencies { implementation 'com.github.solkin:disk-lru-cache:1.4' implementation 'io.noties.markwon:core:4.6.2' - implementation 'ch.acra:acra-http:5.10.1' - implementation 'ch.acra:acra-dialog:5.10.1' + implementation 'ch.acra:acra-http:5.11.0' + implementation 'ch.acra:acra-dialog:5.11.0' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12' -- 2.54.0 From 42bb5a65ab8adedc02977e6c4215d32c37df8ab8 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 24 Jul 2023 16:08:25 +0300 Subject: [PATCH 3/5] Fix crash in ScrobblingInfoSheet --- .../details/ui/scrobbling/ScrobblingInfoSheet.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/scrobbling/ScrobblingInfoSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/scrobbling/ScrobblingInfoSheet.kt index faa310f6b..c48304386 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/scrobbling/ScrobblingInfoSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/scrobbling/ScrobblingInfoSheet.kt @@ -121,13 +121,14 @@ class ScrobblingInfoSheet : dismissAllowingStateLoss() return } - requireViewBinding().textViewTitle.text = scrobbling.title - requireViewBinding().ratingBar.rating = scrobbling.rating * requireViewBinding().ratingBar.numStars - requireViewBinding().textViewDescription.text = scrobbling.description?.sanitize() - requireViewBinding().spinnerStatus.setSelection(scrobbling.status?.ordinal ?: -1) - requireViewBinding().imageViewLogo.contentDescription = getString(scrobbling.scrobbler.titleResId) - requireViewBinding().imageViewLogo.setImageResource(scrobbling.scrobbler.iconResId) - requireViewBinding().imageViewCover.newImageRequest(viewLifecycleOwner, scrobbling.coverUrl)?.apply { + val binding = viewBinding ?: return + binding.textViewTitle.text = scrobbling.title + binding.ratingBar.rating = scrobbling.rating * binding.ratingBar.numStars + binding.textViewDescription.text = scrobbling.description?.sanitize() + binding.spinnerStatus.setSelection(scrobbling.status?.ordinal ?: -1) + binding.imageViewLogo.contentDescription = getString(scrobbling.scrobbler.titleResId) + binding.imageViewLogo.setImageResource(scrobbling.scrobbler.iconResId) + binding.imageViewCover.newImageRequest(viewLifecycleOwner, scrobbling.coverUrl)?.apply { placeholder(R.drawable.ic_placeholder) fallback(R.drawable.ic_placeholder) error(R.drawable.ic_error_placeholder) -- 2.54.0 From 07af79a6bd3797059b465a0ca562041dfd5cc9eb Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 25 Jul 2023 09:42:55 +0300 Subject: [PATCH 4/5] Update parsers --- app/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d468f00b9..cde956463 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { //TODO: update as soon as sources becomes available //noinspection OldTargetApi targetSdkVersion 33 - versionCode 566 - versionName '5.3.9' + versionCode 567 + versionName '5.3.10' generatedDensities = [] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -81,7 +81,7 @@ afterEvaluate { } dependencies { //noinspection GradleDependency - implementation('com.github.KotatsuApp:kotatsu-parsers:42cc0430f8') { + implementation('com.github.KotatsuApp:kotatsu-parsers:8e452f4271') { exclude group: 'org.json', module: 'json' } -- 2.54.0 From 08f3880db65c32527d4fb28accb6eb3eed319276 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 26 Jul 2023 06:24:37 +0530 Subject: [PATCH 5/5] Add uses of NotificationManagerCompat and related classes --- .../ui/worker/DownloadNotificationFactory.kt | 28 +++----- .../koitharu/kotatsu/local/ui/ImportWorker.kt | 25 ++++--- .../local/ui/LocalChaptersRemoveService.kt | 22 +++---- .../suggestions/ui/SuggestionsWorker.kt | 50 ++++++-------- .../kotatsu/tracker/work/TrackWorker.kt | 30 ++++----- .../work/TrackerNotificationChannels.kt | 66 +++++++------------ 6 files changed, 89 insertions(+), 132 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt index 41568e832..5cc5eb747 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt @@ -1,13 +1,11 @@ package org.koitharu.kotatsu.download.ui.worker import android.app.Notification -import android.app.NotificationChannel -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.graphics.drawable.Drawable -import android.os.Build import android.text.format.DateUtils +import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat @@ -24,6 +22,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.details.ui.DetailsActivity import org.koitharu.kotatsu.download.domain.DownloadState import org.koitharu.kotatsu.download.ui.list.DownloadsActivity @@ -32,7 +31,6 @@ import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.util.format import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.search.ui.MangaListActivity -import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import java.util.UUID import com.google.android.material.R as materialR @@ -246,20 +244,14 @@ class DownloadNotificationFactory @AssistedInject constructor( } private fun createChannel() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val manager = NotificationManagerCompat.from(context) - if (manager.getNotificationChannel(CHANNEL_ID) == null) { - val channel = NotificationChannel( - CHANNEL_ID, - context.getString(R.string.downloads), - NotificationManager.IMPORTANCE_LOW, - ) - channel.enableVibration(false) - channel.enableLights(false) - channel.setSound(null, null) - manager.createNotificationChannel(channel) - } - } + val manager = NotificationManagerCompat.from(context) + val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(context.getString(R.string.downloads)) + .setVibrationEnabled(false) + .setLightsEnabled(false) + .setSound(null, null) + .build() + manager.createNotificationChannel(channel) } @AssistedFactory diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/ImportWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/ImportWorker.kt index fc719ae5b..083abb1c9 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/ImportWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/ImportWorker.kt @@ -1,13 +1,12 @@ package org.koitharu.kotatsu.local.ui import android.app.Notification -import android.app.NotificationChannel -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.net.Uri -import android.os.Build +import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat import androidx.hilt.work.HiltWorker import androidx.work.Constraints @@ -39,9 +38,7 @@ class ImportWorker @AssistedInject constructor( private val coil: ImageLoader ) : CoroutineWorker(appContext, params) { - private val notificationManager by lazy { - applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - } + private val notificationManager by lazy { NotificationManagerCompat.from(appContext) } override suspend fun doWork(): Result { val uri = inputData.getString(DATA_URI)?.toUriOrNull() ?: return Result.failure() @@ -56,14 +53,14 @@ class ImportWorker @AssistedInject constructor( override suspend fun getForegroundInfo(): ForegroundInfo { val title = applicationContext.getString(R.string.importing_manga) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel(CHANNEL_ID, title, NotificationManager.IMPORTANCE_LOW) - channel.setShowBadge(false) - channel.enableVibration(false) - channel.setSound(null, null) - channel.enableLights(false) - notificationManager.createNotificationChannel(channel) - } + val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(title) + .setShowBadge(false) + .setVibrationEnabled(false) + .setSound(null, null) + .setLightsEnabled(false) + .build() + notificationManager.createNotificationChannel(channel) val notification = NotificationCompat.Builder(applicationContext, CHANNEL_ID) .setContentTitle(title) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/LocalChaptersRemoveService.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/LocalChaptersRemoveService.kt index 09a87391e..b26447821 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/LocalChaptersRemoveService.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/LocalChaptersRemoveService.kt @@ -1,11 +1,11 @@ package org.koitharu.kotatsu.local.ui -import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent -import android.os.Build +import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import androidx.core.app.ServiceCompat import androidx.core.content.ContextCompat import dagger.hilt.android.AndroidEntryPoint @@ -67,15 +67,15 @@ class LocalChaptersRemoveService : CoroutineIntentService() { private fun startForeground() { val title = getString(R.string.local_manga_processing) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val channel = NotificationChannel(CHANNEL_ID, title, NotificationManager.IMPORTANCE_LOW) - channel.setShowBadge(false) - channel.enableVibration(false) - channel.setSound(null, null) - channel.enableLights(false) - manager.createNotificationChannel(channel) - } + val manager = NotificationManagerCompat.from(this) + val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(title) + .setShowBadge(false) + .setVibrationEnabled(false) + .setSound(null, null) + .setLightsEnabled(false) + .build() + manager.createNotificationChannel(channel) val notification = NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle(title) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt index e8e2700f4..f46cb0054 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt @@ -1,12 +1,11 @@ package org.koitharu.kotatsu.suggestions.ui -import android.app.NotificationChannel -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context -import android.os.Build import androidx.annotation.FloatRange +import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat import androidx.core.text.HtmlCompat import androidx.core.text.buildSpannedString @@ -77,6 +76,8 @@ class SuggestionsWorker @AssistedInject constructor( private val mangaRepositoryFactory: MangaRepository.Factory, ) : CoroutineWorker(appContext, params) { + private val notificationManager by lazy { NotificationManagerCompat.from(appContext) } + override suspend fun doWork(): Result { trySetForeground() if (!appSettings.isSuggestionsEnabled) { @@ -89,20 +90,15 @@ class SuggestionsWorker @AssistedInject constructor( } override suspend fun getForegroundInfo(): ForegroundInfo { - val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val title = applicationContext.getString(R.string.suggestions_updating) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel( - WORKER_CHANNEL_ID, - title, - NotificationManager.IMPORTANCE_LOW, - ) - channel.setShowBadge(false) - channel.enableVibration(false) - channel.setSound(null, null) - channel.enableLights(false) - manager.createNotificationChannel(channel) - } + val channel = NotificationChannelCompat.Builder(WORKER_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(title) + .setShowBadge(true) + .setVibrationEnabled(false) + .setSound(null, null) + .setLightsEnabled(true) + .build() + notificationManager.createNotificationChannel(channel) val notification = NotificationCompat.Builder(applicationContext, WORKER_CHANNEL_ID) .setContentTitle(title) @@ -203,18 +199,14 @@ class SuggestionsWorker @AssistedInject constructor( }.getOrDefault(emptyList()) private suspend fun showNotification(manga: Manga) { - val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel( - MANGA_CHANNEL_ID, - applicationContext.getString(R.string.suggestions), - NotificationManager.IMPORTANCE_DEFAULT, - ) - channel.description = applicationContext.getString(R.string.suggestions_summary) - channel.enableLights(true) - channel.setShowBadge(true) - manager.createNotificationChannel(channel) - } + val channel = NotificationChannelCompat.Builder(MANGA_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_DEFAULT) + .setName(applicationContext.getString(R.string.suggestions)) + .setDescription(applicationContext.getString(R.string.suggestions_summary)) + .setLightsEnabled(true) + .setShowBadge(true) + .build() + notificationManager.createNotificationChannel(channel) + val id = manga.url.hashCode() val title = applicationContext.getString(R.string.suggestion_manga, manga.title) val builder = NotificationCompat.Builder(applicationContext, MANGA_CHANNEL_ID) @@ -284,7 +276,7 @@ class SuggestionsWorker @AssistedInject constructor( ), ) } - manager.notify(TAG, id, builder.build()) + notificationManager.notify(TAG, id, builder.build()) } @FloatRange(from = 0.0, to = 1.0) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackWorker.kt index 2880969dc..11c636b5e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackWorker.kt @@ -1,13 +1,13 @@ package org.koitharu.kotatsu.tracker.work -import android.app.NotificationChannel -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.os.Build +import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.VISIBILITY_PUBLIC import androidx.core.app.NotificationCompat.VISIBILITY_SECRET +import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat import androidx.core.content.ContextCompat import androidx.hilt.work.HiltWorker @@ -64,10 +64,7 @@ class TrackWorker @AssistedInject constructor( private val tracker: Tracker, @TrackerLogger private val logger: FileLogger, ) : CoroutineWorker(context, workerParams) { - - private val notificationManager by lazy { - applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - } + private val notificationManager by lazy { NotificationManagerCompat.from(applicationContext) } override suspend fun doWork(): Result { trySetForeground() @@ -204,18 +201,15 @@ class TrackWorker @AssistedInject constructor( override suspend fun getForegroundInfo(): ForegroundInfo { val title = applicationContext.getString(R.string.check_for_new_chapters) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel( - WORKER_CHANNEL_ID, - title, - NotificationManager.IMPORTANCE_LOW, - ) - channel.setShowBadge(false) - channel.enableVibration(false) - channel.setSound(null, null) - channel.enableLights(false) - notificationManager.createNotificationChannel(channel) - } + val channel = NotificationChannelCompat.Builder(WORKER_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(title) + .setShowBadge(false) + .setVibrationEnabled(false) + .setSound(null, null) + .setLightsEnabled(false) + .build() + notificationManager.createNotificationChannel(channel) + val notification = NotificationCompat.Builder(applicationContext, WORKER_CHANNEL_ID) .setContentTitle(title) .setPriority(NotificationCompat.PRIORITY_MIN) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationChannels.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationChannels.kt index 3c100b6a0..4525aa9b3 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationChannels.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationChannels.kt @@ -1,11 +1,10 @@ package org.koitharu.kotatsu.tracker.work -import android.app.NotificationChannel -import android.app.NotificationChannelGroup import android.app.NotificationManager import android.content.Context import android.os.Build -import androidx.annotation.RequiresApi +import androidx.core.app.NotificationChannelCompat +import androidx.core.app.NotificationChannelGroupCompat import androidx.core.app.NotificationManagerCompat import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject @@ -24,9 +23,6 @@ class TrackerNotificationChannels @Inject constructor( get() = !manager.areNotificationsEnabled() fun updateChannels(categories: Collection) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - return - } manager.deleteNotificationChannel(OLD_CHANNEL_ID) val group = createGroup() val existingChannels = group.channels.associateByTo(HashMap()) { it.id } @@ -35,8 +31,10 @@ class TrackerNotificationChannels @Inject constructor( if (existingChannels.remove(id)?.name == category.title) { continue } - val channel = NotificationChannel(id, category.title, NotificationManager.IMPORTANCE_DEFAULT) - channel.group = GROUP_ID + val channel = NotificationChannelCompat.Builder(id, NotificationManagerCompat.IMPORTANCE_DEFAULT) + .setName(category.title) + .setGroup(GROUP_ID) + .build() manager.createNotificationChannel(channel) } existingChannels.remove(CHANNEL_ID_HISTORY) @@ -47,23 +45,15 @@ class TrackerNotificationChannels @Inject constructor( } fun createChannel(category: FavouriteCategory) { - renameChannel(category.id, category.title) - } - - fun renameChannel(categoryId: Long, name: String) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - return - } - val id = getFavouritesChannelId(categoryId) - val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT) - channel.group = createGroup().id + val id = getFavouritesChannelId(category.id) + val channel = NotificationChannelCompat.Builder(id, NotificationManagerCompat.IMPORTANCE_DEFAULT) + .setName(category.title) + .setGroup(createGroup().id) + .build() manager.createNotificationChannel(channel) } fun deleteChannel(categoryId: Long) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - return - } manager.deleteNotificationChannel(getFavouritesChannelId(categoryId)) } @@ -97,11 +87,8 @@ class TrackerNotificationChannels @Inject constructor( if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return settings.isTrackerNotificationsEnabled } - val group = manager.getNotificationChannelGroup(GROUP_ID) ?: return true - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && group.isBlocked) { - return false - } - return group.channels.any { it.importance != NotificationManagerCompat.IMPORTANCE_NONE } + val group = manager.getNotificationChannelGroupCompat(GROUP_ID) ?: return true + return !group.isBlocked && group.channels.any { it.importance != NotificationManagerCompat.IMPORTANCE_NONE } } fun getFavouritesChannelId(categoryId: Long): String { @@ -112,26 +99,21 @@ class TrackerNotificationChannels @Inject constructor( return CHANNEL_ID_HISTORY } - @RequiresApi(Build.VERSION_CODES.O) - private fun createGroup(): NotificationChannelGroup { - manager.getNotificationChannelGroup(GROUP_ID)?.let { - return it + private fun createGroup(): NotificationChannelGroupCompat { + return manager.getNotificationChannelGroupCompat(GROUP_ID) ?: run { + val group = NotificationChannelGroupCompat.Builder(GROUP_ID) + .setName(context.getString(R.string.new_chapters)) + .build() + manager.createNotificationChannelGroup(group) + group } - val group = NotificationChannelGroup(GROUP_ID, context.getString(R.string.new_chapters)) - manager.createNotificationChannelGroup(group) - return group } private fun createHistoryChannel() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - return - } - val channel = NotificationChannel( - CHANNEL_ID_HISTORY, - context.getString(R.string.history), - NotificationManager.IMPORTANCE_DEFAULT, - ) - channel.group = GROUP_ID + val channel = NotificationChannelCompat.Builder(CHANNEL_ID_HISTORY, NotificationManagerCompat.IMPORTANCE_DEFAULT) + .setName(context.getString(R.string.history)) + .setGroup(GROUP_ID) + .build() manager.createNotificationChannel(channel) } -- 2.54.0