diff --git a/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeImageButton.kt b/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeImageButton.kt deleted file mode 100644 index 109c7355cf4..00000000000 --- a/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeImageButton.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.odk.collect.androidshared.ui.multiclicksafe - -import android.content.Context -import android.util.AttributeSet -import androidx.appcompat.widget.AppCompatImageButton -import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard.allowClick - -class MultiClickSafeImageButton : AppCompatImageButton { - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet?) : super( - context, - attrs - ) - - override fun performClick(): Boolean { - return allowClick() && super.performClick() - } -} diff --git a/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeButton.kt b/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeMaterialButton.kt similarity index 71% rename from androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeButton.kt rename to androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeMaterialButton.kt index 8e6898cbd88..e270628f7f4 100644 --- a/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeButton.kt +++ b/androidshared/src/main/java/org/odk/collect/androidshared/ui/multiclicksafe/MultiClickSafeMaterialButton.kt @@ -5,7 +5,7 @@ import android.util.AttributeSet import com.google.android.material.button.MaterialButton import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard.allowClick -class MultiClickSafeButton : MaterialButton { +open class MultiClickSafeMaterialButton : MaterialButton { constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet?) : super( @@ -13,6 +13,12 @@ class MultiClickSafeButton : MaterialButton { attrs ) + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) + override fun performClick(): Boolean { return allowClick() && super.performClick() } diff --git a/collect_app/src/main/java/org/odk/collect/android/audio/AudioButton.java b/collect_app/src/main/java/org/odk/collect/android/audio/AudioButton.java index 5d447aab2c6..90893db6a7e 100644 --- a/collect_app/src/main/java/org/odk/collect/android/audio/AudioButton.java +++ b/collect_app/src/main/java/org/odk/collect/android/audio/AudioButton.java @@ -19,15 +19,14 @@ import android.util.AttributeSet; import android.view.View; -import com.google.android.material.button.MaterialButton; - import org.odk.collect.android.R; +import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton; /** * @author ctsims * @author carlhartung */ -public class AudioButton extends MaterialButton implements View.OnClickListener { +public class AudioButton extends MultiClickSafeMaterialButton implements View.OnClickListener { private Listener listener; diff --git a/collect_app/src/main/java/org/odk/collect/android/audio/AudioControllerView.java b/collect_app/src/main/java/org/odk/collect/android/audio/AudioControllerView.java index 2ffd53829b1..6c666ee11e1 100644 --- a/collect_app/src/main/java/org/odk/collect/android/audio/AudioControllerView.java +++ b/collect_app/src/main/java/org/odk/collect/android/audio/AudioControllerView.java @@ -24,10 +24,9 @@ import androidx.core.content.ContextCompat; -import com.google.android.material.button.MaterialButton; - import org.odk.collect.android.R; import org.odk.collect.android.databinding.AudioControllerLayoutBinding; +import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton; import static java.lang.Math.max; import static java.lang.Math.min; @@ -39,7 +38,7 @@ public class AudioControllerView extends FrameLayout { private final TextView currentDurationLabel; private final TextView totalDurationLabel; - private final MaterialButton playButton; + private final MultiClickSafeMaterialButton playButton; private final SeekBar seekBar; private final SwipeListener swipeListener; diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/ODKView.java b/collect_app/src/main/java/org/odk/collect/android/formentry/ODKView.java index 98a99a73abc..4f21dec5e79 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/ODKView.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/ODKView.java @@ -42,8 +42,6 @@ import androidx.core.widget.NestedScrollView; import androidx.lifecycle.LifecycleOwner; -import com.google.android.material.button.MaterialButton; - import org.javarosa.core.model.Constants; import org.javarosa.core.model.FormIndex; import org.javarosa.core.model.IFormElement; @@ -84,6 +82,7 @@ import org.odk.collect.android.widgets.utilities.WaitingForDataRegistry; import org.odk.collect.androidshared.system.IntentLauncher; import org.odk.collect.androidshared.ui.ToastUtils; +import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton; import org.odk.collect.audioclips.PlaybackFailedException; import org.odk.collect.audiorecorder.recording.AudioRecorder; import org.odk.collect.permissions.PermissionListener; @@ -425,7 +424,7 @@ private void addIntentLaunchButton(Context context, FormEntryPrompt[] questionPr errorString = (v != null) ? v : context.getString(org.odk.collect.strings.R.string.no_app); // set button formatting - MaterialButton launchIntentButton = findViewById(R.id.launchIntentButton); + MultiClickSafeMaterialButton launchIntentButton = findViewById(R.id.launchIntentButton); launchIntentButton.setText(buttonText); launchIntentButton.setTextSize(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), QuestionFontSizeUtils.FontSize.BODY_LARGE)); launchIntentButton.setVisibility(VISIBLE); diff --git a/collect_app/src/main/java/org/odk/collect/android/instancemanagement/send/InstanceUploaderListActivity.java b/collect_app/src/main/java/org/odk/collect/android/instancemanagement/send/InstanceUploaderListActivity.java index 4af87357257..c499dfdf88d 100644 --- a/collect_app/src/main/java/org/odk/collect/android/instancemanagement/send/InstanceUploaderListActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/instancemanagement/send/InstanceUploaderListActivity.java @@ -350,10 +350,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } - if (!MultiClickGuard.allowClick(getClass().getName())) { - return true; - } - if (item.getItemId() == R.id.menu_sort) { new FormListSortingBottomSheetDialog( this, diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/PrinterWidget.kt b/collect_app/src/main/java/org/odk/collect/android/widgets/PrinterWidget.kt index feddaf95abe..64df71b147c 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/PrinterWidget.kt +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/PrinterWidget.kt @@ -5,13 +5,13 @@ import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import com.google.android.material.button.MaterialButton import org.javarosa.core.model.data.IAnswerData import org.javarosa.form.api.FormEntryPrompt import org.odk.collect.android.R import org.odk.collect.android.formentry.questions.QuestionDetails import org.odk.collect.android.utilities.QuestionMediaManager import org.odk.collect.android.widgets.interfaces.Printer +import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton class PrinterWidget( context: Context, @@ -27,7 +27,7 @@ class PrinterWidget( override fun onCreateAnswerView(context: Context, prompt: FormEntryPrompt, answerFontSize: Int): View { val answerView = LayoutInflater.from(context).inflate(R.layout.printer_widget, null) answerView - .findViewById(R.id.printer_button) + .findViewById(R.id.printer_button) .setOnClickListener { print() } diff --git a/collect_app/src/main/res/layout/annotate_widget.xml b/collect_app/src/main/res/layout/annotate_widget.xml index e75ae05fde9..6d7fc825649 100644 --- a/collect_app/src/main/res/layout/annotate_widget.xml +++ b/collect_app/src/main/res/layout/annotate_widget.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (R.id.save_as_draft).visibility, + view.findViewById(R.id.save_as_draft).visibility, equalTo(View.VISIBLE) ) } @@ -55,7 +55,7 @@ class FormEndViewTest { whenever(formEndViewModel.isSaveDraftEnabled()).thenReturn(false) val view = FormEndView(context, "blah", formEndViewModel, listener) assertThat( - view.findViewById(R.id.save_as_draft).visibility, + view.findViewById(R.id.save_as_draft).visibility, equalTo(View.GONE) ) } @@ -64,7 +64,7 @@ class FormEndViewTest { fun `when 'Save as draft' button is clicked then onSaveClicked is called with false value`() { whenever(formEndViewModel.isSaveDraftEnabled()).thenReturn(true) val view = FormEndView(context, "blah", formEndViewModel, listener) - view.findViewById(R.id.save_as_draft).performClick() + view.findViewById(R.id.save_as_draft).performClick() verify(listener).onSaveClicked(false) } @@ -73,7 +73,7 @@ class FormEndViewTest { whenever(formEndViewModel.isFinalizeEnabled()).thenReturn(true) val view = FormEndView(context, "blah", formEndViewModel, listener) assertThat( - view.findViewById(R.id.finalize).visibility, + view.findViewById(R.id.finalize).visibility, equalTo(View.VISIBLE) ) } @@ -82,14 +82,14 @@ class FormEndViewTest { fun `when finalizing forms is disabled in settings should 'Finalize' button be hidden`() { whenever(formEndViewModel.isFinalizeEnabled()).thenReturn(false) val view = FormEndView(context, "blah", formEndViewModel, listener) - assertThat(view.findViewById(R.id.finalize).visibility, equalTo(View.GONE)) + assertThat(view.findViewById(R.id.finalize).visibility, equalTo(View.GONE)) } @Test fun `when 'Finalize' button is clicked then onSaveClicked is called with true value`() { whenever(formEndViewModel.isFinalizeEnabled()).thenReturn(true) val view = FormEndView(context, "blah", formEndViewModel, listener) - view.findViewById(R.id.finalize).performClick() + view.findViewById(R.id.finalize).performClick() verify(listener).onSaveClicked(true) } @@ -98,7 +98,7 @@ class FormEndViewTest { whenever(formEndViewModel.shouldFormBeSentAutomatically()).thenReturn(false) val view = FormEndView(context, "blah", formEndViewModel, listener) assertThat( - view.findViewById(R.id.finalize).text, + view.findViewById(R.id.finalize).text, equalTo(context.getString(org.odk.collect.strings.R.string.finalize)) ) } @@ -108,7 +108,7 @@ class FormEndViewTest { whenever(formEndViewModel.shouldFormBeSentAutomatically()).thenReturn(true) val view = FormEndView(context, "blah", formEndViewModel, listener) assertThat( - view.findViewById(R.id.finalize).text, + view.findViewById(R.id.finalize).text, equalTo( context.getString( org.odk.collect.strings.R.string.send diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/PrinterWidgetTest.kt b/collect_app/src/test/java/org/odk/collect/android/widgets/PrinterWidgetTest.kt index 3b167f80699..251a8ee9cf7 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/PrinterWidgetTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/PrinterWidgetTest.kt @@ -1,6 +1,5 @@ package org.odk.collect.android.widgets -import com.google.android.material.button.MaterialButton import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat import org.javarosa.core.model.data.IAnswerData @@ -16,6 +15,7 @@ import org.odk.collect.android.formentry.questions.QuestionDetails import org.odk.collect.android.support.WidgetTestActivity import org.odk.collect.android.utilities.QuestionMediaManager import org.odk.collect.android.widgets.base.QuestionWidgetTest +import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton import org.odk.collect.printer.HtmlPrinter import org.odk.collect.qrcode.QRCodeCreator import org.odk.collect.testshared.FakeScheduler @@ -33,7 +33,7 @@ class PrinterWidgetTest : QuestionWidgetTest() { whenever(formEntryPrompt.answerText).thenReturn("blah") val widget = createWidget() - widget.findViewById(R.id.printer_button).performClick() + widget.findViewById(R.id.printer_button).performClick() scheduler.runBackground() scheduler.runForeground() @@ -45,7 +45,7 @@ class PrinterWidgetTest : QuestionWidgetTest() { whenever(formEntryPrompt.answerText).thenReturn(null) val widget = createWidget() - widget.findViewById(R.id.printer_button).performClick() + widget.findViewById(R.id.printer_button).performClick() verifyNoInteractions(htmlPrinter) } diff --git a/geo/src/main/res/layout/selection_summary_sheet_layout.xml b/geo/src/main/res/layout/selection_summary_sheet_layout.xml index a401ac626ce..55864930ffe 100644 --- a/geo/src/main/res/layout/selection_summary_sheet_layout.xml +++ b/geo/src/main/res/layout/selection_summary_sheet_layout.xml @@ -51,7 +51,7 @@ app:layout_constraintTop_toBottomOf="@id/name" tools:text="Info" /> - - -