Skip to content

Commit

Permalink
disable button
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminHalko committed Sep 25, 2023
1 parent eda3ceb commit 57e70ce
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package app.revanced.manager.ui.component

import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector

@Composable
fun FloatingActionButton(
text: String,
icon: ImageVector,
onClick: () -> Unit,
enabled: Boolean = true
) {
val tint = if (enabled) MaterialTheme.colorScheme.primary else Color.Gray
CompositionLocalProvider(
LocalRippleTheme provides if (enabled) {
LocalRippleTheme.current
} else NoRippleTheme
) {
ExtendedFloatingActionButton(
text = {
Text(
text = text,
color = tint
)
},
icon = {
Icon(
imageVector = icon,
contentDescription = null,
tint = tint
)
},
onClick = {
if (enabled) onClick()
},
containerColor = if (enabled) MaterialTheme.colorScheme.primaryContainer else Color.LightGray,
)
}
}

private object NoRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = Color.Unspecified

@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f, 0.0f, 0.0f, 0.0f)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -48,6 +47,7 @@ import app.revanced.manager.R
import app.revanced.manager.patcher.patch.PatchInfo
import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.patches.OptionItem
import app.revanced.manager.ui.component.FloatingActionButton
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_SUPPORTED
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_UNIVERSAL
Expand Down Expand Up @@ -101,18 +101,17 @@ fun PatchesSelectorScreen(
)
},
floatingActionButton = {
if (!vm.isSelectionEmpty()) {
ExtendedFloatingActionButton(
text = { Text(stringResource(R.string.patch)) },
icon = { Icon(Icons.Default.Build, null) },
onClick = {
composableScope.launch {
// TODO: only allow this if all required options have been set.
onPatchClick(vm.getAndSaveSelection(), vm.getOptions())
}
FloatingActionButton(
text = stringResource(R.string.patch),
icon = Icons.Default.Build,
enabled = !vm.isSelectionEmpty(),
onClick = {
composableScope.launch {
// TODO: only allow this if all required options have been set.
onPatchClick(vm.getAndSaveSelection(), vm.getOptions())
}
)
}
}
)
}
) { paddingValues ->
Column(
Expand Down

0 comments on commit 57e70ce

Please sign in to comment.