Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MultiClickSafeButton instad of MaterialButton directly #6003

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ 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(
context,
attrs
)

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)

override fun performClick(): Boolean {
return allowClick() && super.performClick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<MaterialButton>(R.id.printer_button)
.findViewById<MultiClickSafeMaterialButton>(R.id.printer_button)
.setOnClickListener {
print()
}
Expand Down
6 changes: 3 additions & 3 deletions collect_app/src/main/res/layout/annotate_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/capture_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:layout_width="match_parent"
Expand All @@ -17,7 +17,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/choose_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:layout_width="match_parent"
Expand All @@ -30,7 +30,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/capture_button" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/annotate_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/arbitrary_file_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/choose_file"
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/audio_controller_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/play"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -72,7 +72,7 @@ limitations under the License.
android:layout_height="wrap_content"
android:orientation="horizontal">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/remove"
style="?materialButtonOutlinedIconStyle"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
android:layout_marginStart="@dimen/margin_standard"
android:orientation="horizontal">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/pause_recording"
style="?materialIconButtonOutlinedStyle"
android:layout_width="wrap_content"
Expand All @@ -58,7 +58,7 @@
android:contentDescription="@string/pause_recording"
app:icon="@drawable/ic_pause_24dp" />

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/stop_recording"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
android:visibility="gone"
tools:visibility="visible" />

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/videoButton"
style="?materialIconButtonOutlinedStyle"
android:layout_width="@dimen/touch_target_size"
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/audio_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/record_audio_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/capture_audio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_baseline_mic_white_24" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/choose_audio_button"
android:layout_marginTop="@dimen/margin_extra_small"
style="?widgetButtonIconQuestionWidgetStyle"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/barcode_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/barcode_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/get_barcode"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/bearing_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/bearing_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/get_bearing"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/date_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/date_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/select_date"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/draw_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/draw_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/ex_arbitrary_file_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/launch_app"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/ex_audio_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/launch_external_app_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/launch_app"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/ex_image_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/launch_external_app_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/launch_app"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/ex_printer_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/print_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/launch_app_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/launch_app"
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/ex_video_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/capture_video_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/launch_app"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_baseline_videocam_white_24" />

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/play_video_button"
style="?widgetButtonIconQuestionWidgetStyle"
android:text="@string/play_video"
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/first_launch_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/logo" />

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/configure_via_qr_button"
style="?materialButtonIconStyle"
android:layout_width="0dp"
Expand All @@ -57,7 +57,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintWidth_min="wrap"/>

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/configure_manually_button"
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/map_button"
style="?materialIconButtonOutlinedStyle"
android:layout_width="wrap_content"
Expand Down
6 changes: 3 additions & 3 deletions collect_app/src/main/res/layout/form_download_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ the License.
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/toggle_button"
style="?materialButtonOutlinedStyle"
android:layout_width="0dp"
Expand All @@ -72,7 +72,7 @@ the License.
android:layout_weight="1"
android:text="@string/select_all" />

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/refresh_button"
style="?materialButtonOutlinedStyle"
android:layout_width="0dp"
Expand All @@ -81,7 +81,7 @@ the License.
android:layout_weight="1"
android:text="@string/refresh" />

<com.google.android.material.button.MaterialButton
<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/add_button"
style="?materialButtonStyle"
android:layout_width="0dp"
Expand Down
Loading