Skip to content

Commit

Permalink
make permission item fully touchable
Browse files Browse the repository at this point in the history
  • Loading branch information
gayatriii0803 committed Jun 11, 2024
1 parent 1928dd0 commit 4d0a6d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/layout/permission_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:minHeight="?attr/listPreferredItemHeight"
android:paddingTop="16dp"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:background="?attr/selectableItemBackground"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
tools:context=".ui.windows.permissions.PermissionItem">

Expand Down

0 comments on commit 4d0a6d7

Please sign in to comment.