-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a color marker next to each server entry [#35]
- Loading branch information
Showing
13 changed files
with
380 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ import org.comixedproject.variant.model.Server | |
@Composable | ||
fun EditServer( | ||
entry: Server, | ||
onSave: (String, String, String, String) -> Unit, | ||
onSave: (String, String, String, String, String) -> Unit, | ||
onCancel: () -> Unit | ||
) { | ||
Surface( | ||
|
@@ -85,6 +85,7 @@ fun EditServer( | |
var url by remember { mutableStateOf(entry.url) } | ||
var username by remember { mutableStateOf(entry.username) } | ||
var password by remember { mutableStateOf(entry.password) } | ||
var serverColor by remember { mutableStateOf(entry.serverColor) } | ||
var passwordVisible by remember { mutableStateOf(false) } | ||
var isValid by remember { mutableStateOf(false) } | ||
|
||
|
@@ -132,6 +133,11 @@ fun EditServer( | |
Icon(imageVector = image, "") | ||
} | ||
}) | ||
ServerColorPicker( | ||
currentColor = serverColor, | ||
onColorPicked = { input -> | ||
serverColor = input.hex | ||
}) | ||
Spacer( | ||
modifier = Modifier.weight(1.0f) | ||
) | ||
|
@@ -144,7 +150,7 @@ fun EditServer( | |
} | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
Button(onClick = { | ||
onSave(name, url, username, password) | ||
onSave(name, url, username, password, serverColor) | ||
}) { | ||
Text(text = stringResource(id = R.string.save_button)) | ||
} | ||
|
@@ -170,7 +176,7 @@ fun EditServerAndroidPreview() { | |
"[email protected]", | ||
"password" | ||
), | ||
onSave = { _, _, _, _ -> {} }, onCancel = {} | ||
onSave = { _, _, _, _, _ -> {} }, onCancel = {} | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
composeApp/src/androidMain/kotlin/org/comixedproject/variant/ui/server/Extensions.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,29 @@ | ||
/* | ||
* Variant - A digital comic book reading application for iPad, Android, and desktops. | ||
* Copyright (C) 2023, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
package org.comixedproject.variant.ui.server | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import org.comixedproject.variant.model.ServerColorOption | ||
|
||
/** | ||
* Converts a hex string to a color. | ||
*/ | ||
fun ServerColorOption.Companion.fromHex(hex: String): Color { | ||
return Color(android.graphics.Color.parseColor(hex)) | ||
} |
65 changes: 65 additions & 0 deletions
65
composeApp/src/androidMain/kotlin/org/comixedproject/variant/ui/server/ServerColor.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,65 @@ | ||
/* | ||
* Variant - A digital comic book reading application for iPad, Android, and desktops. | ||
* Copyright (C) 2023, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
package org.comixedproject.variant.ui.server | ||
|
||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import org.comixedproject.variant.VariantTheme | ||
|
||
|
||
/** | ||
* Displays a color indicator next to the name of a server. | ||
* | ||
* @author Darryl L. Pierce | ||
*/ | ||
@Composable | ||
fun ServerColor( | ||
modifier: Modifier = Modifier, | ||
color: Color, | ||
size: Dp, | ||
border: Dp | ||
) { | ||
Box( | ||
modifier = modifier | ||
.size(size) | ||
.clip(CircleShape) | ||
.background(color) | ||
.border(BorderStroke(border, SolidColor(Color.Black)), CircleShape) | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun ServerColorPreview() { | ||
VariantTheme { | ||
ServerColor(color = Color.Blue, size = 40.dp, border = 2.dp) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
composeApp/src/androidMain/kotlin/org/comixedproject/variant/ui/server/ServerColorOption.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,67 @@ | ||
package org.comixedproject.variant.ui.server | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import org.comixedproject.variant.model.ServerColorOption | ||
|
||
@Composable | ||
fun ServerColorOption( | ||
color: ServerColorOption, | ||
currentColor: String, | ||
onColorPicked: (ServerColorOption) -> Unit | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clickable( | ||
onClick = { | ||
onColorPicked(color) | ||
} | ||
) | ||
) { | ||
val fontWeight = if (currentColor == color.hex) FontWeight.Bold else FontWeight.Normal | ||
ServerColor( | ||
modifier = Modifier.padding(10.dp), | ||
color = ServerColorOption.fromHex(color.hex), | ||
size = 40.dp, | ||
border = 2.dp | ||
) | ||
Text( | ||
text = color.name, | ||
fontWeight = fontWeight, | ||
fontSize = 22.sp, | ||
modifier = Modifier | ||
.padding(2.dp) | ||
.align(Alignment.CenterVertically) | ||
) | ||
|
||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun ServerColorItemPreview() { | ||
ServerColorOption( | ||
color = ServerColorOption.COLORS[0], | ||
ServerColorOption.COLORS[1].hex, | ||
onColorPicked = {}) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun ServerColorItemCurrentPreview() { | ||
ServerColorOption( | ||
color = ServerColorOption.COLORS[0], | ||
ServerColorOption.COLORS[0].hex, | ||
onColorPicked = {}) | ||
} |
56 changes: 56 additions & 0 deletions
56
composeApp/src/androidMain/kotlin/org/comixedproject/variant/ui/server/ServerColorPicker.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,56 @@ | ||
/* | ||
* Variant - A digital comic book reading application for iPad, Android, and desktops. | ||
* Copyright (C) 2023, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
package org.comixedproject.variant.ui.server | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import org.comixedproject.variant.VariantTheme | ||
import org.comixedproject.variant.model.ServerColorOption | ||
|
||
@Composable | ||
fun ServerColorPicker( | ||
modifier: Modifier = Modifier, | ||
currentColor: String, | ||
onColorPicked: (ServerColorOption) -> Unit | ||
) { | ||
LazyRow( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
) { | ||
items(ServerColorOption.COLORS.size) { itemIndex -> | ||
val color = ServerColorOption.COLORS[itemIndex] | ||
ServerColorOption( | ||
color = color, | ||
currentColor = currentColor, | ||
onColorPicked = onColorPicked | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun ServerColorPickerPreview() { | ||
VariantTheme { | ||
ServerColorPicker(currentColor = ServerColorOption.COLORS[0].hex, onColorPicked = {}) | ||
} | ||
} |
Oops, something went wrong.