Skip to content

Commit

Permalink
Merge pull request #6497 from seadowg/view-only-leak
Browse files Browse the repository at this point in the history
Fix leaking form session when viewing submission
  • Loading branch information
grzesiek2010 authored Nov 5, 2024
2 parents a1c16f9 + 5e9be8c commit 8a26bf8
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.odk.collect.android.formhierarchy
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.activity.OnBackPressedCallback
import org.javarosa.core.model.FormIndex
import org.odk.collect.android.R
import org.odk.collect.android.javarosawrapper.FormController
Expand All @@ -14,7 +15,16 @@ import org.odk.collect.android.javarosawrapper.FormController
class ViewOnlyFormHierarchyActivity : FormHierarchyActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

onBackPressedCallback.remove()
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
setResult(RESULT_OK)
finish()
val sessionId = intent.getStringExtra(EXTRA_SESSION_ID)!!
formSessionRepository.clear(sessionId)
}
})
}

/**
Expand All @@ -23,10 +33,7 @@ class ViewOnlyFormHierarchyActivity : FormHierarchyActivity() {
*/
public override fun configureButtons(formController: FormController) {
val exitButton = findViewById<Button>(R.id.exitButton)
exitButton.setOnClickListener {
setResult(RESULT_OK)
finish()
}
exitButton.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
exitButton.visibility = View.VISIBLE
jumpBeginningButton.visibility = View.GONE
jumpEndButton.visibility = View.GONE
Expand Down

0 comments on commit 8a26bf8

Please sign in to comment.