Skip to content

Commit

Permalink
Add Exit Dialog (#3487)
Browse files Browse the repository at this point in the history
* Add exit dialog

* Fix a typo

* Show Dialog only when Map or Register is visible

* PR feedback changes

* Fix failing check

* Remove incorrect test

* Refactor dialog condition logic

---------

Co-authored-by: Benjamin Mwalimu <dubdabasoduba@gmail.com>
  • Loading branch information
hamza-vd and dubdabasoduba authored Oct 7, 2024
1 parent 3b66b02 commit e9bc0de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.os.Bundle
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.domain.model.LauncherType
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 @@ open class AppMainActivity : BaseMultiLanguageActivity(), QuestionnaireHandler,
}

setupLocationServices()
overrideOnBackPressListener()

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,26 @@ open class AppMainActivity : BaseMultiLanguageActivity(), QuestionnaireHandler,
}
}
}

private fun overrideOnBackPressListener() {
onBackPressedDispatcher.addCallback(
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
val navHostFragment =
(supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment)
if (navHostFragment.childFragmentManager.backStackEntryCount == 0) {
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() },
)
} else navHostFragment.navController.navigateUp()
}
},
)
}
}
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

0 comments on commit e9bc0de

Please sign in to comment.