From 1fa470fd0034a0de147940293570e9e26cef7610 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 24 Feb 2025 14:39:16 +0200 Subject: [PATCH] Option to disable captcha notification for specific source (#1253 #1300) --- .../kotatsu/browser/cloudflare/CaptchaNotifier.kt | 4 ++++ .../koitharu/kotatsu/core/prefs/SourceSettings.kt | 4 ++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_source.xml | 13 +++++++++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/browser/cloudflare/CaptchaNotifier.kt b/app/src/main/kotlin/org/koitharu/kotatsu/browser/cloudflare/CaptchaNotifier.kt index c889e11dd..41ea4dc6c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/browser/cloudflare/CaptchaNotifier.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/browser/cloudflare/CaptchaNotifier.kt @@ -18,6 +18,7 @@ import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException import org.koitharu.kotatsu.core.model.getTitle import org.koitharu.kotatsu.core.model.isNsfw import org.koitharu.kotatsu.core.nav.AppRouter +import org.koitharu.kotatsu.core.prefs.SourceSettings import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission import org.koitharu.kotatsu.parsers.model.MangaSource @@ -29,6 +30,9 @@ class CaptchaNotifier( if (!context.checkNotificationPermission(CHANNEL_ID)) { return } + if (exception.source != null && SourceSettings(context, exception.source).isCaptchaNotificationsDisabled) { + return + } val manager = NotificationManagerCompat.from(context) val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) .setName(context.getString(R.string.captcha_required)) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt index 6e3425ffa..ab620658d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt @@ -25,6 +25,9 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig val isSlowdownEnabled: Boolean get() = prefs.getBoolean(KEY_SLOWDOWN, false) + val isCaptchaNotificationsDisabled: Boolean + get() = prefs.getBoolean(KEY_NO_CAPTCHA, false) + @Suppress("UNCHECKED_CAST") override fun get(key: ConfigKey): T { return when (key) { @@ -65,5 +68,6 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig const val KEY_SORT_ORDER = "sort_order" const val KEY_SLOWDOWN = "slowdown" + const val KEY_NO_CAPTCHA = "no_captcha" } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5fa50193..6023f5a7c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -804,4 +804,6 @@ Search everywhere Simple Global search + Disable captcha notifications + You will not receive notifications about solving CAPTCHA for this source but this can lead to breaking background operations (checking for new chapters, obtaining recommendations, etc) diff --git a/app/src/main/res/xml/pref_source.xml b/app/src/main/res/xml/pref_source.xml index 42798249a..1a6d65fc5 100644 --- a/app/src/main/res/xml/pref_source.xml +++ b/app/src/main/res/xml/pref_source.xml @@ -1,7 +1,8 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> + + + app:isPreferenceVisible="false" + tools:isPreferenceVisible="true" />