From 806d70a4a14a8c69a1c82694b6d8f2b69dc312d0 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 11 Sep 2024 16:16:06 +0530 Subject: [PATCH 1/6] Added support for translations to fetch from server for repeat group button and title --- .../activities/FormEntryActivityUIController.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/org/commcare/activities/FormEntryActivityUIController.java b/app/src/org/commcare/activities/FormEntryActivityUIController.java index f917a62542..e65249dfcd 100644 --- a/app/src/org/commcare/activities/FormEntryActivityUIController.java +++ b/app/src/org/commcare/activities/FormEntryActivityUIController.java @@ -49,6 +49,7 @@ import org.javarosa.core.model.data.InvalidData; import org.javarosa.core.services.Logger; import org.javarosa.core.services.locale.Localization; +import org.javarosa.form.api.FormEntryCaption; import org.javarosa.form.api.FormEntryController; import org.javarosa.form.api.FormEntryPrompt; import org.javarosa.xpath.XPathException; @@ -493,20 +494,19 @@ private void createRepeatDialog() { final boolean backExitsForm = !details.relevantBeforeCurrentScreen; final boolean nextExitsForm = details.relevantAfterCurrentScreen == 0; + final FormEntryCaption repeatCaptionPrompt = FormEntryActivity.mFormController.getCaptionPrompt(); + // Assign title and text strings based on the current state String backText = Localization.get("repeat.dialog.go.back"); - String addAnotherText = Localization.get("repeat.dialog.add"); + String addAnotherText = repeatCaptionPrompt.getRepeatText(FormEntryActivity.mFormController.getLastRepeatCount() > 0 ? "add" : "add-empty"); String title, skipText; if (!nextExitsForm) { skipText = Localization.get("repeat.dialog.leave"); } else { skipText = Localization.get("repeat.dialog.exit"); } - if (FormEntryActivity.mFormController.getLastRepeatCount() > 0) { - title = Localization.get("repeat.dialog.add.another", FormEntryActivity.mFormController.getLastGroupText()); - } else { - title = Localization.get("repeat.dialog.add.new", FormEntryActivity.mFormController.getLastGroupText()); - } + + title = addAnotherText; // Create the choice dialog ContextThemeWrapper wrapper = new ContextThemeWrapper(activity, R.style.DialogBaseTheme); From 509c3173d65dc164fac3d306a2f14a86424e063d Mon Sep 17 00:00:00 2001 From: Devansh Date: Thu, 12 Sep 2024 15:32:36 +0530 Subject: [PATCH 2/6] Updated the translation strings --- app/assets/locales/android_translatable_strings.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/locales/android_translatable_strings.txt b/app/assets/locales/android_translatable_strings.txt index 588441a279..0be9d6d93c 100644 --- a/app/assets/locales/android_translatable_strings.txt +++ b/app/assets/locales/android_translatable_strings.txt @@ -896,8 +896,8 @@ repeat.dialog.go.back=Go Back repeat.dialog.leave=Do Not Add repeat.dialog.exit=Do Not Add. I'm Finished. repeat.dialog.add=Add Group -repeat.dialog.add.another=Add another "${0}" group? -repeat.dialog.add.new=Add a new "${0}" group? +repeat.dialog.add.another=Add another ${0}? +repeat.dialog.add.new=Add a new ${0}? lookup.table.missing.error=Unable to find lookup table "${0}". Make sure it exists and this user has access to it. ethiopian_months=Mäskäräm,T’ïk’ïmt,Hïdar,Tahsas,T’ïr,Yäkatit,Mägabit,Miyaziya,Gïnbot,Säne,Hämle,Nähäse,P’agume From 9f72403a7a2696cfcd17c72dd71271821c0d3cb3 Mon Sep 17 00:00:00 2001 From: Devansh Date: Thu, 12 Sep 2024 15:33:16 +0530 Subject: [PATCH 3/6] Making code more readable --- .../activities/FormEntryActivityUIController.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/org/commcare/activities/FormEntryActivityUIController.java b/app/src/org/commcare/activities/FormEntryActivityUIController.java index e65249dfcd..93b41224b6 100644 --- a/app/src/org/commcare/activities/FormEntryActivityUIController.java +++ b/app/src/org/commcare/activities/FormEntryActivityUIController.java @@ -498,8 +498,14 @@ private void createRepeatDialog() { // Assign title and text strings based on the current state String backText = Localization.get("repeat.dialog.go.back"); - String addAnotherText = repeatCaptionPrompt.getRepeatText(FormEntryActivity.mFormController.getLastRepeatCount() > 0 ? "add" : "add-empty"); + + // Checking the repetitions here + boolean hasRepetitions = FormEntryActivity.mFormController.getLastRepeatCount() > 0; + // Setting the text based on repetitions + String addAnotherText = repeatCaptionPrompt.getRepeatText(hasRepetitions ? "add" : "add-empty"); + String title, skipText; + if (!nextExitsForm) { skipText = Localization.get("repeat.dialog.leave"); } else { From 7eae6d6e5d2da1fad826ecb1a966143879b84b8d Mon Sep 17 00:00:00 2001 From: Devansh Date: Fri, 13 Sep 2024 15:31:51 +0530 Subject: [PATCH 4/6] Updated the DialogTests as per the new text expectations --- .../src/org/commcare/androidTests/DialogTests.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/instrumentation-tests/src/org/commcare/androidTests/DialogTests.kt b/app/instrumentation-tests/src/org/commcare/androidTests/DialogTests.kt index ddb24a05f1..78f92ce3d5 100644 --- a/app/instrumentation-tests/src/org/commcare/androidTests/DialogTests.kt +++ b/app/instrumentation-tests/src/org/commcare/androidTests/DialogTests.kt @@ -2,6 +2,7 @@ package org.commcare.androidTests import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -44,15 +45,16 @@ class DialogTests: BaseTest() { onView(withId(R.id.nav_btn_next)) .perform(click()) - withText("Add a new \"Error on add\" group?").isDisplayed() + onView(withId(R.id.choice_dialog_panel_2)).check(matches(withText("Add a new Error on add?"))) InstrumentationUtility.rotateLeft() //TODO Expect dialog to not persist due to a activity lifecycle bug in our dialog framework. - withText("Add a new \"Error on add\" group?").doesNotExist() + withText(R.id.choice_dialog_panel_2).doesNotExist() + InstrumentationUtility.rotatePortrait() onView(withId(R.id.nav_btn_next)) .perform(click()) - onView(withText("ADD GROUP")) + onView(withId(R.id.choice_dialog_panel_2)) .perform(click()) checkDialogExistence_withRotation("Error Occurred") From d734ac6488397d661c9c73b6f5c56691581340a6 Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 16 Sep 2024 19:23:32 +0530 Subject: [PATCH 5/6] Removed comments from self-explanatory code as per suggestions --- .../org/commcare/activities/FormEntryActivityUIController.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/org/commcare/activities/FormEntryActivityUIController.java b/app/src/org/commcare/activities/FormEntryActivityUIController.java index 93b41224b6..36e3614bd8 100644 --- a/app/src/org/commcare/activities/FormEntryActivityUIController.java +++ b/app/src/org/commcare/activities/FormEntryActivityUIController.java @@ -499,9 +499,7 @@ private void createRepeatDialog() { // Assign title and text strings based on the current state String backText = Localization.get("repeat.dialog.go.back"); - // Checking the repetitions here boolean hasRepetitions = FormEntryActivity.mFormController.getLastRepeatCount() > 0; - // Setting the text based on repetitions String addAnotherText = repeatCaptionPrompt.getRepeatText(hasRepetitions ? "add" : "add-empty"); String title, skipText; From e0fe2c5475279d175cb02ac3a8d588f291d3ad01 Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 16 Sep 2024 19:41:27 +0530 Subject: [PATCH 6/6] Removed extra variable usage --- .../activities/FormEntryActivityUIController.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/org/commcare/activities/FormEntryActivityUIController.java b/app/src/org/commcare/activities/FormEntryActivityUIController.java index 36e3614bd8..e06b0da10b 100644 --- a/app/src/org/commcare/activities/FormEntryActivityUIController.java +++ b/app/src/org/commcare/activities/FormEntryActivityUIController.java @@ -500,9 +500,9 @@ private void createRepeatDialog() { String backText = Localization.get("repeat.dialog.go.back"); boolean hasRepetitions = FormEntryActivity.mFormController.getLastRepeatCount() > 0; - String addAnotherText = repeatCaptionPrompt.getRepeatText(hasRepetitions ? "add" : "add-empty"); + final String addAnotherText = repeatCaptionPrompt.getRepeatText(hasRepetitions ? "add" : "add-empty"); - String title, skipText; + String skipText; if (!nextExitsForm) { skipText = Localization.get("repeat.dialog.leave"); @@ -510,11 +510,9 @@ private void createRepeatDialog() { skipText = Localization.get("repeat.dialog.exit"); } - title = addAnotherText; - // Create the choice dialog ContextThemeWrapper wrapper = new ContextThemeWrapper(activity, R.style.DialogBaseTheme); - final PaneledChoiceDialog dialog = new HorizontalPaneledChoiceDialog(wrapper, title); + final PaneledChoiceDialog dialog = new HorizontalPaneledChoiceDialog(wrapper, addAnotherText); // Panel 1: Back option View.OnClickListener backListener = v -> {