Skip to content

Commit

Permalink
Fix for crash “PdfReaderViewModel.onCleared”
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima-Android committed Jan 9, 2025
1 parent 9c9fcf8 commit 9500b65
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,11 @@ class PdfReaderViewModel @Inject constructor(
fragmentManager.commit(allowStateLoss = true) {
remove(this@PdfReaderViewModel.pdfUiFragment)
}
pdfFragment.removeOnAnnotationUpdatedListener(onAnnotationUpdatedListener!!)
if (this::pdfFragment.isInitialized) {
onAnnotationUpdatedListener?.let {
pdfFragment.removeOnAnnotationUpdatedListener(it)
}
}

EventBus.getDefault().unregister(this)
liveAnnotations?.removeAllChangeListeners()
Expand All @@ -2072,16 +2076,18 @@ class PdfReaderViewModel @Inject constructor(
annotationPreviewManager.cancelProcessing()
annotationPreviewFileCache.cancelProcessing()
clearThumbnailCaches()
document.annotationProvider
.getAllAnnotationsOfTypeAsync(AnnotationsConfig.supported)
.toList()
.blockingGet()
.forEach {
this.document.annotationProvider.removeAnnotationFromPage(it)
}
val activity = pdfUiFragment.activity
if (activity != null) {
WindowCompat.getInsetsController(activity.window, activity.window.decorView).show(
if (this::document.isInitialized) {
document.annotationProvider
.getAllAnnotationsOfTypeAsync(AnnotationsConfig.supported)
.toList()
.blockingGet()
.forEach {
this.document.annotationProvider.removeAnnotationFromPage(it)
}
}

pdfUiFragment.activity?.let {
WindowCompat.getInsetsController(it.window, it.window.decorView).show(
WindowInsetsCompat.Type.systemBars()
)
}
Expand Down

0 comments on commit 9500b65

Please sign in to comment.