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 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ package org.odk.collect.androidshared.ui.multiclicksafe

import android.content.Context
import android.util.AttributeSet
import androidx.core.content.withStyledAttributes
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 lateinit var screenName: String

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

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
init {
context.withStyledAttributes(attrs, R.styleable.MultiClickSafeMaterialButton) {
screenName = getString(R.styleable.MultiClickSafeMaterialButton_screenName) ?: javaClass.name
}
}

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>
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import android.graphics.Typeface
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.content.withStyledAttributes
import com.google.android.material.badge.BadgeDrawable
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 All @@ -20,25 +20,16 @@ class MainMenuButton(context: Context, attrs: AttributeSet?) : FrameLayout(conte

private val binding = MainMenuButtonBinding.inflate(LayoutInflater.from(context), this, true)
private val badge: BadgeDrawable
private val highlightable: Boolean
private var highlightable: Boolean = false

init {
context.theme.obtainStyledAttributes(
attrs,
R.styleable.MainMenuButton,
0,
0
).apply {
try {
val buttonIcon = this.getResourceId(R.styleable.MainMenuButton_icon, 0)
val buttonName = this.getString(R.styleable.MainMenuButton_name)
highlightable = this.getBoolean(R.styleable.MainMenuButton_highlightable, false)
context.withStyledAttributes(attrs, R.styleable.MainMenuButton) {
val buttonIcon = this.getResourceId(R.styleable.MainMenuButton_icon, 0)
val buttonName = this.getString(R.styleable.MainMenuButton_name)
highlightable = this.getBoolean(R.styleable.MainMenuButton_highlightable, false)

binding.icon.setImageResource(buttonIcon)
binding.name.text = buttonName
} finally {
recycle()
}
binding.icon.setImageResource(buttonIcon)
binding.name.text = buttonName
}

badge = BadgeDrawable.create(context).apply {
Expand All @@ -51,7 +42,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(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(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
5 changes: 5 additions & 0 deletions collect_app/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"?>
<resources>
<string name="main_menu_screen" translatable="false">mainMenuScreen</string>
<string name="form_end_screen" translatable="false">formEndScreen</string>
</resources>
26 changes: 9 additions & 17 deletions lists/src/main/java/org/odk/collect/lists/EmptyListView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.annotation.DrawableRes
import androidx.core.content.withStyledAttributes
import org.odk.collect.lists.databinding.EmptyListViewBinding

class EmptyListView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
Expand All @@ -13,23 +14,14 @@ class EmptyListView(context: Context, attrs: AttributeSet?) : FrameLayout(contex
private val binding = EmptyListViewBinding.inflate(LayoutInflater.from(context), this, true)

init {
context.theme.obtainStyledAttributes(
attrs,
R.styleable.EmptyListView,
0,
0
).apply {
try {
val icon = this.getResourceId(R.styleable.EmptyListView_icon, 0)
val title = this.getString(R.styleable.EmptyListView_title)
val subtitle = this.getString(R.styleable.EmptyListView_subtitle)

binding.icon.setImageResource(icon)
binding.title.text = title
binding.subtitle.text = subtitle
} finally {
recycle()
}
context.withStyledAttributes(attrs, R.styleable.EmptyListView) {
val icon = this.getResourceId(R.styleable.EmptyListView_icon, 0)
val title = this.getString(R.styleable.EmptyListView_title)
val subtitle = this.getString(R.styleable.EmptyListView_subtitle)

binding.icon.setImageResource(icon)
binding.title.text = title
binding.subtitle.text = subtitle
}
}

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