From 5132f4850fff164a5a4e34be56eb742fb1841997 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 19 Mar 2016 19:30:55 +0100 Subject: [PATCH] Minor changes --- .../data/download/DownloadManager.kt | 15 +++--------- .../tachiyomi/data/source/base/Source.kt | 24 +++++++++---------- .../manga/myanimelist/MyAnimeListFragment.kt | 3 ++- .../manga/myanimelist/MyAnimeListPresenter.kt | 17 ++++++------- .../eu/kanade/tachiyomi/util/ToastUtil.java | 24 ------------------- 5 files changed, 24 insertions(+), 59 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/ToastUtil.java diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 46c6f69ce..8df5923ea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -162,11 +162,7 @@ class DownloadManager(private val context: Context, private val sourceManager: S // Download the entire chapter private fun downloadChapter(download: Download): Observable { - try { - DiskUtils.createDirectory(download.directory) - } catch (e: IOException) { - return Observable.error(e) - } + DiskUtils.createDirectory(download.directory) 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(e) - } + DiskUtils.saveBufferedSourceToDirectory(resp.body().source(), directory, filename) + Observable.just(page) }).retry(2) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.kt index d817e23d2..50775c99d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.kt @@ -74,7 +74,7 @@ abstract class Source(context: Context) : BaseSource() { } // Get the most popular mangas from the source - fun pullPopularMangasFromNetwork(page: MangasPage): Observable { + open fun pullPopularMangasFromNetwork(page: MangasPage): Observable { 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 { + open fun searchMangasFromNetwork(page: MangasPage, query: String): Observable { 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 { + open fun pullMangaFromNetwork(mangaUrl: String): Observable { 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> { + open fun getCachedPageListOrPullFromNetwork(chapterUrl: String): Observable> { return chapterCache.getPageListFromCache(getChapterCacheKey(chapterUrl)) .onErrorResumeNext { pullPageListFromNetwork(chapterUrl) } .onBackpressureBuffer() } - fun pullPageListFromNetwork(chapterUrl: String): Observable> { + open fun pullPageListFromNetwork(chapterUrl: String): Observable> { 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): Observable { + open fun getAllImageUrlsFromPageList(pages: List): Observable { 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): Observable { + open fun getRemainingImageUrlsFromPageList(pages: List): Observable { return Observable.from(pages) .filter { page -> page.imageUrl == null } .concatMap { getImageUrlFromPage(it) } } - fun getImageUrlFromPage(page: Page): Observable { + open fun getImageUrlFromPage(page: Page): Observable { 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 { + open fun getCachedImage(page: Page): Observable { 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 { + open fun getImageProgressResponse(page: Page): Observable { 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): List { + protected open fun convertToPages(pageUrls: List): List { val pages = ArrayList() 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]) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListFragment.kt index 7d31eeb02..55926eff3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListFragment.kt @@ -60,8 +60,9 @@ class MyAnimeListFragment : BaseRxFragment() { swipe_refresh.isRefreshing = false } - fun onRefreshError() { + fun onRefreshError(error: Throwable) { swipe_refresh.isRefreshing = false + context.toast(error.message) } fun setSearchResults(results: List) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.kt index 16abc10f6..ab6b4be95 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.kt @@ -57,7 +57,7 @@ class MyAnimeListPresenter : BasePresenter() { startableFirst(REFRESH, { getRefreshObservable() }, { view, result -> view.onRefreshDone() }, - { view, error -> view.onRefreshError() }) + { view, error -> view.onRefreshError(error) }) registerForEvents() } @@ -93,15 +93,12 @@ class MyAnimeListPresenter : BasePresenter() { fun getRefreshObservable(): Observable { 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(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()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ToastUtil.java b/app/src/main/java/eu/kanade/tachiyomi/util/ToastUtil.java deleted file mode 100644 index 231734b34..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ToastUtil.java +++ /dev/null @@ -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(); - } - -}