Skip to content

Commit

Permalink
ANDROID 11624 - Minor UI (#24)
Browse files Browse the repository at this point in the history
* ANDROID-11624 Improvement on Reset Button. Now appears only when an editableTweak is set.

* ANDROID-11624 Boolean tweak show its value

* ANDROID-11624 Improvements in a tweak with a value with too much data

* ANDROID-11624 Remove visual padding to checkboxes

* ANDROID-11624 Align to end

* Update README.md

* ANDROID-11624 Modified label color has same color as background

* ANDROID-11624 Avoid breaking change keeping same logic
  • Loading branch information
dagonco authored Feb 13, 2023
1 parent b9d67d5 commit 5789d7d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,19 @@ fun dropDownMenu(
)
```
A DropDownMenu
Please review the app module for configuration examples.
Please review the app module for configuration examples.

## Reset Button
When a group of tweaks is created, only if there is at least one editable tweak, a reset button will be automatically added.
If you do not want the reset button to be added automatically, there is a parameter in group node `withClearButton` that can be set.
```kotlin
group(
title = "Group Title",
withClearButton = true
) {
// Your tweaks
}
```

## Custom screens:
You can add your custom screens to the TweaksGraph by using the `customComposableScreens` parameter of `addTweakGraph` function, for example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun DefaultTweaksTheme(
tweaksBackground = TweaksDarkBlue,
tweaksOnBackground = Color.White,
tweaksGroupBackground = TweaksDarkBlueBackground,
tweaksColorModified = TweaksDarkBlueBackground,
tweaksColorModified = TweaksGreen,
)
CompositionLocalProvider(LocalTweaksColors provides tweaksColors) {
content()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -26,8 +27,10 @@ import androidx.compose.material.ContentAlpha
import androidx.compose.material.Divider
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.LocalMinimumTouchTargetEnforcement
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
Expand All @@ -37,6 +40,7 @@ import androidx.compose.material.contentColorFor
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -57,6 +61,7 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
Expand Down Expand Up @@ -185,7 +190,8 @@ fun TweakGroupBody(
onCustomNavigation)
}
}
if (tweakGroup.withClearButton) {

if (tweakGroup.entries.any { it is Editable<*> } && tweakGroup.withClearButton) {
Divider(thickness = 2.dp)
ResetButton(onResetClicked = { tweakGroupViewModel.reset(tweakGroup) })
}
Expand Down Expand Up @@ -259,7 +265,8 @@ fun ReadOnlyStringTweakEntryBody(
Text(
text = "$value",
fontFamily = FontFamily.Monospace,
color = TweaksTheme.colors.tweaksOnBackground
color = TweaksTheme.colors.tweaksOnBackground,
textAlign = TextAlign.End,
)
}
}
Expand Down Expand Up @@ -287,6 +294,7 @@ fun EditableStringTweakEntryBody(
)
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun EditableBooleanTweakEntryBody(
entry: EditableBooleanTweakEntry,
Expand All @@ -303,17 +311,20 @@ fun EditableBooleanTweakEntryBody(
tweakEntry = entry,
onClick = {
Toast
.makeText(context, "Current value is $entry.", Toast.LENGTH_LONG)
.makeText(context, "Current value is $value.", Toast.LENGTH_LONG)
.show()
},
shouldShowOverriddenLabel = isOverridden) {
Checkbox(
checked = value ?: false,
onCheckedChange = {
tweakRowViewModel.setValue(entry, it)
},
colors = tweaksCheckboxColors(),
)
shouldShowOverriddenLabel = isOverridden
) {
CompositionLocalProvider(LocalMinimumTouchTargetEnforcement provides false) {
Checkbox(
checked = value ?: false,
onCheckedChange = {
tweakRowViewModel.setValue(entry, it)
},
colors = tweaksCheckboxColors(),
)
}
}
}

Expand Down Expand Up @@ -436,7 +447,7 @@ private fun TweakRow(
content: @Composable RowScope.() -> Unit,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.fillMaxWidth()
Expand All @@ -447,6 +458,7 @@ private fun TweakRow(
)
) {
TweakNameText(entry = tweakEntry, shouldShowOverriddenLabel = shouldShowOverriddenLabel)
Spacer(modifier = Modifier.padding(horizontal = 8.dp))
content()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class TweaksGraph(val cover: TweakGroup?, val categories: List<TweakCategor
private val categories = mutableListOf<TweakCategory>()
private var cover: TweakGroup? = null

fun cover(title: String, withClearButton: Boolean = false, block: TweakGroup.Builder.() -> Unit) {
fun cover(title: String, withClearButton: Boolean = true, block: TweakGroup.Builder.() -> Unit) {
val builder = TweakGroup.Builder(title, withClearButton)
builder.block()
cover = builder.build()
Expand Down

0 comments on commit 5789d7d

Please sign in to comment.