Fix saving pages from cbz
This commit is contained in:
@@ -14,7 +14,7 @@ val readerModule
|
|||||||
factory { MangaDataRepository(get()) }
|
factory { MangaDataRepository(get()) }
|
||||||
single { PagesCache(get()) }
|
single { PagesCache(get()) }
|
||||||
|
|
||||||
factory { PageSaveHelper(get(), androidContext()) }
|
factory { PageSaveHelper(androidContext()) }
|
||||||
|
|
||||||
viewModel { params ->
|
viewModel { params ->
|
||||||
ReaderViewModel(
|
ReaderViewModel(
|
||||||
@@ -25,7 +25,7 @@ val readerModule
|
|||||||
historyRepository = get(),
|
historyRepository = get(),
|
||||||
settings = get(),
|
settings = get(),
|
||||||
pageSaveHelper = get(),
|
pageSaveHelper = get(),
|
||||||
bookmarksRepository = get(),
|
bookmarksRepository = get()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,10 @@ import android.content.Context
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.resume
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
@@ -11,19 +15,14 @@ import kotlinx.coroutines.withContext
|
|||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
import org.koitharu.kotatsu.base.domain.MangaUtils
|
import org.koitharu.kotatsu.base.domain.MangaUtils
|
||||||
import org.koitharu.kotatsu.local.data.PagesCache
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import java.io.File
|
|
||||||
import kotlin.coroutines.Continuation
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
|
|
||||||
private const val MAX_FILENAME_LENGTH = 10
|
private const val MAX_FILENAME_LENGTH = 10
|
||||||
private const val EXTENSION_FALLBACK = "png"
|
private const val EXTENSION_FALLBACK = "png"
|
||||||
|
|
||||||
class PageSaveHelper(
|
class PageSaveHelper(
|
||||||
private val cache: PagesCache,
|
|
||||||
context: Context,
|
context: Context,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -61,7 +60,11 @@ class PageSaveHelper(
|
|||||||
} != null
|
} != null
|
||||||
|
|
||||||
private suspend fun getProposedFileName(url: String, file: File): String {
|
private suspend fun getProposedFileName(url: String, file: File): String {
|
||||||
var name = url.toHttpUrl().pathSegments.last()
|
var name = if (url.startsWith("cbz://")) {
|
||||||
|
requireNotNull(url.toUri().fragment)
|
||||||
|
} else {
|
||||||
|
url.toHttpUrl().pathSegments.last()
|
||||||
|
}
|
||||||
var extension = name.substringAfterLast('.', "")
|
var extension = name.substringAfterLast('.', "")
|
||||||
name = name.substringBeforeLast('.')
|
name = name.substringBeforeLast('.')
|
||||||
if (extension.length !in 2..4) {
|
if (extension.length !in 2..4) {
|
||||||
|
|||||||
Reference in New Issue
Block a user