-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Stop soft keyboard being forced open * First implementation of autocomplete list card * Made viewmodel scope more private * Restructure package structure * Moved autocompletion logic back into usecase * Larger font on quick keys. Autocomplete list shows most relevant item on the buttom (easier to reach)
- Loading branch information
1 parent
54db549
commit 3fba63f
Showing
21 changed files
with
286 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/jherkenhoff/qalculate/ui/AltKeyboard.kt → ...ff/qalculate/ui/calculator/AltKeyboard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...kenhoff/qalculate/ui/AutocompleteChips.kt → ...culate/ui/calculator/AutocompleteChips.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
app/src/main/java/com/jherkenhoff/qalculate/ui/calculator/AutocompleteList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.jherkenhoff.qalculate.ui.calculator | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.ListItem | ||
import androidx.compose.material3.ListItemDefaults | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.SwipeToDismissBox | ||
import androidx.compose.material3.SwipeToDismissBoxValue | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.rememberSwipeToDismissBoxState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.buildAnnotatedString | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.withStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.jherkenhoff.qalculate.domain.AutocompleteItem | ||
|
||
|
||
@Composable | ||
fun AutocompleteList( | ||
autocompleteText: () -> String, | ||
entries: () -> List<AutocompleteItem>, | ||
modifier: Modifier = Modifier, | ||
onEntryClick: (String) -> Unit = {}, | ||
onDismiss: () -> Unit = {} | ||
) { | ||
val dismissState = rememberSwipeToDismissBoxState() | ||
|
||
when (dismissState.currentValue) { | ||
SwipeToDismissBoxValue.EndToStart -> { | ||
|
||
} | ||
|
||
else -> { } | ||
} | ||
|
||
SwipeToDismissBox( | ||
state = dismissState, | ||
backgroundContent = {}, | ||
) { | ||
Card( | ||
modifier = modifier, | ||
elevation = CardDefaults.elevatedCardElevation(defaultElevation = 6.dp) | ||
) { | ||
Text( | ||
buildAnnotatedString { | ||
append("Suggestions for ") | ||
|
||
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) { | ||
append(autocompleteText()) | ||
} | ||
}, | ||
style = MaterialTheme.typography.bodySmall, | ||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.8f), | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp).fillMaxWidth() | ||
) | ||
HorizontalDivider() | ||
LazyColumn( | ||
reverseLayout = true | ||
) { | ||
for (entry in entries()) { | ||
item { | ||
ListItem( | ||
headlineContent = { Text(entry.title) }, | ||
trailingContent = { Text(entry.name) }, | ||
modifier = Modifier.clickable { onEntryClick(entry.abbreviation) }, | ||
colors = ListItemDefaults.colors(containerColor = Color.Transparent) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
@Preview | ||
@Composable | ||
private fun DefaultPreview() { | ||
val list = listOf( | ||
AutocompleteItem("Tesla", "M", "T"), | ||
AutocompleteItem("Thomson cross section", "M", "T"), | ||
AutocompleteItem("Terabyte", "M", "T"), | ||
AutocompleteItem("Planck temperature", "M", "T"), | ||
) | ||
AutocompleteList( | ||
{ "t" }, | ||
{ list } | ||
) | ||
} |
3 changes: 1 addition & 2 deletions
3
...enhoff/qalculate/ui/CalculationDivider.kt → ...ulate/ui/calculator/CalculationDivider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...erkenhoff/qalculate/ui/CalculationList.kt → ...alculate/ui/calculator/CalculationList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.