From 876831480af4fb311c4dbe29e64c1795ef040d30 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 8 Oct 2016 19:48:55 +0200 Subject: [PATCH] Remove unused context from sources --- app/src/main/AndroidManifest.xml | 3 +- .../tachiyomi/data/source/SourceManager.kt | 46 ++++++------------- .../data/source/online/OnlineSource.kt | 5 +- .../data/source/online/ParsedOnlineSource.kt | 5 +- .../data/source/online/YamlOnlineSource.kt | 3 +- .../data/source/online/english/Batoto.kt | 3 +- .../data/source/online/english/Kissmanga.kt | 2 +- .../data/source/online/english/Mangafox.kt | 2 +- .../data/source/online/english/Mangahere.kt | 2 +- .../data/source/online/english/Mangasee.kt | 2 +- .../source/online/english/Readmangatoday.kt | 2 +- .../data/source/online/german/WieManga.kt | 2 +- .../data/source/online/russian/Mangachan.kt | 2 +- .../data/source/online/russian/Mintmanga.kt | 2 +- .../data/source/online/russian/Readmanga.kt | 2 +- 15 files changed, 29 insertions(+), 54 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0b2888726..ca07c95df 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,8 +22,7 @@ android:largeHeap="true" android:theme="@style/Theme.Tachiyomi" > + android:name=".ui.main.MainActivity"> diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt index 1b1b8ef08..fe5cdb51e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt @@ -18,20 +18,7 @@ import java.io.File open class SourceManager(private val context: Context) { - val BATOTO = 1 - val MANGAHERE = 2 - val MANGAFOX = 3 - val KISSMANGA = 4 - val READMANGA = 5 - val MINTMANGA = 6 - val MANGACHAN = 7 - val READMANGATODAY = 8 - val MANGASEE = 9 - val WIEMANGA = 10 - - val LAST_SOURCE = 10 - - val sourcesMap = createSources() + private val sourcesMap = createSources() open fun get(sourceKey: Int): Source? { return sourcesMap[sourceKey] @@ -39,24 +26,21 @@ open class SourceManager(private val context: Context) { fun getOnlineSources() = sourcesMap.values.filterIsInstance(OnlineSource::class.java) - private fun createSource(id: Int): Source? = when (id) { - BATOTO -> Batoto(context, id) - KISSMANGA -> Kissmanga(context, id) - MANGAHERE -> Mangahere(context, id) - MANGAFOX -> Mangafox(context, id) - READMANGA -> Readmanga(context, id) - MINTMANGA -> Mintmanga(context, id) - MANGACHAN -> Mangachan(context, id) - READMANGATODAY -> Readmangatoday(context, id) - MANGASEE -> Mangasee(context, id) - WIEMANGA -> WieManga(context, id) - else -> null - } + private fun createOnlineSourceList(): List = listOf( + Batoto(1), + Kissmanga(2), + Mangahere(3), + Mangafox(4), + Readmanga(5), + Mintmanga(6), + Mangachan(7), + Readmangatoday(8), + Mangasee(9), + WieManga(10) + ) private fun createSources(): Map = hashMapOf().apply { - for (i in 1..LAST_SOURCE) { - createSource(i)?.let { put(i, it) } - } + createOnlineSourceList().forEach { put(it.id, it) } val parsersDir = File(Environment.getExternalStorageDirectory().absolutePath + File.separator + context.getString(R.string.app_name), "parsers") @@ -66,7 +50,7 @@ open class SourceManager(private val context: Context) { for (file in parsersDir.listFiles().filter { it.extension == "yml" }) { try { val map = file.inputStream().use { yaml.loadAs(it, Map::class.java) } - YamlOnlineSource(context, map).let { put(it.id, it) } + YamlOnlineSource(map).let { put(it.id, it) } } catch (e: Exception) { Timber.e("Error loading source from file. Bad format?") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt index 18cc1c17d..0d7cd7221 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.source.online -import android.content.Context import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga @@ -23,10 +22,8 @@ import uy.kohesive.injekt.injectLazy /** * A simple implementation for sources from a website. - * - * @param context the application context. */ -abstract class OnlineSource(context: Context) : Source { +abstract class OnlineSource() : Source { /** * Network service. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/ParsedOnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/ParsedOnlineSource.kt index 172d7bea4..6b0e21158 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/ParsedOnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/ParsedOnlineSource.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.source.online -import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.source.model.MangasPage @@ -12,10 +11,8 @@ import org.jsoup.nodes.Element /** * A simple implementation for sources from a website using Jsoup, an HTML parser. - * - * @param context the application context. */ -abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) { +abstract class ParsedOnlineSource() : OnlineSource() { /** * Parse the response from the site and fills [page]. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt index ea4cb7a8d..b10f0fe10 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.source.online -import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.network.GET @@ -17,7 +16,7 @@ import org.jsoup.nodes.Element import java.text.SimpleDateFormat import java.util.* -class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(context) { +class YamlOnlineSource(mappings: Map<*, *>) : OnlineSource() { val map = YamlSourceNode(mappings) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt index edc70a9f1..d21279775 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.source.online.english -import android.content.Context import android.net.Uri import android.text.Html import eu.kanade.tachiyomi.data.database.models.Chapter @@ -28,7 +27,7 @@ import java.text.SimpleDateFormat import java.util.* import java.util.regex.Pattern -class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(context), LoginSource { +class Batoto(override val id: Int) : ParsedOnlineSource(), LoginSource { override val name = "Batoto" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt index 5bb4f2a4b..5b10172eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt @@ -19,7 +19,7 @@ import org.jsoup.nodes.Element import java.text.SimpleDateFormat import java.util.regex.Pattern -class Kissmanga(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Kissmanga(override val id: Int) : ParsedOnlineSource() { override val name = "Kissmanga" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt index ba92a148a..4ec7c632b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt @@ -15,7 +15,7 @@ import java.text.ParseException import java.text.SimpleDateFormat import java.util.* -class Mangafox(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Mangafox(override val id: Int) : ParsedOnlineSource() { override val name = "Mangafox" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt index b040022ee..ec7a11a0f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt @@ -13,7 +13,7 @@ import java.text.ParseException import java.text.SimpleDateFormat import java.util.* -class Mangahere(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Mangahere(override val id: Int) : ParsedOnlineSource() { override val name = "Mangahere" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt index f191a0c10..9c1b50673 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt @@ -14,7 +14,7 @@ import org.jsoup.nodes.Element import java.util.* import java.util.regex.Pattern -class Mangasee(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Mangasee(override val id: Int) : ParsedOnlineSource() { override val name = "Mangasee" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt index 8177eedf9..105d77d66 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt @@ -17,7 +17,7 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.util.* -class Readmangatoday(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Readmangatoday(override val id: Int) : ParsedOnlineSource() { override val name = "ReadMangaToday" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt index 6683891c7..b33fbe45c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt @@ -13,7 +13,7 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.text.SimpleDateFormat -class WieManga(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class WieManga(override val id: Int) : ParsedOnlineSource() { override val name = "Wie Manga!" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt index 607ddc71c..dbe01dccb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt @@ -13,7 +13,7 @@ import org.jsoup.nodes.Element import java.text.SimpleDateFormat import java.util.* -class Mangachan(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Mangachan(override val id: Int) : ParsedOnlineSource() { override val name = "Mangachan" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt index 5eb2773cd..c56bf326b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt @@ -14,7 +14,7 @@ import java.text.SimpleDateFormat import java.util.* import java.util.regex.Pattern -class Mintmanga(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Mintmanga(override val id: Int) : ParsedOnlineSource() { override val name = "Mintmanga" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt index 555f9892a..0775b1a1f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt @@ -14,7 +14,7 @@ import java.text.SimpleDateFormat import java.util.* import java.util.regex.Pattern -class Readmanga(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Readmanga(override val id: Int) : ParsedOnlineSource() { override val name = "Readmanga"