mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 02:51:47 +01:00
Ask for confirmation before changing the cover. Fixes #562
This commit is contained in:
parent
7c42ab885b
commit
2dd58e5f7d
@ -234,7 +234,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
.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<ReaderPresenter>() {
|
||||
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<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].
|
||||
* 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()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -523,19 +523,13 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
|
@ -297,6 +297,7 @@
|
||||
<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="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>
|
||||
|
||||
<!-- Backup fragment -->
|
||||
|
Loading…
Reference in New Issue
Block a user