Browse Source

Keep compatibility with YAML sources. Reorder methods

len 8 years ago
parent
commit
6d0689fe6c

+ 32 - 32
app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt

@@ -54,7 +54,7 @@ abstract class OnlineSource(context: Context) : Source {
     abstract val lang: Language
 
     /**
-     * If the Source has Support for Latest Updates
+     * Whether the source has support for latest updates.
      */
     abstract val supportsLatest : Boolean
 
@@ -101,17 +101,6 @@ abstract class OnlineSource(context: Context) : Source {
                 page
             }
 
-    /**
-     * Returns an observable containing a page with a list of latest manga.
-     */
-    open fun fetchLatestUpdates(page: MangasPage): Observable<MangasPage> = client
-            .newCall(latestUpdatesRequest(page))
-            .asObservable()
-            .map { response ->
-                latestUpdatesParse(response, page)
-                page
-            }
-
     /**
      * Returns the request for the popular manga given the page. Override only if it's needed to
      * send different headers or request method like POST.
@@ -125,26 +114,11 @@ abstract class OnlineSource(context: Context) : Source {
         return GET(page.url, headers)
     }
 
-    /**
-     * Returns the request for latest manga given the page.
-     */
-    open protected fun latestUpdatesRequest(page: MangasPage): Request {
-        if (page.page == 1) {
-            page.url = latestUpdatesInitialUrl()
-        }
-        return GET(page.url, headers)
-    }
-
     /**
      * Returns the absolute url of the first page to popular manga.
      */
     abstract protected fun popularMangaInitialUrl(): String
 
-    /**
-     * Returns the absolute url of the first page to latest manga.
-     */
-    abstract protected fun latestUpdatesInitialUrl(): String
-
     /**
      * Parse the response from the site. It should add a list of manga and the absolute url to the
      * next page (if it has a next one) to [page].
@@ -154,11 +128,6 @@ abstract class OnlineSource(context: Context) : Source {
      */
     abstract protected fun popularMangaParse(response: Response, page: MangasPage)
 
-    /**
-     * Same as [popularMangaParse], but for latest manga.
-     */
-    abstract protected fun latestUpdatesParse(response: Response, page: MangasPage)
-
     /**
      * Returns an observable containing a page with a list of manga. Normally it's not needed to
      * override this method.
@@ -206,6 +175,37 @@ abstract class OnlineSource(context: Context) : Source {
      */
     abstract protected fun searchMangaParse(response: Response, page: MangasPage, query: String, filters: List<Filter>)
 
+    /**
+     * Returns an observable containing a page with a list of latest manga.
+     */
+    open fun fetchLatestUpdates(page: MangasPage): Observable<MangasPage> = client
+            .newCall(latestUpdatesRequest(page))
+            .asObservable()
+            .map { response ->
+                latestUpdatesParse(response, page)
+                page
+            }
+
+    /**
+     * Returns the request for latest manga given the page.
+     */
+    open protected fun latestUpdatesRequest(page: MangasPage): Request {
+        if (page.page == 1) {
+            page.url = latestUpdatesInitialUrl()
+        }
+        return GET(page.url, headers)
+    }
+
+    /**
+     * Returns the absolute url of the first page to latest manga.
+     */
+    abstract protected fun latestUpdatesInitialUrl(): String
+
+    /**
+     * Same as [popularMangaParse], but for latest manga.
+     */
+    abstract protected fun latestUpdatesParse(response: Response, page: MangasPage)
+
     /**
      * Returns an observable with the updated details for a manga. Normally it's not needed to
      * override this method.

+ 32 - 32
app/src/main/java/eu/kanade/tachiyomi/data/source/online/ParsedOnlineSource.kt

@@ -37,33 +37,11 @@ abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) {
         }
     }
 
-    /**
-     * Parse the response from the site for latest updates and fills [page].
-     */
-    override fun latestUpdatesParse(response: Response, page: MangasPage) {
-        val document = response.asJsoup()
-        for (element in document.select(latestUpdatesSelector())) {
-            Manga.create(id).apply {
-                latestUpdatesFromElement(element, this)
-                page.mangas.add(this)
-            }
-        }
-
-        latestUpdatesNextPageSelector()?.let { selector ->
-            page.nextPageUrl = document.select(selector).first()?.absUrl("href")
-        }
-    }
-
     /**
      * Returns the Jsoup selector that returns a list of [Element] corresponding to each manga.
      */
     abstract protected fun popularMangaSelector(): String
 
-    /**
-     * Returns the Jsoup selector similar to [popularMangaSelector], but for latest updates.
-     */
-    abstract protected fun latestUpdatesSelector(): String
-
     /**
      * Fills [manga] with the given [element]. Most sites only show the title and the url, it's
      * totally safe to fill only those two values.
@@ -73,22 +51,12 @@ abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) {
      */
     abstract protected fun popularMangaFromElement(element: Element, manga: Manga)
 
-    /**
-     * Fills [manga] with the given [element]. For latest updates.
-     */
-    abstract protected fun latestUpdatesFromElement(element: Element, manga: Manga)
-
     /**
      * Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if
      * there's no next page.
      */
     abstract protected fun popularMangaNextPageSelector(): String?
 
-    /**
-     * Returns the Jsoup selector that returns the <a> tag, like [popularMangaNextPageSelector].
-     */
-    abstract protected fun latestUpdatesNextPageSelector(): String?
-
     /**
      * Parse the response from the site and fills [page].
      *
@@ -130,6 +98,38 @@ abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) {
      */
     abstract protected fun searchMangaNextPageSelector(): String?
 
+    /**
+     * Parse the response from the site for latest updates and fills [page].
+     */
+    override fun latestUpdatesParse(response: Response, page: MangasPage) {
+        val document = response.asJsoup()
+        for (element in document.select(latestUpdatesSelector())) {
+            Manga.create(id).apply {
+                latestUpdatesFromElement(element, this)
+                page.mangas.add(this)
+            }
+        }
+
+        latestUpdatesNextPageSelector()?.let { selector ->
+            page.nextPageUrl = document.select(selector).first()?.absUrl("href")
+        }
+    }
+
+    /**
+     * Returns the Jsoup selector similar to [popularMangaSelector], but for latest updates.
+     */
+    abstract protected fun latestUpdatesSelector(): String
+
+    /**
+     * Fills [manga] with the given [element]. For latest updates.
+     */
+    abstract protected fun latestUpdatesFromElement(element: Element, manga: Manga)
+
+    /**
+     * Returns the Jsoup selector that returns the <a> tag, like [popularMangaNextPageSelector].
+     */
+    abstract protected fun latestUpdatesNextPageSelector(): String?
+
     /**
      * Parse the response from the site and fills the details of [manga].
      *

+ 24 - 26
app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt

@@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.data.database.models.Chapter
 import eu.kanade.tachiyomi.data.database.models.Manga
 import eu.kanade.tachiyomi.data.network.GET
 import eu.kanade.tachiyomi.data.network.POST
-import eu.kanade.tachiyomi.data.source.Source
 import eu.kanade.tachiyomi.data.source.getLanguages
 import eu.kanade.tachiyomi.data.source.model.MangasPage
 import eu.kanade.tachiyomi.data.source.model.Page
@@ -15,7 +14,6 @@ import okhttp3.Request
 import okhttp3.Response
 import org.jsoup.Jsoup
 import org.jsoup.nodes.Element
-import rx.Observable
 import java.text.SimpleDateFormat
 import java.util.*
 
@@ -34,7 +32,7 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
         getLanguages().find { code == it.code }!!
     }
 
-    override val supportsLatest = map.supportsLatest.toBoolean()
+    override val supportsLatest = map.latestupdates != null
 
     override val client = when(map.client) {
         "cloudflare" -> network.cloudflareClient
@@ -55,20 +53,8 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
         }
     }
 
-    override fun latestUpdatesRequest(page: MangasPage): Request {
-        if (page.page == 1) {
-            page.url = latestUpdatesInitialUrl()
-        }
-        return when (map.latestupdates.method?.toLowerCase()) {
-            "post" -> POST(page.url, headers, map.latestupdates.createForm())
-            else -> GET(page.url, headers)
-        }
-    }
-
     override fun popularMangaInitialUrl() = map.popular.url
 
-    override fun latestUpdatesInitialUrl() = map.latestupdates.url
-
     override fun popularMangaParse(response: Response, page: MangasPage) {
         val document = response.asJsoup()
         for (element in document.select(map.popular.manga_css)) {
@@ -84,9 +70,21 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
         }
     }
 
-    override fun latestUpdatesParse(response: Response, page: MangasPage) {
+    override fun searchMangaRequest(page: MangasPage, query: String, filters: List<Filter>): Request {
+        if (page.page == 1) {
+            page.url = searchMangaInitialUrl(query, filters)
+        }
+        return when (map.search.method?.toLowerCase()) {
+            "post" -> POST(page.url, headers, map.search.createForm())
+            else -> GET(page.url, headers)
+        }
+    }
+
+    override fun searchMangaInitialUrl(query: String, filters: List<Filter>) = map.search.url.replace("\$query", query)
+
+    override fun searchMangaParse(response: Response, page: MangasPage, query: String, filters: List<Filter>) {
         val document = response.asJsoup()
-        for (element in document.select(map.latestupdates.manga_css)) {
+        for (element in document.select(map.search.manga_css)) {
             Manga.create(id).apply {
                 title = element.text()
                 setUrlWithoutDomain(element.attr("href"))
@@ -94,26 +92,26 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
             }
         }
 
-        map.popular.next_url_css?.let { selector ->
+        map.search.next_url_css?.let { selector ->
             page.nextPageUrl = document.select(selector).first()?.absUrl("href")
         }
     }
 
-    override fun searchMangaRequest(page: MangasPage, query: String, filters: List<Filter>): Request {
+    override fun latestUpdatesRequest(page: MangasPage): Request {
         if (page.page == 1) {
-            page.url = searchMangaInitialUrl(query, filters)
+            page.url = latestUpdatesInitialUrl()
         }
-        return when (map.search.method?.toLowerCase()) {
-            "post" -> POST(page.url, headers, map.search.createForm())
+        return when (map.latestupdates!!.method?.toLowerCase()) {
+            "post" -> POST(page.url, headers, map.latestupdates.createForm())
             else -> GET(page.url, headers)
         }
     }
 
-    override fun searchMangaInitialUrl(query: String, filters: List<Filter>) = map.search.url.replace("\$query", query)
+    override fun latestUpdatesInitialUrl() = map.latestupdates!!.url
 
-    override fun searchMangaParse(response: Response, page: MangasPage, query: String, filters: List<Filter>) {
+    override fun latestUpdatesParse(response: Response, page: MangasPage) {
         val document = response.asJsoup()
-        for (element in document.select(map.search.manga_css)) {
+        for (element in document.select(map.latestupdates!!.manga_css)) {
             Manga.create(id).apply {
                 title = element.text()
                 setUrlWithoutDomain(element.attr("href"))
@@ -121,7 +119,7 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
             }
         }
 
-        map.search.next_url_css?.let { selector ->
+        map.latestupdates.next_url_css?.let { selector ->
             page.nextPageUrl = document.select(selector).first()?.absUrl("href")
         }
     }

+ 1 - 3
app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSourceMappings.kt

@@ -25,14 +25,12 @@ class YamlSourceNode(uncheckedMap: Map<*, *>) {
 
     val lang: String by map
 
-    val supportsLatest: String by map
-
     val client: String?
         get() = map["client"] as? String
 
     val popular = PopularNode(toMap(map["popular"])!!)
 
-    val latestupdates = LatestUpdatesNode(toMap(map["latest_updates"])!!)
+    val latestupdates = toMap(map["latest_updates"])?.let { LatestUpdatesNode(it) }
 
     val search = SearchNode(toMap(map["search"])!!)
 

+ 9 - 9
app/src/main/res/drawable-anydpi/ic_watch_later.xml → app/src/main/res/drawable/ic_watch_later_black_24dp.xml

@@ -1,9 +1,9 @@
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="24dp"
-        android:height="24dp"
-        android:viewportWidth="24.0"
-        android:viewportHeight="24.0">
-    <path
-        android:fillColor="#FF000000"
-        android:pathData="M12,2C6.5,2 2,6.5 2,12s4.5,10 10,10 10,-4.5 10,-10S17.5,2 12,2zM16.2,16.2L11,13L11,7h1.5v5.2l4.5,2.7 -0.8,1.3z"/>
-</vector>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M12,2C6.5,2 2,6.5 2,12s4.5,10 10,10 10,-4.5 10,-10S17.5,2 12,2zM16.2,16.2L11,13L11,7h1.5v5.2l4.5,2.7 -0.8,1.3z"/>
+</vector>

+ 1 - 1
app/src/main/res/menu/menu_navigation.xml

@@ -21,7 +21,7 @@
             android:title="@string/label_catalogues" />
         <item
             android:id="@+id/nav_drawer_latest_updates"
-            android:icon="@drawable/ic_watch_later"
+            android:icon="@drawable/ic_watch_later_black_24dp"
             android:title="@string/label_latest_updates" />
         <item
             android:id="@+id/nav_drawer_downloads"