refactor: logging
This commit is contained in:
parent
df818e3081
commit
d97ca6e517
43 changed files with 255 additions and 154 deletions
|
|
@ -13,6 +13,8 @@ import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.presentation.crash.CrashActivity
|
import ua.acclorite.book_story.presentation.crash.CrashActivity
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
private const val TAG = "CrashHandler"
|
||||||
|
|
||||||
class CrashHandler(
|
class CrashHandler(
|
||||||
private val context: Context
|
private val context: Context
|
||||||
) : Thread.UncaughtExceptionHandler {
|
) : Thread.UncaughtExceptionHandler {
|
||||||
|
|
@ -20,7 +22,7 @@ class CrashHandler(
|
||||||
override fun uncaughtException(thread: Thread, throwable: Throwable) {
|
override fun uncaughtException(thread: Thread, throwable: Throwable) {
|
||||||
val crashLog = throwable.stackTraceToString()
|
val crashLog = throwable.stackTraceToString()
|
||||||
|
|
||||||
logE(crashLog)
|
logE(TAG, crashLog)
|
||||||
if (!CrashUtils.saveCrashLog(context, crashLog)) return
|
if (!CrashUtils.saveCrashLog(context, crashLog)) return
|
||||||
|
|
||||||
val intent = Intent(context, CrashActivity::class.java).apply {
|
val intent = Intent(context, CrashActivity::class.java).apply {
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,18 @@ package ua.acclorite.book_story.core.log
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
|
||||||
fun logI(message: String) {
|
fun logI(tag: String, message: String) {
|
||||||
Log.i("INFO", message)
|
Log.i(tag, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logD(message: String) {
|
fun logD(tag: String, message: String) {
|
||||||
Log.d("DEBUG", message)
|
Log.d(tag, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logW(message: String) {
|
fun logW(tag: String, message: String) {
|
||||||
Log.w("WARNING", message)
|
Log.w(tag, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logE(message: String) {
|
fun logE(tag: String, message: String) {
|
||||||
Log.e("ERROR", message)
|
Log.e(tag, message)
|
||||||
}
|
}
|
||||||
|
|
@ -11,6 +11,8 @@ import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "CoverParser"
|
||||||
|
|
||||||
class CoverParserImpl @Inject constructor(
|
class CoverParserImpl @Inject constructor(
|
||||||
private val epubCoverParser: EpubCoverParser,
|
private val epubCoverParser: EpubCoverParser,
|
||||||
private val txtCoverParser: TxtCoverParser,
|
private val txtCoverParser: TxtCoverParser,
|
||||||
|
|
@ -21,7 +23,7 @@ class CoverParserImpl @Inject constructor(
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): CoverImage? {
|
override suspend fun parse(cachedFile: CachedFile): CoverImage? {
|
||||||
if (!cachedFile.canAccess()) {
|
if (!cachedFile.canAccess()) {
|
||||||
logE("File does not exist or no read access is granted.")
|
logE(TAG, "File does not exist or no read access is granted.")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +58,7 @@ class CoverParserImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
logE("Wrong file format, could not find supported extension.")
|
logE(TAG, "Wrong file format, could not find supported extension.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ import java.nio.charset.StandardCharsets
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "EpubCoverParser"
|
||||||
|
|
||||||
class EpubCoverParser @Inject constructor() : CoverParser {
|
class EpubCoverParser @Inject constructor() : CoverParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): CoverImage? {
|
override suspend fun parse(cachedFile: CachedFile): CoverImage? {
|
||||||
|
|
@ -76,7 +78,7 @@ class EpubCoverParser @Inject constructor() : CoverParser {
|
||||||
}
|
}
|
||||||
coverImage
|
coverImage
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
logE("Could not parse cover image.")
|
logE(TAG, "Could not parse cover image.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
package ua.acclorite.book_story.data.parser.file
|
package ua.acclorite.book_story.data.parser.file
|
||||||
|
|
||||||
import android.util.Log
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.library.Book
|
import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val FILE_PARSER = "File Parser"
|
private const val TAG = "FileParser"
|
||||||
|
|
||||||
class FileParserImpl @Inject constructor(
|
class FileParserImpl @Inject constructor(
|
||||||
private val txtFileParser: TxtFileParser,
|
private val txtFileParser: TxtFileParser,
|
||||||
|
|
@ -23,7 +23,7 @@ class FileParserImpl @Inject constructor(
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): Book? {
|
override suspend fun parse(cachedFile: CachedFile): Book? {
|
||||||
if (!cachedFile.canAccess()) {
|
if (!cachedFile.canAccess()) {
|
||||||
Log.e(FILE_PARSER, "File does not exist or no read access is granted.")
|
logE(TAG, "File does not exist or no read access is granted.")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ class FileParserImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
Log.e(FILE_PARSER, "Wrong file format, could not find supported extension.")
|
logE(TAG, "Wrong file format, could not find supported extension.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,10 @@ class TxtFileParser @Inject constructor() : FileParser {
|
||||||
override suspend fun parse(cachedFile: CachedFile): Book? {
|
override suspend fun parse(cachedFile: CachedFile): Book? {
|
||||||
return try {
|
return try {
|
||||||
val title = cachedFile.name.substringBeforeLast(".").trim()
|
val title = cachedFile.name.substringBeforeLast(".").trim()
|
||||||
val author = UIText.StringResource(R.string.unknown_author)
|
|
||||||
|
|
||||||
Book(
|
Book(
|
||||||
title = title,
|
title = title,
|
||||||
author = author,
|
author = UIText.StringResource(R.string.unknown_author),
|
||||||
description = null,
|
description = null,
|
||||||
scrollIndex = 0,
|
scrollIndex = 0,
|
||||||
scrollOffset = 0,
|
scrollOffset = 0,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
package ua.acclorite.book_story.data.parser.text
|
package ua.acclorite.book_story.data.parser.text
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
|
@ -21,6 +20,9 @@ import org.jsoup.parser.Parser
|
||||||
import ua.acclorite.book_story.core.data.ExtensionsData
|
import ua.acclorite.book_story.core.data.ExtensionsData
|
||||||
import ua.acclorite.book_story.core.helpers.addAll
|
import ua.acclorite.book_story.core.helpers.addAll
|
||||||
import ua.acclorite.book_story.core.helpers.containsVisibleText
|
import ua.acclorite.book_story.core.helpers.containsVisibleText
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
|
import ua.acclorite.book_story.core.log.logI
|
||||||
|
import ua.acclorite.book_story.core.log.logW
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.data.parser.document.DocumentParser
|
import ua.acclorite.book_story.data.parser.document.DocumentParser
|
||||||
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
|
|
@ -32,7 +34,7 @@ import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val EPUB_TAG = "EPUB Parser"
|
private const val TAG = "EpubTextParser"
|
||||||
private typealias Source = String
|
private typealias Source = String
|
||||||
|
|
||||||
private val dispatcher = Dispatchers.IO.limitedParallelism(3)
|
private val dispatcher = Dispatchers.IO.limitedParallelism(3)
|
||||||
|
|
@ -42,7 +44,7 @@ class EpubTextParser @Inject constructor(
|
||||||
) : TextParser {
|
) : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
||||||
Log.i(EPUB_TAG, "Started EPUB parsing: ${cachedFile.name}.")
|
logI(TAG, "Started EPUB parsing: ${cachedFile.name}.")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
yield()
|
yield()
|
||||||
|
|
@ -68,10 +70,10 @@ class EpubTextParser @Inject constructor(
|
||||||
}
|
}
|
||||||
val chapterTitleEntries = zip.getChapterTitleMapFromToc(tocEntry)
|
val chapterTitleEntries = zip.getChapterTitleMapFromToc(tocEntry)
|
||||||
|
|
||||||
Log.i(EPUB_TAG, "TOC Entry: ${tocEntry?.name ?: "no toc.ncx"}")
|
logI(TAG, "TOC Entry: ${tocEntry?.name ?: "no toc.ncx"}")
|
||||||
Log.i(EPUB_TAG, "OPF Entry: ${opfEntry?.name ?: "no .opf entry"}")
|
logI(TAG, "OPF Entry: ${opfEntry?.name ?: "no .opf entry"}")
|
||||||
Log.i(EPUB_TAG, "Chapter entries, size: ${chapterEntries.size}")
|
logI(TAG, "Chapter entries, size: ${chapterEntries.size}")
|
||||||
Log.i(EPUB_TAG, "Title entries, size: ${chapterTitleEntries?.size}")
|
logI(TAG, "Title entries, size: ${chapterTitleEntries?.size}")
|
||||||
|
|
||||||
readerText = zip.parseEpub(
|
readerText = zip.parseEpub(
|
||||||
chapterEntries = chapterEntries,
|
chapterEntries = chapterEntries,
|
||||||
|
|
@ -87,11 +89,11 @@ class EpubTextParser @Inject constructor(
|
||||||
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
||||||
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
||||||
) {
|
) {
|
||||||
Log.e(EPUB_TAG, "Could not extract text from EPUB.")
|
logE(TAG, "Could not extract text from EPUB.")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(EPUB_TAG, "Successfully finished EPUB parsing.")
|
logI(TAG, "Successfully finished EPUB parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|
@ -204,7 +206,7 @@ class EpubTextParser @Inject constructor(
|
||||||
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
||||||
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
||||||
) {
|
) {
|
||||||
Log.w(EPUB_TAG, "Could not extract text from [${entry.name}].")
|
logW(TAG, "Could not extract text from [${entry.name}].")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,12 +326,12 @@ class EpubTextParser @Inject constructor(
|
||||||
}.also { entries ->
|
}.also { entries ->
|
||||||
if (entries.isEmpty()) return@let
|
if (entries.isEmpty()) return@let
|
||||||
|
|
||||||
Log.i(EPUB_TAG, "Successfully parsed OPF to get entries from spine.")
|
logI(TAG, "Successfully parsed OPF to get entries from spine.")
|
||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.w(EPUB_TAG, "Could not parse OPF, manual filtering.")
|
logW(TAG, "Could not parse OPF, manual filtering.")
|
||||||
return entries().toList().filter { entry ->
|
return entries().toList().filter { entry ->
|
||||||
listOf(".html", ".htm", ".xhtml").any {
|
listOf(".html", ".htm", ".xhtml").any {
|
||||||
entry.name.endsWith(it, ignoreCase = true)
|
entry.name.endsWith(it, ignoreCase = true)
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,24 @@
|
||||||
|
|
||||||
package ua.acclorite.book_story.data.parser.text
|
package ua.acclorite.book_story.data.parser.text
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.parser.Parser
|
import org.jsoup.parser.Parser
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
|
import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.data.parser.document.DocumentParser
|
import ua.acclorite.book_story.data.parser.document.DocumentParser
|
||||||
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val HTML_TAG = "HTML Parser"
|
private const val TAG = "HtmlTextParser"
|
||||||
|
|
||||||
class HtmlTextParser @Inject constructor(
|
class HtmlTextParser @Inject constructor(
|
||||||
private val documentParser: DocumentParser
|
private val documentParser: DocumentParser
|
||||||
) : TextParser {
|
) : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
||||||
Log.i(HTML_TAG, "Started HTML parsing: ${cachedFile.name}.")
|
logI(TAG, "Started HTML parsing: ${cachedFile.name}.")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val readerText = cachedFile.openInputStream()?.use { stream ->
|
val readerText = cachedFile.openInputStream()?.use { stream ->
|
||||||
|
|
@ -36,14 +37,14 @@ class HtmlTextParser @Inject constructor(
|
||||||
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
||||||
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
||||||
) {
|
) {
|
||||||
Log.e(HTML_TAG, "Could not extract text from HTML.")
|
logE(TAG, "Could not extract text from HTML.")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(HTML_TAG, "Successfully finished HTML parsing.")
|
logI(TAG, "Successfully finished HTML parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, e.message ?: "")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,19 @@
|
||||||
package ua.acclorite.book_story.data.parser.text
|
package ua.acclorite.book_story.data.parser.text
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.util.Log
|
|
||||||
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
|
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
|
||||||
import com.tom_roush.pdfbox.pdmodel.PDDocument
|
import com.tom_roush.pdfbox.pdmodel.PDDocument
|
||||||
import com.tom_roush.pdfbox.text.PDFTextStripper
|
import com.tom_roush.pdfbox.text.PDFTextStripper
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import ua.acclorite.book_story.core.helpers.clearAllMarkdown
|
import ua.acclorite.book_story.core.helpers.clearAllMarkdown
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
|
import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.data.parser.document.MarkdownParser
|
import ua.acclorite.book_story.data.parser.document.MarkdownParser
|
||||||
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val PDF_TAG = "PDF Parser"
|
private const val TAG = "PdfTextParser"
|
||||||
|
|
||||||
class PdfTextParser @Inject constructor(
|
class PdfTextParser @Inject constructor(
|
||||||
private val markdownParser: MarkdownParser,
|
private val markdownParser: MarkdownParser,
|
||||||
|
|
@ -26,7 +27,7 @@ class PdfTextParser @Inject constructor(
|
||||||
) : TextParser {
|
) : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
||||||
Log.i(PDF_TAG, "Started PDF parsing: ${cachedFile.name}.")
|
logI(TAG, "Started PDF parsing: ${cachedFile.name}.")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
yield()
|
yield()
|
||||||
|
|
@ -148,14 +149,14 @@ class PdfTextParser @Inject constructor(
|
||||||
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
||||||
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
||||||
) {
|
) {
|
||||||
Log.e(PDF_TAG, "Could not extract text from PDF.")
|
logE(TAG, "Could not extract text from PDF.")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(PDF_TAG, "Successfully finished PDF parsing.")
|
logI(TAG, "Successfully finished PDF parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, e.message ?: "")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
package ua.acclorite.book_story.data.parser.text
|
package ua.acclorite.book_story.data.parser.text
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val TEXT_PARSER = "Text Parser"
|
private const val TAG = "TextParser"
|
||||||
|
|
||||||
class TextParserImpl @Inject constructor(
|
class TextParserImpl @Inject constructor(
|
||||||
// Markdown parser (Markdown)
|
// Markdown parser (Markdown)
|
||||||
|
|
@ -28,7 +28,7 @@ class TextParserImpl @Inject constructor(
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
||||||
if (!cachedFile.canAccess()) {
|
if (!cachedFile.canAccess()) {
|
||||||
Log.e(TEXT_PARSER, "File does not exist or no read access is granted.")
|
logE(TAG, "File does not exist or no read access is granted.")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ class TextParserImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
Log.e(TEXT_PARSER, "Wrong file format, could not find supported extension.")
|
logE(TAG, "Wrong file format, could not find supported extension.")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,25 @@
|
||||||
|
|
||||||
package ua.acclorite.book_story.data.parser.text
|
package ua.acclorite.book_story.data.parser.text
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import ua.acclorite.book_story.core.helpers.clearAllMarkdown
|
import ua.acclorite.book_story.core.helpers.clearAllMarkdown
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
|
import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.data.parser.document.MarkdownParser
|
import ua.acclorite.book_story.data.parser.document.MarkdownParser
|
||||||
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val TXT_TAG = "TXT Parser"
|
private const val TAG = "TxtTextParser"
|
||||||
|
|
||||||
class TxtTextParser @Inject constructor(
|
class TxtTextParser @Inject constructor(
|
||||||
private val markdownParser: MarkdownParser
|
private val markdownParser: MarkdownParser
|
||||||
) : TextParser {
|
) : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
||||||
Log.i(TXT_TAG, "Started TXT parsing: ${cachedFile.name}.")
|
logI(TAG, "Started TXT parsing: ${cachedFile.name}.")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val readerText = mutableListOf<ReaderText>()
|
val readerText = mutableListOf<ReaderText>()
|
||||||
|
|
@ -65,14 +66,14 @@ class TxtTextParser @Inject constructor(
|
||||||
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
||||||
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
||||||
) {
|
) {
|
||||||
Log.e(TXT_TAG, "Could not extract text from TXT.")
|
logE(TAG, "Could not extract text from TXT.")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(TXT_TAG, "Successfully finished TXT parsing.")
|
logI(TAG, "Successfully finished TXT parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, e.message ?: "")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,24 @@
|
||||||
|
|
||||||
package ua.acclorite.book_story.data.parser.text
|
package ua.acclorite.book_story.data.parser.text
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.parser.Parser
|
import org.jsoup.parser.Parser
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
|
import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.data.parser.document.DocumentParser
|
import ua.acclorite.book_story.data.parser.document.DocumentParser
|
||||||
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val XML_TAG = "XML Parser"
|
private const val TAG = "XmlTextParser"
|
||||||
|
|
||||||
class XmlTextParser @Inject constructor(
|
class XmlTextParser @Inject constructor(
|
||||||
private val documentParser: DocumentParser
|
private val documentParser: DocumentParser
|
||||||
) : TextParser {
|
) : TextParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
override suspend fun parse(cachedFile: CachedFile): List<ReaderText> {
|
||||||
Log.i(XML_TAG, "Started XML parsing: ${cachedFile.name}.")
|
logI(TAG, "Started XML parsing: ${cachedFile.name}.")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val readerText = cachedFile.openInputStream()?.use { stream ->
|
val readerText = cachedFile.openInputStream()?.use { stream ->
|
||||||
|
|
@ -36,14 +37,14 @@ class XmlTextParser @Inject constructor(
|
||||||
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
readerText.filterIsInstance<ReaderText.Text>().isEmpty() ||
|
||||||
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
readerText.filterIsInstance<ReaderText.Chapter>().isEmpty()
|
||||||
) {
|
) {
|
||||||
Log.e(XML_TAG, "Could not extract text from XML.")
|
logE(TAG, "Could not extract text from XML.")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(XML_TAG, "Successfully finished XML parsing.")
|
logI(TAG, "Successfully finished XML parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, e.message ?: "")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
private const val TAG = "SettingsManager"
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@Singleton
|
@Singleton
|
||||||
class SettingsManager @Inject constructor(
|
class SettingsManager @Inject constructor(
|
||||||
|
|
@ -346,7 +348,7 @@ class SettingsManager @Inject constructor(
|
||||||
default = default,
|
default = default,
|
||||||
setSetting = {
|
setSetting = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
logI("Updating setting: [${key.name}].")
|
logI(TAG, "Updating setting: [${key.name}].")
|
||||||
dataStore.putData(key, it)
|
dataStore.putData(key, it)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -355,7 +357,7 @@ class SettingsManager @Inject constructor(
|
||||||
).also { setting ->
|
).also { setting ->
|
||||||
scope.launch {
|
scope.launch {
|
||||||
setting.init(dataStore.getNullableData<P>(key))
|
setting.init(dataStore.getNullableData<P>(key))
|
||||||
logI("Successfully initialized setting: [${key.name}].")
|
logI(TAG, "Successfully initialized setting: [${key.name}].")
|
||||||
initializeSetting()
|
initializeSetting()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -363,7 +365,7 @@ class SettingsManager @Inject constructor(
|
||||||
|
|
||||||
private fun initializeSetting() {
|
private fun initializeSetting() {
|
||||||
if (initializedSettingsCount.incrementAndGet() == settingsCount.get()) {
|
if (initializedSettingsCount.incrementAndGet() == settingsCount.get()) {
|
||||||
logI("Successfully initialized all $settingsCount settings.")
|
logI(TAG, "Successfully initialized all $settingsCount settings.")
|
||||||
_initialized.update { true }
|
_initialized.update { true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,22 +16,24 @@ import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "AddBook"
|
||||||
|
|
||||||
class AddBookUseCase @Inject constructor(
|
class AddBookUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
private val coverImageHandler: CoverImageHandler
|
private val coverImageHandler: CoverImageHandler
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(book: Book, coverImage: CoverImage?) {
|
suspend operator fun invoke(book: Book, coverImage: CoverImage?) {
|
||||||
logI("Inserting [${book.title}].")
|
logI(TAG, "Inserting [${book.title}].")
|
||||||
|
|
||||||
val coverImageUri = coverImage?.let { coverImage ->
|
val coverImageUri = coverImage?.let { coverImage ->
|
||||||
coverImageHandler.saveCover(coverImage).fold(
|
coverImageHandler.saveCover(coverImage).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully saved cover image of [${book.title}].")
|
logI(TAG, "Successfully saved cover image of [${book.title}].")
|
||||||
it.toUri()
|
it.toUri()
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logW("Could not save cover image with error: ${it.message}")
|
logW(TAG, "Could not save cover image with error: ${it.message}")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -39,10 +41,10 @@ class AddBookUseCase @Inject constructor(
|
||||||
|
|
||||||
bookRepository.addBook(book = book.copy(coverImage = coverImageUri)).fold(
|
bookRepository.addBook(book = book.copy(coverImage = coverImageUri)).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully inserted [${book.title}].")
|
logI(TAG, "Successfully inserted [${book.title}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not insert [${book.title}] with error: ${it.message}")
|
logE(TAG, "Could not insert [${book.title}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "CanResetCover"
|
||||||
|
|
||||||
class CanResetCoverImageUseCase @Inject constructor(
|
class CanResetCoverImageUseCase @Inject constructor(
|
||||||
private val application: Application,
|
private val application: Application,
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
|
|
@ -21,7 +23,7 @@ class CanResetCoverImageUseCase @Inject constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int): Boolean {
|
suspend operator fun invoke(bookId: Int): Boolean {
|
||||||
logI("Checking if can reset cover image of [$bookId].")
|
logI(TAG, "Checking if can reset cover image of [$bookId].")
|
||||||
|
|
||||||
bookRepository.getBook(bookId).mapCatching { book ->
|
bookRepository.getBook(bookId).mapCatching { book ->
|
||||||
// Getting default cover image
|
// Getting default cover image
|
||||||
|
|
@ -43,11 +45,14 @@ class CanResetCoverImageUseCase @Inject constructor(
|
||||||
!compressedDefaultCoverImage.sameAs(compressedCoverImage)
|
!compressedDefaultCoverImage.sameAs(compressedCoverImage)
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Can reset cover image of [$bookId]: $it.")
|
logI(TAG, "Can reset cover image of [$bookId]: $it.")
|
||||||
return it
|
return it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not check if can reset cover image of [$bookId] with error: ${it.message}")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not check if can reset cover image of [$bookId] with error: ${it.message}"
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "DeleteBook"
|
||||||
|
|
||||||
class DeleteBookUseCase @Inject constructor(
|
class DeleteBookUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
private val historyRepository: HistoryRepository,
|
private val historyRepository: HistoryRepository,
|
||||||
|
|
@ -22,25 +24,25 @@ class DeleteBookUseCase @Inject constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(book: Book) {
|
suspend operator fun invoke(book: Book) {
|
||||||
logI("Deleting [${book.title}].")
|
logI(TAG, "Deleting [${book.title}].")
|
||||||
|
|
||||||
// Deleting cover image
|
// Deleting cover image
|
||||||
book.coverImage?.let { coverImageHandler.deleteCover(it) }?.onFailure {
|
book.coverImage?.let { coverImageHandler.deleteCover(it) }?.onFailure {
|
||||||
logW("Could not delete cover image with error: ${it.message}")
|
logW(TAG, "Could not delete cover image with error: ${it.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deleting history
|
// Deleting history
|
||||||
historyRepository.deleteHistoryForBook(bookId = book.id).onFailure {
|
historyRepository.deleteHistoryForBook(bookId = book.id).onFailure {
|
||||||
logW("Could not delete history for [${book.title}] with error: ${it.message}")
|
logW(TAG, "Could not delete history for [${book.title}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deleting book
|
// Deleting book
|
||||||
bookRepository.deleteBook(book).fold(
|
bookRepository.deleteBook(book).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully deleted [${book.title}].")
|
logI(TAG, "Successfully deleted [${book.title}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not delete [${book.title}] with error: ${it.message}")
|
logE(TAG, "Could not delete [${book.title}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,25 +13,27 @@ import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetBook"
|
||||||
|
|
||||||
class GetBookUseCase @Inject constructor(
|
class GetBookUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int): Book? {
|
suspend operator fun invoke(bookId: Int): Book? {
|
||||||
logI("Getting book: [$bookId].")
|
logI(TAG, "Getting book: [$bookId].")
|
||||||
|
|
||||||
bookRepository.getBook(bookId).fold(
|
bookRepository.getBook(bookId).fold(
|
||||||
onSuccess = { book ->
|
onSuccess = { book ->
|
||||||
val history = historyRepository.getHistoryForBook(book.id).getOrNull()
|
val history = historyRepository.getHistoryForBook(book.id).getOrNull()
|
||||||
|
|
||||||
logI("Successfully got book: [$bookId].")
|
logI(TAG, "Successfully got book: [$bookId].")
|
||||||
return book.copy(
|
return book.copy(
|
||||||
lastOpened = history?.time
|
lastOpened = history?.time
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get book [$bookId] with error: ${it.message}")
|
logE(TAG, "Could not get book [$bookId] with error: ${it.message}")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,22 @@ import ua.acclorite.book_story.domain.model.file.File
|
||||||
import ua.acclorite.book_story.domain.repository.BookRepository
|
import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetFileFromBook"
|
||||||
|
|
||||||
class GetFileFromBookUseCase @Inject constructor(
|
class GetFileFromBookUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository
|
private val bookRepository: BookRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int): File? {
|
suspend operator fun invoke(bookId: Int): File? {
|
||||||
logI("Getting file from book [$bookId].")
|
logI(TAG, "Getting file from book [$bookId].")
|
||||||
|
|
||||||
return bookRepository.getFileFromBook(bookId).fold(
|
return bookRepository.getFileFromBook(bookId).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully got file from book [$bookId].")
|
logI(TAG, "Successfully got file from book [$bookId].")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get file from book [$bookId] with error: ${it.message}")
|
logE(TAG, "Could not get file from book [$bookId] with error: ${it.message}")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,14 @@ import ua.acclorite.book_story.domain.model.reader.ReaderText
|
||||||
import ua.acclorite.book_story.domain.repository.BookRepository
|
import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetText"
|
||||||
|
|
||||||
class GetTextUseCase @Inject constructor(
|
class GetTextUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository
|
private val bookRepository: BookRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int): List<ReaderText> {
|
suspend operator fun invoke(bookId: Int): List<ReaderText> {
|
||||||
logI("Getting text from: [$bookId].")
|
logI(TAG, "Getting text from: [$bookId].")
|
||||||
if (bookId == -1) return emptyList()
|
if (bookId == -1) return emptyList()
|
||||||
|
|
||||||
bookRepository.getText(bookId).mapCatching { readerText ->
|
bookRepository.getText(bookId).mapCatching { readerText ->
|
||||||
|
|
@ -31,11 +33,11 @@ class GetTextUseCase @Inject constructor(
|
||||||
readerText
|
readerText
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully loaded text from [$bookId] with markdown.")
|
logI(TAG, "Successfully loaded text from [$bookId] with markdown.")
|
||||||
return it
|
return it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not load text with exception: ${it.message}")
|
logE(TAG, "Could not load text with exception: ${it.message}")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,15 @@ import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "ResetCoverImage"
|
||||||
|
|
||||||
class ResetCoverImageUseCase @Inject constructor(
|
class ResetCoverImageUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
private val coverImageHandler: CoverImageHandler
|
private val coverImageHandler: CoverImageHandler
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int): Boolean {
|
suspend operator fun invoke(bookId: Int): Boolean {
|
||||||
logI("Resetting cover image of [$bookId].")
|
logI(TAG, "Resetting cover image of [$bookId].")
|
||||||
|
|
||||||
bookRepository.getBook(bookId).mapCatching { book ->
|
bookRepository.getBook(bookId).mapCatching { book ->
|
||||||
// Getting default cover image
|
// Getting default cover image
|
||||||
|
|
@ -29,7 +31,7 @@ class ResetCoverImageUseCase @Inject constructor(
|
||||||
|
|
||||||
// Deleting old cover
|
// Deleting old cover
|
||||||
book.coverImage?.let { coverImageHandler.deleteCover(it) }?.onFailure {
|
book.coverImage?.let { coverImageHandler.deleteCover(it) }?.onFailure {
|
||||||
logW("Could not delete old cover image with error: ${it.message}")
|
logW(TAG, "Could not delete old cover image with error: ${it.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resetting cover
|
// Resetting cover
|
||||||
|
|
@ -42,11 +44,11 @@ class ResetCoverImageUseCase @Inject constructor(
|
||||||
bookRepository.updateBook(newBook).getOrThrow()
|
bookRepository.updateBook(newBook).getOrThrow()
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully reset cover image of [$bookId].")
|
logI(TAG, "Successfully reset cover image of [$bookId].")
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not reset cover image of [$bookId] with error: ${it.message}")
|
logE(TAG, "Could not reset cover image of [$bookId] with error: ${it.message}")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,19 @@ import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "SearchBooks"
|
||||||
|
|
||||||
class SearchBooksUseCase @Inject constructor(
|
class SearchBooksUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(query: String): List<Book> {
|
suspend operator fun invoke(query: String): List<Book> {
|
||||||
logI("Searching for books with query: \"$query\".")
|
logI(TAG, "Searching for books with query: \"$query\".")
|
||||||
|
|
||||||
return bookRepository.searchBooks(query).fold(
|
return bookRepository.searchBooks(query).fold(
|
||||||
onSuccess = { books ->
|
onSuccess = { books ->
|
||||||
logI("Successfully found [${books.size}] books.")
|
logI(TAG, "Successfully found [${books.size}] books.")
|
||||||
books.map { book ->
|
books.map { book ->
|
||||||
val history = historyRepository.getHistoryForBook(book.id).getOrNull()
|
val history = historyRepository.getHistoryForBook(book.id).getOrNull()
|
||||||
|
|
||||||
|
|
@ -33,7 +35,7 @@ class SearchBooksUseCase @Inject constructor(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not find books with error: ${it.message}")
|
logE(TAG, "Could not find books with error: ${it.message}")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,21 @@ import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import ua.acclorite.book_story.domain.repository.BookRepository
|
import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "UpdateBook"
|
||||||
|
|
||||||
class UpdateBookUseCase @Inject constructor(
|
class UpdateBookUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository
|
private val bookRepository: BookRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(book: Book) {
|
suspend operator fun invoke(book: Book) {
|
||||||
logI("Updating [${book.title}].")
|
logI(TAG, "Updating [${book.title}].")
|
||||||
|
|
||||||
bookRepository.updateBook(book).fold(
|
bookRepository.updateBook(book).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully updated [${book.title}].")
|
logI(TAG, "Successfully updated [${book.title}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not update [${book.title}] with error: ${it.message}")
|
logE(TAG, "Could not update [${book.title}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,22 @@ import ua.acclorite.book_story.domain.repository.BookRepository
|
||||||
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
import ua.acclorite.book_story.domain.service.CoverImageHandler
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "UpdateCoverImage"
|
||||||
|
|
||||||
class UpdateCoverImageUseCase @Inject constructor(
|
class UpdateCoverImageUseCase @Inject constructor(
|
||||||
private val bookRepository: BookRepository,
|
private val bookRepository: BookRepository,
|
||||||
private val coverImageHandler: CoverImageHandler
|
private val coverImageHandler: CoverImageHandler
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int, coverImage: CoverImage?) {
|
suspend operator fun invoke(bookId: Int, coverImage: CoverImage?) {
|
||||||
logI("Updating cover image of [$bookId].")
|
logI(TAG, "Updating cover image of [$bookId].")
|
||||||
|
|
||||||
bookRepository.getBook(bookId).mapCatching { book ->
|
bookRepository.getBook(bookId).mapCatching { book ->
|
||||||
if (book.coverImage == coverImage) return
|
if (book.coverImage == coverImage) return
|
||||||
|
|
||||||
// Deleting old cover
|
// Deleting old cover
|
||||||
book.coverImage?.let { coverImageHandler.deleteCover(it) }?.onFailure {
|
book.coverImage?.let { coverImageHandler.deleteCover(it) }?.onFailure {
|
||||||
logW("Could not delete old cover image with error: ${it.message}")
|
logW(TAG, "Could not delete old cover image with error: ${it.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saving new cover
|
// Saving new cover
|
||||||
|
|
@ -41,10 +43,10 @@ class UpdateCoverImageUseCase @Inject constructor(
|
||||||
bookRepository.updateBook(newBook).getOrThrow()
|
bookRepository.updateBook(newBook).getOrThrow()
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully updated cover image of [$bookId].")
|
logI(TAG, "Successfully updated cover image of [$bookId].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not update cover image of [$bookId] with error: ${it.message}")
|
logE(TAG, "Could not update cover image of [$bookId] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,21 @@ import ua.acclorite.book_story.domain.model.library.Category
|
||||||
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "AddCategory"
|
||||||
|
|
||||||
class AddCategoryUseCase @Inject constructor(
|
class AddCategoryUseCase @Inject constructor(
|
||||||
private val categoryRepository: CategoryRepository
|
private val categoryRepository: CategoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(title: String) {
|
suspend operator fun invoke(title: String) {
|
||||||
logI("Inserting [${title}] category.")
|
logI(TAG, "Inserting [${title}] category.")
|
||||||
|
|
||||||
categoryRepository.addCategory(Category(title = title)).fold(
|
categoryRepository.addCategory(Category(title = title)).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully inserted [${title}] category.")
|
logI(TAG, "Successfully inserted [${title}] category.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not insert [${title}] category with error: ${it.message}")
|
logE(TAG, "Could not insert [${title}] category with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,21 @@ import ua.acclorite.book_story.domain.model.library.Category
|
||||||
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "DeleteCategory"
|
||||||
|
|
||||||
class DeleteCategoryUseCase @Inject constructor(
|
class DeleteCategoryUseCase @Inject constructor(
|
||||||
private val categoryRepository: CategoryRepository
|
private val categoryRepository: CategoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(category: Category) {
|
suspend operator fun invoke(category: Category) {
|
||||||
logI("Deleting category [${category.id}].")
|
logI(TAG, "Deleting category [${category.id}].")
|
||||||
|
|
||||||
categoryRepository.deleteCategory(category).fold(
|
categoryRepository.deleteCategory(category).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully deleted category [${category.id}].")
|
logI(TAG, "Successfully deleted category [${category.id}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logI("Could not delete category [${category.id}] with error: ${it.message}")
|
logI(TAG, "Could not delete category [${category.id}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,22 @@ import ua.acclorite.book_story.domain.model.library.Category
|
||||||
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetCategories"
|
||||||
|
|
||||||
class GetCategoriesUseCase @Inject constructor(
|
class GetCategoriesUseCase @Inject constructor(
|
||||||
private val categoryRepository: CategoryRepository
|
private val categoryRepository: CategoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(): List<Category> {
|
suspend operator fun invoke(): List<Category> {
|
||||||
logI("Getting all categories.")
|
logI(TAG, "Getting all categories.")
|
||||||
|
|
||||||
return categoryRepository.getCategories().fold(
|
return categoryRepository.getCategories().fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully got [${it.size}] categories.")
|
logI(TAG, "Successfully got [${it.size}] categories.")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get categories with error: ${it.message}")
|
logE(TAG, "Could not get categories with error: ${it.message}")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,24 @@ import ua.acclorite.book_story.domain.model.library.Category
|
||||||
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "UpdateCategoryOrder"
|
||||||
|
|
||||||
class UpdateCategoriesOrderUseCase @Inject constructor(
|
class UpdateCategoriesOrderUseCase @Inject constructor(
|
||||||
private val categoryRepository: CategoryRepository
|
private val categoryRepository: CategoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(categories: List<Category>) {
|
suspend operator fun invoke(categories: List<Category>) {
|
||||||
logI("Updating order of [${categories.size}] categories.")
|
logI(TAG, "Updating order of [${categories.size}] categories.")
|
||||||
|
|
||||||
categoryRepository.updateOrder(categories).fold(
|
categoryRepository.updateOrder(categories).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully updated order of [${categories.size}] categories.")
|
logI(TAG, "Successfully updated order of [${categories.size}] categories.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logI("Could not update order of [${categories.size}] categories with error: ${it.message}")
|
logI(
|
||||||
|
TAG,
|
||||||
|
"Could not update order of [${categories.size}] categories with error: ${it.message}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,21 @@ import ua.acclorite.book_story.domain.model.library.Category
|
||||||
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
import ua.acclorite.book_story.domain.repository.CategoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "UpdateCategory"
|
||||||
|
|
||||||
class UpdateCategoryUseCase @Inject constructor(
|
class UpdateCategoryUseCase @Inject constructor(
|
||||||
private val categoryRepository: CategoryRepository
|
private val categoryRepository: CategoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(category: Category) {
|
suspend operator fun invoke(category: Category) {
|
||||||
logI("Updating category [${category.id}].")
|
logI(TAG, "Updating category [${category.id}].")
|
||||||
|
|
||||||
categoryRepository.updateCategory(category).fold(
|
categoryRepository.updateCategory(category).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully updated [${category.id}].")
|
logI(TAG, "Successfully updated [${category.id}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logI("Could not update [${category.id}] with error: ${it.message}")
|
logI(TAG, "Could not update [${category.id}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,24 @@ import ua.acclorite.book_story.domain.model.reader.ColorPreset
|
||||||
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "DeleteColorPreset"
|
||||||
|
|
||||||
class DeleteColorPresetUseCase @Inject constructor(
|
class DeleteColorPresetUseCase @Inject constructor(
|
||||||
private val colorPresetRepository: ColorPresetRepository
|
private val colorPresetRepository: ColorPresetRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(colorPreset: ColorPreset) {
|
suspend operator fun invoke(colorPreset: ColorPreset) {
|
||||||
logI("Deleting [${colorPreset.id}] color preset.")
|
logI(TAG, "Deleting [${colorPreset.id}] color preset.")
|
||||||
|
|
||||||
colorPresetRepository.deleteColorPreset(colorPreset).fold(
|
colorPresetRepository.deleteColorPreset(colorPreset).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully deleted [${colorPreset.id}] color preset.")
|
logI(TAG, "Successfully deleted [${colorPreset.id}] color preset.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not delete [${colorPreset.id}] color preset with error: ${it.message}")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not delete [${colorPreset.id}] color preset with error: ${it.message}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,22 @@ import ua.acclorite.book_story.domain.model.reader.ColorPreset
|
||||||
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetColorPresets"
|
||||||
|
|
||||||
class GetColorPresetsUseCase @Inject constructor(
|
class GetColorPresetsUseCase @Inject constructor(
|
||||||
private val colorPresetRepository: ColorPresetRepository
|
private val colorPresetRepository: ColorPresetRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(): List<ColorPreset> {
|
suspend operator fun invoke(): List<ColorPreset> {
|
||||||
logI("Getting color presets.")
|
logI(TAG, "Getting color presets.")
|
||||||
|
|
||||||
return colorPresetRepository.getColorPresets().fold(
|
return colorPresetRepository.getColorPresets().fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully got [${it.size}] color presets.")
|
logI(TAG, "Successfully got [${it.size}] color presets.")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get color presets with error: ${it.message}")
|
logE(TAG, "Could not get color presets with error: ${it.message}")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,24 @@ import ua.acclorite.book_story.domain.model.reader.ColorPreset
|
||||||
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "ReorderPresets"
|
||||||
|
|
||||||
class ReorderColorPresetsUseCase @Inject constructor(
|
class ReorderColorPresetsUseCase @Inject constructor(
|
||||||
private val colorPresetRepository: ColorPresetRepository
|
private val colorPresetRepository: ColorPresetRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(colorPresets: List<ColorPreset>) {
|
suspend operator fun invoke(colorPresets: List<ColorPreset>) {
|
||||||
logI("Reordering [${colorPresets.size}] color presets.")
|
logI(TAG, "Reordering [${colorPresets.size}] color presets.")
|
||||||
|
|
||||||
colorPresetRepository.reorderColorPresets(colorPresets).fold(
|
colorPresetRepository.reorderColorPresets(colorPresets).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully reordered [${colorPresets.size}] color presets.")
|
logI(TAG, "Successfully reordered [${colorPresets.size}] color presets.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not reorder [${colorPresets.size}] color presets with error: ${it.message}")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not reorder [${colorPresets.size}] color presets with error: ${it.message}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,24 @@ import ua.acclorite.book_story.domain.model.reader.ColorPreset
|
||||||
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "SelectColorPreset"
|
||||||
|
|
||||||
class SelectColorPresetUseCase @Inject constructor(
|
class SelectColorPresetUseCase @Inject constructor(
|
||||||
private val colorPresetRepository: ColorPresetRepository
|
private val colorPresetRepository: ColorPresetRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(colorPreset: ColorPreset) {
|
suspend operator fun invoke(colorPreset: ColorPreset) {
|
||||||
logI("Selecting [${colorPreset.id}] color preset.")
|
logI(TAG, "Selecting [${colorPreset.id}] color preset.")
|
||||||
|
|
||||||
colorPresetRepository.selectColorPreset(colorPreset).fold(
|
colorPresetRepository.selectColorPreset(colorPreset).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully selected [${colorPreset.id}] color preset.")
|
logI(TAG, "Successfully selected [${colorPreset.id}] color preset.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not select [${colorPreset.id}] color preset with error: ${it.message}")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not select [${colorPreset.id}] color preset with error: ${it.message}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,24 @@ import ua.acclorite.book_story.domain.model.reader.ColorPreset
|
||||||
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
import ua.acclorite.book_story.domain.repository.ColorPresetRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "UpdateColorPreset"
|
||||||
|
|
||||||
class UpdateColorPresetUseCase @Inject constructor(
|
class UpdateColorPresetUseCase @Inject constructor(
|
||||||
private val colorPresetRepository: ColorPresetRepository
|
private val colorPresetRepository: ColorPresetRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(colorPreset: ColorPreset) {
|
suspend operator fun invoke(colorPreset: ColorPreset) {
|
||||||
logI("Updating [${colorPreset.id}] color preset.")
|
logI(TAG, "Updating [${colorPreset.id}] color preset.")
|
||||||
|
|
||||||
colorPresetRepository.updateColorPreset(colorPreset).fold(
|
colorPresetRepository.updateColorPreset(colorPreset).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully updated [${colorPreset.id}] color preset.")
|
logI(TAG, "Successfully updated [${colorPreset.id}] color preset.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not update [${colorPreset.id}] color preset with error: ${it.message}")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not update [${colorPreset.id}] color preset with error: ${it.message}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,22 @@ import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import ua.acclorite.book_story.domain.repository.FileSystemRepository
|
import ua.acclorite.book_story.domain.repository.FileSystemRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetBookFromFile"
|
||||||
|
|
||||||
class GetBookFromFileUseCase @Inject constructor(
|
class GetBookFromFileUseCase @Inject constructor(
|
||||||
private val fileSystemRepository: FileSystemRepository
|
private val fileSystemRepository: FileSystemRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(file: File): Pair<Book, CoverImage?>? {
|
suspend operator fun invoke(file: File): Pair<Book, CoverImage?>? {
|
||||||
logI("Getting book from [${file.name}] file.")
|
logI(TAG, "Getting book from [${file.name}] file.")
|
||||||
|
|
||||||
return fileSystemRepository.getBookFromFile(file).fold(
|
return fileSystemRepository.getBookFromFile(file).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully got [${it.first.title}] book from file.")
|
logI(TAG, "Successfully got [${it.first.title}] book from file.")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get book from file with error: ${it.message}")
|
logE(TAG, "Could not get book from file with error: ${it.message}")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,15 @@ import ua.acclorite.book_story.domain.repository.FileSystemRepository
|
||||||
import ua.acclorite.book_story.presentation.browse.model.BrowseSortOrder
|
import ua.acclorite.book_story.presentation.browse.model.BrowseSortOrder
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetFiles"
|
||||||
|
|
||||||
class GetFilesUseCase @Inject constructor(
|
class GetFilesUseCase @Inject constructor(
|
||||||
private val fileSystemRepository: FileSystemRepository,
|
private val fileSystemRepository: FileSystemRepository,
|
||||||
private val settings: SettingsManager
|
private val settings: SettingsManager
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(query: String = ""): List<File> {
|
suspend operator fun invoke(query: String = ""): List<File> {
|
||||||
logI("Searching for files with query: \"$query\".")
|
logI(TAG, "Searching for files with query: \"$query\".")
|
||||||
|
|
||||||
fun List<File>.filterFiles(): List<File> {
|
fun List<File>.filterFiles(): List<File> {
|
||||||
return if (settings.browseIncludedFilterItems.lastValue.isEmpty()) this
|
return if (settings.browseIncludedFilterItems.lastValue.isEmpty()) this
|
||||||
|
|
@ -60,11 +62,11 @@ class GetFilesUseCase @Inject constructor(
|
||||||
.sortFiles()
|
.sortFiles()
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully found [${it.size}] files.")
|
logI(TAG, "Successfully found [${it.size}] files.")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not find files with error: ${it.message}")
|
logE(TAG, "Could not find files with error: ${it.message}")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,24 @@ import ua.acclorite.book_story.domain.model.history.History
|
||||||
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "AddHistory"
|
||||||
|
|
||||||
class AddHistoryUseCase @Inject constructor(
|
class AddHistoryUseCase @Inject constructor(
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(history: History) {
|
suspend operator fun invoke(history: History) {
|
||||||
logI("Inserting history for [${history.book.id}].")
|
logI(TAG, "Inserting history for [${history.book.id}].")
|
||||||
|
|
||||||
historyRepository.addHistory(history = history).fold(
|
historyRepository.addHistory(history = history).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully inserted history for [${history.book.id}].")
|
logI(TAG, "Successfully inserted history for [${history.book.id}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not insert history for [${history.book.id}] with error: ${it.message}")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not insert history for [${history.book.id}] with error: ${it.message}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,21 @@ import ua.acclorite.book_story.domain.model.history.History
|
||||||
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "DeleteHistory"
|
||||||
|
|
||||||
class DeleteHistoryUseCase @Inject constructor(
|
class DeleteHistoryUseCase @Inject constructor(
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(history: History) {
|
suspend operator fun invoke(history: History) {
|
||||||
logI("Deleting history [${history.id}].")
|
logI(TAG, "Deleting history [${history.id}].")
|
||||||
|
|
||||||
return historyRepository.deleteHistory(history).fold(
|
return historyRepository.deleteHistory(history).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully deleted history [${history.id}].")
|
logI(TAG, "Successfully deleted history [${history.id}].")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not delete history [${history.id}] with error: ${it.message}")
|
logE(TAG, "Could not delete history [${history.id}] with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,21 @@ import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "DeleteWholeHistory"
|
||||||
|
|
||||||
class DeleteWholeHistoryUseCase @Inject constructor(
|
class DeleteWholeHistoryUseCase @Inject constructor(
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke() {
|
suspend operator fun invoke() {
|
||||||
logI("Deleting whole history.")
|
logI(TAG, "Deleting whole history.")
|
||||||
|
|
||||||
return historyRepository.deleteWholeHistory().fold(
|
return historyRepository.deleteWholeHistory().fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully deleted whole history.")
|
logI(TAG, "Successfully deleted whole history.")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not delete whole history with error: ${it.message}")
|
logE(TAG, "Could not delete whole history with error: ${it.message}")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,22 @@ import ua.acclorite.book_story.domain.model.history.History
|
||||||
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
import ua.acclorite.book_story.domain.repository.HistoryRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetHistoryForBook"
|
||||||
|
|
||||||
class GetHistoryForBookUseCase @Inject constructor(
|
class GetHistoryForBookUseCase @Inject constructor(
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(bookId: Int): History? {
|
suspend operator fun invoke(bookId: Int): History? {
|
||||||
logI("Getting history for [$bookId].")
|
logI(TAG, "Getting history for [$bookId].")
|
||||||
|
|
||||||
return historyRepository.getHistoryForBook(bookId = bookId).fold(
|
return historyRepository.getHistoryForBook(bookId = bookId).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully got history for [$bookId].")
|
logI(TAG, "Successfully got history for [$bookId].")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get history for [$bookId] with error: ${it.message}")
|
logE(TAG, "Could not get history for [$bookId] with error: ${it.message}")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,14 @@ import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GetHistory"
|
||||||
|
|
||||||
class GetHistoryUseCase @Inject constructor(
|
class GetHistoryUseCase @Inject constructor(
|
||||||
private val historyRepository: HistoryRepository
|
private val historyRepository: HistoryRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(query: String): List<GroupedHistory> {
|
suspend operator fun invoke(query: String): List<GroupedHistory> {
|
||||||
logI("Getting all history.")
|
logI(TAG, "Getting all history.")
|
||||||
|
|
||||||
fun getDayLabel(timeMillis: Long): String {
|
fun getDayLabel(timeMillis: Long): String {
|
||||||
val historyDate = Instant.ofEpochMilli(timeMillis)
|
val historyDate = Instant.ofEpochMilli(timeMillis)
|
||||||
|
|
@ -54,11 +56,11 @@ class GetHistoryUseCase @Inject constructor(
|
||||||
.map { (day, history) -> GroupedHistory(day, filterMaxElementsById(history)) }
|
.map { (day, history) -> GroupedHistory(day, filterMaxElementsById(history)) }
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully got ${it.size} grouped history entries.")
|
logI(TAG, "Successfully got ${it.size} grouped history entries.")
|
||||||
it
|
it
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not get grouped history entries with error: ${it.message}")
|
logE(TAG, "Could not get grouped history entries with error: ${it.message}")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,24 @@ import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.domain.repository.PermissionRepository
|
import ua.acclorite.book_story.domain.repository.PermissionRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "GrantUriPermission"
|
||||||
|
|
||||||
class GrantPersistableUriPermissionUseCase @Inject constructor(
|
class GrantPersistableUriPermissionUseCase @Inject constructor(
|
||||||
private val permissionRepository: PermissionRepository
|
private val permissionRepository: PermissionRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(uri: String) {
|
suspend operator fun invoke(uri: String) {
|
||||||
logI("Granting persistable URI permission to \"$uri\".")
|
logI(TAG, "Granting persistable URI permission to \"$uri\".")
|
||||||
|
|
||||||
permissionRepository.grantPersistableUriPermission(uri).fold(
|
permissionRepository.grantPersistableUriPermission(uri).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully granted persistable URI permission to \"$uri\".")
|
logI(TAG, "Successfully granted persistable URI permission to \"$uri\".")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not grant persistable URI permission to \"$uri\" with error: ${it.message}.")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not grant persistable URI permission to \"$uri\" with error: ${it.message}."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,24 @@ import ua.acclorite.book_story.core.log.logI
|
||||||
import ua.acclorite.book_story.domain.repository.PermissionRepository
|
import ua.acclorite.book_story.domain.repository.PermissionRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "ReleaseUriPermission"
|
||||||
|
|
||||||
class ReleasePersistableUriPermissionUseCase @Inject constructor(
|
class ReleasePersistableUriPermissionUseCase @Inject constructor(
|
||||||
private val permissionRepository: PermissionRepository
|
private val permissionRepository: PermissionRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(uri: String) {
|
suspend operator fun invoke(uri: String) {
|
||||||
logI("Releasing persistable URI permission from \"$uri\".")
|
logI(TAG, "Releasing persistable URI permission from \"$uri\".")
|
||||||
|
|
||||||
permissionRepository.releasePersistableUriPermission(uri).fold(
|
permissionRepository.releasePersistableUriPermission(uri).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
logI("Successfully released persistable URI permission from \"$uri\".")
|
logI(TAG, "Successfully released persistable URI permission from \"$uri\".")
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
logE("Could not release persistable URI permission from \"$uri\" with error: ${it.message}.")
|
logE(
|
||||||
|
TAG,
|
||||||
|
"Could not release persistable URI permission from \"$uri\" with error: ${it.message}."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import ua.acclorite.book_story.core.log.logD
|
import ua.acclorite.book_story.core.log.logD
|
||||||
|
|
||||||
|
private const val TAG = "ThemeLogger"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function logs all the colors of the colorScheme.
|
* This function logs all the colors of the colorScheme.
|
||||||
* You can use it to extract colors from Material You theme and add it to the app.
|
* You can use it to extract colors from Material You theme and add it to the app.
|
||||||
|
|
@ -32,6 +34,7 @@ fun ColorScheme.logTheme(darkTheme: Boolean): ColorScheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
logD(
|
logD(
|
||||||
|
TAG,
|
||||||
"Theme $suffix:\n" +
|
"Theme $suffix:\n" +
|
||||||
"------------------------\n" +
|
"------------------------\n" +
|
||||||
primary.convertToVal("primary") +
|
primary.convertToVal("primary") +
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue