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 7, 2024
1 parent 1928dd0 commit a09b113
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 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,11 +108,6 @@ class PermissionItem(context: Context, attrs: AttributeSet) : FrameLayout(contex
* The listener isn't invoked if the permission is already granted
* */
fun setOnSwitchClickListener(listener: () -> Unit) {
switch.setOnClickListener {
if (!isGranted) {
Timber.i("permission switch pressed")
listener.invoke()
}
}
this.listener = listener
}
}
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 a09b113

Please sign in to comment.