From 9e1c3392d21aef0e31e56bc7edc5424fe10971ac Mon Sep 17 00:00:00 2001 From: Dima Date: Fri, 10 Jan 2025 17:21:22 +0900 Subject: [PATCH] =?UTF-8?q?Fix=20for=20crash=20=E2=80=9Cjava.lang.IllegalS?= =?UTF-8?q?tateException=20-=20Can't=20render=20annotations=20that=20aren'?= =?UTF-8?q?t=20attached=20to=20a=20document=20page=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upping versionCode to 129 --- .../pdf/data/AnnotationPreviewManager.kt | 19 +++++++++++++++---- buildSrc/src/main/kotlin/BuildConfig.kt | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/zotero/android/pdf/data/AnnotationPreviewManager.kt b/app/src/main/java/org/zotero/android/pdf/data/AnnotationPreviewManager.kt index 1a33b4a..6064457 100644 --- a/app/src/main/java/org/zotero/android/pdf/data/AnnotationPreviewManager.kt +++ b/app/src/main/java/org/zotero/android/pdf/data/AnnotationPreviewManager.kt @@ -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 @@ -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, @@ -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) @@ -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) @@ -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() diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 6a55cb7..a7cce01 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -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,