Added code to prevent OutOfMemory error. Made notification optional. Can now save image on long press. Bug fixes

This commit is contained in:
Bram van de Kerkhof
2016-10-06 21:51:51 +02:00
parent 1210691fdd
commit 4975787afa
14 changed files with 180 additions and 48 deletions

View File

@@ -145,8 +145,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
when (item.itemId) {
R.id.action_settings -> ReaderSettingsDialog().show(supportFragmentManager, "settings")
R.id.action_custom_filter -> ReaderCustomFilterDialog().show(supportFragmentManager, "filter")
R.id.action_save_page -> presenter.savePage()
R.id.action_set_as_cover -> presenter.setCover()
else -> return super.onOptionsItemSelected(item)
}
return true
@@ -230,6 +228,22 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
// Ignore
}
fun onLongPress() {
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()
}
}.show()
}
}
/**
* Called from the presenter at startup, allowing to prepare the selected reader.
*/

View File

@@ -1,5 +1,7 @@
package eu.kanade.tachiyomi.ui.reader
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import eu.kanade.tachiyomi.R
@@ -576,6 +578,19 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
return false
}
fun shareImage() {
chapter.pages?.get(chapter.last_page_read)?.let { page ->
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, Uri.parse(page.imagePath))
flags = Intent.FLAG_ACTIVITY_NEW_TASK
type = "image/jpeg"
}
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 })
}
}
/**
* Save page to local storage
* @throws IOException
@@ -595,7 +610,10 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
//Check if file doesn't already exist
if (destFile.exists()) {
imageNotifier.onComplete(destFile)
if (prefs.showSavePageNotification())
imageNotifier.onComplete(destFile)
else
context.toast(context.getString(R.string.page_downloaded, destFile.path))
} else {
if (inputFile.exists()) {
// Copy file
@@ -606,7 +624,10 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
{ imageNotifier.onComplete(it) },
{ error ->
Timber.e(error.message)
imageNotifier.onError(error.message)
if (prefs.showSavePageNotification())
imageNotifier.onError(error.message)
else
context.toast(error.message)
})
}
}

View File

@@ -185,6 +185,11 @@ abstract class PagerReader : BaseReader() {
}
return true
}
override fun onLongPress(e: MotionEvent?) {
super.onLongPress(e)
readerActivity.onLongPress()
}
})
}

View File

@@ -140,6 +140,11 @@ class WebtoonReader : BaseReader() {
}
return true
}
override fun onLongPress(e: MotionEvent?) {
super.onLongPress(e)
readerActivity.onLongPress()
}
})
}