Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leaking form session when viewing submission #6497

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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