Skip to content

Commit

Permalink
added filtering + expose a state for the current hierarchical level
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Sep 9, 2024
1 parent 320fb91 commit e4ec46b
Show file tree
Hide file tree
Showing 31 changed files with 435 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

35 changes: 0 additions & 35 deletions .idea/jarRepositories.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-parcelize")
alias(libs.plugins.compose.compiler)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.michaelflisar.composepreferences.demo.classes.LocalDataStore
import com.michaelflisar.composepreferences.demo.composables.MyInfoLine
import com.michaelflisar.composepreferences.demo.demos.PrefScreenCustomDemo
import com.michaelflisar.composepreferences.demo.demos.PrefScreenDemo
import com.michaelflisar.composepreferences.demo.demos.PrefScreenDemoFilter
import com.michaelflisar.composepreferences.demo.demos.PrefScreenDemoKotPreferences1
import com.michaelflisar.composepreferences.kotpreferences.asPreferenceData
import com.michaelflisar.composepreferences.screen.bool.PreferenceBool
Expand Down Expand Up @@ -106,12 +107,13 @@ private fun Content(
when (page.value) {
0 -> Root(
page, theme, dynamicTheme, expandedRootRegions,
listOf("Demo", "Demo KotPreference", "Demo Custom")
listOf("Demo", "Demo KotPreference", "Demo Custom", "Demo Filter")
)

1 -> PrefScreenDemo()
2 -> PrefScreenDemoKotPreferences1()
3 -> PrefScreenCustomDemo()
4 -> PrefScreenDemoFilter()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.michaelflisar.composepreferences.demo.demos

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.michaelflisar.composepreferences.core.PreferenceInfo
import com.michaelflisar.composepreferences.core.PreferenceScreen
import com.michaelflisar.composepreferences.core.PreferenceSectionHeader
import com.michaelflisar.composepreferences.core.PreferenceSubScreen
import com.michaelflisar.composepreferences.core.classes.PreferenceFilter
import com.michaelflisar.composepreferences.core.classes.rememberPreferenceFilter
import com.michaelflisar.composepreferences.core.hierarchy.PreferenceScope
import com.michaelflisar.composepreferences.demo.classes.DemoPrefs
import com.michaelflisar.kotpreferences.core.initialisation.SettingSetup

@Composable
fun PrefScreenDemoFilter() {

val settings = DemoPrefs.preferenceSettings()
val filter = rememberPreferenceFilter(
mode = PreferenceFilter.Mode.AllWords,
highlightSpan = SpanStyle(color = Color.Red)
)

Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp),
value = filter.search.value,
onValueChange = { filter.search.value = it },
label = { Text("Search") },
trailingIcon = if (filter.search.value.isNotEmpty()) {
{
IconButton(onClick = { filter.search.value = "" }) {
Icon(
Icons.Default.Clear,
contentDescription = "clear"
)
}
}
} else null
)

PreferenceScreen(
settings = settings,
filter = filter
) {
PreferenceSectionHeader(
title = { Text("Demos") }
)
PreferenceInfoExamples()
}
}
}

@Composable
private fun PreferenceScope.PreferenceInfoExamples() {
PreferenceSubScreen(
title = { Text("Infos") },
subtitle = { Text("Click to see some info preference examples") },
icon = { Icon(Icons.Outlined.Info, null) }
) {
PreferenceSectionHeader(
title = { Text("Infos") }
)

// either use the TEXT BASED OVERLOADS (those will add all texts to the filter tags list)
// or provide a list of manually defined filter tags
PreferenceInfo(title = "Info 1", subtitle = "Color")
PreferenceInfo(
title = "Info 2",
subtitle = "Color2",
filterTags = listOf("red", "green", "blue")
)
PreferenceInfo(title = "Info 3")
PreferenceInfo(title = "Info 4")
PreferenceInfo(title = "Info 5")
PreferenceInfo(title = "Info 6")

PreferenceInfo(
title = { Text("Info 7") },
filterTags = listOf("Info 7")
)

PreferenceSubScreen(
title = { Text("Sub Infos") },
icon = { Icon(Icons.Outlined.Info, null) }
) {
PreferenceInfo(title = "Sub Info 1", subtitle = "Theme", filterTags = listOf("style"))
PreferenceInfo(title = "Sub Info 2")
PreferenceInfo(title = "Sub Info 3")
PreferenceInfo(title = "Sub Info 4")
PreferenceInfo(title = "Sub Info 5")
PreferenceInfo(title = "Sub Info 6")

PreferenceSubScreen(
title = { Text("Sub Sub Infos") },
icon = { Icon(Icons.Outlined.Info, null) }
) {
PreferenceInfo(title = "Sub Sub Info 1")
PreferenceInfo(title = "Sub Sub Info 2")
PreferenceInfo(title = "Sub Sub Info 3")
}
}
}
}

