From b5cdb8c0320f76ac71ccd7b165dd223686c00da6 Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Mon, 20 Mar 2023 18:52:37 +0100 Subject: [PATCH 1/5] Add warning when typing in instance name --- .../android/formentry/FormEndView.java | 6 ++++ .../src/main/res/layout/form_entry_end.xml | 36 +++++++++++++++++++ .../src/main/res/values-night/colors.xml | 1 + collect_app/src/main/res/values/colors.xml | 1 + collect_app/src/main/res/values/theme.xml | 1 + .../android/formentry/FormEndViewTest.kt | 36 +++++++++++++++++++ strings/src/main/res/values/strings.xml | 1 + 7 files changed, 82 insertions(+) create mode 100644 collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java b/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java index be5e5ee57d6..198810e4168 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java @@ -4,6 +4,7 @@ import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; +import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; @@ -35,6 +36,11 @@ private void init(Context context, boolean instanceComplete) { ((TextView) findViewById(R.id.description)).setText(context.getString(R.string.save_enter_data_description, formTitle)); EditText saveAs = findViewById(R.id.save_name); + saveAs.setOnFocusChangeListener((view, isFocused) -> { + if (isFocused) { + findViewById(R.id.manual_name_warning).setVisibility(View.VISIBLE); + } + }); // disallow carriage returns in the name InputFilter returnFilter = (source, start, end, dest, dstart, dend) -> FormNameUtils.normalizeFormName(source.toString().substring(start, end), true); diff --git a/collect_app/src/main/res/layout/form_entry_end.xml b/collect_app/src/main/res/layout/form_entry_end.xml index 09c73645fe0..fa0fb97e5f4 100644 --- a/collect_app/src/main/res/layout/form_entry_end.xml +++ b/collect_app/src/main/res/layout/form_entry_end.xml @@ -11,6 +11,7 @@ the specific language governing permissions and limitations under the License. @@ -41,7 +42,42 @@ the specific language governing permissions and limitations under the License. android:textSize="21sp" android:textStyle="bold" /> + + + + + + + + + + + #121212 + #41484d #FFFFFF false diff --git a/collect_app/src/main/res/values/colors.xml b/collect_app/src/main/res/values/colors.xml index 6c32aebb7a0..9727a988d5f 100644 --- a/collect_app/src/main/res/values/colors.xml +++ b/collect_app/src/main/res/values/colors.xml @@ -8,6 +8,7 @@ #ffffff #FFFFFF + #dce3e9 #000000 true diff --git a/collect_app/src/main/res/values/theme.xml b/collect_app/src/main/res/values/theme.xml index 059163d6e98..473dc761166 100644 --- a/collect_app/src/main/res/values/theme.xml +++ b/collect_app/src/main/res/values/theme.xml @@ -50,6 +50,7 @@ + @color/colorSurfaceVariant ?colorPrimary ?colorOnPrimary diff --git a/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt b/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt new file mode 100644 index 00000000000..78f7670a859 --- /dev/null +++ b/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt @@ -0,0 +1,36 @@ +package org.odk.collect.android.formentry + +import android.content.Context +import android.view.View +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.junit.runner.RunWith +import org.odk.collect.android.R + +@RunWith(AndroidJUnit4::class) +class FormEndViewTest { + + @Test + fun `focusing on save as field shows warning`() { + val context = ApplicationProvider.getApplicationContext().also { + it.setTheme(R.style.Theme_Material3_Light) + } + + val formEndView = FormEndView( + context, + null, + null, + false, + null + ) + + val warningView = formEndView.findViewById(R.id.manual_name_warning) + assertThat(warningView.visibility, equalTo(View.GONE)) + + formEndView.findViewById(R.id.save_name).requestFocus() + assertThat(warningView.visibility, equalTo(View.VISIBLE)) + } +} diff --git a/strings/src/main/res/values/strings.xml b/strings/src/main/res/values/strings.xml index cc79bb7989d..fec8248b1c6 100644 --- a/strings/src/main/res/values/strings.xml +++ b/strings/src/main/res/values/strings.xml @@ -166,6 +166,7 @@ Saved name must not be blank! Mark form as finalized Save Form and Exit + Soon manually naming forms will be removed. Form design needs to be updated. Sorry, form save failed! Form successfully saved! From ce932d6f41455a14e46832e554096291cc29d1a3 Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Tue, 21 Mar 2023 11:39:12 +0100 Subject: [PATCH 2/5] Correct shape appearance for Material 3 cards --- collect_app/src/main/res/layout/form_entry_end.xml | 4 +++- collect_app/src/main/res/values/theme.xml | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/collect_app/src/main/res/layout/form_entry_end.xml b/collect_app/src/main/res/layout/form_entry_end.xml index fa0fb97e5f4..0eb368b90f2 100644 --- a/collect_app/src/main/res/layout/form_entry_end.xml +++ b/collect_app/src/main/res/layout/form_entry_end.xml @@ -12,6 +12,7 @@ the specific language governing permissions and limitations under the License. android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:fillViewport="true" android:id="@+id/scroll_view" android:orientation="vertical"> @@ -47,7 +48,8 @@ the specific language governing permissions and limitations under the License. style="@style/Widget.Material3.CardView.Filled" android:layout_width="match_parent" android:layout_height="wrap_content" - android:visibility="gone"> + android:visibility="gone" + tools:visibility="visible"> ?colorOnPrimary @style/TextAppearance.Material3.LabelLarge + + @style/ShapeAppearance.Material3.Corner.Medium From 242c62664a1b249dd21cc385034fce50373d382b Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Tue, 21 Mar 2023 11:48:11 +0100 Subject: [PATCH 3/5] Enable using Material 3 body appearance --- collect_app/src/main/res/layout/form_entry_end.xml | 4 ++-- collect_app/src/main/res/values/theme.xml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/collect_app/src/main/res/layout/form_entry_end.xml b/collect_app/src/main/res/layout/form_entry_end.xml index 0eb368b90f2..c5bc915634b 100644 --- a/collect_app/src/main/res/layout/form_entry_end.xml +++ b/collect_app/src/main/res/layout/form_entry_end.xml @@ -63,14 +63,14 @@ the specific language governing permissions and limitations under the License. android:src="@drawable/ic_outline_info_24" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:tint="?colorOnSurface" /> + app:tint="?colorPrimary" /> diff --git a/collect_app/src/main/res/values/theme.xml b/collect_app/src/main/res/values/theme.xml index 10cd332ff65..a2cff766d71 100644 --- a/collect_app/src/main/res/values/theme.xml +++ b/collect_app/src/main/res/values/theme.xml @@ -55,6 +55,7 @@ ?colorOnPrimary + ?textAppearanceBody1 @style/TextAppearance.Material3.LabelLarge @style/ShapeAppearance.Material3.Corner.Medium From 8fb4af4a77d50255d24ad3820320dd238fbb96bf Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Tue, 21 Mar 2023 15:43:02 +0100 Subject: [PATCH 4/5] Add learn more button to instance name warning --- .../android/formentry/FormEndView.java | 9 +++++ .../src/main/res/layout/form_entry_end.xml | 17 ++++++++-- .../android/formentry/FormEndViewTest.kt | 34 ++++++++++++++++--- strings/src/main/res/values/strings.xml | 1 + 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java b/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java index 198810e4168..fed2413b9bb 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/FormEndView.java @@ -1,6 +1,8 @@ package org.odk.collect.android.formentry; import android.content.Context; +import android.content.Intent; +import android.net.Uri; import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; @@ -68,6 +70,13 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { findViewById(R.id.save_exit_button).setOnClickListener(v -> { listener.onSaveClicked(markAsFinalized.isChecked()); }); + + findViewById(R.id.instance_name_learn_more).setOnClickListener(v -> { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setData(Uri.parse("https://forum.getodk.org/t/collect-manual-instance-naming-will-be-removed-in-v2023-2/40313")); + context.startActivity(intent); + }); } @Override diff --git a/collect_app/src/main/res/layout/form_entry_end.xml b/collect_app/src/main/res/layout/form_entry_end.xml index c5bc915634b..d5afbcb4924 100644 --- a/collect_app/src/main/res/layout/form_entry_end.xml +++ b/collect_app/src/main/res/layout/form_entry_end.xml @@ -57,7 +57,7 @@ the specific language governing permissions and limitations under the License. android:padding="@dimen/margin"> + app:layout_constraintStart_toEndOf="@id/instance_name_info_icon" + app:layout_constraintTop_toTopOf="@id/instance_name_info_icon" /> + + diff --git a/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt b/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt index 78f7670a859..71d796140ba 100644 --- a/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/formentry/FormEndViewTest.kt @@ -1,6 +1,8 @@ package org.odk.collect.android.formentry -import android.content.Context +import android.app.Application +import android.content.Intent +import android.net.Uri import android.view.View import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -9,16 +11,18 @@ import org.hamcrest.Matchers.equalTo import org.junit.Test import org.junit.runner.RunWith import org.odk.collect.android.R +import org.robolectric.Shadows.shadowOf @RunWith(AndroidJUnit4::class) class FormEndViewTest { - @Test - fun `focusing on save as field shows warning`() { - val context = ApplicationProvider.getApplicationContext().also { + private val context: Application = + ApplicationProvider.getApplicationContext().also { it.setTheme(R.style.Theme_Material3_Light) } + @Test + fun `focusing on save as field shows warning`() { val formEndView = FormEndView( context, null, @@ -33,4 +37,26 @@ class FormEndViewTest { formEndView.findViewById(R.id.save_name).requestFocus() assertThat(warningView.visibility, equalTo(View.VISIBLE)) } + + @Test + fun `clicking learn more in warning opens forum post`() { + val formEndView = FormEndView( + context, + null, + null, + false, + null + ) + + formEndView.findViewById(R.id.save_name).requestFocus() + formEndView.findViewById(R.id.instance_name_learn_more).performClick() + + val intent = shadowOf(context).nextStartedActivity + assertThat(intent.action, equalTo(Intent.ACTION_VIEW)) + assertThat(intent.flags, equalTo(Intent.FLAG_ACTIVITY_NEW_TASK)) + assertThat( + intent.data, + equalTo(Uri.parse("https://forum.getodk.org/t/collect-manual-instance-naming-will-be-removed-in-v2023-2/40313")) + ) + } } diff --git a/strings/src/main/res/values/strings.xml b/strings/src/main/res/values/strings.xml index fec8248b1c6..8bbfbc9f38b 100644 --- a/strings/src/main/res/values/strings.xml +++ b/strings/src/main/res/values/strings.xml @@ -167,6 +167,7 @@ Mark form as finalized Save Form and Exit Soon manually naming forms will be removed. Form design needs to be updated. + Learn more Sorry, form save failed! Form successfully saved! From 4c542c982ac8a86ad694138adc90fc03a419ff4b Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Thu, 23 Mar 2023 10:45:52 +0100 Subject: [PATCH 5/5] Reformat imports --- collect_app/src/main/res/layout/form_entry_end.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/collect_app/src/main/res/layout/form_entry_end.xml b/collect_app/src/main/res/layout/form_entry_end.xml index d5afbcb4924..ff757f67fa2 100644 --- a/collect_app/src/main/res/layout/form_entry_end.xml +++ b/collect_app/src/main/res/layout/form_entry_end.xml @@ -9,12 +9,12 @@ the specific language governing permissions and limitations under the License. -->