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

Delete saved draft feature #3631

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 @@ -62,4 +62,7 @@

/** A workflow to launch pdf generation */
LAUNCH_PDF_GENERATION,

/** A workflow to launch delete draft */
LAUNCH_DELETE_DRAFT_FORM,

Check warning on line 67 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/workflow/ApplicationWorkflow.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/workflow/ApplicationWorkflow.kt#L67

Added line #L67 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ object AlertDialogue {
)
}

fun showCancelAlert(
fun showThreeButtonAlert(
context: Context,
@StringRes message: Int,
@StringRes title: Int? = null,
Expand Down
2 changes: 2 additions & 0 deletions android/engine/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<string name="questionnaire_alert_invalid_message">Given details have validation errors. Resolve errors and submit again</string>
<string name="questionnaire_alert_invalid_title">Validation Failed</string>
<string name="questionnaire_alert_ack_button_title">OK</string>
<string name="questionnaire_alert_open_draft_button_title">Open draft</string>
<string name="questionnaire_alert_delete_draft_button_title">Delete draft</string>
<string name="username">Username</string>
<string name="password">Password</string>
<string name="forgot_password">Forgot Password</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class AlertDialogueTest : ActivityRobolectricTest() {

@Test
fun testShowCancelAlertShowsWithCorrectData() {
AlertDialogue.showCancelAlert(
AlertDialogue.showThreeButtonAlert(
context = context,
message = R.string.questionnaire_in_progress_alert_back_pressed_message,
title = R.string.questionnaire_alert_back_pressed_title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@ sealed class MainNavigationScreen(
route = org.smartregister.fhircore.quest.R.id.summaryBottomSheetFragment,
)

data object AlertDialogFragment :
MainNavigationScreen(
route = org.smartregister.fhircore.quest.R.id.alertDialogFragment,
)

fun eventId(id: String) = route.toString() + "_" + id
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ object NavigationArg {
const val REPORT_ID = "reportId"
const val PARAMS = "params"
const val TOOL_BAR_HOME_NAVIGATION = "toolBarHomeNavigation"
const val QUESTIONNAIRE_CONFIG = "questionnaireConfig"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.quest.ui.dialog

import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.navArgs
import dagger.hilt.android.AndroidEntryPoint
import org.smartregister.fhircore.engine.ui.base.AlertDialogue
import org.smartregister.fhircore.quest.ui.shared.QuestionnaireHandler

@AndroidEntryPoint
class AlertDialogFragment() : DialogFragment() {

private val alertDialogFragmentArgs by navArgs<AlertDialogFragmentArgs>()
private val alertDialogViewModel by viewModels<AlertDialogViewModel>()

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialogue.showThreeButtonAlert(
context = requireContext(),
message =
org.smartregister.fhircore.engine.R.string
.questionnaire_in_progress_alert_back_pressed_message,
title = org.smartregister.fhircore.engine.R.string.questionnaire_alert_back_pressed_title,
confirmButtonListener = {
if (requireContext() is QuestionnaireHandler) {
(requireContext() as QuestionnaireHandler).launchQuestionnaire(
context = requireContext(),
questionnaireConfig = alertDialogFragmentArgs.questionnaireConfig,
actionParams = listOf(),
)
}
},
confirmButtonText =
org.smartregister.fhircore.engine.R.string.questionnaire_alert_open_draft_button_title,
neutralButtonListener = {},
neutralButtonText =
org.smartregister.fhircore.engine.R.string.questionnaire_alert_neutral_button_title,
negativeButtonListener = {
alertDialogViewModel.deleteDraft(alertDialogFragmentArgs.questionnaireConfig)
this.dismiss()
},
negativeButtonText =
org.smartregister.fhircore.engine.R.string.questionnaire_alert_delete_draft_button_title,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.quest.ui.dialog

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.util.DispatcherProvider

@HiltViewModel
class AlertDialogViewModel
@Inject
constructor(
val defaultRepository: DefaultRepository,
val dispatcherProvider: DispatcherProvider,
) : ViewModel() {
fun deleteDraft(questionnaireConfig: QuestionnaireConfig?) {
TODO("Add implementation")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {
if (questionnaireConfig.isReadOnly()) {
finish()
} else if (questionnaireConfig.saveDraft) {
AlertDialogue.showCancelAlert(
AlertDialogue.showThreeButtonAlert(
context = this,
message =
org.smartregister.fhircore.engine.R.string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ fun ActionConfig.handleClickEvent(
val appCompatActivity = (navController.context as AppCompatActivity)
PdfLauncherFragment.launch(appCompatActivity, interpolatedPdfConfig.encodeJson())
}
ApplicationWorkflow.LAUNCH_DELETE_DRAFT_FORM -> {
val args =
bundleOf(
NavigationArg.QUESTIONNAIRE_CONFIG to actionConfig.questionnaire,
)
navController.navigate(MainNavigationScreen.AlertDialogFragment.route, args)
}
else -> return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,12 @@
android:name="org.smartregister.fhircore.quest.ui.bottomsheet.SummaryBottomSheetFragment" >

</dialog>
<dialog
android:id="@+id/alertDialogFragment"
android:name="org.smartregister.fhircore.quest.ui.dialog.AlertDialogFragment" >
<argument
android:name="questionnaireConfig"
app:argType="org.smartregister.fhircore.engine.configuration.QuestionnaireConfig"
app:nullable="true" />
</dialog>
</navigation>
Loading