@Composable
@Preview(showBackground = true)
fun Preview() {
SettingSetup.init(LocalContext.current)
MaterialTheme {
Surface(
modifier = Modifier
.height(400.dp)
) {
PrefScreenDemoFilter()
}
}
}
2 changes: 1 addition & 1 deletion gradle/compose.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
composeBom = "2024.04.00"
compiler = "1.5.11"
compiler = "1.5.15"

activity = "1.8.2"
accompanist = "0.32.0"
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[versions]

gradle = "8.3.2"
kotlin = "1.9.23"
gradle = "8.6.0"
kotlin = "2.0.20"
kotlinx-coroutines = "1.8.0"

[plugins]
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

[libraries]

Expand Down
1 change: 1 addition & 0 deletions library/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("kotlin-android")
id("kotlin-parcelize")
id("maven-publish")
alias(libs.plugins.compose.compiler)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ package com.michaelflisar.composepreferences.core
import android.content.res.Configuration
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.michaelflisar.composepreferences.core.classes.Dependency
import com.michaelflisar.composepreferences.core.classes.LocalPreferenceSettings
import com.michaelflisar.composepreferences.core.classes.PreferenceStyle
import com.michaelflisar.composepreferences.core.classes.PreferenceStyleDefaults
import com.michaelflisar.composepreferences.core.composables.BasePreference
import com.michaelflisar.composepreferences.core.composables.PreferenceItemSetup
import com.michaelflisar.composepreferences.core.composables.PreferenceItemSetupDefaults
import com.michaelflisar.composepreferences.core.composables.PreviewPreference
import com.michaelflisar.composepreferences.core.helper.SearchText
import com.michaelflisar.composepreferences.core.hierarchy.PreferenceScope

/**
Expand All @@ -41,7 +38,8 @@ fun PreferenceScope.PreferenceInfo(
subtitle: @Composable (() -> Unit)? = null,
icon: (@Composable () -> Unit)? = null,
preferenceStyle: PreferenceStyle = LocalPreferenceSettings.current.itemStyle,
itemSetup: PreferenceItemSetup = PreferenceInfoDefaults.itemSetup()
itemSetup: PreferenceItemSetup = PreferenceInfoDefaults.itemSetup(),
filterTags: List<String> = emptyList()
) {
BasePreference(
itemSetup = itemSetup,
Expand All @@ -52,7 +50,36 @@ fun PreferenceScope.PreferenceInfo(
icon = icon,
onLongClick = onLongClick,
preferenceStyle = preferenceStyle,
content = null
content = null,
filterTags = filterTags
)
}

@Composable
fun PreferenceScope.PreferenceInfo(
// Special
onLongClick: (() -> Unit)? = null,
// Base Preference
title: String,
enabled: Dependency = Dependency.Enabled,
visible: Dependency = Dependency.Enabled,
subtitle: String? = null,
icon: (@Composable () -> Unit)? = null,
preferenceStyle: PreferenceStyle = LocalPreferenceSettings.current.itemStyle,
itemSetup: PreferenceItemSetup = PreferenceInfoDefaults.itemSetup(),
filterTags: List<String> = emptyList()
) {
BasePreference(
itemSetup = itemSetup,
enabled = enabled,
visible = visible,
title = { SearchText(title) },
subtitle = subtitle?.let { { SearchText(subtitle) } },
icon = icon,
onLongClick = onLongClick,
preferenceStyle = preferenceStyle,
content = null,
filterTags = filterTags + listOfNotNull(title, subtitle)
)
}

Expand Down
Loading

0 comments on commit e4ec46b

Please sign in to comment.