Option to use disabled sources for suggestions
This commit is contained in:
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.MangaParserSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.splitTwoParts
|
||||
import java.util.Locale
|
||||
import com.google.android.material.R as materialR
|
||||
|
||||
data object LocalMangaSource : MangaSource {
|
||||
@@ -79,6 +80,8 @@ tailrec fun MangaSource.unwrap(): MangaSource = if (this is MangaSourceInfo) {
|
||||
this
|
||||
}
|
||||
|
||||
fun MangaSource.getLocale(): Locale? = (unwrap() as? MangaParserSource)?.locale?.toLocale()
|
||||
|
||||
fun MangaSource.getSummary(context: Context): String? = when (val source = unwrap()) {
|
||||
is MangaParserSource -> {
|
||||
val type = context.getString(source.contentType.titleResId)
|
||||
|
||||
@@ -359,6 +359,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
val isSuggestionsExcludeNsfw: Boolean
|
||||
get() = prefs.getBoolean(KEY_SUGGESTIONS_EXCLUDE_NSFW, false)
|
||||
|
||||
val isSuggestionsIncludeDisabledSources: Boolean
|
||||
get() = prefs.getBoolean(KEY_SUGGESTIONS_DISABLED_SOURCES, false)
|
||||
|
||||
val isSuggestionsNotificationAvailable: Boolean
|
||||
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_EXCLUDE_NSFW = "suggestions_exclude_nsfw"
|
||||
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_SHIKIMORI = "shikimori"
|
||||
const val KEY_ANILIST = "anilist"
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.room.withTransaction
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.channels.trySendBlocking
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -354,7 +353,7 @@ class MangaSourcesRepository @Inject constructor(
|
||||
.conflate()
|
||||
}
|
||||
|
||||
private fun getExternalSources() = context.packageManager.queryIntentContentProviders(
|
||||
fun getExternalSources(): List<ExternalMangaSource> = context.packageManager.queryIntentContentProviders(
|
||||
Intent("app.kotatsu.parser.PROVIDE_MANGA"), 0,
|
||||
).map { resolveInfo ->
|
||||
ExternalMangaSource(
|
||||
|
||||
@@ -48,11 +48,13 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.browser.cloudflare.CaptchaNotifier
|
||||
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
||||
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.nav.AppRouter
|
||||
import org.koitharu.kotatsu.core.nav.ReaderIntent
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
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.awaitUniqueWorkInfoByName
|
||||
import org.koitharu.kotatsu.core.util.ext.awaitWorkInfosByTag
|
||||
@@ -179,7 +181,7 @@ class SuggestionsWorker @AssistedInject constructor(
|
||||
historyRepository.getList(0, 20) +
|
||||
favouritesRepository.getLastManga(20)
|
||||
).distinctById()
|
||||
val sources = sourcesRepository.getEnabledSources()
|
||||
val sources = getSources()
|
||||
if (seed.isEmpty() || sources.isEmpty()) {
|
||||
return 0
|
||||
}
|
||||
@@ -188,7 +190,7 @@ class SuggestionsWorker @AssistedInject constructor(
|
||||
|
||||
val semaphore = Semaphore(MAX_PARALLELISM)
|
||||
val producer = channelFlow {
|
||||
for (it in sources.shuffled()) {
|
||||
for (it in sources) {
|
||||
if (it.isNsfw() && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) {
|
||||
continue
|
||||
}
|
||||
@@ -243,6 +245,18 @@ class SuggestionsWorker @AssistedInject constructor(
|
||||
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(
|
||||
source: MangaSource,
|
||||
tags: List<String>,
|
||||
|
||||
@@ -819,4 +819,7 @@
|
||||
<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="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>
|
||||
|
||||
@@ -17,6 +17,13 @@
|
||||
android:summary="@string/suggestions_wifi_only_summary"
|
||||
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
|
||||
android:defaultValue="false"
|
||||
android:dependency="suggestions"
|
||||
@@ -35,6 +42,7 @@
|
||||
android:defaultValue="false"
|
||||
android:dependency="suggestions"
|
||||
android:key="suggestions_exclude_nsfw"
|
||||
android:summary="@string/exclude_nsfw_from_suggestions_summary"
|
||||
android:title="@string/exclude_nsfw_from_suggestions" />
|
||||
|
||||
<Preference
|
||||
|
||||
Reference in New Issue
Block a user