Reader fixes and minor changes

This commit is contained in:
len 2016-06-02 14:11:10 +02:00
parent 18cdddf433
commit 1ac8ef5341
6 changed files with 70 additions and 35 deletions

View File

@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.data.source.model.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.LoginSource import eu.kanade.tachiyomi.data.source.online.LoginSource
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
import eu.kanade.tachiyomi.util.selectText
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
@ -51,30 +52,13 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex
override fun headersBuilder() = super.headersBuilder() override fun headersBuilder() = super.headersBuilder()
.add("Cookie", "lang_option=English") .add("Cookie", "lang_option=English")
private val pageHeaders = super.headersBuilder()
.add("Referer", "http://bato.to/reader") .add("Referer", "http://bato.to/reader")
.build()
override fun popularMangaInitialUrl() = "$baseUrl/search_ajax?order_cond=views&order=desc&p=1" override fun popularMangaInitialUrl() = "$baseUrl/search_ajax?order_cond=views&order=desc&p=1"
override fun searchMangaInitialUrl(query: String) = "$baseUrl/search_ajax?name=${Uri.encode(query)}&p=1"
override fun mangaDetailsRequest(manga: Manga): Request {
val mangaId = manga.url.substringAfterLast("r")
return GET("$baseUrl/comic_pop?id=$mangaId", headers)
}
override fun pageListRequest(chapter: Chapter): Request {
val id = chapter.url.substringAfterLast("#")
return GET("$baseUrl/areader?id=$id&p=1", headers)
}
override fun imageUrlRequest(page: Page): Request {
val pageUrl = page.url
val start = pageUrl.indexOf("#") + 1
val end = pageUrl.indexOf("_", start)
val id = pageUrl.substring(start, end)
return GET("$baseUrl/areader?id=$id&p=${pageUrl.substring(end+1)}", headers)
}
override fun popularMangaParse(response: Response, page: MangasPage) { override fun popularMangaParse(response: Response, page: MangasPage) {
val document = Jsoup.parse(response.body().string()) val document = Jsoup.parse(response.body().string())
for (element in document.select(popularMangaSelector())) { for (element in document.select(popularMangaSelector())) {
@ -101,6 +85,8 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex
override fun popularMangaNextPageSelector() = "#show_more_row" override fun popularMangaNextPageSelector() = "#show_more_row"
override fun searchMangaInitialUrl(query: String) = "$baseUrl/search_ajax?name=${Uri.encode(query)}&p=1"
override fun searchMangaParse(response: Response, page: MangasPage, query: String) { override fun searchMangaParse(response: Response, page: MangasPage, query: String) {
val document = Jsoup.parse(response.body().string()) val document = Jsoup.parse(response.body().string())
for (element in document.select(searchMangaSelector())) { for (element in document.select(searchMangaSelector())) {
@ -124,15 +110,20 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex
override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() override fun searchMangaNextPageSelector() = popularMangaNextPageSelector()
override fun mangaDetailsRequest(manga: Manga): Request {
val mangaId = manga.url.substringAfterLast("r")
return GET("$baseUrl/comic_pop?id=$mangaId", headers)
}
override fun mangaDetailsParse(document: Document, manga: Manga) { override fun mangaDetailsParse(document: Document, manga: Manga) {
val tbody = document.select("tbody").first() val tbody = document.select("tbody").first()
val artistElement = tbody.select("tr:contains(Author/Artist:)").first() val artistElement = tbody.select("tr:contains(Author/Artist:)").first()
manga.author = artistElement.select("td:eq(1)").first()?.text() manga.author = artistElement.selectText("td:eq(1)")
manga.artist = artistElement.select("td:eq(2)").first()?.text() ?: manga.author manga.artist = artistElement.selectText("td:eq(2)") ?: manga.author
manga.description = tbody.select("tr:contains(Description:) > td:eq(1)").first()?.text() manga.description = tbody.selectText("tr:contains(Description:) > td:eq(1)")
manga.thumbnail_url = document.select("img[src^=http://img.bato.to/forums/uploads/]").first()?.attr("src") manga.thumbnail_url = document.select("img[src^=http://img.bato.to/forums/uploads/]").first()?.attr("src")
manga.status = parseStatus(document.select("tr:contains(Status:) > td:eq(1)").first()?.text()) manga.status = parseStatus(document.selectText("tr:contains(Status:) > td:eq(1)"))
manga.genre = tbody.select("tr:contains(Genres:) img").map { it.attr("alt") }.joinToString(", ") manga.genre = tbody.select("tr:contains(Genres:) img").map { it.attr("alt") }.joinToString(", ")
} }
@ -147,7 +138,7 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex
val matcher = staffNotice.matcher(body) val matcher = staffNotice.matcher(body)
if (matcher.find()) { if (matcher.find()) {
val notice = Html.fromHtml(matcher.group(1)).toString().trim() val notice = Html.fromHtml(matcher.group(1)).toString().trim()
throw RuntimeException(notice) throw Exception(notice)
} }
val document = Jsoup.parse(body) val document = Jsoup.parse(body)
@ -197,6 +188,11 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex
return date.time return date.time
} }
override fun pageListRequest(chapter: Chapter): Request {
val id = chapter.url.substringAfterLast("#")
return GET("$baseUrl/areader?id=$id&p=1", pageHeaders)
}
override fun pageListParse(document: Document, pages: MutableList<Page>) { override fun pageListParse(document: Document, pages: MutableList<Page>) {
val selectElement = document.select("#page_select").first() val selectElement = document.select("#page_select").first()
if (selectElement != null) { if (selectElement != null) {
@ -212,6 +208,14 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex
} }
} }
override fun imageUrlRequest(page: Page): Request {
val pageUrl = page.url
val start = pageUrl.indexOf("#") + 1
val end = pageUrl.indexOf("_", start)
val id = pageUrl.substring(start, end)
return GET("$baseUrl/areader?id=$id&p=${pageUrl.substring(end+1)}", pageHeaders)
}
override fun imageUrlParse(document: Document): String { override fun imageUrlParse(document: Document): String {
return document.select("#comic_page").first().attr("src") return document.select("#comic_page").first().attr("src")
} }

View File

@ -226,19 +226,24 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
// Ignore // Ignore
} }
fun onChapterReady(manga: Manga, chapter: Chapter, currentPage: Page?) { fun onMangaOpen(manga: Manga) {
val activePage = currentPage ?: chapter.pages.last()
if (viewer == null) { if (viewer == null) {
viewer = getOrCreateViewer(manga) viewer = getOrCreateViewer(manga)
} }
viewer?.onPageListReady(chapter, activePage)
if (viewer is RightToLeftReader && page_seekbar.rotation != 180f) { if (viewer is RightToLeftReader && page_seekbar.rotation != 180f) {
// Invert the seekbar for the right to left reader // Invert the seekbar for the right to left reader
page_seekbar.rotation = 180f page_seekbar.rotation = 180f
} }
setToolbarTitle(manga.title) setToolbarTitle(manga.title)
please_wait.visibility = View.VISIBLE
please_wait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long))
}
fun onChapterReady(manga: Manga, chapter: Chapter, currentPage: Page?) {
please_wait.visibility = View.GONE
val activePage = currentPage ?: chapter.pages.last()
viewer?.onPageListReady(chapter, activePage)
setActiveChapter(chapter, activePage.pageNumber) setActiveChapter(chapter, activePage.pageNumber)
} }

View File

@ -57,10 +57,11 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
private var appenderSubscription: Subscription? = null private var appenderSubscription: Subscription? = null
private val GET_PAGE_LIST = 1 private val PREPARE_READER = 1
private val GET_ADJACENT_CHAPTERS = 2 private val GET_PAGE_LIST = 2
private val GET_MANGA_SYNC = 3 private val GET_ADJACENT_CHAPTERS = 3
private val PRELOAD_NEXT_CHAPTER = 4 private val GET_MANGA_SYNC = 4
private val PRELOAD_NEXT_CHAPTER = 5
private val MANGA_KEY = "manga_key" private val MANGA_KEY = "manga_key"
private val CHAPTER_KEY = "chapter_key" private val CHAPTER_KEY = "chapter_key"
@ -83,6 +84,10 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
initializeSubjects() initializeSubjects()
restartableLatestCache(PREPARE_READER,
{ Observable.just(manga) },
{ view, manga -> view.onMangaOpen(manga) })
startableLatestCache(GET_ADJACENT_CHAPTERS, startableLatestCache(GET_ADJACENT_CHAPTERS,
{ getAdjacentChaptersObservable() }, { getAdjacentChaptersObservable() },
{ view, pair -> view.onAdjacentChapters(pair.first, pair.second) }) { view, pair -> view.onAdjacentChapters(pair.first, pair.second) })
@ -102,6 +107,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
{ view, error -> view.onChapterError(error) }) { view, error -> view.onChapterError(error) })
if (savedState == null) { if (savedState == null) {
start(PREPARE_READER)
loadChapter(chapter) loadChapter(chapter)
if (prefs.autoUpdateMangaSync()) { if (prefs.autoUpdateMangaSync()) {
start(GET_MANGA_SYNC) start(GET_MANGA_SYNC)

View File

@ -98,7 +98,11 @@ class WebtoonReader : BaseReader() {
.doOnNext { setDecoderClass(it) } .doOnNext { setDecoderClass(it) }
.skip(1) .skip(1)
.distinctUntilChanged() .distinctUntilChanged()
.subscribe { recycler.adapter = adapter }) .subscribe {
val activePage = layoutManager.findFirstVisibleItemPosition()
recycler.adapter = adapter
setActivePage(activePage)
})
setPagesOnAdapter() setPagesOnAdapter()
return recycler return recycler

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="2000"
android:fillAfter="true"/>
</set>

View File

@ -9,6 +9,13 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
</FrameLayout> </FrameLayout>
<ProgressBar
android:id="@+id/please_wait"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView <TextView
android:id="@+id/page_number" android:id="@+id/page_number"
style="@style/TextAppearance.Regular.Caption" style="@style/TextAppearance.Regular.Caption"