Skip to content

Commit

Permalink
clean up mangadex some
Browse files Browse the repository at this point in the history
remove some strings unused
remove catalog view
add captcha option when logging in
  • Loading branch information
nonproto committed Apr 12, 2019
1 parent c8392e7 commit 365a60c
Show file tree
Hide file tree
Showing 44 changed files with 216 additions and 1,650 deletions.
8 changes: 4 additions & 4 deletions app/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
android:enabled="true"
android:icon="@drawable/sc_explore_48dp"
android:shortcutDisabledMessage="@string/app_not_available"
android:shortcutId="show_catalogues"
android:shortcutLongLabel="@string/label_catalogues"
android:shortcutShortLabel="@string/label_catalogues">
android:shortcutId="show_browse"
android:shortcutLongLabel="@string/label_browse"
android:shortcutShortLabel="@string/label_browse">
<intent
android:action="eu.kanade.tachiyomi.SHOW_CATALOGUES"
android:action="eu.kanade.tachiyomi.SHOW_BROWSE"
android:targetClass="eu.kanade.tachiyomi.ui.main.MainActivity" />
</shortcut>
</shortcuts>
2 changes: 1 addition & 1 deletion app/src/main/java/eu/kanade/tachiyomi/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AppModule(val app: Application) : InjektModule {

addSingletonFactory { NetworkHelper(app) }

addSingletonFactory { SourceManager(app) }
addSingletonFactory { SourceManager() }

addSingletonFactory { DownloadManager(app) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class BackupRestoreService : Service() {
categories: List<String>, history: List<DHistory>,
tracks: List<Track>): Observable<Manga>? {
// Get source
val source = backupManager.sourceManager.getOrStub(manga.source)
val source = backupManager.sourceManager.getSource(manga.source)
val dbManga = backupManager.getMangaFromDatabase(manga)

return if (dbManga == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DownloadCache(
* Renews the downloads cache.
*/
private fun renew() {
val onlineSources = sourceManager.getOnlineSources()
val onlineSources = sourceManager.getSources()

val sourceDirs = rootDir.dir.listFiles()
.orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ object PreferenceKeys {

const val downloadBadge = "display_download_badge"

@Deprecated("Use the preferences of the source")
const val showR18 = "show_r18"

fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId"

@Deprecated("Use the preferences of the source")
fun sourcePassword(sourceId: Long) = "pref_source_password_$sourceId"

fun sourceSharedPref(sourceId: Long) = "source_$sourceId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class PreferencesHelper(val context: Context) {

fun showPageNumber() = rxPrefs.getBoolean(Keys.showPageNumber, true)

fun r18() = prefs.getInt(Keys.showR18, 0)


fun trueColor() = rxPrefs.getBoolean(Keys.trueColor, false)

fun fullscreen() = rxPrefs.getBoolean(Keys.fullscreen, true)
Expand Down
29 changes: 20 additions & 9 deletions app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package eu.kanade.tachiyomi.network

import android.content.Context
import eu.kanade.tachiyomi.BuildConfig
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.io.File

class NetworkHelper(context: Context) {
Expand All @@ -13,13 +15,22 @@ class NetworkHelper(context: Context) {

val cookieManager = AndroidCookieJar()

val client = OkHttpClient.Builder()
.cookieJar(cookieManager)
.cache(Cache(cacheDir, cacheSize))
.build()
val client =
if(BuildConfig.DEBUG) {
OkHttpClient.Builder()
.cookieJar(cookieManager)
.cache(Cache(cacheDir, cacheSize))
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build()
}else {
OkHttpClient.Builder()
.cookieJar(cookieManager)
.cache(Cache(cacheDir, cacheSize))
.build()
}

val cloudflareClient = client.newBuilder()
.addInterceptor(CloudflareInterceptor(context))
.build()
}

val cloudflareClient = client.newBuilder()
.addInterceptor(CloudflareInterceptor(context))
.build()

}

This file was deleted.

12 changes: 0 additions & 12 deletions app/src/main/java/eu/kanade/tachiyomi/source/SourceFactory.kt

This file was deleted.

64 changes: 5 additions & 59 deletions app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt
Original file line number Diff line number Diff line change
@@ -1,75 +1,21 @@
package eu.kanade.tachiyomi.source

import android.content.Context
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.source.online.english.Mangadex
import rx.Observable

open class SourceManager(private val context: Context) {
open class SourceManager {

private val sourcesMap = mutableMapOf<Long, Source>()

private val stubSourcesMap = mutableMapOf<Long, StubSource>()

init {
createInternalSources().forEach { registerSource(it) }
val source = Mangadex("en", "gb", 1)
sourcesMap[source.id] = source
}

open fun get(sourceKey: Long): Source? {
return sourcesMap[sourceKey]
}
fun getSource(sourceKey: Long): Source = sourcesMap[sourceKey]!!

fun getOrStub(sourceKey: Long): Source {
return sourcesMap[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) {
StubSource(sourceKey)
}
}

fun getOnlineSources() = sourcesMap.values.filterIsInstance<HttpSource>()

fun getCatalogueSources() = sourcesMap.values.filterIsInstance<CatalogueSource>()

internal fun registerSource(source: Source, overwrite: Boolean = false) {
if (overwrite || !sourcesMap.containsKey(source.id)) {
sourcesMap[source.id] = source
}
}

internal fun unregisterSource(source: Source) {
sourcesMap.remove(source.id)
}

private fun createInternalSources(): List<Source> = listOf(
Mangadex("en", "gb", 1)
)

private inner class StubSource(override val id: Long) : Source {

override val name: String
get() = id.toString()

override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
return Observable.error(getSourceNotInstalledException())
}
fun getSources() = sourcesMap.values.toList()

override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
return Observable.error(getSourceNotInstalledException())
}

override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
return Observable.error(getSourceNotInstalledException())
}

override fun toString(): String {
return name
}

private fun getSourceNotInstalledException(): Exception {
return Exception(context.getString(R.string.source_not_installed, id.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package eu.kanade.tachiyomi.source.online.english

import android.app.Application
import android.content.SharedPreferences
import android.support.v7.preference.ListPreference
import android.support.v7.preference.PreferenceScreen
import com.github.salomonbrys.kotson.*
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.network.asObservable
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
Expand All @@ -21,13 +17,13 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.net.URLEncoder
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.collections.set

open class Mangadex(override val lang: String, private val internalLang: String, private val langCode: Int) : ConfigurableSource, LoginSource, ParsedHttpSource() {
open class Mangadex(override val lang: String, private val internalLang: String, private val langCode: Int) : LoginSource, ParsedHttpSource() {

override val name = "MangaDex"

Expand All @@ -37,11 +33,9 @@ open class Mangadex(override val lang: String, private val internalLang: String,

override val supportsLatest = true

private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
private val preferences: PreferencesHelper by injectLazy()

private fun clientBuilder(): OkHttpClient = clientBuilder(getShowR18())
private fun clientBuilder(): OkHttpClient = clientBuilder(preferences.r18())

private fun clientBuilder(r18Toggle: Int): OkHttpClient = network.cloudflareClient.newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
Expand Down Expand Up @@ -138,7 +132,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return if (query.startsWith(PREFIX_ID_SEARCH)) {
val realQuery = query.removePrefix(PREFIX_ID_SEARCH)
client.newCall(searchMangaByIdRequest(realQuery))
clientBuilder().newCall(searchMangaByIdRequest(realQuery))
.asObservableSuccess()
.map { response ->
val details = mangaDetailsParse(response)
Expand Down Expand Up @@ -478,26 +472,6 @@ open class Mangadex(override val lang: String, private val internalLang: String,
return baseUrl + attr
}

override fun setupPreferenceScreen(screen: PreferenceScreen) {
val myPref = ListPreference(screen.context).apply {
key = SHOW_R18_PREF_Title
title = SHOW_R18_PREF_Title

title = SHOW_R18_PREF_Title
entries = arrayOf("Show No R18+", "Show All", "Show Only R18+")
entryValues = arrayOf("0", "1", "2")
summary = "%s"

setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = this.findIndexOfValue(selected)
preferences.edit().putInt(SHOW_R18_PREF, index).commit()
}
}

screen.addPreference(myPref)
}

override fun isLogged(): Boolean {
val httpUrl = HttpUrl.parse(baseUrl)!!
return network.cookieManager.get(httpUrl).any { it.name() == "mangadex_rememberme_token" }
Expand All @@ -512,7 +486,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
.build()


return client.newCall(POST("$baseUrl/ajax/actions.ajax.php?function=login", headers, formBody))
return clientBuilder().newCall(POST("$baseUrl/ajax/actions.ajax.php?function=login", headers, formBody))
.asObservable()
.map { isAuthenticationSuccessful(it) }
}
Expand All @@ -525,8 +499,6 @@ open class Mangadex(override val lang: String, private val internalLang: String,
return false
}

private fun getShowR18(): Int = preferences.getInt(SHOW_R18_PREF, 0)


private class TextField(name: String, val key: String) : Filter.Text(name)
private class Tag(val id: String, name: String) : Filter.TriState(name)
Expand All @@ -544,7 +516,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
sortables.map { it.first }.toTypedArray(),
Filter.Sort.Selection(0, true))

private class OriginalLanguage : Filter.Select<String>("Original Language", SOURCE_LANG_LIST.map { it -> it.first }.toTypedArray())
private class OriginalLanguage : Filter.Select<String>("Original Language", SOURCE_LANG_LIST.map { it.first }.toTypedArray())

override fun getFilterList() = FilterList(
TextField("Author", "author"),
Expand Down Expand Up @@ -662,10 +634,6 @@ open class Mangadex(override val lang: String, private val internalLang: String,
private const val ALL = 1
private const val ONLY_R18 = 2

private const val SHOW_R18_PREF_Title = "Default R18 Setting"
private const val SHOW_R18_PREF = "showR18Default"
private const val REMEMBER_ME_TOKEN = "rememberMeToken"


private const val API_MANGA = "/api/manga/"
private const val API_CHAPTER = "/api/chapter/"
Expand Down

This file was deleted.

Loading

0 comments on commit 365a60c

Please sign in to comment.