Skip to content

Commit 6d282b6

Browse files
committed
Updated epub lib
1 parent 63b8125 commit 6d282b6

File tree

84 files changed

+14135
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+14135
-36
lines changed

app/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
minSdkVersion 21
2323
targetSdkVersion 35
2424
versionCode 56
25-
versionName "3.3.5"
25+
versionName "3.3.6"
2626
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2727
}
2828

@@ -45,12 +45,12 @@ android {
4545
buildFeatures.buildConfig true
4646

4747
compileOptions {
48-
sourceCompatibility JavaVersion.VERSION_1_8
49-
targetCompatibility JavaVersion.VERSION_1_8
48+
sourceCompatibility JavaVersion.VERSION_1_9
49+
targetCompatibility JavaVersion.VERSION_1_9
5050
}
5151

5252
kotlinOptions {
53-
jvmTarget = JavaVersion.VERSION_1_8.toString()
53+
jvmTarget = JavaVersion.VERSION_1_9.toString()
5454
}
5555
namespace 'com.lagradost.quicknovel'
5656
}
@@ -82,10 +82,10 @@ dependencies {
8282
implementation "androidx.preference:preference-ktx:1.2.1"
8383
implementation "me.xdrop:fuzzywuzzy:1.4.0"
8484

85-
implementation('io.documentnode:epub4j-core:4.2.1') {
86-
exclude group: 'org.slf4j'
87-
exclude group: 'xmlpull'
88-
}
85+
//implementation('com.positiondev.epublib:epublib-core:3.1') {
86+
//exclude group: 'org.slf4j'
87+
//exclude group: 'xmlpull'
88+
//}
8989
implementation 'org.slf4j:slf4j-android:1.7.25'
9090

9191
implementation "androidx.recyclerview:recyclerview:1.4.0"

app/src/main/java/com/lagradost/quicknovel/BookDownloader2.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ import com.lagradost.quicknovel.util.Event
5656
import com.lagradost.quicknovel.util.ResultCached
5757
import com.lagradost.quicknovel.util.UIHelper.colorFromAttribute
5858
import com.lagradost.quicknovel.util.pmap
59-
import io.documentnode.epub4j.domain.Author
60-
import io.documentnode.epub4j.domain.Book
61-
import io.documentnode.epub4j.domain.MediaType
62-
import io.documentnode.epub4j.domain.MediaTypes
63-
import io.documentnode.epub4j.domain.Resource
64-
import io.documentnode.epub4j.epub.EpubWriter
59+
import me.ag2s.epublib.domain.Author
60+
import me.ag2s.epublib.domain.EpubBook
61+
import me.ag2s.epublib.domain.MediaType
62+
import me.ag2s.epublib.domain.Resource
63+
import me.ag2s.epublib.epub.EpubWriter
64+
import me.ag2s.epublib.domain.MediaTypes
6565
import kotlinx.coroutines.Dispatchers
6666
import kotlinx.coroutines.delay
6767
import kotlinx.coroutines.sync.Mutex
@@ -680,7 +680,7 @@ object BookDownloader2Helper {
680680
setKey(DOWNLOAD_EPUB_SIZE, id.toString(), 1)
681681
} else {
682682

683-
val book = Book()
683+
val book = EpubBook()
684684
val metadata = book.metadata
685685
if (author != null) {
686686
metadata.addAuthor(Author(author))

app/src/main/java/com/lagradost/quicknovel/ReadActivity2.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,18 +930,26 @@ class ReadActivity2 : AppCompatActivity(), ColorPickerDialogListener {
930930
}
931931
}
932932

933+
var last: Resource<Boolean> = Resource.Loading() // very dirty
933934
observe(viewModel.loadingStatus) { loading ->
935+
val different = last != loading
936+
last = loading
934937
when (loading) {
935938
is Resource.Success -> {
936939
binding.readLoading.isVisible = false
937940
binding.readFail.isVisible = false
938941

939942
binding.readNormalLayout.isVisible = true
940-
binding.readNormalLayout.alpha = 0.01f
941943

942-
ObjectAnimator.ofFloat(binding.readNormalLayout, "alpha", 1f).apply {
943-
duration = 300
944-
start()
944+
if (different) {
945+
binding.readNormalLayout.alpha = 0.01f
946+
947+
ObjectAnimator.ofFloat(binding.readNormalLayout, "alpha", 1f).apply {
948+
duration = 300
949+
start()
950+
}
951+
} else {
952+
binding.readNormalLayout.alpha = 1.0f
945953
}
946954
}
947955

@@ -1068,6 +1076,7 @@ class ReadActivity2 : AppCompatActivity(), ColorPickerDialogListener {
10681076
observe(viewModel.chapter) { chapter ->
10691077
cachedChapter = chapter.data
10701078
textAdapter.submitList(chapter.data) {
1079+
viewModel._loadingStatus.postValue(Resource.Success(true)) // submitList can take 500ms, very dirty :(
10711080
if (chapter.seekToDesired) {
10721081
scrollToDesired()
10731082
}

app/src/main/java/com/lagradost/quicknovel/ReadActivityViewModel.kt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ import kotlinx.coroutines.isActive
8282
import kotlinx.coroutines.runBlocking
8383
import kotlinx.coroutines.sync.Mutex
8484
import kotlinx.coroutines.sync.withLock
85-
import io.documentnode.epub4j.domain.Book
86-
import io.documentnode.epub4j.domain.TOCReference
87-
import io.documentnode.epub4j.epub.EpubReader
85+
import me.ag2s.epublib.domain.EpubBook
86+
import me.ag2s.epublib.domain.TOCReference
87+
import me.ag2s.epublib.epub.EpubReader
88+
import me.ag2s.epublib.util.zip.AndroidZipFile
8889
import org.commonmark.node.Node
8990
import org.jsoup.Jsoup
9091
import java.io.File
@@ -285,7 +286,7 @@ class QuickBook(val data: QuickStreamData) : AbstractBook() {
285286
}
286287
}
287288

288-
class RegularBook(val data: Book) : AbstractBook() {
289+
class RegularBook(val data: EpubBook) : AbstractBook() {
289290
init {
290291
var refs = mutableListOf<TOCReference>()
291292
data.tableOfContents.tocReferences.forEach { ref ->
@@ -429,7 +430,7 @@ class ReadActivityViewModel : ViewModel() {
429430
val chapter: LiveData<ChapterUpdate> = _chapterData
430431

431432
// we use bool as we cant construct Nothing, does not represent anything
432-
private val _loadingStatus: MutableLiveData<Resource<Boolean>> =
433+
val _loadingStatus: MutableLiveData<Resource<Boolean>> =
433434
MutableLiveData<Resource<Boolean>>(null)
434435
val loadingStatus: LiveData<Resource<Boolean>> = _loadingStatus
435436

@@ -1008,9 +1009,9 @@ class ReadActivityViewModel : ViewModel() {
10081009
// update what we have read
10091010
updateReadArea()
10101011

1011-
_loadingStatus.postValue(
1012+
/*_loadingStatus.postValue(
10121013
Resource.Success(true)
1013-
)
1014+
)*/
10141015
}
10151016

10161017
private suspend fun initMLFromSettings(settings: MLSettings, allowDownload: Boolean) {
@@ -1055,15 +1056,17 @@ class ReadActivityViewModel : ViewModel() {
10551056
if (intent == null) throw ErrorLoadingException("No intent")
10561057

10571058
val data = intent.data ?: throw ErrorLoadingException("Empty intent")
1058-
val input = context.contentResolver.openInputStream(data)
1059-
?: throw ErrorLoadingException("Empty data")
10601059
val isFromEpub = intent.type != "quickstream"
10611060

10621061
val epub = if (isFromEpub) {
1063-
val epubReader = EpubReader()
1064-
val book = epubReader.readEpub(input)
1062+
val fd = context.contentResolver.openFileDescriptor(data, "r")
1063+
?: throw ErrorLoadingException("Unable to open file descriptor")
1064+
val zipFile = AndroidZipFile(fd, "")
1065+
val book = EpubReader().readEpubLazy(zipFile, "utf-8")
10651066
RegularBook(book)
10661067
} else {
1068+
val input = context.contentResolver.openInputStream(data)
1069+
?: throw ErrorLoadingException("Empty data")
10671070
QuickBook(DataStore.mapper.readValue(input.reader().readText()))
10681071
}
10691072

@@ -1092,7 +1095,13 @@ class ReadActivityViewModel : ViewModel() {
10921095

10931096
// we the current loaded thing here, but because loadedChapter can be >= book.size (expand) we have to check
10941097
if (loadedChapterIndex < book.size()) {
1095-
_loadingStatus.postValue(Resource.Loading(book.getLoadingStatus(loadedChapterIndex)))
1098+
_loadingStatus.postValue(
1099+
Resource.Loading(
1100+
book.getLoadingStatus(
1101+
loadedChapterIndex
1102+
)
1103+
)
1104+
)
10961105
}
10971106

10981107
currentIndex = loadedChapterIndex
@@ -1129,9 +1138,9 @@ class ReadActivityViewModel : ViewModel() {
11291138
// notify once because initial load is 3 chapters I don't care about 10 notifications when the user cant see it
11301139
updateReadArea(seekToDesired = true)
11311140

1132-
_loadingStatus.postValue(
1141+
/*_loadingStatus.postValue(
11331142
Resource.Success(true)
1134-
)
1143+
)*/
11351144
}
11361145

11371146
is Resource.Failure -> {
@@ -1578,7 +1587,6 @@ class ReadActivityViewModel : ViewModel() {
15781587

15791588
// load the chapters
15801589
updateIndexAsync(index, notify = false)
1581-
15821590
// set the keys
15831591
setKey(EPUB_CURRENT_POSITION, book.title(), index)
15841592
setKey(EPUB_CURRENT_POSITION_SCROLL_CHAR, book.title(), 0)
@@ -1590,10 +1598,9 @@ class ReadActivityViewModel : ViewModel() {
15901598

15911599
// push the update
15921600
updateReadArea(seekToDesired = true)
1593-
15941601
// update the view
15951602
_chapterTile.postValue(chaptersTitlesInternal[index])
1596-
_loadingStatus.postValue(Resource.Success(true))
1603+
//_loadingStatus.postValue(Resource.Success(true))
15971604
}
15981605

15991606
/*private fun changeIndex(index: Int, updateArea: Boolean = true) {

app/src/main/java/me/ag2s/LICENSE

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
GNU LESSER GENERAL PUBLIC LICENSE
2+
Version 3, 29 June 2007
3+
4+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5+
Everyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
7+
8+
9+
This version of the GNU Lesser General Public License incorporates
10+
the terms and conditions of version 3 of the GNU General Public
11+
License, supplemented by the additional permissions listed below.
12+
13+
0. Additional Definitions.
14+
15+
As used herein, "this License" refers to version 3 of the GNU Lesser
16+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
17+
General Public License.
18+
19+
"The Library" refers to a covered work governed by this License,
20+
other than an Application or a Combined Work as defined below.
21+
22+
An "Application" is any work that makes use of an interface provided
23+
by the Library, but which is not otherwise based on the Library.
24+
Defining a subclass of a class defined by the Library is deemed a mode
25+
of using an interface provided by the Library.
26+
27+
A "Combined Work" is a work produced by combining or linking an
28+
Application with the Library. The particular version of the Library
29+
with which the Combined Work was made is also called the "Linked
30+
Version".
31+
32+
The "Minimal Corresponding Source" for a Combined Work means the
33+
Corresponding Source for the Combined Work, excluding any source code
34+
for portions of the Combined Work that, considered in isolation, are
35+
based on the Application, and not on the Linked Version.
36+
37+
The "Corresponding Application Code" for a Combined Work means the
38+
object code and/or source code for the Application, including any data
39+
and utility programs needed for reproducing the Combined Work from the
40+
Application, but excluding the System Libraries of the Combined Work.
41+
42+
1. Exception to Section 3 of the GNU GPL.
43+
44+
You may convey a covered work under sections 3 and 4 of this License
45+
without being bound by section 3 of the GNU GPL.
46+
47+
2. Conveying Modified Versions.
48+
49+
If you modify a copy of the Library, and, in your modifications, a
50+
facility refers to a function or data to be supplied by an Application
51+
that uses the facility (other than as an argument passed when the
52+
facility is invoked), then you may convey a copy of the modified
53+
version:
54+
55+
a) under this License, provided that you make a good faith effort to
56+
ensure that, in the event an Application does not supply the
57+
function or data, the facility still operates, and performs
58+
whatever part of its purpose remains meaningful, or
59+
60+
b) under the GNU GPL, with none of the additional permissions of
61+
this License applicable to that copy.
62+
63+
3. Object Code Incorporating Material from Library Header Files.
64+
65+
The object code form of an Application may incorporate material from
66+
a header file that is part of the Library. You may convey such object
67+
code under terms of your choice, provided that, if the incorporated
68+
material is not limited to numerical parameters, data structure
69+
layouts and accessors, or small macros, inline functions and templates
70+
(ten or fewer lines in length), you do both of the following:
71+
72+
a) Give prominent notice with each copy of the object code that the
73+
Library is used in it and that the Library and its use are
74+
covered by this License.
75+
76+
b) Accompany the object code with a copy of the GNU GPL and this license
77+
document.
78+
79+
4. Combined Works.
80+
81+
You may convey a Combined Work under terms of your choice that,
82+
taken together, effectively do not restrict modification of the
83+
portions of the Library contained in the Combined Work and reverse
84+
engineering for debugging such modifications, if you also do each of
85+
the following:
86+
87+
a) Give prominent notice with each copy of the Combined Work that
88+
the Library is used in it and that the Library and its use are
89+
covered by this License.
90+
91+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
92+
document.
93+
94+
c) For a Combined Work that displays copyright notices during
95+
execution, include the copyright notice for the Library among
96+
these notices, as well as a reference directing the user to the
97+
copies of the GNU GPL and this license document.
98+
99+
d) Do one of the following:
100+
101+
0) Convey the Minimal Corresponding Source under the terms of this
102+
License, and the Corresponding Application Code in a form
103+
suitable for, and under terms that permit, the user to
104+
recombine or relink the Application with a modified version of
105+
the Linked Version to produce a modified Combined Work, in the
106+
manner specified by section 6 of the GNU GPL for conveying
107+
Corresponding Source.
108+
109+
1) Use a suitable shared library mechanism for linking with the
110+
Library. A suitable mechanism is one that (a) uses at run time
111+
a copy of the Library already present on the user's computer
112+
system, and (b) will operate properly with a modified version
113+
of the Library that is interface-compatible with the Linked
114+
Version.
115+
116+
e) Provide Installation Information, but only if you would otherwise
117+
be required to provide such information under section 6 of the
118+
GNU GPL, and only to the extent that such information is
119+
necessary to install and execute a modified version of the
120+
Combined Work produced by recombining or relinking the
121+
Application with a modified version of the Linked Version. (If
122+
you use option 4d0, the Installation Information must accompany
123+
the Minimal Corresponding Source and Corresponding Application
124+
Code. If you use option 4d1, you must provide the Installation
125+
Information in the manner specified by section 6 of the GNU GPL
126+
for conveying Corresponding Source.)
127+
128+
5. Combined Libraries.
129+
130+
You may place library facilities that are a work based on the
131+
Library side by side in a single library together with other library
132+
facilities that are not Applications and are not covered by this
133+
License, and convey such a combined library under terms of your
134+
choice, if you do both of the following:
135+
136+
a) Accompany the combined library with a copy of the same work based
137+
on the Library, uncombined with any other library facilities,
138+
conveyed under the terms of this License.
139+
140+
b) Give prominent notice with the combined library that part of it
141+
is a work based on the Library, and explaining where to find the
142+
accompanying uncombined form of the same work.
143+
144+
6. Revised Versions of the GNU Lesser General Public License.
145+
146+
The Free Software Foundation may publish revised and/or new versions
147+
of the GNU Lesser General Public License from time to time. Such new
148+
versions will be similar in spirit to the present version, but may
149+
differ in detail to address new problems or concerns.
150+
151+
Each version is given a distinguishing version number. If the
152+
Library as you received it specifies that a certain numbered version
153+
of the GNU Lesser General Public License "or any later version"
154+
applies to it, you have the option of following the terms and
155+
conditions either of that published version or of any later version
156+
published by the Free Software Foundation. If the Library as you
157+
received it does not specify a version number of the GNU Lesser
158+
General Public License, you may choose any version of the GNU Lesser
159+
General Public License ever published by the Free Software Foundation.
160+
161+
If the Library as you received it specifies that a proxy can decide
162+
whether future versions of the GNU Lesser General Public License shall
163+
apply, that proxy's public statement of acceptance of any version is
164+
permanent authorization for you to choose that version for the
165+
Library.

0 commit comments

Comments
 (0)