Ignoring file format case(adds support for .TXT, .PDF, .EPUB, .FB2 and whatever like .TxT or .pDF). (v1.0.1)
This commit is contained in:
parent
6e70901429
commit
09f9bbc027
9 changed files with 12 additions and 12 deletions
|
|
@ -16,7 +16,7 @@ import javax.inject.Inject
|
|||
class EpubFileParser @Inject constructor() : FileParser {
|
||||
|
||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
||||
if (!file.name.endsWith(".epub") || !file.exists()) {
|
||||
if (!file.name.endsWith(".epub", true) || !file.exists()) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import javax.inject.Inject
|
|||
class EpubTextParser @Inject constructor() : TextParser {
|
||||
|
||||
override suspend fun parse(file: File): Resource<List<String>> {
|
||||
if (!file.name.endsWith(".epub") || !file.exists()) {
|
||||
if (!file.name.endsWith(".epub", true) || !file.exists()) {
|
||||
return Resource.Error(UIText.StringResource(R.string.error_wrong_file_format))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import javax.xml.parsers.DocumentBuilderFactory
|
|||
class Fb2FileParser @Inject constructor() : FileParser {
|
||||
|
||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
||||
if (!file.name.endsWith(".fb2") || !file.exists()) {
|
||||
if (!file.name.endsWith(".fb2", true) || !file.exists()) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import javax.xml.parsers.DocumentBuilderFactory
|
|||
class Fb2TextParser @Inject constructor() : TextParser {
|
||||
|
||||
override suspend fun parse(file: File): Resource<List<String>> {
|
||||
if (!file.name.endsWith(".fb2") || !file.exists()) {
|
||||
if (!file.name.endsWith(".fb2", true) || !file.exists()) {
|
||||
return Resource.Error(UIText.StringResource(R.string.error_wrong_file_format))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import javax.inject.Inject
|
|||
class PdfFileParser @Inject constructor(private val application: Application) : FileParser {
|
||||
|
||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
||||
if (!file.name.endsWith(".pdf") || !file.exists()) {
|
||||
if (!file.name.endsWith(".pdf", true) || !file.exists()) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import javax.inject.Inject
|
|||
class PdfTextParser @Inject constructor(private val application: Application) : TextParser {
|
||||
|
||||
override suspend fun parse(file: File): Resource<List<String>> {
|
||||
if (!file.name.endsWith(".pdf") || !file.exists()) {
|
||||
if (!file.name.endsWith(".pdf", true) || !file.exists()) {
|
||||
return Resource.Error(UIText.StringResource(R.string.error_wrong_file_format))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import javax.inject.Inject
|
|||
class TxtFileParser @Inject constructor() : FileParser {
|
||||
|
||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
||||
if (!file.name.endsWith(".txt") || !file.exists()) {
|
||||
if (!file.name.endsWith(".txt", true) || !file.exists()) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import javax.inject.Inject
|
|||
class TxtTextParser @Inject constructor() : TextParser {
|
||||
|
||||
override suspend fun parse(file: File): Resource<List<String>> {
|
||||
if (!file.name.endsWith(".txt") || !file.exists()) {
|
||||
if (!file.name.endsWith(".txt", true) || !file.exists()) {
|
||||
return Resource.Error(UIText.StringResource(R.string.error_wrong_file_format))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -499,8 +499,8 @@ class BookRepositoryImpl @Inject constructor(
|
|||
}
|
||||
|
||||
val isFileNotAdded = existingBooks.all {
|
||||
it.filePath.substringAfterLast("/") !=
|
||||
file.path.substringAfterLast("/")
|
||||
it.filePath.substringAfterLast("/").lowercase() !=
|
||||
file.path.substringAfterLast("/").lowercase()
|
||||
}
|
||||
|
||||
if (!isFileNotAdded) {
|
||||
|
|
@ -537,7 +537,7 @@ class BookRepositoryImpl @Inject constructor(
|
|||
val books = mutableListOf<NullableBook>()
|
||||
|
||||
for (file in files) {
|
||||
val parsedBook = if (Constants.EXTENSIONS.any { file.name.endsWith(it) }) {
|
||||
val parsedBook = if (Constants.EXTENSIONS.any { file.name.endsWith(it, true) }) {
|
||||
fileParser.parse(file)
|
||||
} else {
|
||||
books.add(
|
||||
|
|
@ -549,7 +549,7 @@ class BookRepositoryImpl @Inject constructor(
|
|||
continue
|
||||
}
|
||||
|
||||
val parsedText = if (Constants.EXTENSIONS.any { file.name.endsWith(it) }) {
|
||||
val parsedText = if (Constants.EXTENSIONS.any { file.name.endsWith(it, true) }) {
|
||||
textParser.parse(file)
|
||||
} else {
|
||||
books.add(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue