Fixed edit remotes dialog buttons

This commit is contained in:
Abdelilah El Aissaoui 2022-10-23 16:15:30 +02:00
parent a0383b2781
commit 302376a23e
3 changed files with 25 additions and 20 deletions

View File

@ -11,7 +11,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.extensions.backgroundIf
import com.jetpackduba.gitnuro.extensions.handMouseClickable import com.jetpackduba.gitnuro.extensions.handMouseClickable
import com.jetpackduba.gitnuro.extensions.handOnHover
@Composable @Composable
@ -20,16 +22,22 @@ fun PrimaryButton(
text: String, text: String,
enabled: Boolean = true, enabled: Boolean = true,
backgroundColor: Color = MaterialTheme.colors.primary, backgroundColor: Color = MaterialTheme.colors.primary,
backgroundDisabled: Color = MaterialTheme.colors.primary.copy(0.5f),
textColor: Color = MaterialTheme.colors.onPrimary, textColor: Color = MaterialTheme.colors.onPrimary,
disabledTextColor: Color = MaterialTheme.colors.onBackground, disabledTextColor: Color = MaterialTheme.colors.onPrimary.copy(alpha = 0.5f),
onClick: () -> Unit, onClick: () -> Unit,
) { ) {
Box( Box(
modifier = modifier modifier = modifier
.clip(RoundedCornerShape(4.dp)) .clip(RoundedCornerShape(4.dp))
.background(backgroundColor) .backgroundIf(enabled, backgroundColor, backgroundDisabled)
.handMouseClickable { .run {
onClick() if(enabled) {
handMouseClickable {
onClick()
}
} else
handOnHover()
}, },
) { ) {
Text( Text(

View File

@ -105,7 +105,7 @@ fun AuthorDialog(
text = "Cancel", text = "Cancel",
modifier = Modifier.padding(end = 8.dp), modifier = Modifier.padding(end = 8.dp),
onClick = onClose, onClick = onClose,
backgroundColor = Color.Transparent backgroundColor = Color.Transparent,
) )
PrimaryButton( PrimaryButton(
onClick = { onClick = {

View File

@ -10,6 +10,7 @@ import androidx.compose.material.icons.filled.Clear
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.extensions.handMouseClickable import com.jetpackduba.gitnuro.extensions.handMouseClickable
@ -280,15 +281,15 @@ fun EditRemotesDialog(
Row( Row(
modifier = Modifier modifier = Modifier
.padding(top = 16.dp) .padding(top = 16.dp)
.align(Alignment.End) .align(Alignment.End),
verticalAlignment = Alignment.CenterVertically,
) { ) {
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
if (!selectedRemote.isNew) { if (!selectedRemote.isNew) {
TextButton( PrimaryButton(
text = "Discard changes",
modifier = Modifier.padding(end = 8.dp), modifier = Modifier.padding(end = 8.dp),
enabled = remoteChanged,
colors = textButtonColors(),
onClick = { onClick = {
remotesEditorData = remotesEditorData.copy( remotesEditorData = remotesEditorData.copy(
selectedRemote = selectedRemote.copy( selectedRemote = selectedRemote.copy(
@ -298,17 +299,13 @@ fun EditRemotesDialog(
) )
remoteChanged = false remoteChanged = false
} },
) { backgroundColor = Color.Transparent,
Text( backgroundDisabled = Color.Transparent,
"Discard changes", enabled = remoteChanged,
style = MaterialTheme.typography.body1, textColor = MaterialTheme.colors.onBackground,
color = if (remoteChanged) disabledTextColor = MaterialTheme.colors.onBackground.copy(alpha = 0.5f),
MaterialTheme.colors.primaryVariant )
else
MaterialTheme.colors.onBackground,
)
}
} }
val text = if (selectedRemote.isNew) val text = if (selectedRemote.isNew)