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

Make permission item fully touchable #16535

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -82,8 +82,19 @@ class PermissionItem(context: Context, attrs: AttributeSet) : FrameLayout(contex
}
}
}
setOnClickListener {
if (!isGranted) {
Timber.i("Permission item clicked, requesting permission")
listener?.invoke()
} else {
switch.isChecked = !switch.isChecked
}
}
updateSwitchCheckedStatus()
}

private var listener: (() -> Unit)? = null

/**
* Checks the switch if the permission is granted,
* or uncheck if not
Expand All @@ -97,6 +108,7 @@ class PermissionItem(context: Context, attrs: AttributeSet) : FrameLayout(contex
* The listener isn't invoked if the permission is already granted
* */
fun setOnSwitchClickListener(listener: () -> Unit) {
this.listener = listener
switch.setOnClickListener {
if (!isGranted) {
Timber.i("permission switch pressed")
Expand Down
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/res/layout/permission_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:paddingTop="16dp"
android:paddingVertical="16dp"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:background="?attr/selectableItemBackground"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
tools:context=".ui.windows.permissions.PermissionItem">

Expand Down