Switch to the Mangadex extension for the low quality covers setting

This commit is contained in:
Jobobby04 2020-10-19 15:47:14 -04:00
parent 9945752667
commit a8b1e8fdb0
7 changed files with 21 additions and 22 deletions

View File

@ -307,8 +307,6 @@ object PreferenceKeys {
const val useNewSourceNavigation = "use_new_source_navigation"
const val mangaDexLowQualityCovers = "manga_dex_low_quality_covers"
const val mangaDexForceLatestCovers = "manga_dex_force_latest_covers"
const val preferredMangaDexId = "preferred_mangaDex_id"

View File

@ -427,8 +427,6 @@ class PreferencesHelper(val context: Context) {
fun useNewSourceNavigation() = flowPrefs.getBoolean(Keys.useNewSourceNavigation, true)
fun mangaDexLowQualityCovers() = flowPrefs.getBoolean(Keys.mangaDexLowQualityCovers, false)
fun mangaDexForceLatestCovers() = flowPrefs.getBoolean(Keys.mangaDexForceLatestCovers, false)
fun preferredMangaDexId() = flowPrefs.getString(Keys.preferredMangaDexId, "0")

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.source.online.all
import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.net.Uri
import androidx.core.text.HtmlCompat
import com.bluelinelabs.conductor.Controller
@ -84,6 +85,12 @@ class MangaDex(delegate: HttpSource, val context: Context) :
val preferences: PreferencesHelper by injectLazy()
val trackManager: TrackManager by injectLazy()
private val sourcePreferences: SharedPreferences by lazy {
context.getSharedPreferences("source_$id", 0x0000)
}
private fun useLowQualityThumbnail() = sourcePreferences.getInt(SHOW_THUMBNAIL_PREF, 0) == LOW_QUALITY
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> =
urlImportFetchSearchManga(context, query) {
importIdToMdId(query) {
@ -144,7 +151,7 @@ class MangaDex(delegate: HttpSource, val context: Context) :
}
override fun fetchFollows(): Observable<MangasPage> {
return FollowsHandler(client, headers, Injekt.get()).fetchFollows()
return FollowsHandler(client, headers, Injekt.get(), useLowQualityThumbnail()).fetchFollows()
}
override val needsLogin: Boolean = true
@ -218,15 +225,15 @@ class MangaDex(delegate: HttpSource, val context: Context) :
}
override fun fetchAllFollows(forceHd: Boolean): Flow<List<Pair<SManga, MangaDexSearchMetadata>>> {
return flow { emit(FollowsHandler(client, headers, Injekt.get()).fetchAllFollows(forceHd)) }
return flow { emit(FollowsHandler(client, headers, Injekt.get(), useLowQualityThumbnail()).fetchAllFollows(forceHd)) }
}
fun updateReadingProgress(track: Track): Flow<Boolean> {
return flow { FollowsHandler(client, headers, Injekt.get()).updateReadingProgress(track) }
return flow { FollowsHandler(client, headers, Injekt.get(), useLowQualityThumbnail()).updateReadingProgress(track) }
}
fun updateRating(track: Track): Flow<Boolean> {
return flow { FollowsHandler(client, headers, Injekt.get()).updateRating(track) }
return flow { FollowsHandler(client, headers, Injekt.get(), useLowQualityThumbnail()).updateRating(track) }
}
override fun fetchTrackingInfo(url: String): Flow<Track> {
@ -234,12 +241,12 @@ class MangaDex(delegate: HttpSource, val context: Context) :
if (!isLogged()) {
throw Exception("Not Logged in")
}
emit(FollowsHandler(client, headers, Injekt.get()).fetchTrackingInfo(url))
emit(FollowsHandler(client, headers, Injekt.get(), useLowQualityThumbnail()).fetchTrackingInfo(url))
}
}
override fun updateFollowStatus(mangaID: String, followStatus: FollowStatus): Flow<Boolean> {
return flow { emit(FollowsHandler(client, headers, Injekt.get()).updateFollowStatus(mangaID, followStatus)) }
return flow { emit(FollowsHandler(client, headers, Injekt.get(), useLowQualityThumbnail()).updateFollowStatus(mangaID, followStatus)) }
}
override fun getFilterHeader(controller: Controller): MangaDexFabHeaderAdapter {
@ -273,5 +280,7 @@ class MangaDex(delegate: HttpSource, val context: Context) :
companion object {
private const val REMEMBER_ME = "mangadex_rememberme_token"
private const val SHOW_THUMBNAIL_PREF = "showThumbnailDefault"
private const val LOW_QUALITY = 1
}
}

View File

@ -54,12 +54,6 @@ class SettingsMangaDexController :
entryValues = mangaDexs.map { it.id.toString() }.toTypedArray()
}
switchPreference {
key = PreferenceKeys.mangaDexLowQualityCovers
titleRes = R.string.mangadex_low_quality_covers
defaultValue = false
}
switchPreference {
key = PreferenceKeys.mangaDexForceLatestCovers
titleRes = R.string.mangadex_use_latest_cover

View File

@ -28,7 +28,7 @@ import okhttp3.Request
import okhttp3.Response
import rx.Observable
class FollowsHandler(val client: OkHttpClient, val headers: Headers, val preferences: PreferencesHelper) {
class FollowsHandler(val client: OkHttpClient, val headers: Headers, val preferences: PreferencesHelper, private val useLowQualityCovers: Boolean) {
/**
* fetch follows by page
@ -62,7 +62,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
if (empty == null || empty) {
return MetadataMangasPage(mutableListOf(), false, mutableListOf())
}
val lowQualityCovers = if (forceHd) false else preferences.mangaDexLowQualityCovers().get()
val lowQualityCovers = if (forceHd) false else useLowQualityCovers
val follows = followsPageResult!!.result.map {
followFromElement(it, lowQualityCovers)

View File

@ -21,7 +21,7 @@ import uy.kohesive.injekt.injectLazy
/**
* Returns the latest manga from the updates url since it actually respects the users settings
*/
class PopularHandler(val client: OkHttpClient, private val headers: Headers) {
class PopularHandler(val client: OkHttpClient, private val headers: Headers, private val useLowQualityCovers: Boolean) {
private val preferences: PreferencesHelper by injectLazy()
@ -59,7 +59,7 @@ class PopularHandler(val client: OkHttpClient, private val headers: Headers) {
manga.title = it.text().trim()
}
manga.thumbnail_url = MdUtil.formThumbUrl(manga.url, preferences.mangaDexLowQualityCovers().get())
manga.thumbnail_url = MdUtil.formThumbUrl(manga.url, useLowQualityCovers)
return manga
}

View File

@ -20,7 +20,7 @@ import rx.Observable
import uy.kohesive.injekt.injectLazy
// Unused, kept for reference todo
class SearchHandler(val client: OkHttpClient, private val headers: Headers, val langs: List<String>) {
class SearchHandler(val client: OkHttpClient, private val headers: Headers, val langs: List<String>, private val useLowQualityCovers: Boolean) {
private val preferences: PreferencesHelper by injectLazy()
@ -191,7 +191,7 @@ class SearchHandler(val client: OkHttpClient, private val headers: Headers, val
manga.title = it.text().trim()
}
manga.thumbnail_url = MdUtil.formThumbUrl(manga.url, preferences.mangaDexLowQualityCovers().get())
manga.thumbnail_url = MdUtil.formThumbUrl(manga.url, useLowQualityCovers)
return manga
}