Skip to content

Commit

Permalink
Add description to epub (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahM0hamed authored Feb 8, 2024
1 parent 857da5e commit c02a888
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
30 changes: 18 additions & 12 deletions app/src/main/java/com/lagradost/quicknovel/BookDownloader2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ object BookDownloader2Helper {
}

@WorkerThread
fun turnToEpub(activity: Activity?, author: String?, name: String, apiName: String): Boolean {
fun turnToEpub(activity: Activity?, author: String?, name: String, apiName: String, synopsis: String?): Boolean {
if (activity == null) return false
if (!activity.checkWrite()) {
activity.requestRW()
Expand Down Expand Up @@ -689,6 +689,11 @@ object BookDownloader2Helper {
if (author != null) {
metadata.addAuthor(Author(author))
}

if (synopsis != null) {
metadata.addDescription(synopsis)
}

metadata.addTitle(name)

val posterFilepath =
Expand Down Expand Up @@ -1017,7 +1022,7 @@ object BookDownloader2 {
@WorkerThread
suspend fun stream(res: EpubResponse, apiName: String) {
downloadAsync(res, getApiFromName(apiName))
readEpub(res.author, res.name, apiName)
readEpub(res.author, res.name, apiName, res.synopsis)
}

@WorkerThread
Expand Down Expand Up @@ -1064,20 +1069,20 @@ object BookDownloader2 {
}
}

private fun generateAndReadEpub(author: String?, name: String, apiName: String) {
private fun generateAndReadEpub(author: String?, name: String, apiName: String, synopsis: String?) {
showToast(R.string.generating_epub)
if (!turnToEpub(author, name, apiName)) {
if (!turnToEpub(author, name, apiName, synopsis)) {
showToast(R.string.error_loading_novel)
return
}
openEpub(name)
}

private fun readEpub(author: String?, name: String, apiName: String) {
private fun readEpub(author: String?, name: String, apiName: String, synopsis: String?) {
if (hasEpub(name)) {
openEpub(name)
} else {
generateAndReadEpub(author, name, apiName)
generateAndReadEpub(author, name, apiName, synopsis)
}
}

Expand All @@ -1089,16 +1094,17 @@ object BookDownloader2 {
downloadedCount: Int,
author: String?,
name: String,
apiName: String
apiName: String,
synopsis: String?
) {
if (readEpubMutex.isLocked) return
readEpubMutex.withLock {
val downloaded = getKey(DOWNLOAD_EPUB_SIZE, id.toString(), 0)!!
val shouldUpdate = downloadedCount - downloaded != 0
if (shouldUpdate) {
generateAndReadEpub(author, name, apiName)
generateAndReadEpub(author, name, apiName, synopsis)
} else {
readEpub(author, name, apiName)
readEpub(author, name, apiName, synopsis)
}
}
}
Expand Down Expand Up @@ -1138,8 +1144,8 @@ object BookDownloader2 {
deleteNovelAsync(author, name, apiName)
}

private fun turnToEpub(author: String?, name: String, apiName: String): Boolean {
return BookDownloader2Helper.turnToEpub(activity, author, name, apiName)
private fun turnToEpub(author: String?, name: String, apiName: String, synopsis: String?): Boolean {
return BookDownloader2Helper.turnToEpub(activity, author, name, apiName, synopsis)
}

private fun hasEpub(name: String): Boolean {
Expand Down Expand Up @@ -1789,4 +1795,4 @@ object BookDownloader2 {
init {
initDownloadProgress()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class DownloadViewModel : ViewModel() {
card.downloadedCount,
card.author,
card.name,
card.apiName
card.apiName,
card.synopsis
)
} finally {
setKey(DOWNLOAD_EPUB_LAST_ACCESS, card.id.toString(), System.currentTimeMillis())
Expand Down Expand Up @@ -454,4 +455,4 @@ class DownloadViewModel : ViewModel() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ class ResultViewModel : ViewModel() {
downloadState.value?.progress ?: return@launch,
load.author,
load.name,
apiName
apiName,
load.synopsis
)
}
}
Expand Down Expand Up @@ -533,4 +534,4 @@ class ResultViewModel : ViewModel() {
loadResponse.postValue(data)
}
}
}
}

0 comments on commit c02a888

Please sign in to comment.