Minor changes
This commit is contained in:
parent
53fae2939a
commit
5132f4850f
@ -162,11 +162,7 @@ class DownloadManager(private val context: Context, private val sourceManager: S
|
||||
|
||||
// Download the entire chapter
|
||||
private fun downloadChapter(download: Download): Observable<Download> {
|
||||
try {
|
||||
DiskUtils.createDirectory(download.directory)
|
||||
} catch (e: IOException) {
|
||||
return Observable.error<Download>(e)
|
||||
}
|
||||
|
||||
val pageListObservable = if (download.pages == null)
|
||||
// Pull page list from network and add them to download object
|
||||
@ -236,13 +232,8 @@ class DownloadManager(private val context: Context, private val sourceManager: S
|
||||
page.status = Page.DOWNLOAD_IMAGE
|
||||
return source.getImageProgressResponse(page)
|
||||
.flatMap({ resp ->
|
||||
try {
|
||||
DiskUtils.saveBufferedSourceToDirectory(resp.body().source(), directory, filename)
|
||||
Observable.just(page)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e.cause, e.message)
|
||||
Observable.error<Page>(e)
|
||||
}
|
||||
}).retry(2)
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
}
|
||||
|
||||
// Get the most popular mangas from the source
|
||||
fun pullPopularMangasFromNetwork(page: MangasPage): Observable<MangasPage> {
|
||||
open fun pullPopularMangasFromNetwork(page: MangasPage): Observable<MangasPage> {
|
||||
return networkService.requestBody(popularMangaRequest(page), true)
|
||||
.map { Jsoup.parse(it) }
|
||||
.doOnNext { doc -> page.mangas = parsePopularMangasFromHtml(doc) }
|
||||
@ -83,7 +83,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
}
|
||||
|
||||
// Get mangas from the source with a query
|
||||
fun searchMangasFromNetwork(page: MangasPage, query: String): Observable<MangasPage> {
|
||||
open fun searchMangasFromNetwork(page: MangasPage, query: String): Observable<MangasPage> {
|
||||
return networkService.requestBody(searchMangaRequest(page, query), true)
|
||||
.map { Jsoup.parse(it) }
|
||||
.doOnNext { doc -> page.mangas = parseSearchFromHtml(doc) }
|
||||
@ -92,7 +92,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
}
|
||||
|
||||
// Get manga details from the source
|
||||
fun pullMangaFromNetwork(mangaUrl: String): Observable<Manga> {
|
||||
open fun pullMangaFromNetwork(mangaUrl: String): Observable<Manga> {
|
||||
return networkService.requestBody(mangaDetailsRequest(mangaUrl))
|
||||
.flatMap { Observable.just(parseHtmlToManga(mangaUrl, it)) }
|
||||
}
|
||||
@ -109,13 +109,13 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getCachedPageListOrPullFromNetwork(chapterUrl: String): Observable<List<Page>> {
|
||||
open fun getCachedPageListOrPullFromNetwork(chapterUrl: String): Observable<List<Page>> {
|
||||
return chapterCache.getPageListFromCache(getChapterCacheKey(chapterUrl))
|
||||
.onErrorResumeNext { pullPageListFromNetwork(chapterUrl) }
|
||||
.onBackpressureBuffer()
|
||||
}
|
||||
|
||||
fun pullPageListFromNetwork(chapterUrl: String): Observable<List<Page>> {
|
||||
open fun pullPageListFromNetwork(chapterUrl: String): Observable<List<Page>> {
|
||||
return networkService.requestBody(pageListRequest(chapterUrl))
|
||||
.flatMap { unparsedHtml ->
|
||||
val pages = convertToPages(parseHtmlToPageUrls(unparsedHtml))
|
||||
@ -126,20 +126,20 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllImageUrlsFromPageList(pages: List<Page>): Observable<Page> {
|
||||
open fun getAllImageUrlsFromPageList(pages: List<Page>): Observable<Page> {
|
||||
return Observable.from(pages)
|
||||
.filter { page -> page.imageUrl != null }
|
||||
.mergeWith(getRemainingImageUrlsFromPageList(pages))
|
||||
}
|
||||
|
||||
// Get the URLs of the images of a chapter
|
||||
fun getRemainingImageUrlsFromPageList(pages: List<Page>): Observable<Page> {
|
||||
open fun getRemainingImageUrlsFromPageList(pages: List<Page>): Observable<Page> {
|
||||
return Observable.from(pages)
|
||||
.filter { page -> page.imageUrl == null }
|
||||
.concatMap { getImageUrlFromPage(it) }
|
||||
}
|
||||
|
||||
fun getImageUrlFromPage(page: Page): Observable<Page> {
|
||||
open fun getImageUrlFromPage(page: Page): Observable<Page> {
|
||||
page.status = Page.LOAD_PAGE
|
||||
return networkService.requestBody(imageUrlRequest(page))
|
||||
.flatMap { unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml)) }
|
||||
@ -154,7 +154,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun getCachedImage(page: Page): Observable<Page> {
|
||||
open fun getCachedImage(page: Page): Observable<Page> {
|
||||
val pageObservable = Observable.just(page)
|
||||
if (page.imageUrl == null)
|
||||
return pageObservable
|
||||
@ -186,7 +186,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getImageProgressResponse(page: Page): Observable<Response> {
|
||||
open fun getImageProgressResponse(page: Page): Observable<Response> {
|
||||
return networkService.requestBodyProgress(imageRequest(page), page)
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
chapterCache.putPageListToCache(getChapterCacheKey(chapterUrl), pages)
|
||||
}
|
||||
|
||||
protected fun convertToPages(pageUrls: List<String>): List<Page> {
|
||||
protected open fun convertToPages(pageUrls: List<String>): List<Page> {
|
||||
val pages = ArrayList<Page>()
|
||||
for (i in pageUrls.indices) {
|
||||
pages.add(Page(i, pageUrls[i]))
|
||||
@ -218,7 +218,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||
|
||||
}
|
||||
|
||||
protected fun glideHeadersBuilder(): LazyHeaders.Builder {
|
||||
protected open fun glideHeadersBuilder(): LazyHeaders.Builder {
|
||||
val builder = LazyHeaders.Builder()
|
||||
for ((key, value) in requestHeaders.toMultimap()) {
|
||||
builder.addHeader(key, value[0])
|
||||
|
@ -60,8 +60,9 @@ class MyAnimeListFragment : BaseRxFragment<MyAnimeListPresenter>() {
|
||||
swipe_refresh.isRefreshing = false
|
||||
}
|
||||
|
||||
fun onRefreshError() {
|
||||
fun onRefreshError(error: Throwable) {
|
||||
swipe_refresh.isRefreshing = false
|
||||
context.toast(error.message)
|
||||
}
|
||||
|
||||
fun setSearchResults(results: List<MangaSync>) {
|
||||
|
@ -57,7 +57,7 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||
startableFirst(REFRESH,
|
||||
{ getRefreshObservable() },
|
||||
{ view, result -> view.onRefreshDone() },
|
||||
{ view, error -> view.onRefreshError() })
|
||||
{ view, error -> view.onRefreshError(error) })
|
||||
|
||||
registerForEvents()
|
||||
}
|
||||
@ -93,15 +93,12 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||
fun getRefreshObservable(): Observable<PutResult> {
|
||||
return mangaSync?.let { mangaSync ->
|
||||
myAnimeList.getList()
|
||||
.flatMap { myList ->
|
||||
for (myManga in myList) {
|
||||
if (myManga.remote_id == mangaSync.remote_id) {
|
||||
mangaSync.copyPersonalFrom(myManga)
|
||||
mangaSync.total_chapters = myManga.total_chapters
|
||||
return@flatMap Observable.just(mangaSync)
|
||||
}
|
||||
}
|
||||
Observable.error<MangaSync>(Exception("Could not find manga"))
|
||||
.map { myList ->
|
||||
myList.find { it.remote_id == mangaSync.remote_id }?.let {
|
||||
mangaSync.copyPersonalFrom(it)
|
||||
mangaSync.total_chapters = it.total_chapters
|
||||
mangaSync
|
||||
} ?: throw Exception("Could not find manga")
|
||||
}
|
||||
.flatMap { db.insertMangaSync(it).asRxObservable() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -1,24 +0,0 @@
|
||||
package eu.kanade.tachiyomi.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ToastUtil {
|
||||
|
||||
public static void showShort(Context context, int resourceId) {
|
||||
Toast.makeText(context, resourceId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static void showLong(Context context, int resourceId) {
|
||||
Toast.makeText(context, resourceId, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public static void showShort(Context context, String message) {
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static void showLong(Context context, String message) {
|
||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user