🛠️ Use File.separator to correctly separate paths
* Replaced "/" with "File.separator" to ensure correctness of the separation
This commit is contained in:
parent
181f1c94eb
commit
32cea59c7a
5 changed files with 23 additions and 18 deletions
|
|
@ -9,6 +9,7 @@ import ua.acclorite.book_story.domain.reader.ReaderText
|
||||||
import ua.acclorite.book_story.presentation.core.util.clearAllMarkdown
|
import ua.acclorite.book_story.presentation.core.util.clearAllMarkdown
|
||||||
import ua.acclorite.book_story.presentation.core.util.clearMarkdown
|
import ua.acclorite.book_story.presentation.core.util.clearMarkdown
|
||||||
import ua.acclorite.book_story.presentation.core.util.containsVisibleText
|
import ua.acclorite.book_story.presentation.core.util.containsVisibleText
|
||||||
|
import java.io.File
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
@ -72,11 +73,11 @@ class DocumentParser @Inject constructor(
|
||||||
select("img").forEach { element ->
|
select("img").forEach { element ->
|
||||||
val src = element.attr("src")
|
val src = element.attr("src")
|
||||||
.trim()
|
.trim()
|
||||||
.substringAfterLast("/")
|
.substringAfterLast(File.separator)
|
||||||
.lowercase()
|
.lowercase()
|
||||||
.takeIf {
|
.takeIf {
|
||||||
it.containsVisibleText() && imageEntries?.any { image ->
|
it.containsVisibleText() && imageEntries?.any { image ->
|
||||||
it == image.name.substringAfterLast('/').lowercase()
|
it == image.name.substringAfterLast(File.separator).lowercase()
|
||||||
} == true
|
} == true
|
||||||
} ?: return@forEach
|
} ?: return@forEach
|
||||||
|
|
||||||
|
|
@ -91,11 +92,11 @@ class DocumentParser @Inject constructor(
|
||||||
select("image").forEach { element ->
|
select("image").forEach { element ->
|
||||||
val src = element.attr("xlink:href")
|
val src = element.attr("xlink:href")
|
||||||
.trim()
|
.trim()
|
||||||
.substringAfterLast("/")
|
.substringAfterLast(File.separator)
|
||||||
.lowercase()
|
.lowercase()
|
||||||
.takeIf {
|
.takeIf {
|
||||||
it.containsVisibleText() && imageEntries?.any { image ->
|
it.containsVisibleText() && imageEntries?.any { image ->
|
||||||
it == image.name.substringAfterLast('/').lowercase()
|
it == image.name.substringAfterLast(File.separator).lowercase()
|
||||||
} == true
|
} == true
|
||||||
} ?: return@forEach
|
} ?: return@forEach
|
||||||
|
|
||||||
|
|
@ -125,7 +126,7 @@ class DocumentParser @Inject constructor(
|
||||||
|
|
||||||
val image = try {
|
val image = try {
|
||||||
val imageEntry = imageEntries?.find { image ->
|
val imageEntry = imageEntries?.find { image ->
|
||||||
src == image.name.substringAfterLast('/').lowercase()
|
src == image.name.substringAfterLast(File.separator).lowercase()
|
||||||
} ?: return@forEach
|
} ?: return@forEach
|
||||||
|
|
||||||
zipFile?.getImage(imageEntry)?.asImageBitmap()
|
zipFile?.getImage(imageEntry)?.asImageBitmap()
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ class EpubTextParser @Inject constructor(
|
||||||
.let {
|
.let {
|
||||||
if (it == null) return@forEach
|
if (it == null) return@forEach
|
||||||
Uri.parse(it).path ?: it
|
Uri.parse(it).path ?: it
|
||||||
}.substringAfterLast("/")
|
}.substringAfterLast(File.separator)
|
||||||
|
|
||||||
titleMap[source] = (titleMap[source] ?: emptyList()) + title
|
titleMap[source] = (titleMap[source] ?: emptyList()) + title
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +245,7 @@ class EpubTextParser @Inject constructor(
|
||||||
): String? {
|
): String? {
|
||||||
if (chapterTitleMap.isNullOrEmpty()) return null
|
if (chapterTitleMap.isNullOrEmpty()) return null
|
||||||
return chapterTitleMap
|
return chapterTitleMap
|
||||||
.getOrElse(chapterSource.substringAfterLast("/")) { null }
|
.getOrElse(chapterSource.substringAfterLast(File.separator)) { null }
|
||||||
?.joinToString(separator = " / ")
|
?.joinToString(separator = " / ")
|
||||||
?.ifBlank { null }
|
?.ifBlank { null }
|
||||||
?.trim()
|
?.trim()
|
||||||
|
|
@ -278,11 +278,13 @@ class EpubTextParser @Inject constructor(
|
||||||
|
|
||||||
document.select("spine > itemref").mapNotNull { itemRef ->
|
document.select("spine > itemref").mapNotNull { itemRef ->
|
||||||
val spineId = itemRef.attr("idref")
|
val spineId = itemRef.attr("idref")
|
||||||
val chapterSource = manifestItems[spineId]?.substringAfterLast('/')?.lowercase()
|
val chapterSource = manifestItems[spineId]
|
||||||
|
?.substringAfterLast(File.separator)
|
||||||
|
?.lowercase()
|
||||||
?: return@mapNotNull null
|
?: return@mapNotNull null
|
||||||
|
|
||||||
zipEntries.find { entry ->
|
zipEntries.find { entry ->
|
||||||
entry.name.substringAfterLast('/').lowercase() == chapterSource
|
entry.name.substringAfterLast(File.separator).lowercase() == chapterSource
|
||||||
}
|
}
|
||||||
}.also { entries ->
|
}.also { entries ->
|
||||||
if (entries.isEmpty()) return@let
|
if (entries.isEmpty()) return@let
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ class BookRepositoryImpl @Inject constructor(
|
||||||
if (book.image != null) {
|
if (book.image != null) {
|
||||||
try {
|
try {
|
||||||
val fileToDelete = File(
|
val fileToDelete = File(
|
||||||
"$coversDir/${book.image.substringAfterLast("/")}"
|
"$coversDir${File.separator}${book.image.substringAfterLast(File.separator)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (fileToDelete.exists()) {
|
if (fileToDelete.exists()) {
|
||||||
|
|
@ -288,7 +288,7 @@ class BookRepositoryImpl @Inject constructor(
|
||||||
if (book.image != null) {
|
if (book.image != null) {
|
||||||
try {
|
try {
|
||||||
val fileToDelete = File(
|
val fileToDelete = File(
|
||||||
"$coversDir/${book.image.substringAfterLast("/")}"
|
"$coversDir${File.separator}${book.image.substringAfterLast(File.separator)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (fileToDelete.exists()) {
|
if (fileToDelete.exists()) {
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ fun BookInfoDetailsBottomSheet(
|
||||||
else ""
|
else ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fileName = remember {
|
||||||
|
book.filePath.substringAfterLast(File.separatorChar)
|
||||||
|
}
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
|
|
@ -67,11 +71,11 @@ fun BookInfoDetailsBottomSheet(
|
||||||
item {
|
item {
|
||||||
BookInfoDetailsBottomSheetItem(
|
BookInfoDetailsBottomSheetItem(
|
||||||
title = stringResource(id = R.string.file_name),
|
title = stringResource(id = R.string.file_name),
|
||||||
description = book.filePath.substringAfterLast("/").trim()
|
description = fileName
|
||||||
) {
|
) {
|
||||||
copyToClipboard(
|
copyToClipboard(
|
||||||
BookInfoEvent.OnCopyToClipboard(
|
BookInfoEvent.OnCopyToClipboard(
|
||||||
text = book.filePath.substringAfterLast("/").trim(),
|
text = fileName,
|
||||||
context = context
|
context = context
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -81,11 +85,11 @@ fun BookInfoDetailsBottomSheet(
|
||||||
item {
|
item {
|
||||||
BookInfoDetailsBottomSheetItem(
|
BookInfoDetailsBottomSheetItem(
|
||||||
title = stringResource(id = R.string.file_path),
|
title = stringResource(id = R.string.file_path),
|
||||||
description = book.filePath.trim()
|
description = book.filePath
|
||||||
) {
|
) {
|
||||||
copyToClipboard(
|
copyToClipboard(
|
||||||
BookInfoEvent.OnCopyToClipboard(
|
BookInfoEvent.OnCopyToClipboard(
|
||||||
text = book.filePath.trim(),
|
text = book.filePath,
|
||||||
context = context
|
context = context
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
|
@ -46,9 +45,8 @@ fun BookInfoDetailsBottomSheetItem(
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
Text(
|
Text(
|
||||||
description,
|
description,
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue