|
| 1 | +package dev.sagar.progressbutton |
| 2 | + |
| 3 | +import android.os.Bundle |
| 4 | +import androidx.activity.ComponentActivity |
| 5 | +import androidx.activity.compose.setContent |
| 6 | +import androidx.compose.foundation.ExperimentalFoundationApi |
| 7 | +import androidx.compose.foundation.layout.* // ktlint-disable no-wildcard-imports |
| 8 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 9 | +import androidx.compose.material.Button |
| 10 | +import androidx.compose.material.Surface |
| 11 | +import androidx.compose.material.Text |
| 12 | +import androidx.compose.runtime.* // ktlint-disable no-wildcard-imports |
| 13 | +import androidx.compose.ui.Alignment |
| 14 | +import androidx.compose.ui.Modifier |
| 15 | +import androidx.compose.ui.graphics.Color |
| 16 | +import androidx.compose.ui.tooling.preview.Preview |
| 17 | +import androidx.compose.ui.unit.dp |
| 18 | +import dev.sagar.progress_button_compose.ButtonState |
| 19 | +import dev.sagar.progress_button_compose.ProgressButton |
| 20 | +import dev.sagar.progress_button_compose.ProgressButtonColors |
| 21 | + |
| 22 | +class ComposeActivity : ComponentActivity() { |
| 23 | + @ExperimentalFoundationApi |
| 24 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 25 | + super.onCreate(savedInstanceState) |
| 26 | + setContent { |
| 27 | + Surface(color = Color.White) { |
| 28 | + MainScreenContent() |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +@ExperimentalFoundationApi |
| 35 | +@Composable |
| 36 | +@Preview |
| 37 | +fun MainScreenContent() { |
| 38 | + |
| 39 | + var buttonState by remember { |
| 40 | + mutableStateOf(ButtonState.DISABLED) |
| 41 | + } |
| 42 | + |
| 43 | + Column( |
| 44 | + modifier = Modifier |
| 45 | + .fillMaxSize() |
| 46 | + .padding(32.dp), |
| 47 | + verticalArrangement = Arrangement.Center, |
| 48 | + horizontalAlignment = Alignment.CenterHorizontally |
| 49 | + ) { |
| 50 | + ProgressButton( |
| 51 | + buttonState = buttonState, |
| 52 | + text = "Button", |
| 53 | + completedText = "Finished", |
| 54 | + shape = RoundedCornerShape(12.dp), |
| 55 | + modifier = Modifier |
| 56 | + .fillMaxWidth(), |
| 57 | + progressButtonColors = ProgressButtonColors() |
| 58 | + ) { } |
| 59 | + |
| 60 | + Spacer(modifier = Modifier.height(100.dp)) |
| 61 | + |
| 62 | + ControlButton(text = "Enable") { |
| 63 | + buttonState = ButtonState.ENABLED |
| 64 | + } |
| 65 | + Spacer(modifier = Modifier.height(16.dp)) |
| 66 | + ControlButton(text = "Disable") { |
| 67 | + buttonState = ButtonState.DISABLED |
| 68 | + } |
| 69 | + Spacer(modifier = Modifier.height(16.dp)) |
| 70 | + ControlButton(text = "Loading") { |
| 71 | + buttonState = ButtonState.LOADING |
| 72 | + } |
| 73 | + Spacer(modifier = Modifier.height(16.dp)) |
| 74 | + ControlButton(text = "Finished") { |
| 75 | + buttonState = ButtonState.FINISHED |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +@Composable |
| 81 | +fun ControlButton(text: String, onClick: () -> Unit) { |
| 82 | + Button(onClick = onClick, contentPadding = PaddingValues(horizontal = 16.dp)) { |
| 83 | + Text(text = text, color = Color.White) |
| 84 | + } |
| 85 | +} |
0 commit comments