From 2dd58e5f7d58d10bf8804f2d2a6d9bc5297bc8c4 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 10 Dec 2016 23:16:46 +0100 Subject: [PATCH] Ask for confirmation before changing the cover. Fixes #562 --- .../tachiyomi/ui/reader/ReaderActivity.kt | 66 ++++++++++++------- .../tachiyomi/ui/reader/ReaderPresenter.kt | 16 ++--- app/src/main/res/values/strings.xml | 1 + 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 04f2fb9dfc..e96ffbccd6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -234,7 +234,7 @@ class ReaderActivity : BaseRxActivity() { .itemsIds(R.array.reader_image_options_values) .itemsCallback { materialDialog, view, i, charSequence -> when (i) { - 0 -> presenter.setCover(page) + 0 -> setImageAsCover(page) 1 -> shareImage(page) 2 -> presenter.savePage(page) } @@ -316,14 +316,14 @@ class ReaderActivity : BaseRxActivity() { val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer() else manga.viewer // 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) { // Create a new viewer - when (mangaViewer) { - RIGHT_TO_LEFT -> fragment = RightToLeftReader() - VERTICAL -> fragment = VerticalReader() - WEBTOON -> fragment = WebtoonReader() - else -> fragment = LeftToRightReader() + fragment = when (mangaViewer) { + RIGHT_TO_LEFT -> RightToLeftReader() + VERTICAL -> VerticalReader() + WEBTOON -> WebtoonReader() + else -> LeftToRightReader() } supportFragmentManager.beginTransaction().replace(R.id.reader, fragment, manga.viewer.toString()).commit() @@ -472,23 +472,6 @@ class ReaderActivity : BaseRxActivity() { } } - /** - * 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]. * 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() { } } + /** + * 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() + + } + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 87c869e93b..151ff02a2c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -523,19 +523,13 @@ class ReaderPresenter : BasePresenter() { /** * Update cover with page file. */ - internal fun setCover(page: Page) { - if (page.status != Page.READY) - return - + internal fun setImageAsCover(page: Page) { try { + val thumbUrl = manga.thumbnail_url ?: throw Exception("Image url not found") if (manga.favorite) { - if (manga.thumbnail_url != null) { - val input = context.contentResolver.openInputStream(page.uri) - coverCache.copyToCache(manga.thumbnail_url!!, input) - context.toast(R.string.cover_updated) - } else { - throw Exception("Image url not found") - } + val input = context.contentResolver.openInputStream(page.uri) + coverCache.copyToCache(thumbUrl, input) + context.toast(R.string.cover_updated) } else { context.toast(R.string.notification_first_add_to_library) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c412edda2f..f3845b957a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -297,6 +297,7 @@ Previous chapter not found Image could not be loaded.\nTry changing the image decoder or with one of the options below Update last chapter read in enabled services to %1$d? + Do you want to set this image as the cover? Viewer for this series