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 ce54abcccf..845fa17a9c 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 @@ -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.online.LoginSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource +import eu.kanade.tachiyomi.util.selectText import okhttp3.FormBody import okhttp3.Request import okhttp3.Response @@ -51,30 +52,13 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex override fun headersBuilder() = super.headersBuilder() .add("Cookie", "lang_option=English") + + private val pageHeaders = super.headersBuilder() .add("Referer", "http://bato.to/reader") + .build() 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) { val document = Jsoup.parse(response.body().string()) 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 searchMangaInitialUrl(query: String) = "$baseUrl/search_ajax?name=${Uri.encode(query)}&p=1" + override fun searchMangaParse(response: Response, page: MangasPage, query: String) { val document = Jsoup.parse(response.body().string()) 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 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) { val tbody = document.select("tbody").first() val artistElement = tbody.select("tr:contains(Author/Artist:)").first() - manga.author = artistElement.select("td:eq(1)").first()?.text() - manga.artist = artistElement.select("td:eq(2)").first()?.text() ?: manga.author - manga.description = tbody.select("tr:contains(Description:) > td:eq(1)").first()?.text() + manga.author = artistElement.selectText("td:eq(1)") + manga.artist = artistElement.selectText("td:eq(2)") ?: manga.author + 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.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(", ") } @@ -147,7 +138,7 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex val matcher = staffNotice.matcher(body) if (matcher.find()) { val notice = Html.fromHtml(matcher.group(1)).toString().trim() - throw RuntimeException(notice) + throw Exception(notice) } val document = Jsoup.parse(body) @@ -197,6 +188,11 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex 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) { val selectElement = document.select("#page_select").first() 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 { return document.select("#comic_page").first().attr("src") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 464b17547c..fbcd1e1c5f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -226,19 +226,24 @@ class ReaderActivity : BaseRxActivity() { // Ignore } - fun onChapterReady(manga: Manga, chapter: Chapter, currentPage: Page?) { - val activePage = currentPage ?: chapter.pages.last() - + fun onMangaOpen(manga: Manga) { if (viewer == null) { viewer = getOrCreateViewer(manga) } - viewer?.onPageListReady(chapter, activePage) - if (viewer is RightToLeftReader && page_seekbar.rotation != 180f) { // Invert the seekbar for the right to left reader page_seekbar.rotation = 180f } 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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index a5518baa4b..da546352bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -57,10 +57,11 @@ class ReaderPresenter : BasePresenter() { private var appenderSubscription: Subscription? = null - private val GET_PAGE_LIST = 1 - private val GET_ADJACENT_CHAPTERS = 2 - private val GET_MANGA_SYNC = 3 - private val PRELOAD_NEXT_CHAPTER = 4 + private val PREPARE_READER = 1 + private val GET_PAGE_LIST = 2 + private val GET_ADJACENT_CHAPTERS = 3 + private val GET_MANGA_SYNC = 4 + private val PRELOAD_NEXT_CHAPTER = 5 private val MANGA_KEY = "manga_key" private val CHAPTER_KEY = "chapter_key" @@ -83,6 +84,10 @@ class ReaderPresenter : BasePresenter() { initializeSubjects() + restartableLatestCache(PREPARE_READER, + { Observable.just(manga) }, + { view, manga -> view.onMangaOpen(manga) }) + startableLatestCache(GET_ADJACENT_CHAPTERS, { getAdjacentChaptersObservable() }, { view, pair -> view.onAdjacentChapters(pair.first, pair.second) }) @@ -102,6 +107,7 @@ class ReaderPresenter : BasePresenter() { { view, error -> view.onChapterError(error) }) if (savedState == null) { + start(PREPARE_READER) loadChapter(chapter) if (prefs.autoUpdateMangaSync()) { start(GET_MANGA_SYNC) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt index e93f696cf0..43adbb5169 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt @@ -98,7 +98,11 @@ class WebtoonReader : BaseReader() { .doOnNext { setDecoderClass(it) } .skip(1) .distinctUntilChanged() - .subscribe { recycler.adapter = adapter }) + .subscribe { + val activePage = layoutManager.findFirstVisibleItemPosition() + recycler.adapter = adapter + setActivePage(activePage) + }) setPagesOnAdapter() return recycler diff --git a/app/src/main/res/anim/fade_in_long.xml b/app/src/main/res/anim/fade_in_long.xml new file mode 100644 index 0000000000..0a71c8b842 --- /dev/null +++ b/app/src/main/res/anim/fade_in_long.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_reader.xml b/app/src/main/res/layout/activity_reader.xml index 53f22748fb..e71d6f5ae0 100644 --- a/app/src/main/res/layout/activity_reader.xml +++ b/app/src/main/res/layout/activity_reader.xml @@ -9,6 +9,13 @@ android:layout_height="match_parent"> + +