Просмотр исходного кода

feat: add method for darken color

unknown 3 дней назад
Родитель
Сommit
8283894012

+ 18 - 0
mobile_app/Wabi/app/src/main/java/com/example/wabi/view/components/colors/darkenColor.kt

@@ -0,0 +1,18 @@
+package com.example.wabi.view.components.colors
+
+import android.os.Build
+import androidx.annotation.RequiresApi
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.toArgb
+import android.graphics.Color as AndroidColor
+
+@RequiresApi(Build.VERSION_CODES.O)
+fun darkenColor(color: Color, factor: Float = 0.2f): Color {
+    val androidColor = color.toArgb()
+    val hsl = FloatArray(3)
+
+    AndroidColor.colorToHSV(androidColor, hsl)
+    hsl[2] -= factor // Уменьшаем значение Lightness
+    hsl[2] = hsl[2].coerceIn(0f, 1f) // Убеждаемся, что значение находится в диапазоне [0, 1]
+    return Color(AndroidColor.HSVToColor(hsl))
+}

+ 14 - 3
mobile_app/Wabi/app/src/main/java/com/example/wabi/view/screeens/profile/Profile.kt

@@ -1,14 +1,18 @@
 package com.example.wabi.view.screeens.profile
 
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Row
 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.runtime.Composable
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
 import androidx.hilt.navigation.compose.hiltViewModel
 import androidx.navigation.NavHostController
 import com.example.wabi.ui.theme.WabiTheme
@@ -18,17 +22,24 @@ import com.example.wabi.view.components.buttons.MainButton
 fun Profile(navHostController: NavHostController, vm: ProfileViewModel = hiltViewModel()) {
 
     Column(
-        modifier = Modifier.fillMaxSize(),
+        modifier = Modifier
+            .fillMaxSize()
+            .background(color = WabiTheme.colors.backgroundColor),
         verticalArrangement = Arrangement.SpaceBetween,
         horizontalAlignment = Alignment.CenterHorizontally
     ) {
 
 
-
         Column(
             modifier = Modifier
                 .fillMaxHeight(0.4f)
-                .fillMaxWidth(),
+                .fillMaxWidth()
+                .border(
+                    width = 3.dp,
+                    color = WabiTheme.colors.mainColor,
+                    shape = RoundedCornerShape(topStart = 15.dp, topEnd = 15.dp)
+                )
+                .background(color = WabiTheme.colors.backgroundColor),
             verticalArrangement = Arrangement.SpaceBetween,
             horizontalAlignment = Alignment.CenterHorizontally
         ) {