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 1 commit
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>
4 changes: 4 additions & 0 deletions androidshared/src/main/res/values/screen_names.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
<resources>
<string name="form_end_screen" translatable="false">formEndScreen</string>
</resources>
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>