Settings: Allow using icon for ComposePreference

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
Pranav Vashi
2024-09-30 23:17:26 +05:30
committed by Joey
parent c5a5cc1924
commit 452dd2c86b
2 changed files with 47 additions and 3 deletions

View File

@@ -18,6 +18,8 @@ package com.android.settings.spa.preference
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import androidx.annotation.VisibleForTesting
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
@@ -68,7 +70,18 @@ constructor(
holder.isDividerAllowedAbove = false
holder.isDividerAllowedBelow = false
(holder.itemView as ComposeView).apply {
val iconView = holder.findViewById(android.R.id.icon) as? ImageView
iconView?.let {
if (icon != null) {
it.visibility = View.VISIBLE
it.setImageDrawable(icon)
} else {
it.visibility = View.GONE
}
}
val composeView = holder.findViewById(R.id.compose_view) as? ComposeView
composeView?.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
SettingsTheme {