Skip to content

Commit

Permalink
Change new rule button
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelyteapot committed Mar 18, 2024
1 parent 910aec1 commit 645d733
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 44 deletions.
39 changes: 39 additions & 0 deletions app/src/main/java/dev/phonecontrol/ui/components/NewRuleCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.phonecontrol.ui.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import dev.phonecontrol.R

@Composable
fun NewRuleCard(
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
ElevatedCard(
shape = ruleCardShape,
onClick = onClick,
modifier = Modifier.fillMaxWidth().height(128.dp).then(modifier)
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize(),
) {
Icon(Icons.Default.Add, contentDescription = null)
Text(stringResource(R.string.new_rule))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import java.util.UUID

private const val ANIMATION_DURATION_MS = 300

val ruleCardShape = RoundedCornerShape(16.dp)

private fun <T> slideLeftTransitionSpec(): AnimatedContentTransitionScope<T>.() -> ContentTransform {
return {
slideInHorizontally(tween(ANIMATION_DURATION_MS)) { width -> width } + fadeIn(
Expand Down Expand Up @@ -128,7 +130,7 @@ fun RuleCard2(

ElevatedCard(
colors = elevatedCardColors(enabled = rule.enabled),
shape = RoundedCornerShape(16.dp),
shape = ruleCardShape,
modifier = Modifier
.fillMaxWidth()
.then(modifier),
Expand Down
55 changes: 12 additions & 43 deletions app/src/main/java/dev/phonecontrol/ui/views/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import dev.phonecontrol.R
import dev.phonecontrol.misc.conditional
import dev.phonecontrol.misc.gesturesDisabled
import dev.phonecontrol.ui.components.CustomButton1
import dev.phonecontrol.ui.components.NewRuleCard
import dev.phonecontrol.ui.components.RuleCard2
import dev.phonecontrol.ui.theme.PhoneControlTheme
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -113,20 +114,6 @@ class MainActivity : ComponentActivity() {
Scaffold(
contentWindowInsets = WindowInsets.systemBars.exclude(WindowInsets.navigationBars),
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(8.dp),
floatingActionButton = {
if (hasCallScreeningRoleState.value) ExtendedFloatingActionButton(
text = { Text(stringResource(R.string.new_rule)) },
icon = { Icon(Icons.Default.Add, contentDescription = null) },
onClick = {
coroutineScope.launch {
viewModel.createNewRule(ruleListState.value.size)
// TODO -1 lastIndex
listState.animateScrollToItem(ruleListState.value.lastIndex)
}
},
modifier = Modifier.navigationBarsPadding(),
)
},
snackbarHost = {
SnackbarHost(snackbarHostState)
},
Expand Down Expand Up @@ -227,7 +214,7 @@ class MainActivity : ComponentActivity() {
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(
top = 24.dp,
bottom = 16.dp + 72.dp + WindowInsets.navigationBars.asPaddingValues()
bottom = 16.dp + WindowInsets.navigationBars.asPaddingValues()
.calculateBottomPadding(),
start = 16.dp,
end = 16.dp,
Expand Down Expand Up @@ -281,33 +268,6 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.animateItemPlacement(),
)
// RuleCard(
// rule = rule,
// deleteRule = {
// viewModel.deleteRule(rule)
// },
// updateRule = { newRule ->
// viewModel.updateRule(newRule)
// },
// modifier = Modifier.animateItemPlacement(),
// onEveryoneDisabledClick = {
// coroutineScope.launch {
// if (snackbarHostState.currentSnackbarData != null) {
// return@launch
// }
// val snackbarResult = snackbarHostState.showSnackbar(
// "Access to contacts is required to use this",
// actionLabel = "Allow",
// duration = SnackbarDuration.Short,
// )
// when (snackbarResult) {
// SnackbarResult.ActionPerformed -> {
// requestPermissionLauncher.launch(Manifest.permission.READ_CONTACTS)
// }
//
// else -> {}
// }
// }
// },
// onRemovedSimCardClick = {
// coroutineScope.launch {
// if (snackbarHostState.currentSnackbarData != null) {
Expand All @@ -319,9 +279,18 @@ class MainActivity : ComponentActivity() {
// )
// }
// },
// subscriptions = subscriptionsState.value,
// )
}
item(key = "new_rule") {
NewRuleCard(
modifier = Modifier.animateItemPlacement(),
onClick = {
coroutineScope.launch {
viewModel.createNewRule(ruleListState.value.size)
}
},
)
}
}
}
}
Expand Down

0 comments on commit 645d733

Please sign in to comment.