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 {
|
class EpubFileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import javax.inject.Inject
|
||||||
class EpubTextParser @Inject constructor() : TextParser {
|
class EpubTextParser @Inject constructor() : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Resource<List<String>> {
|
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))
|
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 {
|
class Fb2FileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import javax.xml.parsers.DocumentBuilderFactory
|
||||||
class Fb2TextParser @Inject constructor() : TextParser {
|
class Fb2TextParser @Inject constructor() : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Resource<List<String>> {
|
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))
|
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 {
|
class PdfFileParser @Inject constructor(private val application: Application) : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import javax.inject.Inject
|
||||||
class PdfTextParser @Inject constructor(private val application: Application) : TextParser {
|
class PdfTextParser @Inject constructor(private val application: Application) : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Resource<List<String>> {
|
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))
|
return Resource.Error(UIText.StringResource(R.string.error_wrong_file_format))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import javax.inject.Inject
|
||||||
class TxtFileParser @Inject constructor() : FileParser {
|
class TxtFileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Pair<Book, CoverImage?>? {
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import javax.inject.Inject
|
||||||
class TxtTextParser @Inject constructor() : TextParser {
|
class TxtTextParser @Inject constructor() : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(file: File): Resource<List<String>> {
|
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))
|
return Resource.Error(UIText.StringResource(R.string.error_wrong_file_format))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -499,8 +499,8 @@ class BookRepositoryImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
val isFileNotAdded = existingBooks.all {
|
val isFileNotAdded = existingBooks.all {
|
||||||
it.filePath.substringAfterLast("/") !=
|
it.filePath.substringAfterLast("/").lowercase() !=
|
||||||
file.path.substringAfterLast("/")
|
file.path.substringAfterLast("/").lowercase()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFileNotAdded) {
|
if (!isFileNotAdded) {
|
||||||
|
|
@ -537,7 +537,7 @@ class BookRepositoryImpl @Inject constructor(
|
||||||
val books = mutableListOf<NullableBook>()
|
val books = mutableListOf<NullableBook>()
|
||||||
|
|
||||||
for (file in files) {
|
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)
|
fileParser.parse(file)
|
||||||
} else {
|
} else {
|
||||||
books.add(
|
books.add(
|
||||||
|
|
@ -549,7 +549,7 @@ class BookRepositoryImpl @Inject constructor(
|
||||||
continue
|
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)
|
textParser.parse(file)
|
||||||
} else {
|
} else {
|
||||||
books.add(
|
books.add(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue