From 4d0a6d790e6038a1f8f849b2b806e5d59566fe3e Mon Sep 17 00:00:00 2001 From: "sargamgayatri0803@gmail.com" Date: Tue, 11 Jun 2024 16:28:36 +0530 Subject: [PATCH] make permission item fully touchable --- .../anki/ui/windows/permissions/PermissionItem.kt | 12 ++++++++++++ AnkiDroid/src/main/res/layout/permission_item.xml | 1 + 2 files changed, 13 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionItem.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionItem.kt index 11e043e5be31..d3b06d3e5f2c 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionItem.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionItem.kt @@ -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 @@ -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") diff --git a/AnkiDroid/src/main/res/layout/permission_item.xml b/AnkiDroid/src/main/res/layout/permission_item.xml index a731cd7e85b0..75772c9f7ea1 100644 --- a/AnkiDroid/src/main/res/layout/permission_item.xml +++ b/AnkiDroid/src/main/res/layout/permission_item.xml @@ -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">