Skip to content

Commit

Permalink
Fix for crash “java.lang.IllegalStateException - Can't render annotat…
Browse files Browse the repository at this point in the history
…ions that aren't attached to a document page”

Upping versionCode to 129
  • Loading branch information
Dima-Android committed Jan 10, 2025
1 parent 9500b65 commit 9e1c339
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.zotero.android.ktx.previewId
import org.zotero.android.ktx.shouldRenderPreview
import org.zotero.android.pdf.cache.AnnotationPreviewMemoryCache
import org.zotero.android.sync.LibraryIdentifier
import timber.log.Timber
import java.io.FileOutputStream
import java.util.Collections
import javax.inject.Inject
Expand All @@ -43,9 +44,6 @@ class AnnotationPreviewManager @Inject constructor(
isDark: Boolean,
annotationMaxSideSize: Int,
) {
if (!annotation.shouldRenderPreview || !annotation.isZoteroAnnotation || !annotation.isAttached) {
return
}
enqueue(
annotation = annotation,
key = annotation.previewId,
Expand Down Expand Up @@ -104,7 +102,7 @@ class AnnotationPreviewManager @Inject constructor(
isDark: Boolean = false,
bitmapSize: Int
) = coroutineScope.launch {
if (currentlyProcessingAnnotations.contains(key)) {
if (currentlyProcessingAnnotations.contains(key) || !isAnnotationInDrawableState(annotation)) {
return@launch
}
currentlyProcessingAnnotations.add(key)
Expand All @@ -115,6 +113,10 @@ class AnnotationPreviewManager @Inject constructor(
maxSide = bitmapSize
)

if (!isAnnotationInDrawableState(annotation)) {
return@launch
}

val shouldDrawAnnotation = annotation is InkAnnotation || annotation is FreeTextAnnotation
if (shouldDrawAnnotation) {
drawAnnotationOnBitmap(resultBitmap, annotation)
Expand Down Expand Up @@ -225,6 +227,15 @@ class AnnotationPreviewManager @Inject constructor(
tempFile.renameTo(finalFile)
}

fun isAnnotationInDrawableState(annotation: Annotation): Boolean {
val isInDrawableState =
annotation.shouldRenderPreview && annotation.isZoteroAnnotation && annotation.isAttached
if (!annotation.isAttached) {
Timber.w("Trying to draw an annotation while it's not in an attached state. Skipping.")
}
return isInDrawableState
}

fun cancelProcessing() {
currentlyProcessingAnnotations.clear()
coroutineScope.cancel()
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object BuildConfig {
const val compileSdkVersion = 34
const val targetSdk = 34

val versionCode = 128 // Must be updated on every build
val versionCode = 129 // Must be updated on every build
val version = Version(
major = 1,
minor = 0,
Expand Down

0 comments on commit 9e1c339

Please sign in to comment.