mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 04:58:56 +01:00
Add share and save cover actions (closes #3011)
This commit is contained in:
@@ -76,7 +76,9 @@ import eu.kanade.tachiyomi.util.chapter.NoChaptersException
|
||||
import eu.kanade.tachiyomi.util.hasCustomCover
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.toShareIntent
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.getCoordinates
|
||||
import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
||||
@@ -400,8 +402,11 @@ class MangaController :
|
||||
R.id.download_custom, R.id.download_unread, R.id.download_all
|
||||
-> downloadChapters(item.itemId)
|
||||
|
||||
R.id.action_share_cover -> shareCover()
|
||||
R.id.action_save_cover -> saveCover()
|
||||
R.id.action_edit_cover -> changeCover()
|
||||
|
||||
R.id.action_edit_categories -> onCategoriesClick()
|
||||
R.id.action_edit_cover -> handleChangeCover()
|
||||
R.id.action_migrate -> migrateManga()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
@@ -640,20 +645,35 @@ class MangaController :
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleChangeCover() {
|
||||
val manga = manga ?: return
|
||||
if (manga.hasCustomCover(coverCache)) {
|
||||
showEditCoverDialog(manga)
|
||||
} else {
|
||||
openMangaCoverPicker(manga)
|
||||
private fun shareCover() {
|
||||
try {
|
||||
val activity = activity!!
|
||||
val cover = presenter.shareCover(activity)
|
||||
val uri = cover.getUriCompat(activity)
|
||||
startActivity(Intent.createChooser(uri.toShareIntent(), activity.getString(R.string.action_share)))
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
activity?.toast(R.string.error_sharing_cover)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit custom cover for selected manga.
|
||||
*/
|
||||
private fun showEditCoverDialog(manga: Manga) {
|
||||
ChangeMangaCoverDialog(this, manga).showDialog(router)
|
||||
private fun saveCover() {
|
||||
try {
|
||||
presenter.saveCover(activity!!)
|
||||
activity?.toast(R.string.cover_saved)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
activity?.toast(R.string.error_saving_cover)
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeCover() {
|
||||
val manga = manga ?: return
|
||||
if (manga.hasCustomCover(coverCache)) {
|
||||
ChangeMangaCoverDialog(this, manga).showDialog(router)
|
||||
} else {
|
||||
openMangaCoverPicker(manga)
|
||||
}
|
||||
}
|
||||
|
||||
override fun openMangaCoverPicker(manga: Manga) {
|
||||
|
||||
@@ -35,6 +35,10 @@ import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import eu.kanade.tachiyomi.util.prepUpdateCover
|
||||
import eu.kanade.tachiyomi.util.removeCovers
|
||||
import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
import eu.kanade.tachiyomi.util.storage.getPicturesDir
|
||||
import eu.kanade.tachiyomi.util.storage.getTempShareDir
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.updateCoverLastModified
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State
|
||||
@@ -49,6 +53,7 @@ import rx.schedulers.Schedulers
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.File
|
||||
import java.util.Date
|
||||
|
||||
class MangaPresenter(
|
||||
@@ -275,6 +280,33 @@ class MangaPresenter(
|
||||
moveMangaToCategories(manga, listOfNotNull(category))
|
||||
}
|
||||
|
||||
fun shareCover(context: Context): File {
|
||||
return saveCover(getTempShareDir(context))
|
||||
}
|
||||
|
||||
fun saveCover(context: Context) {
|
||||
saveCover(getPicturesDir(context))
|
||||
}
|
||||
|
||||
private fun saveCover(directory: File): File {
|
||||
val cover = coverCache.getCoverFile(manga) ?: throw Exception("Cover url was null")
|
||||
if (!cover.exists()) throw Exception("Cover not in cache")
|
||||
val type = ImageUtil.findImageType(cover.inputStream())
|
||||
?: throw Exception("Not an image")
|
||||
|
||||
directory.mkdirs()
|
||||
|
||||
val filename = DiskUtil.buildValidFilename("${manga.title}.${type.extension}")
|
||||
|
||||
val destFile = File(directory, filename)
|
||||
cover.inputStream().use { input ->
|
||||
destFile.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
return destFile
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cover with local file.
|
||||
*
|
||||
|
||||
@@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import com.jakewharton.rxrelay.BehaviorRelay
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
@@ -29,6 +28,8 @@ import eu.kanade.tachiyomi.util.lang.byteSize
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.takeBytes
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
import eu.kanade.tachiyomi.util.storage.getPicturesDir
|
||||
import eu.kanade.tachiyomi.util.storage.getTempShareDir
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.updateCoverLastModified
|
||||
import kotlinx.coroutines.async
|
||||
@@ -592,9 +593,7 @@ class ReaderPresenter(
|
||||
notifier.onClear()
|
||||
|
||||
// Pictures directory.
|
||||
val baseDir = Environment.getExternalStorageDirectory().absolutePath +
|
||||
File.separator + Environment.DIRECTORY_PICTURES +
|
||||
File.separator + context.getString(R.string.app_name)
|
||||
val baseDir = getPicturesDir(context).absolutePath
|
||||
val destDir = if (preferences.folderPerManga()) {
|
||||
File(baseDir + File.separator + manga.title)
|
||||
} else {
|
||||
@@ -628,7 +627,7 @@ class ReaderPresenter(
|
||||
val manga = manga ?: return
|
||||
val context = Injekt.get<Application>()
|
||||
|
||||
val destDir = File(context.cacheDir, "shared_image")
|
||||
val destDir = getTempShareDir(context)
|
||||
|
||||
Observable.fromCallable { destDir.deleteRecursively() } // Keep only the last shared file
|
||||
.map { saveImage(page, destDir, manga) }
|
||||
|
||||
Reference in New Issue
Block a user