Removed network call now copies from page image
This commit is contained in:
parent
2991906a85
commit
2a4527a8d6
@ -27,6 +27,7 @@ import eu.kanade.tachiyomi.util.RetryWithDelay
|
|||||||
import eu.kanade.tachiyomi.util.SharedData
|
import eu.kanade.tachiyomi.util.SharedData
|
||||||
import eu.kanade.tachiyomi.util.saveTo
|
import eu.kanade.tachiyomi.util.saveTo
|
||||||
import eu.kanade.tachiyomi.util.toast
|
import eu.kanade.tachiyomi.util.toast
|
||||||
|
import okio.BufferedSource
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
@ -34,6 +35,7 @@ import rx.schedulers.Schedulers
|
|||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -587,6 +589,8 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
internal fun savePage() {
|
internal fun savePage() {
|
||||||
chapter.pages?.get(chapter.last_page_read)?.let { page ->
|
chapter.pages?.get(chapter.last_page_read)?.let { page ->
|
||||||
|
val inputFile = File(page.imagePath)
|
||||||
|
|
||||||
// File where the image will be saved
|
// File where the image will be saved
|
||||||
val destFile = File(pictureDirectory, manga.title + " - " + chapter.name +
|
val destFile = File(pictureDirectory, manga.title + " - " + chapter.name +
|
||||||
" - " + downloadManager.getImageFilename(page))
|
" - " + downloadManager.getImageFilename(page))
|
||||||
@ -594,39 +598,17 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
if (destFile.exists()) {
|
if (destFile.exists()) {
|
||||||
imageNotifier.onComplete(destFile)
|
imageNotifier.onComplete(destFile)
|
||||||
} else {
|
} else {
|
||||||
// Progress of the download
|
if (inputFile.exists()) {
|
||||||
var savedProgress = 0
|
Observable.fromCallable { inputFile.copyTo(destFile) }
|
||||||
|
|
||||||
val progressListener = object : ProgressListener {
|
|
||||||
override fun update(bytesRead: Long, contentLength: Long, done: Boolean) {
|
|
||||||
val progress = (100 * bytesRead / contentLength).toInt()
|
|
||||||
if (progress > savedProgress) {
|
|
||||||
savedProgress = progress
|
|
||||||
imageNotifier.onProgressChange(progress)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download and save the image.
|
|
||||||
Observable.fromCallable { ->
|
|
||||||
network.client.newCallWithProgress(GET(page.imageUrl!!), progressListener).execute()
|
|
||||||
}.map {
|
|
||||||
response ->
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
response.body().source().saveTo(destFile)
|
|
||||||
imageNotifier.onComplete(destFile)
|
|
||||||
} else {
|
|
||||||
response.close()
|
|
||||||
throw Exception("Unsuccessful response")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe({}, { error ->
|
.subscribe(
|
||||||
|
{ imageNotifier.onComplete(it) }, { error ->
|
||||||
Timber.e(error.message)
|
Timber.e(error.message)
|
||||||
imageNotifier.onError(error.message)
|
imageNotifier.onError(error.message)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user