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

Add Exit Dialog #3487

Merged
merged 17 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -24,6 +24,7 @@
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -51,6 +52,8 @@
import org.smartregister.fhircore.engine.rulesengine.services.LocationCoordinate
import org.smartregister.fhircore.engine.sync.OnSyncListener
import org.smartregister.fhircore.engine.sync.SyncListenerManager
import org.smartregister.fhircore.engine.ui.base.AlertDialogue
import org.smartregister.fhircore.engine.ui.base.AlertIntent
import org.smartregister.fhircore.engine.ui.base.BaseMultiLanguageActivity
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.parcelable
Expand Down Expand Up @@ -152,6 +155,7 @@
}

setupLocationServices()
overrideOnBackPressListener()

Check warning on line 158 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt#L158

Added line #L158 was not covered by tests

findViewById<View>(R.id.mainScreenProgressBar).apply { visibility = View.GONE }
findViewById<View>(R.id.mainScreenProgressBarText).apply { visibility = View.GONE }
Expand Down Expand Up @@ -300,4 +304,30 @@
}
}
}

private fun overrideOnBackPressListener() {
onBackPressedDispatcher.addCallback(

Check warning on line 309 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt#L309

Added line #L309 was not covered by tests
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
val navController =
(supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment)
.navController

Check warning on line 314 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt#L312-L314

Added lines #L312 - L314 were not covered by tests
if (
navController.currentDestination?.id?.equals(R.id.geoWidgetLauncherFragment)!! ||
navController.currentDestination?.id?.equals(R.id.registerFragment)!!
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this implementation is based on the assumption that the entry point to the app can either be the map or register. However, a user can redirect to a register screen from the profile using the onSubmitQuestionnaire actions. Would it be possible to check if there is no more entry in the navController back stack instead to prompt this dialog?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition updated

AlertDialogue.showAlert(
this@AppMainActivity,
alertIntent = AlertIntent.CONFIRM,
title = getString(R.string.exit_app),
message = getString(R.string.exit_app_message),
cancellable = false,
confirmButtonListener = { finish() },
neutralButtonListener = { dialog -> dialog.dismiss() },

Check warning on line 326 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt#L319-L326

Added lines #L319 - L326 were not covered by tests
)
} else navController.navigateUp()

Check warning on line 328 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt#L328

Added line #L328 was not covered by tests
}
},
)
}
}
2 changes: 2 additions & 0 deletions android/quest/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@
<string name="scan_qr_camera_instruction">Place your camera over the entire QR Code to start scanning</string>
<string name="failed_to_get_gps_location">Failed to get GPS location</string>
<string name="space_asterisk" translatable="false">\u0020\u002a</string>
<string name="exit_app">Exit App</string>
<string name="exit_app_message">Are you sure you want to exit from the app?</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import io.mockk.slot
import io.mockk.spyk
import java.io.Serializable
import java.time.OffsetDateTime
import kotlin.test.assertNotNull
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.junit.Assert
Expand Down
Loading