Option to use disabled sources for suggestions

master
Koitharu 1 year ago
parent 7a663fa9c1
commit 7003463bac
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -22,6 +22,7 @@ import org.koitharu.kotatsu.parsers.model.ContentType
import org.koitharu.kotatsu.parsers.model.MangaParserSource import org.koitharu.kotatsu.parsers.model.MangaParserSource
import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.util.splitTwoParts import org.koitharu.kotatsu.parsers.util.splitTwoParts
import java.util.Locale
import com.google.android.material.R as materialR import com.google.android.material.R as materialR
data object LocalMangaSource : MangaSource { data object LocalMangaSource : MangaSource {
@ -79,6 +80,8 @@ tailrec fun MangaSource.unwrap(): MangaSource = if (this is MangaSourceInfo) {
this this
} }
fun MangaSource.getLocale(): Locale? = (unwrap() as? MangaParserSource)?.locale?.toLocale()
fun MangaSource.getSummary(context: Context): String? = when (val source = unwrap()) { fun MangaSource.getSummary(context: Context): String? = when (val source = unwrap()) {
is MangaParserSource -> { is MangaParserSource -> {
val type = context.getString(source.contentType.titleResId) val type = context.getString(source.contentType.titleResId)

@ -359,6 +359,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
val isSuggestionsExcludeNsfw: Boolean val isSuggestionsExcludeNsfw: Boolean
get() = prefs.getBoolean(KEY_SUGGESTIONS_EXCLUDE_NSFW, false) get() = prefs.getBoolean(KEY_SUGGESTIONS_EXCLUDE_NSFW, false)
val isSuggestionsIncludeDisabledSources: Boolean
get() = prefs.getBoolean(KEY_SUGGESTIONS_DISABLED_SOURCES, false)
val isSuggestionsNotificationAvailable: Boolean val isSuggestionsNotificationAvailable: Boolean
get() = prefs.getBoolean(KEY_SUGGESTIONS_NOTIFICATIONS, false) get() = prefs.getBoolean(KEY_SUGGESTIONS_NOTIFICATIONS, false)
@ -658,6 +661,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY_SUGGESTIONS_WIFI_ONLY = "suggestions_wifi" const val KEY_SUGGESTIONS_WIFI_ONLY = "suggestions_wifi"
const val KEY_SUGGESTIONS_EXCLUDE_NSFW = "suggestions_exclude_nsfw" const val KEY_SUGGESTIONS_EXCLUDE_NSFW = "suggestions_exclude_nsfw"
const val KEY_SUGGESTIONS_EXCLUDE_TAGS = "suggestions_exclude_tags" const val KEY_SUGGESTIONS_EXCLUDE_TAGS = "suggestions_exclude_tags"
const val KEY_SUGGESTIONS_DISABLED_SOURCES = "suggestions_disabled_sources"
const val KEY_SUGGESTIONS_NOTIFICATIONS = "suggestions_notifications" const val KEY_SUGGESTIONS_NOTIFICATIONS = "suggestions_notifications"
const val KEY_SHIKIMORI = "shikimori" const val KEY_SHIKIMORI = "shikimori"
const val KEY_ANILIST = "anilist" const val KEY_ANILIST = "anilist"

@ -6,7 +6,6 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.room.withTransaction import androidx.room.withTransaction
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -354,7 +353,7 @@ class MangaSourcesRepository @Inject constructor(
.conflate() .conflate()
} }
private fun getExternalSources() = context.packageManager.queryIntentContentProviders( fun getExternalSources(): List<ExternalMangaSource> = context.packageManager.queryIntentContentProviders(
Intent("app.kotatsu.parser.PROVIDE_MANGA"), 0, Intent("app.kotatsu.parser.PROVIDE_MANGA"), 0,
).map { resolveInfo -> ).map { resolveInfo ->
ExternalMangaSource( ExternalMangaSource(

@ -48,11 +48,13 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.browser.cloudflare.CaptchaNotifier import org.koitharu.kotatsu.browser.cloudflare.CaptchaNotifier
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
import org.koitharu.kotatsu.core.model.distinctById import org.koitharu.kotatsu.core.model.distinctById
import org.koitharu.kotatsu.core.model.getLocale
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.nav.ReaderIntent import org.koitharu.kotatsu.core.nav.ReaderIntent
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.LocaleComparator
import org.koitharu.kotatsu.core.util.ext.asArrayList import org.koitharu.kotatsu.core.util.ext.asArrayList
import org.koitharu.kotatsu.core.util.ext.awaitUniqueWorkInfoByName import org.koitharu.kotatsu.core.util.ext.awaitUniqueWorkInfoByName
import org.koitharu.kotatsu.core.util.ext.awaitWorkInfosByTag import org.koitharu.kotatsu.core.util.ext.awaitWorkInfosByTag
@ -179,7 +181,7 @@ class SuggestionsWorker @AssistedInject constructor(
historyRepository.getList(0, 20) + historyRepository.getList(0, 20) +
favouritesRepository.getLastManga(20) favouritesRepository.getLastManga(20)
).distinctById() ).distinctById()
val sources = sourcesRepository.getEnabledSources() val sources = getSources()
if (seed.isEmpty() || sources.isEmpty()) { if (seed.isEmpty() || sources.isEmpty()) {
return 0 return 0
} }
@ -188,7 +190,7 @@ class SuggestionsWorker @AssistedInject constructor(
val semaphore = Semaphore(MAX_PARALLELISM) val semaphore = Semaphore(MAX_PARALLELISM)
val producer = channelFlow { val producer = channelFlow {
for (it in sources.shuffled()) { for (it in sources) {
if (it.isNsfw() && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) { if (it.isNsfw() && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) {
continue continue
} }
@ -243,6 +245,18 @@ class SuggestionsWorker @AssistedInject constructor(
return suggestions.size return suggestions.size
} }
private suspend fun getSources(): List<MangaSource> {
if (appSettings.isSuggestionsIncludeDisabledSources) {
val result = sourcesRepository.allMangaSources.toMutableList<MangaSource>()
result.addAll(sourcesRepository.getExternalSources())
result.shuffle()
result.sortWith(compareBy(nullsLast(LocaleComparator())) { it.getLocale() })
return result
} else {
return sourcesRepository.getEnabledSources().shuffled()
}
}
private suspend fun getList( private suspend fun getList(
source: MangaSource, source: MangaSource,
tags: List<String>, tags: List<String>,

@ -819,4 +819,7 @@
<string name="clear_browser_data">Clear browser data</string> <string name="clear_browser_data">Clear browser data</string>
<string name="clear_browser_data_summary">Clear browser data such as cache and cookies. Warning: Authorization in manga sources may become invalid</string> <string name="clear_browser_data_summary">Clear browser data such as cache and cookies. Warning: Authorization in manga sources may become invalid</string>
<string name="no_write_permission_to_file">Does not have permission to write a file</string> <string name="no_write_permission_to_file">Does not have permission to write a file</string>
<string name="exclude_nsfw_from_suggestions_summary">Adult manga will not be shown in suggestions. This option may work inaccurate with some sources</string>
<string name="include_disabled_sources">Include disabled sources</string>
<string name="suggestions_disabled_sources_summary">Show suggestions from all manga sources, including disabled ones</string>
</resources> </resources>

@ -17,6 +17,13 @@
android:summary="@string/suggestions_wifi_only_summary" android:summary="@string/suggestions_wifi_only_summary"
android:title="@string/only_using_wifi" /> android:title="@string/only_using_wifi" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:dependency="suggestions"
android:key="suggestions_disabled_sources"
android:summary="@string/suggestions_disabled_sources_summary"
android:title="@string/include_disabled_sources" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:dependency="suggestions" android:dependency="suggestions"
@ -35,6 +42,7 @@
android:defaultValue="false" android:defaultValue="false"
android:dependency="suggestions" android:dependency="suggestions"
android:key="suggestions_exclude_nsfw" android:key="suggestions_exclude_nsfw"
android:summary="@string/exclude_nsfw_from_suggestions_summary"
android:title="@string/exclude_nsfw_from_suggestions" /> android:title="@string/exclude_nsfw_from_suggestions" />
<Preference <Preference

Loading…
Cancel
Save