Skip to content

Commit

Permalink
Added a color marker next to each server entry [#35]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Dec 9, 2023
1 parent cdb1856 commit 764c67f
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,27 @@ fun MainActivityScreen(
composable(Screen.ServerAdd.route) {
EditServer(
serverTemplate,
onSave = { name, url, username, password ->
onSave = { name, url, username, password, serverColor ->
mainViewModel.createServer(
name,
url,
username,
password
password,
serverColor
)
navController.navigate(Screen.ServerList.route)
}, onCancel = { navController.navigate(Screen.ServerList.route) })
}
composable(Screen.ServerEdit.route) {
EditServer(mainViewModel.currentServer!!,
onSave = { name, url, username, password ->
onSave = { name, url, username, password, serverColor ->
mainViewModel.updateServer(
mainViewModel.currentServer!!.copy(
name = name, url = url, username = username, password = password
name = name,
url = url,
username = username,
password = password,
serverColor = serverColor
)
)
navController.navigate(Screen.ServerList.route)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) }

Expand Down Expand Up @@ -132,6 +133,11 @@ fun EditServer(
Icon(imageVector = image, "")
}
})
ServerColorPicker(
currentColor = serverColor,
onColorPicked = { input ->
serverColor = input.hex
})
Spacer(
modifier = Modifier.weight(1.0f)
)
Expand All @@ -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))
}
Expand All @@ -170,7 +176,7 @@ fun EditServerAndroidPreview() {
"[email protected]",
"password"
),
onSave = { _, _, _, _ -> {} }, onCancel = {}
onSave = { _, _, _, _, _ -> {} }, onCancel = {}
)
}
}
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))
}
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)
}
}
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 = {})
}
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 = {})
}
}
Loading

0 comments on commit 764c67f

Please sign in to comment.