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,