Option to disable captcha notification for specific source (#1253 #1300)

master
Koitharu 1 year ago
parent c835ebff3f
commit 1fa470fd00
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -18,6 +18,7 @@ import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
import org.koitharu.kotatsu.core.model.getTitle import org.koitharu.kotatsu.core.model.getTitle
import org.koitharu.kotatsu.core.model.isNsfw import org.koitharu.kotatsu.core.model.isNsfw
import org.koitharu.kotatsu.core.nav.AppRouter 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.core.util.ext.checkNotificationPermission
import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.model.MangaSource
@ -29,6 +30,9 @@ class CaptchaNotifier(
if (!context.checkNotificationPermission(CHANNEL_ID)) { if (!context.checkNotificationPermission(CHANNEL_ID)) {
return return
} }
if (exception.source != null && SourceSettings(context, exception.source).isCaptchaNotificationsDisabled) {
return
}
val manager = NotificationManagerCompat.from(context) val manager = NotificationManagerCompat.from(context)
val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW) val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW)
.setName(context.getString(R.string.captcha_required)) .setName(context.getString(R.string.captcha_required))

@ -25,6 +25,9 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
val isSlowdownEnabled: Boolean val isSlowdownEnabled: Boolean
get() = prefs.getBoolean(KEY_SLOWDOWN, false) get() = prefs.getBoolean(KEY_SLOWDOWN, false)
val isCaptchaNotificationsDisabled: Boolean
get() = prefs.getBoolean(KEY_NO_CAPTCHA, false)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun <T> get(key: ConfigKey<T>): T { override fun <T> get(key: ConfigKey<T>): T {
return when (key) { return when (key) {
@ -65,5 +68,6 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
const val KEY_SORT_ORDER = "sort_order" const val KEY_SORT_ORDER = "sort_order"
const val KEY_SLOWDOWN = "slowdown" const val KEY_SLOWDOWN = "slowdown"
const val KEY_NO_CAPTCHA = "no_captcha"
} }
} }

@ -804,4 +804,6 @@
<string name="search_everywhere">Search everywhere</string> <string name="search_everywhere">Search everywhere</string>
<string name="simple">Simple</string> <string name="simple">Simple</string>
<string name="global_search">Global search</string> <string name="global_search">Global search</string>
<string name="disable_captcha_notifications">Disable captcha notifications</string>
<string name="disable_captcha_notifications_summary">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)</string>
</resources> </resources>

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
@ -11,6 +12,13 @@
android:persistent="false" android:persistent="false"
android:title="@string/enable_source" /> android:title="@string/enable_source" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="no_captcha"
android:order="104"
android:summary="@string/disable_captcha_notifications_summary"
android:title="@string/disable_captcha_notifications" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="slowdown" android:key="slowdown"
@ -25,6 +33,7 @@
android:persistent="false" android:persistent="false"
android:title="@string/open_in_browser" android:title="@string/open_in_browser"
app:allowDividerAbove="true" app:allowDividerAbove="true"
app:isPreferenceVisible="false" /> app:isPreferenceVisible="false"
tools:isPreferenceVisible="true" />
</PreferenceScreen> </PreferenceScreen>

Loading…
Cancel
Save