mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 03:09:19 +01:00
Minor refactor
This commit is contained in:
parent
93e244b4c4
commit
4ef7b16925
@ -83,7 +83,7 @@ class DownloadProvider(private val context: Context) {
|
|||||||
* @param manga the manga to query.
|
* @param manga the manga to query.
|
||||||
*/
|
*/
|
||||||
fun getMangaDirName(manga: Manga): String {
|
fun getMangaDirName(manga: Manga): String {
|
||||||
return DiskUtil.buildValidFatFilename(manga.title)
|
return DiskUtil.buildValidFilename(manga.title)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +92,7 @@ class DownloadProvider(private val context: Context) {
|
|||||||
* @param chapter the chapter to query.
|
* @param chapter the chapter to query.
|
||||||
*/
|
*/
|
||||||
fun getChapterDirName(chapter: Chapter): String {
|
fun getChapterDirName(chapter: Chapter): String {
|
||||||
return DiskUtil.buildValidFatFilename(chapter.name)
|
return DiskUtil.buildValidFilename(chapter.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -570,17 +570,16 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
val destDir = File(pictureDirectory)
|
val destDir = File(pictureDirectory)
|
||||||
destDir.mkdirs()
|
destDir.mkdirs()
|
||||||
|
|
||||||
// Find out file extension.
|
// Find out file mime type.
|
||||||
val mime = context.contentResolver.getType(page.uri)
|
val mime = context.contentResolver.getType(page.uri)
|
||||||
?: context.contentResolver.openInputStream(page.uri).buffered().use {
|
?: context.contentResolver.openInputStream(page.uri).buffered().use {
|
||||||
URLConnection.guessContentTypeFromStream(it)
|
URLConnection.guessContentTypeFromStream(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build destination file.
|
||||||
val ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) ?: "jpg"
|
val ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) ?: "jpg"
|
||||||
|
val filename = "${manga.title} - ${chapter.name} - ${page.index + 1}"
|
||||||
// Destination file.
|
val destFile = File(destDir, DiskUtil.buildValidFilename(filename) + ".$ext")
|
||||||
|
|
||||||
val filename = "${manga.title} - ${chapter.name} - ${page.index + 1}.$ext"
|
|
||||||
val destFile = File(destDir, DiskUtil.buildValidFatFilename(filename))
|
|
||||||
|
|
||||||
context.contentResolver.openInputStream(page.uri).use { input ->
|
context.contentResolver.openInputStream(page.uri).use { input ->
|
||||||
destFile.outputStream().use { output ->
|
destFile.outputStream().use { output ->
|
||||||
|
@ -36,7 +36,7 @@ object DiskUtil {
|
|||||||
* replacing any invalid characters with "_". This method doesn't allow private files (starting
|
* replacing any invalid characters with "_". This method doesn't allow private files (starting
|
||||||
* with a dot), but you can manually add it later.
|
* with a dot), but you can manually add it later.
|
||||||
*/
|
*/
|
||||||
fun buildValidFatFilename(origName: String): String {
|
fun buildValidFilename(origName: String): String {
|
||||||
val name = origName.trim('.', ' ')
|
val name = origName.trim('.', ' ')
|
||||||
if (name.isNullOrEmpty()) {
|
if (name.isNullOrEmpty()) {
|
||||||
return "(invalid)"
|
return "(invalid)"
|
||||||
|
Loading…
Reference in New Issue
Block a user