Skip to content

Commit

Permalink
Fixing PdfReader jumping to a different page after editing an annotat…
Browse files Browse the repository at this point in the history
…ion. Also fixes PdfReader jumping to a wrong page after app was left minified for a while.

Upping versionCode to 119
  • Loading branch information
Dima-Android committed Nov 26, 2024
1 parent 9bc6fba commit 0aed32c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class PdfReaderViewModel @Inject constructor(
private var annotationEditReaderKey: AnnotationKey? = null
private var isLongPressOnTextAnnotation = false

private var initialPage: Int? = null

val screenArgs: PdfReaderArgs by lazy {
val argsEncoded = stateHandle.get<String>(ARG_PDF_SCREEN).require()
navigationParamsMarshaller.decodeObjectFromBase64(argsEncoded)
Expand Down Expand Up @@ -726,6 +728,7 @@ class PdfReaderViewModel @Inject constructor(
this.activeLineWidth = defaults.getActiveLineWidth()
this.activeEraserSize = defaults.getActiveEraserSize()
this.activeFontSize = defaults.getActiveFontSize()
this.initialPage = params.page

updateState {
copy(
Expand All @@ -735,7 +738,6 @@ class PdfReaderViewModel @Inject constructor(
username = username,
displayName = displayName,
visiblePage = 0,
initialPage = params.page,
selectedAnnotationKey = params.preselectedAnnotationKey?.let {
AnnotationKey(
key = it,
Expand Down Expand Up @@ -865,12 +867,13 @@ class PdfReaderViewModel @Inject constructor(
boundingBoxConverter = annotationBoundingBoxConverter
)

this.initialPage = null

updateState {
copy(
pdfDocumentAnnotations = documentAnnotations,
sortedKeys = sortedKeys,
visiblePage = page,
initialPage = null,
)
}

Expand Down Expand Up @@ -1190,7 +1193,7 @@ class PdfReaderViewModel @Inject constructor(
}
}

val initialPage = viewState.initialPage
val initialPage = this.initialPage
if (initialPage != null && initialPage >= 0 && initialPage < this.document.pageCount) {
return initialPage to null
}
Expand Down Expand Up @@ -2002,7 +2005,6 @@ class PdfReaderViewModel @Inject constructor(
.forEach {
this.document.annotationProvider.removeAnnotationFromPage(it)
}
submitPendingPage(pdfUiFragment.pageIndex)
val activity = pdfUiFragment.activity
if (activity != null) {
WindowCompat.getInsetsController(activity.window, activity.window.decorView).show(
Expand Down Expand Up @@ -2321,6 +2323,7 @@ class PdfReaderViewModel @Inject constructor(

fun onStop(isChangingConfigurations: Boolean) {
pdfDocumentBeforeFragmentDestruction = pdfFragment.document!!
submitPendingPage(pdfUiFragment.pageIndex)
if (isChangingConfigurations) {
removeFragment()
}
Expand Down Expand Up @@ -3346,7 +3349,6 @@ data class PdfReaderViewState(
val displayName: String = "",
val selectedAnnotationKey: AnnotationKey? = null,
val isDark: Boolean = false,
val initialPage: Int? = null,
val visiblePage: Int = 0,
val focusSidebarKey: AnnotationKey? = null,
val focusDocumentLocation: Pair<Int, RectF>? = null,
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 = 118 // Must be updated on every build
val versionCode = 119 // Must be updated on every build
val version = Version(
major = 1,
minor = 0,
Expand Down

0 comments on commit 0aed32c

Please sign in to comment.