Surface errors when saving/sharing covers
This commit is contained in:
parent
d0561705fe
commit
9457b832fc
@ -528,16 +528,18 @@ class MangaController :
|
|||||||
R.id.action_migrate -> migrateManga()
|
R.id.action_migrate -> migrateManga()
|
||||||
// SY -->
|
// SY -->
|
||||||
R.id.action_save -> {
|
R.id.action_save -> {
|
||||||
if (presenter.saveCover(activity!!)) {
|
try {
|
||||||
|
presenter.saveCover(activity!!)
|
||||||
activity?.toast(R.string.cover_saved)
|
activity?.toast(R.string.cover_saved)
|
||||||
} else {
|
} catch (e: Exception) {
|
||||||
activity?.toast(R.string.error_saving_cover)
|
e.message?.let { activity?.toast(it) } ?: activity?.toast(R.string.error_saving_cover)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.action_share_cover -> {
|
R.id.action_share_cover -> {
|
||||||
val cover = presenter.shareCover(activity!!)
|
try {
|
||||||
if (cover != null) {
|
val activity = activity!!
|
||||||
val stream = cover.getUriCompat(activity!!)
|
val cover = presenter.shareCover(activity)
|
||||||
|
val stream = cover.getUriCompat(activity)
|
||||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||||
putExtra(Intent.EXTRA_STREAM, stream)
|
putExtra(Intent.EXTRA_STREAM, stream)
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
@ -545,8 +547,8 @@ class MangaController :
|
|||||||
type = "image/*"
|
type = "image/*"
|
||||||
}
|
}
|
||||||
startActivity(Intent.createChooser(intent, activity?.getString(R.string.action_share)))
|
startActivity(Intent.createChooser(intent, activity?.getString(R.string.action_share)))
|
||||||
} else {
|
} catch (e: Exception) {
|
||||||
activity?.toast(R.string.error_sharing_cover)
|
e.message?.let { activity?.toast(it) } ?: activity?.toast(R.string.error_sharing_cover)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
|
@ -542,32 +542,23 @@ class MangaPresenter(
|
|||||||
// I cant find any way to call the chapter list subscription to get the chapters again
|
// I cant find any way to call the chapter list subscription to get the chapters again
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shareCover(context: Context): File? {
|
fun shareCover(context: Context): File {
|
||||||
return try {
|
val destDir = File(context.cacheDir, "shared_image")
|
||||||
val destDir = File(context.cacheDir, "shared_image")
|
return saveCover(destDir)
|
||||||
val file = saveCover(destDir)
|
|
||||||
file
|
|
||||||
} catch (e: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveCover(context: Context): Boolean {
|
fun saveCover(context: Context) {
|
||||||
return try {
|
val directory = File(
|
||||||
val directory = File(
|
Environment.getExternalStorageDirectory().absolutePath +
|
||||||
Environment.getExternalStorageDirectory().absolutePath +
|
File.separator + Environment.DIRECTORY_PICTURES +
|
||||||
File.separator + Environment.DIRECTORY_PICTURES +
|
File.separator + context.getString(R.string.app_name)
|
||||||
File.separator + context.getString(R.string.app_name)
|
)
|
||||||
)
|
saveCover(directory)
|
||||||
saveCover(directory)
|
|
||||||
true
|
|
||||||
} catch (e: Exception) {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveCover(directory: File): File {
|
private fun saveCover(directory: File): File {
|
||||||
val cover = coverCache.getCoverFile(manga)!!
|
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())
|
val type = ImageUtil.findImageType(cover.inputStream())
|
||||||
?: throw Exception("Not an image")
|
?: throw Exception("Not an image")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user