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 10 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
@@ -0,0 +1,25 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.configuration.app

import kotlinx.serialization.Serializable

@Serializable
data class AppExitDialogConfig(
val title: String,
val message: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ data class ApplicationConfiguration(
id = null,
),
val codingSystems: List<CodingSystemConfig> = emptyList(),
val appExitDialog: AppExitDialogConfig? = null,
) : Configuration()

enum class SyncStrategy {
Expand Down
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,36 @@
}
}
}

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
Contributor Author

Choose a reason for hiding this comment

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

Condition updated

val title =

Check warning on line 319 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

Added line #L319 was not covered by tests
appMainViewModel.applicationConfiguration.appExitDialog?.title
hamza-vd marked this conversation as resolved.
Show resolved Hide resolved
?: getString(R.string.exit_app)
val message =

Check warning on line 322 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#L321-L322

Added lines #L321 - L322 were not covered by tests
appMainViewModel.applicationConfiguration.appExitDialog?.message
?: getString(R.string.exit_app_message)
AlertDialogue.showAlert(
this@AppMainActivity,
alertIntent = AlertIntent.CONFIRM,
title = title,
message = message,
cancellable = false,
confirmButtonListener = { finish() },
neutralButtonListener = { dialog -> dialog.dismiss() },

Check warning on line 332 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#L324-L332

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

Check warning on line 334 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#L334

Added line #L334 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>
Loading