Ask for confirmation before changing the cover. Fixes #562

This commit is contained in:
len 2016-12-10 23:16:46 +01:00
parent 7c42ab885b
commit 2dd58e5f7d
3 changed files with 48 additions and 35 deletions

View file

@ -234,7 +234,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
.itemsIds(R.array.reader_image_options_values) .itemsIds(R.array.reader_image_options_values)
.itemsCallback { materialDialog, view, i, charSequence -> .itemsCallback { materialDialog, view, i, charSequence ->
when (i) { when (i) {
0 -> presenter.setCover(page) 0 -> setImageAsCover(page)
1 -> shareImage(page) 1 -> shareImage(page)
2 -> presenter.savePage(page) 2 -> presenter.savePage(page)
} }
@ -316,14 +316,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer() else manga.viewer val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer() else manga.viewer
// Try to reuse the viewer using its tag // Try to reuse the viewer using its tag
var fragment: BaseReader? = supportFragmentManager.findFragmentByTag(manga.viewer.toString()) as? BaseReader var fragment = supportFragmentManager.findFragmentByTag(manga.viewer.toString()) as? BaseReader
if (fragment == null) { if (fragment == null) {
// Create a new viewer // Create a new viewer
when (mangaViewer) { fragment = when (mangaViewer) {
RIGHT_TO_LEFT -> fragment = RightToLeftReader() RIGHT_TO_LEFT -> RightToLeftReader()
VERTICAL -> fragment = VerticalReader() VERTICAL -> VerticalReader()
WEBTOON -> fragment = WebtoonReader() WEBTOON -> WebtoonReader()
else -> fragment = LeftToRightReader() else -> LeftToRightReader()
} }
supportFragmentManager.beginTransaction().replace(R.id.reader, fragment, manga.viewer.toString()).commit() supportFragmentManager.beginTransaction().replace(R.id.reader, fragment, manga.viewer.toString()).commit()
@ -472,23 +472,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
} }
} }
/**
* Start a share intent that lets user share image
*
* @param page page object containing image information.
*/
fun shareImage(page: Page) {
if (page.status != Page.READY)
return
val intent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_STREAM, page.uri)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
type = "image/*"
}
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
}
/** /**
* Sets the brightness of the screen. Range is [-75, 100]. * Sets the brightness of the screen. Range is [-75, 100].
* From -75 to -1 a semi-transparent black view is shown at the top with the minimum brightness. * From -75 to -1 a semi-transparent black view is shown at the top with the minimum brightness.
@ -573,4 +556,39 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
} }
} }
/**
* Start a share intent that lets user share image
*
* @param page page object containing image information.
*/
private fun shareImage(page: Page) {
if (page.status != Page.READY)
return
val intent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_STREAM, page.uri)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
type = "image/*"
}
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
}
/**
* Sets the given page as the cover of the manga.
*
* @param page the page containing the image to set as cover.
*/
private fun setImageAsCover(page: Page) {
if (page.status != Page.READY)
return
MaterialDialog.Builder(this)
.content(getString(R.string.confirm_set_image_as_cover))
.positiveText(android.R.string.yes)
.negativeText(android.R.string.no)
.onPositive { dialog, which -> presenter.setImageAsCover(page) }
.show()
}
} }

View file

@ -523,19 +523,13 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
/** /**
* Update cover with page file. * Update cover with page file.
*/ */
internal fun setCover(page: Page) { internal fun setImageAsCover(page: Page) {
if (page.status != Page.READY)
return
try { try {
val thumbUrl = manga.thumbnail_url ?: throw Exception("Image url not found")
if (manga.favorite) { if (manga.favorite) {
if (manga.thumbnail_url != null) { val input = context.contentResolver.openInputStream(page.uri)
val input = context.contentResolver.openInputStream(page.uri) coverCache.copyToCache(thumbUrl, input)
coverCache.copyToCache(manga.thumbnail_url!!, input) context.toast(R.string.cover_updated)
context.toast(R.string.cover_updated)
} else {
throw Exception("Image url not found")
}
} else { } else {
context.toast(R.string.notification_first_add_to_library) context.toast(R.string.notification_first_add_to_library)
} }

View file

@ -297,6 +297,7 @@
<string name="no_previous_chapter">Previous chapter not found</string> <string name="no_previous_chapter">Previous chapter not found</string>
<string name="decode_image_error">Image could not be loaded.\nTry changing the image decoder or with one of the options below</string> <string name="decode_image_error">Image could not be loaded.\nTry changing the image decoder or with one of the options below</string>
<string name="confirm_update_manga_sync">Update last chapter read in enabled services to %1$d?</string> <string name="confirm_update_manga_sync">Update last chapter read in enabled services to %1$d?</string>
<string name="confirm_set_image_as_cover">Do you want to set this image as the cover?</string>
<string name="viewer_for_this_series">Viewer for this series</string> <string name="viewer_for_this_series">Viewer for this series</string>
<!-- Backup fragment --> <!-- Backup fragment -->