Skip to content

Commit

Permalink
Fix chapters duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Mar 9, 2024
1 parent 4f2c38d commit 8c2bff7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ afterEvaluate {
}
dependencies {
//noinspection GradleDependency
implementation('com.github.KotatsuApp:kotatsu-parsers:0aa4ea01f7') {
implementation('com.github.KotatsuApp:kotatsu-parsers:b7613606c0') {
exclude group: 'org.json', module: 'json'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ChapterPages private constructor(private val pages: ArrayDeque<ReaderPage>
val chaptersSize: Int
get() = indices.size()

@Synchronized
fun removeFirst() {
val chapterId = pages.first().chapterId
indices.remove(chapterId)
Expand All @@ -25,6 +26,7 @@ class ChapterPages private constructor(private val pages: ArrayDeque<ReaderPage>
shiftIndices(delta)
}

@Synchronized
fun removeLast() {
val chapterId = pages.last().chapterId
indices.remove(chapterId)
Expand All @@ -33,17 +35,28 @@ class ChapterPages private constructor(private val pages: ArrayDeque<ReaderPage>
}
}

fun addLast(id: Long, newPages: List<ReaderPage>) {
@Synchronized
fun addLast(id: Long, newPages: List<ReaderPage>): Boolean {
if (id in indices) {
return false
}
indices.put(id, pages.size until (pages.size + newPages.size))
pages.addAll(newPages)
return true
}

fun addFirst(id: Long, newPages: List<ReaderPage>) {
@Synchronized
fun addFirst(id: Long, newPages: List<ReaderPage>): Boolean {
if (id in indices) {
return false
}
shiftIndices(newPages.size)
indices.put(id, newPages.indices)
pages.addAll(0, newPages)
return true
}

@Synchronized
fun clear() {
indices.clear()
pages.clear()
Expand All @@ -58,7 +71,7 @@ class ChapterPages private constructor(private val pages: ArrayDeque<ReaderPage>
return pages.subList(range.first, range.last + 1)
}

operator fun contains(chapterId: Long) = indices.contains(chapterId)
operator fun contains(chapterId: Long) = chapterId in indices

private fun shiftIndices(delta: Int) {
for (i in 0 until indices.size()) {
Expand Down

0 comments on commit 8c2bff7

Please sign in to comment.