Skip to content

Commit

Permalink
Add delete all for DataStore and Include text style for preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Aug 20, 2024
1 parent ce0e171 commit 5632477
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class DataStoreHelpers {
dataStore?.data?.first()?.toPreferences()?.get(key) ?: default
}

fun clearAllPreferences() = runBlocking {
dataStore?.edit { preferences -> preferences.clear() }
}

companion object {
var dataStore: DataStore<Preferences>? = null
val Context.defaultPreferencesDataStore by preferencesDataStore(name = "default")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.jeluchu.jchucomponents.ktx.colors.opacity
Expand All @@ -35,6 +36,8 @@ fun PreferenceItem(
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onClickLabel: String? = null,
titleStyle: TextStyle = MaterialTheme.typography.titleLarge,
descriptionStyle: TextStyle = MaterialTheme.typography.bodyMedium,
onClick: () -> Unit = {},
) = Surface(
modifier = Modifier.combinedClickable(
Expand Down Expand Up @@ -95,13 +98,15 @@ fun PreferenceItem(
PreferenceItemTitle(
text = title,
enabled = enabled,
style = titleStyle,
color = contentColor
)

if (description != null) PreferenceItemDescription(
enabled = enabled,
text = description,
color = contentColor
color = contentColor,
style = descriptionStyle
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.jeluchu.jchucomponents.ktx.colors.opacity
Expand All @@ -36,6 +37,8 @@ fun PreferenceSwitch(
contentColor: Color = Color.DarkGray,
colors: SwitchColors = SwitchDefaults.colors(),
checkedIcon: ImageVector = Icons.Outlined.Check,
titleStyle: TextStyle = MaterialTheme.typography.titleLarge,
descriptionStyle: TextStyle = MaterialTheme.typography.bodyMedium,
onClick: (() -> Unit) = {},
) {
val thumbContent: (@Composable () -> Unit)? = if (isChecked) {
Expand Down Expand Up @@ -80,12 +83,14 @@ fun PreferenceSwitch(
PreferenceItemTitle(
text = title,
enabled = enabled,
style = titleStyle,
color = contentColor
)
if (!description.isNullOrEmpty()) PreferenceItemDescription(
enabled = enabled,
text = description,
color = contentColor
color = contentColor,
style = descriptionStyle
)
}
Switch(
Expand Down

0 comments on commit 5632477

Please sign in to comment.