diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/IntentGroupTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/IntentGroupTest.java index b9ce5e55e40..98ec789beed 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/IntentGroupTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/IntentGroupTest.java @@ -26,9 +26,11 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isEnabled; import static androidx.test.espresso.matcher.ViewMatchers.withClassName; +import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.StringEndsWith.endsWith; @@ -47,6 +49,7 @@ import androidx.core.content.FileProvider; import androidx.test.core.app.ApplicationProvider; +import androidx.test.espresso.matcher.ViewMatchers; import org.junit.Rule; import org.junit.Test; @@ -204,7 +207,7 @@ public void collect_shouldNotCrashWhenAnyErrorIsThrownWhileReceivingAnswer() { } private void assertImageWidgetWithoutAnswer() { - onView(withTagValue(is("ImageView"))).check(doesNotExist()); + onView(allOf(withTagValue(is("ImageView")), withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))).check(doesNotExist()); onView(withId(R.id.capture_image)).check(doesNotExist()); onView(withId(R.id.choose_image)).check(doesNotExist()); } @@ -223,7 +226,7 @@ private void assertFileWidgetWithoutAnswer() { } private void assertImageWidgetWithAnswer() { - onView(withTagValue(is("ImageView"))).perform(scrollTo()).check(matches(isDisplayed())); + onView(allOf(withTagValue(is("ImageView")), withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))).check(matches(not(doesNotExist()))); onView(withId(R.id.capture_image)).check(doesNotExist()); onView(withId(R.id.choose_image)).check(doesNotExist()); } diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/AnnotateWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/AnnotateWidget.java index 203b9e040e9..4e13243f1fa 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/AnnotateWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/AnnotateWidget.java @@ -67,7 +67,7 @@ public AnnotateWidget(Context context, QuestionDetails prompt, QuestionMediaMana imageClickHandler = new DrawImageClickHandler(DrawActivity.OPTION_ANNOTATE, RequestCodes.ANNOTATE_IMAGE, R.string.annotate_image); imageCaptureHandler = new ImageCaptureHandler(); setUpLayout(); - addCurrentImageToLayout(); + updateAnswer(); adjustAnnotateButtonAvailability(); addAnswerView(answerLayout, WidgetViewUtils.getStandardMargin(context)); } @@ -87,9 +87,9 @@ protected void setUpLayout() { answerLayout.addView(chooseButton); answerLayout.addView(annotateButton); answerLayout.addView(errorTextView); + answerLayout.addView(imageView); hideButtonsIfNeeded(); - errorTextView.setVisibility(View.GONE); } @Override @@ -141,7 +141,7 @@ public void onButtonClick(int buttonId) { } private void adjustAnnotateButtonAvailability() { - if (binaryName == null || imageView == null || imageView.getVisibility() == GONE) { + if (binaryName == null || imageView.getVisibility() == GONE) { annotateButton.setEnabled(false); } } @@ -155,7 +155,7 @@ && getFormEntryPrompt().getAppearanceHint().toLowerCase(Locale.ENGLISH).contains private int calculateScreenOrientation() { Bitmap bmp = null; - if (imageView != null) { + if (imageView.getDrawable() != null) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } @@ -164,7 +164,6 @@ private int calculateScreenOrientation() { } private void captureImage() { - errorTextView.setVisibility(View.GONE); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); // We give the camera an absolute filename/path where to put the // picture because of bug: diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/BaseImageWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/BaseImageWidget.java index ee7d4270180..02db449ac3e 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/BaseImageWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/BaseImageWidget.java @@ -52,7 +52,6 @@ public abstract class BaseImageWidget extends QuestionWidget implements FileWidget, WidgetDataReceiver { - @Nullable protected ImageView imageView; protected String binaryName; protected TextView errorTextView; @@ -81,10 +80,8 @@ public IAnswerData getAnswer() { @Override public void clearAnswer() { deleteFile(); - if (imageView != null) { - imageView.setImageDrawable(null); - } - + imageView.setImageDrawable(null); + imageView.setVisibility(View.GONE); errorTextView.setVisibility(View.GONE); widgetValueChanged(); } @@ -106,7 +103,7 @@ public void setData(Object object) { if (newImage.exists()) { questionMediaManager.replaceAnswerFile(getFormEntryPrompt().getIndex().toString(), newImage.getAbsolutePath()); binaryName = newImage.getName(); - addCurrentImageToLayout(); + updateAnswer(); widgetValueChanged(); } else { Timber.e(new Error("NO IMAGE EXISTS at: " + newImage.getAbsolutePath())); @@ -131,29 +128,23 @@ public void cancelLongPress() { } } - protected void addCurrentImageToLayout() { - answerLayout.removeView(imageView); + protected void updateAnswer() { + imageView.setVisibility(View.GONE); + errorTextView.setVisibility(View.GONE); if (binaryName != null) { File f = getFile(); if (f != null && f.exists()) { - imageView = createAnswerImageView(getContext()); - answerLayout.addView(imageView); + imageView.setVisibility(View.VISIBLE); imageLoader.loadImage(imageView, f, ImageView.ScaleType.FIT_CENTER, new GlideImageLoader.ImageLoaderCallback() { @Override public void onLoadFailed() { - answerLayout.removeView(imageView); - imageView = null; + imageView.setVisibility(View.GONE); errorTextView.setVisibility(View.VISIBLE); } @Override public void onLoadSucceeded() { - imageView.setOnClickListener(v -> { - if (imageClickHandler != null) { - imageClickHandler.clickImage("viewImage"); - } - }); } }); } @@ -169,6 +160,13 @@ protected void setUpLayout() { answerLayout.setOrientation(LinearLayout.VERTICAL); binaryName = getFormEntryPrompt().getAnswerText(); + + imageView = createAnswerImageView(getContext()); + imageView.setOnClickListener(v -> { + if (imageClickHandler != null) { + imageClickHandler.clickImage("viewImage"); + } + }); } /** @@ -221,7 +219,6 @@ public void clickImage(String context) { } private void launchDrawActivity() { - errorTextView.setVisibility(View.GONE); Intent i = new Intent(getContext(), DrawActivity.class); i.putExtra(DrawActivity.OPTION, drawOption); if (binaryName != null) { @@ -255,7 +252,6 @@ public void captureImage(Intent intent, final int requestCode, int stringResourc @Override public void chooseImage(@IdRes final int stringResource) { - errorTextView.setVisibility(View.GONE); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); launchActivityForResult(i, ApplicationConstants.RequestCodes.IMAGE_CHOOSER, stringResource); @@ -303,8 +299,11 @@ private String getDefaultFilePath() { protected abstract boolean doesSupportDefaultValues(); - @Nullable public ImageView getImageView() { return imageView; } + + public TextView getErrorTextView() { + return errorTextView; + } } diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/DrawWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/DrawWidget.java index f79f6f8fe68..c72b7c725c0 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/DrawWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/DrawWidget.java @@ -17,7 +17,6 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; -import android.view.View; import android.widget.Button; import org.odk.collect.android.R; @@ -47,7 +46,7 @@ public DrawWidget(Context context, QuestionDetails prompt, QuestionMediaManager imageClickHandler = new DrawImageClickHandler(DrawActivity.OPTION_DRAW, RequestCodes.DRAW_IMAGE, R.string.draw_image); setUpLayout(); - addCurrentImageToLayout(); + updateAnswer(); addAnswerView(answerLayout, WidgetViewUtils.getStandardMargin(context)); } @@ -58,8 +57,7 @@ protected void setUpLayout() { answerLayout.addView(drawButton); answerLayout.addView(errorTextView); - - errorTextView.setVisibility(View.GONE); + answerLayout.addView(imageView); } @Override diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/ImageWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/ImageWidget.java index 9045abfb257..3562c4b094e 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/ImageWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/ImageWidget.java @@ -67,7 +67,7 @@ public ImageWidget(Context context, final QuestionDetails prompt, QuestionMediaM imageClickHandler = new ViewImageClickHandler(); imageCaptureHandler = new ImageCaptureHandler(); setUpLayout(); - addCurrentImageToLayout(); + updateAnswer(); addAnswerView(answerLayout, WidgetViewUtils.getStandardMargin(context)); } @@ -85,9 +85,9 @@ protected void setUpLayout() { answerLayout.addView(captureButton); answerLayout.addView(chooseButton); answerLayout.addView(errorTextView); + answerLayout.addView(imageView); hideButtonsIfNeeded(appearance); - errorTextView.setVisibility(View.GONE); } @Override @@ -141,7 +141,6 @@ private void hideButtonsIfNeeded(String appearance) { } private void captureImage() { - errorTextView.setVisibility(View.GONE); if (selfie && new CameraUtils().isFrontCameraAvailable(getContext())) { Intent intent = new Intent(getContext(), CaptureSelfieActivity.class); intent.putExtra(CaptureSelfieActivity.EXTRA_TMP_PATH, new StoragePathProvider().getOdkDirPath(StorageSubdirectory.CACHE)); diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/SignatureWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/SignatureWidget.java index 99c705cade7..1f5399bbe75 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/SignatureWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/SignatureWidget.java @@ -17,7 +17,6 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; -import android.view.View; import android.widget.Button; import org.odk.collect.android.R; @@ -47,7 +46,7 @@ public SignatureWidget(Context context, QuestionDetails prompt, QuestionMediaMan imageClickHandler = new DrawImageClickHandler(DrawActivity.OPTION_SIGNATURE, RequestCodes.SIGNATURE_CAPTURE, R.string.signature_capture); setUpLayout(); - addCurrentImageToLayout(); + updateAnswer(); addAnswerView(answerLayout, WidgetViewUtils.getStandardMargin(context)); } @@ -58,8 +57,7 @@ protected void setUpLayout() { answerLayout.addView(signButton); answerLayout.addView(errorTextView); - - errorTextView.setVisibility(View.GONE); + answerLayout.addView(imageView); } @Override diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/AnnotateWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/AnnotateWidgetTest.java index 75ce04d1467..f47b0622371 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/AnnotateWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/AnnotateWidgetTest.java @@ -32,12 +32,14 @@ import org.odk.collect.shared.TempFiles; import java.io.File; +import java.io.IOException; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; import static org.odk.collect.android.support.CollectHelpers.overrideReferenceManager; @@ -129,6 +131,40 @@ public void whenReadOnlyOverrideOptionIsUsed_shouldAllClickableElementsBeDisable assertThat(getSpyWidget().annotateButton.getVisibility(), is(View.GONE)); } + @Test + public void whenThereIsNoAnswer_hideImageViewAndErrorMessage() { + AnnotateWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.GONE)); + } + + @Test + public void whenTheAnswerImageCanNotBeLoaded_hideImageViewAndShowErrorMessage() throws IOException { + CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() { + @Override + public ImageLoader providesImageLoader() { + return new SynchronousImageLoader(true); + } + }); + + String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath(); + currentFile = new File(imagePath); + + formEntryPrompt = new MockFormEntryPromptBuilder() + .withAnswerDisplayText(DrawWidgetTest.USER_SPECIFIED_IMAGE_ANSWER) + .build(); + + AnnotateWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.VISIBLE)); + } + @Test public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception { String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath(); @@ -154,7 +190,7 @@ public ImageLoader providesImageLoader() { AnnotateWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); @@ -180,7 +216,7 @@ public ImageLoader providesImageLoader() { AnnotateWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/DrawWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/DrawWidgetTest.java index 815afa80c5d..7c426500e7c 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/DrawWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/DrawWidgetTest.java @@ -30,12 +30,14 @@ import org.odk.collect.shared.TempFiles; import java.io.File; +import java.io.IOException; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; import static org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager; import static org.robolectric.Shadows.shadowOf; @@ -102,6 +104,40 @@ public void whenReadOnlyOverrideOptionIsUsed_shouldAllClickableElementsBeDisable assertThat(getSpyWidget().drawButton.getVisibility(), is(View.GONE)); } + @Test + public void whenThereIsNoAnswer_hideImageViewAndErrorMessage() { + DrawWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.GONE)); + } + + @Test + public void whenTheAnswerImageCanNotBeLoaded_hideImageViewAndShowErrorMessage() throws IOException { + CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() { + @Override + public ImageLoader providesImageLoader() { + return new SynchronousImageLoader(true); + } + }); + + String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath(); + currentFile = new File(imagePath); + + formEntryPrompt = new MockFormEntryPromptBuilder() + .withAnswerDisplayText(DrawWidgetTest.USER_SPECIFIED_IMAGE_ANSWER) + .build(); + + DrawWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.VISIBLE)); + } + @Test public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception { String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath(); @@ -126,7 +162,7 @@ public ImageLoader providesImageLoader() { DrawWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); @@ -152,7 +188,7 @@ public ImageLoader providesImageLoader() { DrawWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/ImageWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/ImageWidgetTest.java index df6053dd207..5c1b1c99db2 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/ImageWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/ImageWidgetTest.java @@ -29,6 +29,7 @@ import org.odk.collect.shared.TempFiles; import java.io.File; +import java.io.IOException; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; @@ -109,6 +110,40 @@ public void whenReadOnlyOverrideOptionIsUsed_shouldAllClickableElementsBeDisable assertThat(getSpyWidget().chooseButton.getVisibility(), is(View.GONE)); } + @Test + public void whenThereIsNoAnswer_hideImageViewAndErrorMessage() { + ImageWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.GONE)); + } + + @Test + public void whenTheAnswerImageCanNotBeLoaded_hideImageViewAndShowErrorMessage() throws IOException { + CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() { + @Override + public ImageLoader providesImageLoader() { + return new SynchronousImageLoader(true); + } + }); + + String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath(); + currentFile = new File(imagePath); + + formEntryPrompt = new MockFormEntryPromptBuilder() + .withAnswerDisplayText(DrawWidgetTest.USER_SPECIFIED_IMAGE_ANSWER) + .build(); + + ImageWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.VISIBLE)); + } + @Test public void whenPromptHasDefaultAnswer_doesNotShow() throws Exception { String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath(); @@ -133,7 +168,7 @@ public ImageLoader providesImageLoader() { ImageWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, nullValue()); + assertThat(imageView.getVisibility(), is(View.GONE)); } @Test @@ -154,7 +189,7 @@ public ImageLoader providesImageLoader() { ImageWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/SignatureWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/SignatureWidgetTest.java index 55b3181ec96..13c18c1ffbe 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/SignatureWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/SignatureWidgetTest.java @@ -29,12 +29,14 @@ import org.odk.collect.shared.TempFiles; import java.io.File; +import java.io.IOException; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; import static org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager; import static org.robolectric.Shadows.shadowOf; @@ -95,6 +97,40 @@ public void whenReadOnlyOverrideOptionIsUsed_shouldAllClickableElementsBeDisable assertThat(getSpyWidget().signButton.getVisibility(), is(View.GONE)); } + @Test + public void whenThereIsNoAnswer_hideImageViewAndErrorMessage() { + SignatureWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.GONE)); + } + + @Test + public void whenTheAnswerImageCanNotBeLoaded_hideImageViewAndShowErrorMessage() throws IOException { + CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() { + @Override + public ImageLoader providesImageLoader() { + return new SynchronousImageLoader(true); + } + }); + + String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath(); + currentFile = new File(imagePath); + + formEntryPrompt = new MockFormEntryPromptBuilder() + .withAnswerDisplayText(DrawWidgetTest.USER_SPECIFIED_IMAGE_ANSWER) + .build(); + + SignatureWidget widget = createWidget(); + + assertThat(widget.getImageView().getVisibility(), is(View.GONE)); + assertThat(widget.getImageView().getDrawable(), nullValue()); + + assertThat(widget.getErrorTextView().getVisibility(), is(View.VISIBLE)); + } + @Test public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception { String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath(); @@ -120,7 +156,7 @@ public ImageLoader providesImageLoader() { SignatureWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); @@ -146,7 +182,7 @@ public ImageLoader providesImageLoader() { SignatureWidget widget = createWidget(); ImageView imageView = widget.getImageView(); - assertThat(imageView, notNullValue()); + assertThat(imageView.getVisibility(), is(View.VISIBLE)); Drawable drawable = imageView.getDrawable(); assertThat(drawable, notNullValue()); diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/support/SynchronousImageLoader.kt b/collect_app/src/test/java/org/odk/collect/android/widgets/support/SynchronousImageLoader.kt index 88b1dfa561d..697f898aab0 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/support/SynchronousImageLoader.kt +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/support/SynchronousImageLoader.kt @@ -6,13 +6,18 @@ import org.odk.collect.imageloader.GlideImageLoader import org.odk.collect.imageloader.ImageLoader import java.io.File -class SynchronousImageLoader : ImageLoader { +class SynchronousImageLoader(private val fail: Boolean = false) : ImageLoader { override fun loadImage( imageView: ImageView, imageFile: File?, scaleType: ImageView.ScaleType, requestListener: GlideImageLoader.ImageLoaderCallback? ) { - imageView.setImageBitmap(BitmapFactory.decodeFile(imageFile?.absolutePath)) + if (fail) { + requestListener?.onLoadFailed() + } else { + imageView.setImageBitmap(BitmapFactory.decodeFile(imageFile?.absolutePath)) + requestListener?.onLoadSucceeded() + } } }