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 in ProjectSettingsDialog for all the buttons #4815

Merged
merged 8 commits into from
Sep 1, 2021
Merged

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.odk.collect.android.utilities

import android.os.SystemClock

object MultiClickGuard {
private const val CLICK_DEBOUNCE_MS = 1000

@JvmField
var test = false

private var lastClickTime: Long = 0
private var lastClickName: String = javaClass.name

// Debounce multiple clicks within the same screen
@JvmStatic
fun allowClick(className: String = javaClass.name): Boolean {
if (test) {
return true
}
val elapsedRealtime = SystemClock.elapsedRealtime()
val isSameClass = className == lastClickName
val isBeyondThreshold = elapsedRealtime - lastClickTime > CLICK_DEBOUNCE_MS
val isBeyondTestThreshold =
lastClickTime == 0L || lastClickTime == elapsedRealtime // just for tests

val allowClick = !isSameClass || isBeyondThreshold || isBeyondTestThreshold

if (allowClick) {
lastClickTime = elapsedRealtime
lastClickName = className
}
return allowClick
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.odk.collect.android.views.multiclicksafe

import android.content.Context
import android.util.AttributeSet
import com.google.android.material.button.MaterialButton
import org.odk.collect.android.utilities.MultiClickGuard.allowClick

class MultiClickSafeButton : MaterialButton {
constructor(context: Context) : super(context)

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

override fun performClick(): Boolean {
return allowClick() && super.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.odk.collect.android.views.multiclicksafe

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import org.odk.collect.android.utilities.MultiClickGuard

class MultiClickSafeFrameLayout : FrameLayout {
constructor(context: Context) : super(context)

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

override fun performClick(): Boolean {
return MultiClickGuard.allowClick() && super.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.odk.collect.android.views.multiclicksafe

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageButton
import org.odk.collect.android.utilities.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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.odk.collect.android.views.multiclicksafe

import android.content.Context
import android.util.AttributeSet
import com.google.android.material.textfield.TextInputEditText
import org.odk.collect.android.utilities.MultiClickGuard.allowClick

class MultiClickSafeTextInputEditText : TextInputEditText {
constructor(context: Context) : super(context)

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

override fun performClick(): Boolean {
return allowClick() && super.performClick()
}
}
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 @@ -6,12 +6,12 @@
android:paddingTop="@dimen/margin_small"
android:paddingHorizontal="@dimen/margin_standard">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/capture_button"
style="@style/Widget.Collect.Button.WidgetAnswer"
android:text="@string/capture_audio" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/choose_button"
style="@style/Widget.Collect.Button.WidgetAnswer"
android:text="@string/choose_sound" />
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:paddingTop="@dimen/margin_small"
android:paddingHorizontal="@dimen/margin_standard">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/bearing_button"
style="@style/Widget.Collect.Button.WidgetAnswer"
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:paddingTop="@dimen/margin_small"
android:paddingHorizontal="@dimen/margin_standard">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/date_button"
style="@style/Widget.Collect.Button.WidgetAnswer"
android:text="@string/select_date" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/geo_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:paddingTop="@dimen/margin_small"
android:paddingHorizontal="@dimen/margin_standard">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/simple_button"
style="@style/Widget.Collect.Button.WidgetAnswer"
android:text="@string/get_location" />
Expand Down
6 changes: 3 additions & 3 deletions collect_app/src/main/res/layout/hierarchy_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ the License.
android:layout_alignParentBottom="true"
android:orientation="horizontal">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/jumpBeginningButton"
style="@style/Widget.Collect.Button.BottomOption"
android:layout_marginLeft="@dimen/margin_extra_small"
android:layout_marginRight="@dimen/margin_extra_small"
android:text="@string/jump_to_beginning" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/jumpEndButton"
style="@style/Widget.Collect.Button.BottomOption"
android:layout_marginLeft="@dimen/margin_extra_small"
android:layout_marginRight="@dimen/margin_extra_small"
android:text="@string/jump_to_end" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/exitButton"
style="@style/Widget.Collect.Button.BottomOption"
android:layout_marginLeft="@dimen/margin_extra_small"
Expand Down
6 changes: 3 additions & 3 deletions collect_app/src/main/res/layout/instance_map_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
android:layout_below="@id/form_title"
android:layout_above="@id/geometry_status" />

<org.odk.collect.android.views.MultiClickSafeImageButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeImageButton
android:id="@+id/new_instance"
style="@style/Widget.Collect.ImageButton.MapButton"
android:layout_width="wrap_content"
Expand All @@ -57,7 +57,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<org.odk.collect.android.views.MultiClickSafeImageButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeImageButton
android:id="@+id/zoom_to_location"
style="@style/Widget.Collect.ImageButton.MapButton"
android:layout_width="wrap_content"
Expand All @@ -67,7 +67,7 @@
app:srcCompat="@drawable/ic_my_location"
android:padding="15dp" />

<org.odk.collect.android.views.MultiClickSafeImageButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeImageButton
android:id="@+id/zoom_to_bounds"
style="@style/Widget.Collect.ImageButton.MapButton"
android:layout_width="wrap_content"
Expand Down
12 changes: 6 additions & 6 deletions collect_app/src/main/res/layout/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,47 @@
android:paddingRight="@dimen/margin_standard"
android:paddingBottom="@dimen/margin_standard">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/enter_data"
style="@style/Widget.Collect.Button.FullWidth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_small"
tools:text="@string/enter_data" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/review_data"
style="@style/Widget.Collect.Button.FullWidth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_small"
tools:text="@string/review_data" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/send_data"
style="@style/Widget.Collect.Button.FullWidth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_small"
tools:text="@string/send_data" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/view_sent_forms"
style="@style/Widget.Collect.Button.FullWidth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_small"
android:text="@string/view_sent_forms" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/get_forms"
style="@style/Widget.Collect.Button.FullWidth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_small"
tools:text="@string/get_forms" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/manage_forms"
style="@style/Widget.Collect.Button.FullWidth"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
android:src="@drawable/shadow_up"
app:layout_constraintBottom_toTopOf="@+id/cancel_button" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/cancel_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
Expand All @@ -173,7 +173,7 @@
app:layout_constraintEnd_toStartOf="@+id/add_button"
app:layout_constraintTop_toTopOf="@+id/add_button" />

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/add_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/osm_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:paddingTop="@dimen/margin_small"
android:paddingHorizontal="@dimen/margin_standard">

<org.odk.collect.android.views.MultiClickSafeButton
<org.odk.collect.android.views.multiclicksafe.MultiClickSafeButton
android:id="@+id/launch_open_map_kit_button"
style="@style/Widget.Collect.Button.WidgetAnswer"
android:text="@string/capture_osm"
Expand Down
Loading