Skip to content

Commit

Permalink
Merge pull request #5506 from seadowg/instance-name-warning
Browse files Browse the repository at this point in the history
Add warning when typing in instance name
  • Loading branch information
seadowg committed Mar 23, 2023
2 parents cc139ab + 4c542c9 commit cd78864
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -35,6 +38,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);
Expand Down Expand Up @@ -62,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
Expand Down
51 changes: 50 additions & 1 deletion collect_app/src/main/res/layout/form_entry_end.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ the specific language governing permissions and limitations under the License.
-->

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/scroll_view"
android:orientation="vertical">

<LinearLayout
Expand Down Expand Up @@ -41,7 +43,54 @@ the specific language governing permissions and limitations under the License.
android:textSize="21sp"
android:textStyle="bold" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/manual_name_warning"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin">

<ImageView
android:id="@+id/instance_name_info_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_outline_info_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?colorPrimary" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/instance_name_info_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin"
android:text="@string/manual_instance_name_warning"
android:textAppearance="?textAppearanceBodyLarge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/instance_name_info_icon"
app:layout_constraintTop_toTopOf="@id/instance_name_info_icon" />

<com.google.android.material.button.MaterialButton
android:id="@+id/instance_name_learn_more"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/manual_instance_learn_more_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/instance_name_info_text" />

</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

<TextView
android:layout_marginTop="@dimen/margin"
android:id="@+id/save_form_as"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions collect_app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorSurface">#121212</color>
<color name="colorSurfaceVariant">#41484d</color>
<color name="colorOnSurface">#FFFFFF</color>

<bool name="lightStatusBar">false</bool>
Expand Down
1 change: 1 addition & 0 deletions collect_app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<color name="colorOnError">#ffffff</color>

<color name="colorSurface">#FFFFFF</color>
<color name="colorSurfaceVariant">#dce3e9</color>
<color name="colorOnSurface">#000000</color>

<bool name="lightStatusBar">true</bool>
Expand Down
4 changes: 4 additions & 0 deletions collect_app/src/main/res/values/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@

<!-- Material3 attributes (needed for Material3 styles/components because theme is
Theme.MaterialComponents). These can be added on-demand for components that need them. -->
<item name="colorSurfaceVariant">@color/colorSurfaceVariant</item>
<item name="colorPrimaryContainer">?colorPrimary</item>

<item name="colorOnPrimaryContainer">?colorOnPrimary</item>

<item name="textAppearanceBodyLarge">?textAppearanceBody1</item>
<item name="textAppearanceLabelLarge">@style/TextAppearance.Material3.LabelLarge</item>

<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.Medium</item>
<!--/Material3 attributes-->

<!-- Needed to customize the status bar color -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.odk.collect.android.formentry

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
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
import org.robolectric.Shadows.shadowOf

@RunWith(AndroidJUnit4::class)
class FormEndViewTest {

private val context: Application =
ApplicationProvider.getApplicationContext<Application>().also {
it.setTheme(R.style.Theme_Material3_Light)
}

@Test
fun `focusing on save as field shows warning`() {
val formEndView = FormEndView(
context,
null,
null,
false,
null
)

val warningView = formEndView.findViewById<View>(R.id.manual_name_warning)
assertThat(warningView.visibility, equalTo(View.GONE))

formEndView.findViewById<View>(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<View>(R.id.save_name).requestFocus()
formEndView.findViewById<View>(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"))
)
}
}
2 changes: 2 additions & 0 deletions strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
<string name="save_as_error">Saved name must not be blank!</string>
<string name="mark_finished">Mark form as finalized</string>
<string name="quit_entry">Save Form and Exit</string>
<string name="manual_instance_name_warning">Soon manually naming forms will be removed. Form design needs to be updated.</string>
<string name="manual_instance_learn_more_button">Learn more</string>

<string name="data_saved_error">Sorry, form save failed!</string>
<string name="data_saved_ok">Form successfully saved!</string>
Expand Down

0 comments on commit cd78864

Please sign in to comment.