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

Fixed buttons that are blocked too long #6098

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ package org.odk.collect.androidshared.ui.multiclicksafe
import android.content.Context
import android.util.AttributeSet
import com.google.android.material.button.MaterialButton
import org.odk.collect.androidshared.R
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard.allowClick

open class MultiClickSafeMaterialButton : MaterialButton {
constructor(context: Context) : super(context)
open class MultiClickSafeMaterialButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : MaterialButton(context, attrs, defStyleAttr) {
private val screenName: String

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

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
init {
context.theme.obtainStyledAttributes(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a helper to ContextUtils for grabbing theme string theme attributes like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, kotlin offers an extension function called withStyledAttributes so we can use it ffa8c79

attrs,
R.styleable.MultiClickSafeMaterialButton,
0,
0
).apply {
try {
screenName = this.getString(R.styleable.MultiClickSafeMaterialButton_screenName) ?: javaClass.name
} finally {
recycle()
}
}
}

override fun performClick(): Boolean {
return allowClick() && super.performClick()
return allowClick(screenName) && super.performClick()
}
}
6 changes: 6 additions & 0 deletions androidshared/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MultiClickSafeMaterialButton">
<attr name="screenName" format="string" />
</declare-styleable>
</resources>
5 changes: 5 additions & 0 deletions androidshared/src/main/res/values/screen_names.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
<resources>
<string name="main_menu_screen" translatable="false">mainMenuScreen</string>
<string name="form_end_screen" translatable="false">formEndScreen</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.google.android.material.badge.BadgeUtils
import com.google.android.material.badge.ExperimentalBadgeUtils
import org.odk.collect.android.R
import org.odk.collect.android.databinding.MainMenuButtonBinding
import org.odk.collect.android.utilities.ApplicationConstants
import org.odk.collect.androidshared.system.ContextUtils.getThemeAttributeValue
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard

Expand Down Expand Up @@ -51,7 +50,7 @@ class MainMenuButton(context: Context, attrs: AttributeSet?) : FrameLayout(conte
get() = binding.name.text.toString()

override fun performClick(): Boolean {
return MultiClickGuard.allowClick(ApplicationConstants.ScreenName.MAIN_MENU.name) && super.performClick()
return MultiClickGuard.allowClick(context.getString(org.odk.collect.androidshared.R.string.main_menu_screen)) && super.performClick()
}

fun setNumberOfForms(number: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.TextView
import org.odk.collect.android.R
import org.odk.collect.android.utilities.ApplicationConstants
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard

class StartNewFormButton(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
Expand All @@ -20,6 +19,6 @@ class StartNewFormButton(context: Context, attrs: AttributeSet?) : FrameLayout(c
get() = findViewById<TextView>(R.id.name).text.toString()

override fun performClick(): Boolean {
return MultiClickGuard.allowClick(ApplicationConstants.ScreenName.MAIN_MENU.name) && super.performClick()
return MultiClickGuard.allowClick(context.getString(org.odk.collect.androidshared.R.string.main_menu_screen)) && super.performClick()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,4 @@ public abstract static class Namespaces {
public static final String XML_OPENROSA_NAMESPACE = "http://openrosa.org/xforms";
public static final String XML_OPENDATAKIT_NAMESPACE = "http://www.opendatakit.org/xforms";
}

public enum ScreenName {
MAIN_MENU
}
}
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">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
<com.google.android.material.button.MaterialButton
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" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
<com.google.android.material.button.MaterialButton
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" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
<com.google.android.material.button.MaterialButton
android:id="@+id/add_button"
style="?materialButtonStyle"
android:layout_width="0dp"
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/form_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ the License.
android:layout_alignParentBottom="true"
android:orientation="horizontal">

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
<com.google.android.material.button.MaterialButton
android:id="@+id/form_back_button"
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
Expand All @@ -79,7 +79,7 @@ the License.
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
<com.google.android.material.button.MaterialButton
android:id="@+id/form_forward_button"
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
Expand Down
6 changes: 4 additions & 2 deletions collect_app/src/main/res/layout/form_entry_end.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ the specific language governing permissions and limitations under the License.
android:layout_weight="1"
android:text="@string/save_as_draft"
app:icon="@drawable/ic_save_menu_24"
app:iconGravity="textStart" />
app:iconGravity="textStart"
app:screenName="@string/form_end_screen" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/finalize"
Expand All @@ -121,7 +122,8 @@ the specific language governing permissions and limitations under the License.
android:layout_weight="1"
android:text="@string/finalize"
app:icon="@drawable/ic_send_24"
app:iconGravity="textStart" />
app:iconGravity="textStart"
app:screenName="@string/form_end_screen" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/instance_uploader_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ the License.
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

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

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
<com.google.android.material.button.MaterialButton
android:id="@+id/upload_button"
style="?materialButtonStyle"
android:layout_width="0dp"
Expand Down
4 changes: 2 additions & 2 deletions lists/src/main/res/layout/multi_select_controls_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_height="wrap_content"
style="@style/Widget.AndroidShared.ButtonBar">

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

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