Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material3 #115

Merged
merged 6 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ kotlin {
dependencies {
implementation(compose.desktop.currentOs)
implementation(compose.foundation)

implementation(libs.compose.material3)
implementation(libs.koin)
implementation(libs.decompose)
implementation(libs.decompose.extensions)
Expand Down
2 changes: 1 addition & 1 deletion core-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kotlin {
val jvmMain by getting {
dependencies {
implementation(compose.desktop.currentOs)

implementation(libs.compose.material3)
implementation(libs.koin)
implementation(libs.androidx.datastore)
implementation(libs.kotlinx.coroutines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.github.diegoberaldin.metaphrase.core.common.log.DefaultLogManager
import com.github.diegoberaldin.metaphrase.core.common.log.LogManager
import com.github.diegoberaldin.metaphrase.core.common.notification.DefaultNotificationCenter
import com.github.diegoberaldin.metaphrase.core.common.notification.NotificationCenter
import com.github.diegoberaldin.metaphrase.core.common.ui.theme.DefaultThemeRepository
import com.github.diegoberaldin.metaphrase.core.common.ui.theme.ThemeRepository
import org.koin.dsl.module

/**
Expand All @@ -28,4 +30,7 @@ val commonModule = module {
single<LogManager> {
DefaultLogManager(fileManager = get())
}
single<ThemeRepository> {
DefaultThemeRepository()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ internal class DefaultTemporaryKeyStore(
private val scope = CoroutineScope(Dispatchers.Default)
private val dataStore: DataStore<Preferences> = createDataStore()

private fun createDataStore(): DataStore<Preferences> =
PreferenceDataStoreFactory.create(
corruptionHandler = null,
migrations = emptyList(),
scope = scope,
produceFile = {
val path = fileManager.getFilePath(FILE_NAME)
File(path)
},
)
private fun createDataStore(): DataStore<Preferences> = PreferenceDataStoreFactory.create(
corruptionHandler = null,
migrations = emptyList(),
scope = scope,
produceFile = {
val path = fileManager.getFilePath(FILE_NAME)
File(path)
},
)

override suspend fun containsKey(key: String): Boolean = withTimeoutOrNull(500) {
dataStore.data.map {
it.asMap().keys.any { k -> k.name == key }
}.first()
} ?: false

override suspend fun save(key: String, value: Boolean) {
dataStore.edit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ object KeyStoreKeys {
const val LastOpenedProject = "lastOpenedProject"
const val MachineTranslationProvider = "machineTranslationProvider"
const val MachineTranslationKey = "machineTranslationKey"
const val DarkThemeEnabled = "darkThemeEnabled"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ package com.github.diegoberaldin.metaphrase.core.common.keystore
* Secondary storage in the form of a key store (persistence across application restarts).
*/
interface TemporaryKeyStore {
/**
* Determines whether the key store contains a given key.
*
* @param key Key to check
* @return true if the key store contains the key, false otherwise
*/
suspend fun containsKey(key: String): Boolean

/**
* Save a boolean value in the keystore under a given key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -48,15 +48,15 @@ fun CustomDialog(
Column(
modifier = Modifier
.fillMaxWidth()
.background(color = MaterialTheme.colors.background)
.background(color = MaterialTheme.colorScheme.background)
.padding(Spacing.s),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = message,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.body2,
color = MaterialTheme.colors.onBackground,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onBackground,
)
Spacer(modifier = Modifier.height(Spacing.xs))
Row(
Expand All @@ -73,7 +73,7 @@ fun CustomDialog(
) {
Text(
text = text,
style = MaterialTheme.typography.button,
style = MaterialTheme.typography.labelLarge,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -44,7 +44,7 @@ import kotlin.math.sin
@Composable
fun CustomProgressIndicator(
progress: Float,
progressColor: Color = MaterialTheme.colors.primary,
progressColor: Color = MaterialTheme.colorScheme.primary,
modifier: Modifier = Modifier,
) {
Box(
Expand All @@ -67,11 +67,14 @@ fun CustomProgressIndicator(
val stripeWidth = 20.dp.toLocalPixel()
val clipRectCornerRadius = 4.dp.toLocalPixel()
val stripeRotateAngle = 45f
val progressLabelColorBg = MaterialTheme.colorScheme.primary
val progressLabelColor = MaterialTheme.colorScheme.onPrimary
val stripeColor = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.25f)
Canvas(
modifier = Modifier.fillMaxSize(),
) {
val backgroundString = buildAnnotatedString {
withStyle(SpanStyle(color = progressColor)) {
withStyle(SpanStyle(color = progressLabelColorBg)) {
append(progressText)
}
}
Expand All @@ -93,17 +96,8 @@ fun CustomProgressIndicator(
),
)
}
clipPath(path = pathToClip) {
drawText(
textMeasurer = textMeasurer,
text = buildAnnotatedString {
withStyle(SpanStyle(color = Color.White)) {
append(progressText)
}
},
topLeft = Offset(x = textOffsetLeft, y = textOffsetTop),
)

clipPath(path = pathToClip) {
var stripeOffset = -stripeWidth
val stripeHeightDelta = stripeWidth * sin(stripeRotateAngle.toRadians())
while (stripeOffset < size.width * progress) {
Expand All @@ -116,13 +110,23 @@ fun CustomProgressIndicator(
)
rotate(degrees = stripeRotateAngle, pivot = rect.center) {
drawRect(
color = Color.White.copy(alpha = 0.25f),
color = stripeColor,
topLeft = rect.topLeft,
size = rect.size,
)
}
stripeOffset += stripeWidth
}

drawText(
textMeasurer = textMeasurer,
text = buildAnnotatedString {
withStyle(SpanStyle(color = progressLabelColor)) {
append(progressText)
}
},
topLeft = Offset(x = textOffsetLeft, y = textOffsetTop),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.onClick
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowDropDown
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -55,7 +55,7 @@ fun CustomSpinner(
modifier: Modifier = Modifier,
size: DpSize = DpSize(width = 150.dp, height = 20.dp),
onValueChanged: ((Int) -> Unit)? = null,
valueColor: Color = Color.Black,
valueColor: Color = MaterialTheme.colorScheme.onBackground,
) {
var expanded by remember {
mutableStateOf(false)
Expand All @@ -67,7 +67,7 @@ fun CustomSpinner(
BasicTextField(
modifier = Modifier.matchParentSize(),
value = current ?: "",
textStyle = MaterialTheme.typography.caption.copy(color = valueColor),
textStyle = MaterialTheme.typography.labelSmall.copy(color = valueColor),
readOnly = true,
onValueChange = {},
decorationBox = { innerTextField ->
Expand All @@ -86,10 +86,10 @@ fun CustomSpinner(
)
DropdownMenu(
modifier = Modifier.width(size.width)
.background(Color.White)
.background(MaterialTheme.colorScheme.background)
.border(
width = Dp.Hairline,
color = MaterialTheme.colors.background,
color = MaterialTheme.colorScheme.background,
shape = RoundedCornerShape(4.dp),
),
expanded = expanded,
Expand All @@ -103,7 +103,7 @@ fun CustomSpinner(
values.forEachIndexed { idx, value ->
DropdownMenuItem(
modifier = Modifier
.background(color = if (value == hoveredValue) Color.Blue else Color.Transparent)
.background(color = if (value == hoveredValue) MaterialTheme.colorScheme.secondary else Color.Transparent)
.fillMaxWidth().height(24.dp)
.onPointerEvent(PointerEventType.Enter) { hoveredValue = value }
.onPointerEvent(PointerEventType.Exit) { hoveredValue = null }
Expand All @@ -112,13 +112,14 @@ fun CustomSpinner(
onValueChanged?.invoke(idx)
expanded = false
},
) {
Text(
text = value,
style = MaterialTheme.typography.caption,
color = if (value == hoveredValue) Color.White else Color.Black,
)
}
text = {
Text(
text = value,
style = MaterialTheme.typography.labelSmall,
color = if (value == hoveredValue) MaterialTheme.colorScheme.onSecondary else valueColor,
)
},
)
}
}
Spacer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.onClick
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -23,7 +23,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.github.diegoberaldin.metaphrase.core.common.ui.theme.SelectedBackground
import com.github.diegoberaldin.metaphrase.core.common.ui.theme.Spacing

/**
Expand Down Expand Up @@ -78,15 +77,15 @@ private fun Tab(
) {
Row(
modifier = modifier.background(
color = if (selected) SelectedBackground else Color.Transparent,
color = if (selected) MaterialTheme.colorScheme.onBackground.copy(alpha = 0.1f) else Color.Transparent,
shape = RoundedCornerShape(topStart = 8.dp, topEnd = 8.dp),
).padding(horizontal = Spacing.s, vertical = Spacing.s),
verticalAlignment = Alignment.Bottom,
) {
Text(
text = label,
style = MaterialTheme.typography.body2.copy(fontSize = 13.sp),
color = Color.White,
style = MaterialTheme.typography.bodySmall.copy(fontSize = 13.sp),
color = MaterialTheme.colorScheme.onBackground,
)
if (rightIcon != null) {
Spacer(Modifier.width(Spacing.m))
Expand All @@ -99,7 +98,7 @@ private fun Tab(
},
imageVector = rightIcon,
contentDescription = null,
tint = Color.White,
tint = MaterialTheme.colorScheme.onBackground,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -54,11 +54,11 @@ fun CustomTextField(
hint: String = "",
enabled: Boolean = true,
secure: Boolean = false,
labelColor: Color = Color.White,
backgroundColor: Color = Color.White,
textColor: Color = Color.Black,
labelColor: Color = MaterialTheme.colorScheme.onBackground,
backgroundColor: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.1f),
textColor: Color = MaterialTheme.colorScheme.onBackground,
labelExtraSpacing: Dp = 0.dp,
labelStyle: TextStyle = MaterialTheme.typography.caption,
labelStyle: TextStyle = MaterialTheme.typography.labelSmall,
value: String,
singleLine: Boolean = false,
onValueChange: (String) -> Unit,
Expand Down Expand Up @@ -101,7 +101,7 @@ fun CustomTextField(
onValueChange(it.text)
},
cursorBrush = SolidColor(textColor),
textStyle = MaterialTheme.typography.caption.copy(color = textColor),
textStyle = MaterialTheme.typography.labelSmall.copy(color = textColor),
singleLine = singleLine,
enabled = enabled,
visualTransformation = if (secure) PasswordVisualTransformation() else VisualTransformation.None,
Expand All @@ -113,7 +113,7 @@ fun CustomTextField(
if (hint.isNotEmpty() && textFieldValue.text.isEmpty()) {
Text(
text = hint,
style = MaterialTheme.typography.caption,
style = MaterialTheme.typography.labelSmall,
color = Color.Gray,
)
}
Expand Down
Loading