mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Minor changes
This commit is contained in:
parent
53fae2939a
commit
5132f4850f
5 changed files with 24 additions and 59 deletions
|
@ -162,11 +162,7 @@ class DownloadManager(private val context: Context, private val sourceManager: S
|
||||||
|
|
||||||
// Download the entire chapter
|
// Download the entire chapter
|
||||||
private fun downloadChapter(download: Download): Observable<Download> {
|
private fun downloadChapter(download: Download): Observable<Download> {
|
||||||
try {
|
DiskUtils.createDirectory(download.directory)
|
||||||
DiskUtils.createDirectory(download.directory)
|
|
||||||
} catch (e: IOException) {
|
|
||||||
return Observable.error<Download>(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
val pageListObservable = if (download.pages == null)
|
val pageListObservable = if (download.pages == null)
|
||||||
// Pull page list from network and add them to download object
|
// 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
|
page.status = Page.DOWNLOAD_IMAGE
|
||||||
return source.getImageProgressResponse(page)
|
return source.getImageProgressResponse(page)
|
||||||
.flatMap({ resp ->
|
.flatMap({ resp ->
|
||||||
try {
|
DiskUtils.saveBufferedSourceToDirectory(resp.body().source(), directory, filename)
|
||||||
DiskUtils.saveBufferedSourceToDirectory(resp.body().source(), directory, filename)
|
Observable.just(page)
|
||||||
Observable.just(page)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e.cause, e.message)
|
|
||||||
Observable.error<Page>(e)
|
|
||||||
}
|
|
||||||
}).retry(2)
|
}).retry(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the most popular mangas from the source
|
// 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)
|
return networkService.requestBody(popularMangaRequest(page), true)
|
||||||
.map { Jsoup.parse(it) }
|
.map { Jsoup.parse(it) }
|
||||||
.doOnNext { doc -> page.mangas = parsePopularMangasFromHtml(doc) }
|
.doOnNext { doc -> page.mangas = parsePopularMangasFromHtml(doc) }
|
||||||
|
@ -83,7 +83,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get mangas from the source with a query
|
// 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)
|
return networkService.requestBody(searchMangaRequest(page, query), true)
|
||||||
.map { Jsoup.parse(it) }
|
.map { Jsoup.parse(it) }
|
||||||
.doOnNext { doc -> page.mangas = parseSearchFromHtml(doc) }
|
.doOnNext { doc -> page.mangas = parseSearchFromHtml(doc) }
|
||||||
|
@ -92,7 +92,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get manga details from the source
|
// Get manga details from the source
|
||||||
fun pullMangaFromNetwork(mangaUrl: String): Observable<Manga> {
|
open fun pullMangaFromNetwork(mangaUrl: String): Observable<Manga> {
|
||||||
return networkService.requestBody(mangaDetailsRequest(mangaUrl))
|
return networkService.requestBody(mangaDetailsRequest(mangaUrl))
|
||||||
.flatMap { Observable.just(parseHtmlToManga(mangaUrl, it)) }
|
.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))
|
return chapterCache.getPageListFromCache(getChapterCacheKey(chapterUrl))
|
||||||
.onErrorResumeNext { pullPageListFromNetwork(chapterUrl) }
|
.onErrorResumeNext { pullPageListFromNetwork(chapterUrl) }
|
||||||
.onBackpressureBuffer()
|
.onBackpressureBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pullPageListFromNetwork(chapterUrl: String): Observable<List<Page>> {
|
open fun pullPageListFromNetwork(chapterUrl: String): Observable<List<Page>> {
|
||||||
return networkService.requestBody(pageListRequest(chapterUrl))
|
return networkService.requestBody(pageListRequest(chapterUrl))
|
||||||
.flatMap { unparsedHtml ->
|
.flatMap { unparsedHtml ->
|
||||||
val pages = convertToPages(parseHtmlToPageUrls(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)
|
return Observable.from(pages)
|
||||||
.filter { page -> page.imageUrl != null }
|
.filter { page -> page.imageUrl != null }
|
||||||
.mergeWith(getRemainingImageUrlsFromPageList(pages))
|
.mergeWith(getRemainingImageUrlsFromPageList(pages))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the URLs of the images of a chapter
|
// 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)
|
return Observable.from(pages)
|
||||||
.filter { page -> page.imageUrl == null }
|
.filter { page -> page.imageUrl == null }
|
||||||
.concatMap { getImageUrlFromPage(it) }
|
.concatMap { getImageUrlFromPage(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getImageUrlFromPage(page: Page): Observable<Page> {
|
open fun getImageUrlFromPage(page: Page): Observable<Page> {
|
||||||
page.status = Page.LOAD_PAGE
|
page.status = Page.LOAD_PAGE
|
||||||
return networkService.requestBody(imageUrlRequest(page))
|
return networkService.requestBody(imageUrlRequest(page))
|
||||||
.flatMap { unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml)) }
|
.flatMap { unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml)) }
|
||||||
|
@ -154,7 +154,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCachedImage(page: Page): Observable<Page> {
|
open fun getCachedImage(page: Page): Observable<Page> {
|
||||||
val pageObservable = Observable.just(page)
|
val pageObservable = Observable.just(page)
|
||||||
if (page.imageUrl == null)
|
if (page.imageUrl == null)
|
||||||
return pageObservable
|
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)
|
return networkService.requestBodyProgress(imageRequest(page), page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ abstract class Source(context: Context) : BaseSource() {
|
||||||
chapterCache.putPageListToCache(getChapterCacheKey(chapterUrl), pages)
|
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>()
|
val pages = ArrayList<Page>()
|
||||||
for (i in pageUrls.indices) {
|
for (i in pageUrls.indices) {
|
||||||
pages.add(Page(i, pageUrls[i]))
|
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()
|
val builder = LazyHeaders.Builder()
|
||||||
for ((key, value) in requestHeaders.toMultimap()) {
|
for ((key, value) in requestHeaders.toMultimap()) {
|
||||||
builder.addHeader(key, value[0])
|
builder.addHeader(key, value[0])
|
||||||
|
|
|
@ -60,8 +60,9 @@ class MyAnimeListFragment : BaseRxFragment<MyAnimeListPresenter>() {
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRefreshError() {
|
fun onRefreshError(error: Throwable) {
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
|
context.toast(error.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSearchResults(results: List<MangaSync>) {
|
fun setSearchResults(results: List<MangaSync>) {
|
||||||
|
|
|
@ -57,7 +57,7 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||||
startableFirst(REFRESH,
|
startableFirst(REFRESH,
|
||||||
{ getRefreshObservable() },
|
{ getRefreshObservable() },
|
||||||
{ view, result -> view.onRefreshDone() },
|
{ view, result -> view.onRefreshDone() },
|
||||||
{ view, error -> view.onRefreshError() })
|
{ view, error -> view.onRefreshError(error) })
|
||||||
|
|
||||||
registerForEvents()
|
registerForEvents()
|
||||||
}
|
}
|
||||||
|
@ -93,15 +93,12 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||||
fun getRefreshObservable(): Observable<PutResult> {
|
fun getRefreshObservable(): Observable<PutResult> {
|
||||||
return mangaSync?.let { mangaSync ->
|
return mangaSync?.let { mangaSync ->
|
||||||
myAnimeList.getList()
|
myAnimeList.getList()
|
||||||
.flatMap { myList ->
|
.map { myList ->
|
||||||
for (myManga in myList) {
|
myList.find { it.remote_id == mangaSync.remote_id }?.let {
|
||||||
if (myManga.remote_id == mangaSync.remote_id) {
|
mangaSync.copyPersonalFrom(it)
|
||||||
mangaSync.copyPersonalFrom(myManga)
|
mangaSync.total_chapters = it.total_chapters
|
||||||
mangaSync.total_chapters = myManga.total_chapters
|
mangaSync
|
||||||
return@flatMap Observable.just(mangaSync)
|
} ?: throw Exception("Could not find manga")
|
||||||
}
|
|
||||||
}
|
|
||||||
Observable.error<MangaSync>(Exception("Could not find manga"))
|
|
||||||
}
|
}
|
||||||
.flatMap { db.insertMangaSync(it).asRxObservable() }
|
.flatMap { db.insertMangaSync(it).asRxObservable() }
|
||||||
.subscribeOn(Schedulers.io())
|
.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 a new issue