Fixed webtoon page

This commit is contained in:
Bram van de Kerkhof 2016-10-13 15:16:10 +02:00
parent 414b8c9f21
commit 8ff8ab4f27
5 changed files with 37 additions and 41 deletions

View File

@ -64,7 +64,7 @@ class ImageNotifier(private val context: Context) {
}
setContentTitle(context.getString(R.string.picture_saved))
setSmallIcon(R.drawable.ic_insert_photo_black_24dp)
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(100, 100) {
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(96, 96) {
/**
* The method that will be called when the resource load has finished.
* @param resource the loaded resource.
@ -74,7 +74,7 @@ class ImageNotifier(private val context: Context) {
context.notificationManager.notify(notificationId, notificationBuilder.build())
}
})
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(512, 384) {
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(720, 1280) {
/**
* The method that will be called when the resource load has finished.
* @param resource the loaded resource.

View File

@ -228,16 +228,16 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
// Ignore
}
fun onLongPress() {
fun onLongPress(page: Page) {
MaterialDialog.Builder(this).apply {
title = "Choose"
items(R.array.reader_image_options)
.itemsIds(R.array.reader_image_options_values)
itemsCallback { materialDialog, view, i, charSequence ->
when (i) {
0 -> presenter.setCover()
1 -> presenter.shareImage()
2 -> presenter.savePage()
0 -> presenter.setCover(page)
1 -> presenter.shareImage(page)
2 -> presenter.savePage(page)
}
}.show()

View File

@ -547,11 +547,10 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
/**
* Update cover with page file.
*/
internal fun setCover() {
chapter.pages?.get(chapter.last_page_read)?.let {
internal fun setCover(page: Page) {
// Update cover to selected file, show error if something went wrong
try {
if (editCoverWithStream(File(it.imagePath).inputStream(), manga)) {
if (editCoverWithStream(File(page.imagePath).inputStream(), manga)) {
context.toast(R.string.cover_updated)
} else {
throw Exception("Stream copy failed")
@ -560,7 +559,6 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
context.toast(R.string.notification_manga_update_failed)
Timber.e(e.message)
}
}
}
/**
@ -578,8 +576,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
return false
}
fun shareImage() {
chapter.pages?.get(chapter.last_page_read)?.let { page ->
fun shareImage(page: Page) {
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, Uri.parse(page.imagePath))
@ -588,7 +585,6 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
}
context.startActivity(Intent.createChooser(shareIntent, context.resources.getText(R.string.action_share))
.apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK })
}
}
/**
@ -596,34 +592,32 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
* @throws IOException
*/
@Throws(IOException::class)
internal fun savePage() {
chapter.pages?.get(chapter.last_page_read)?.let { page ->
// Location of image file.
val inputFile = File(page.imagePath)
internal fun savePage(page: Page) {
// Location of image file.
val inputFile = File(page.imagePath)
// File where the image will be saved.
val destFile = File(pictureDirectory, manga.title + " - " + chapter.name +
" - " + downloadManager.getImageFilename(page))
// File where the image will be saved.
val destFile = File(pictureDirectory, manga.title + " - " + chapter.name +
" - " + downloadManager.getImageFilename(page))
//Remove the notification if already exist (user feedback)
imageNotifier.onClear()
//Remove the notification if already exist (user feedback)
imageNotifier.onClear()
//Check if file doesn't already exist
if (destFile.exists()) {
imageNotifier.onComplete(destFile)
} else {
if (inputFile.exists()) {
// Copy file
Observable.fromCallable { inputFile.copyTo(destFile) }
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(
{ imageNotifier.onComplete(it) },
{ error ->
Timber.e(error.message)
imageNotifier.onError(error.message)
})
}
//Check if file doesn't already exist
if (destFile.exists()) {
imageNotifier.onComplete(destFile)
} else {
if (inputFile.exists()) {
// Copy file
Observable.fromCallable { inputFile.copyTo(destFile) }
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(
{ imageNotifier.onComplete(it) },
{ error ->
Timber.e(error.message)
imageNotifier.onError(error.message)
})
}
}
}

View File

@ -188,7 +188,7 @@ abstract class PagerReader : BaseReader() {
override fun onLongPress(e: MotionEvent?) {
super.onLongPress(e)
readerActivity.onLongPress()
readerActivity.onLongPress(adapter.pages!![pager.currentItem])
}
})
}

View File

@ -141,9 +141,11 @@ class WebtoonReader : BaseReader() {
return true
}
override fun onLongPress(e: MotionEvent?) {
override fun onLongPress(e: MotionEvent) {
super.onLongPress(e)
readerActivity.onLongPress()
val a = recycler.findChildViewUnder(e.rawX, e.rawY)
val i = recycler.getChildAdapterPosition(a)
readerActivity.onLongPress(adapter.getItem(i))
}
})
}