mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-28 03:48:24 +01:00
Fix filename not having chapter title and page when sharing (#6827)
This commit is contained in:
parent
c581b9eeb9
commit
f8eb9f94f4
@ -565,6 +565,20 @@ class ReaderPresenter(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a filename for the given [manga] and [page]
|
||||||
|
*/
|
||||||
|
private fun generateFilename(
|
||||||
|
manga: Manga,
|
||||||
|
page: ReaderPage,
|
||||||
|
): String {
|
||||||
|
val chapter = page.chapter.chapter
|
||||||
|
val filenameSuffix = " - ${page.number}"
|
||||||
|
return DiskUtil.buildValidFilename(
|
||||||
|
"${manga.title} - ${chapter.name}".takeBytes(MAX_FILE_NAME_BYTES - filenameSuffix.byteSize())
|
||||||
|
) + filenameSuffix
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the image of this [page] on the pictures directory and notifies the UI of the result.
|
* Saves the image of this [page] on the pictures directory and notifies the UI of the result.
|
||||||
* There's also a notification to allow sharing the image somewhere else or deleting it.
|
* There's also a notification to allow sharing the image somewhere else or deleting it.
|
||||||
@ -577,12 +591,7 @@ class ReaderPresenter(
|
|||||||
val notifier = SaveImageNotifier(context)
|
val notifier = SaveImageNotifier(context)
|
||||||
notifier.onClear()
|
notifier.onClear()
|
||||||
|
|
||||||
// Generate filename
|
val filename = generateFilename(manga, page)
|
||||||
val chapter = page.chapter.chapter
|
|
||||||
val filenameSuffix = " - ${page.number}"
|
|
||||||
val filename = DiskUtil.buildValidFilename(
|
|
||||||
"${manga.title} - ${chapter.name}".takeBytes(MAX_FILE_NAME_BYTES - filenameSuffix.byteSize())
|
|
||||||
) + filenameSuffix
|
|
||||||
|
|
||||||
// Pictures directory.
|
// Pictures directory.
|
||||||
val relativePath = if (preferences.folderPerManga()) DiskUtil.buildValidFilename(manga.title) else ""
|
val relativePath = if (preferences.folderPerManga()) DiskUtil.buildValidFilename(manga.title) else ""
|
||||||
@ -624,13 +633,15 @@ class ReaderPresenter(
|
|||||||
val context = Injekt.get<Application>()
|
val context = Injekt.get<Application>()
|
||||||
val destDir = context.cacheImageDir
|
val destDir = context.cacheImageDir
|
||||||
|
|
||||||
|
val filename = generateFilename(manga, page)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
destDir.deleteRecursively()
|
destDir.deleteRecursively()
|
||||||
val uri = imageSaver.save(
|
val uri = imageSaver.save(
|
||||||
image = Image.Page(
|
image = Image.Page(
|
||||||
inputStream = page.stream!!,
|
inputStream = page.stream!!,
|
||||||
name = manga.title,
|
name = filename,
|
||||||
location = Location.Cache
|
location = Location.Cache
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user