ソースを参照

Календарь

Anastasia 6 日 前
コミット
ba176a712c

+ 262 - 1
EatWell/app/src/main/java/com/example/eatwell/view/mainActivity/MyPlan.kt

@@ -109,4 +109,265 @@ import io.github.jan.supabase.gotrue.auth
 //@Preview
 @Composable
 fun myplan(navController: NavController) {
-}
+    var selectedDates by remember { mutableStateOf(mutableSetOf<LocalDate>()) }
+    var currentMonth by remember { mutableStateOf(LocalDate.now().monthValue) }
+
+    val daysInMonth = getDaysInMonth(currentMonth, LocalDate.now().year)
+    val firstDayOfMonth = LocalDate.of(LocalDate.now().year, currentMonth, 1).dayOfWeek.value
+    Box(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(fon)
+    ) {
+        Box(
+            modifier = Modifier
+                .fillMaxSize()
+                .background(fon)
+        )
+        Box(
+            modifier = Modifier
+                .width(359.dp)
+                .height(800.dp)
+                .clip(RoundedCornerShape(30.dp))
+                .background(white)
+                .align(Alignment.Center) //   .shadow(elevation = 10.dp, shape = RoundedCornerShape(30.dp))
+                .padding(16.dp)
+
+
+        ) {
+            Column(
+                modifier = Modifier
+                    .fillMaxSize()
+                    .background(white)
+                    .padding(top = 10.dp, start = 15.dp, end = 15.dp)
+            ) {
+                Text(
+                    text = "Календарь",
+                    fontSize = 20.sp,
+                    fontWeight = FontWeight.Bold,
+                    color = black,
+                    textAlign = TextAlign.Center,
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .padding(bottom = 80.dp)
+                )
+                Text(
+                    text = "Отметьте дни, когда вы следуете своему плану  ",
+                    fontSize = 18.sp,
+                    fontWeight = FontWeight.Bold,
+                    color = black,
+                    textAlign = TextAlign.Left,
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .padding(bottom = 30.dp)
+                )
+
+                Row(
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .padding(16.dp),
+                    horizontalArrangement = Arrangement.SpaceBetween,
+                    verticalAlignment = Alignment.CenterVertically
+                ) {
+                    IconButton(onClick = {
+
+                        currentMonth = (currentMonth - 1).takeIf { it > 0 } ?: 12
+
+                    }) {
+                        Icon(Icons.Filled.ArrowBack, contentDescription = "Previous Month")
+                    }
+
+                    Text(
+                        text = LocalDate.of(LocalDate.now().year, currentMonth, 1)
+                            .format(DateTimeFormatter.ofPattern("MMMM yyyy")),
+                        fontWeight = FontWeight.Bold,
+                        fontSize = 20.sp
+                    )
+
+                    IconButton(onClick = {
+                        currentMonth = (currentMonth + 1).takeIf { it <= 12 } ?: 1
+
+                    }) {
+                        Icon(Icons.Filled.ArrowForward, contentDescription = "Next Month")
+                    }
+                }
+                // Календарь
+                LazyVerticalGrid(
+                    columns = GridCells.Fixed(7),
+                    verticalArrangement = Arrangement.spacedBy(2.dp),
+                    horizontalArrangement = Arrangement.spacedBy(2.dp),
+                    modifier = Modifier.padding(16.dp)
+                ) {
+                    itemsIndexed(listOf("Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс")) { index, day ->
+                        Text(
+                            text = day,
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .padding(4.dp),
+                            textAlign = TextAlign.Center,
+                            fontWeight = FontWeight.Bold
+                        )
+                    }
+                    // Дни месяца
+                    items(daysInMonth + firstDayOfMonth - 1) { index ->
+                        val day = index - (firstDayOfMonth - 1) + 1
+                        if (day > 0) {
+                            val date = LocalDate.of(LocalDate.now().year, currentMonth, day)
+                            val isSelected = selectedDates.contains(date)
+
+
+                            val drawable: Drawable? = ContextCompat.getDrawable(
+                                LocalContext.current,
+                                R.drawable.rounded_item
+                            )
+                            // val painter = drawable?.toBitmap()?.let { BitmapPainter(it) }
+
+                            Box(
+                                modifier = Modifier
+                                    .fillMaxWidth()
+                                    .padding(4.dp)
+                                    .clip(CircleShape)
+                                    // .background(painter = drawable)
+
+                                    //.size(36.dp)
+                                    .clickable {
+
+                                        selectedDates = if (isSelected) {
+                                            selectedDates - date
+                                        } else {
+                                            selectedDates + date
+                                        }.toMutableSet()
+                                    },
+                                contentAlignment = Alignment.Center
+                            ) {
+                                Text(text = day.toString())
+                            }
+                        } else {
+                            Box(modifier = Modifier.fillMaxWidth().padding(4.dp))
+                        }
+                    }
+                }
+                Row(
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .padding(1.dp),
+                    horizontalArrangement = Arrangement.SpaceBetween
+                ) {
+                    repeat(5) { index ->
+                        Box(
+                            modifier = Modifier
+                                .size(5.dp)
+                                .background(if (currentMonth == (index + 1)) Color.Green else Color.LightGray)
+                                .clickable { currentMonth = (index + 1) }
+                        )
+                    }
+                }
+
+
+                //вот
+                Column(
+                    modifier = Modifier
+                        .fillMaxSize()
+                        .background(white)
+                        .padding(top = 670.dp, start = 15.dp, end = 15.dp)
+                ) {
+                    Box(
+                        modifier = Modifier
+                            .fillMaxWidth()
+                            .padding(bottom = 1.dp)
+                    ) {
+                        Divider(
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .height(1.dp)
+                                .background(fon)
+                        )
+                        Row(
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .padding(top = 8.dp),
+                            horizontalArrangement = Arrangement.SpaceBetween,
+                            verticalAlignment = Alignment.CenterVertically
+                        ) {
+                            Column(
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+                                Icon(
+                                    painter = painterResource(id = R.drawable.img),
+                                    contentDescription = "Home",
+                                    tint = text_1
+                                )
+                                Spacer(modifier = Modifier.height(4.dp))
+                                Text("HOME", color = text_1)
+                            }
+
+                            Column(
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+                                Icon(
+                                    painter = painterResource(id = R.drawable.img_1),
+                                    contentDescription = "My Plan",
+                                    tint = Color.Black
+                                )
+                                Spacer(modifier = Modifier.height(4.dp))
+                                Text("MY PLAN", color = Color.Black)
+                            }
+
+                            Column(
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+                                Icon(
+                                    painter = painterResource(id = R.drawable.img_2),
+                                    contentDescription = "Fridge",
+                                    tint = text_1
+                                )
+                                Spacer(modifier = Modifier.height(4.dp))
+                                Text("FRIGE", color = text_1)
+                            }
+
+                            Column(
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+                                Icon(
+                                    painter = painterResource(id = R.drawable.img_3),
+                                    contentDescription = "Log Out",
+                                    tint = text_1
+                                )
+                                Spacer(modifier = Modifier.height(4.dp))
+                                Text("LOG OUT", color = text_1)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
+
+// Функция для получения количества дней в месяце
+fun getDaysInMonth(month: Int, year: Int): Int {
+    return LocalDate.of(year, month, 1).lengthOfMonth()
+}
+
+@Composable
+fun CalendarDay(date: LocalDate, isSelected: Boolean, onDateClick: (LocalDate) -> Unit) {
+    Button(
+        onClick = { onDateClick(date) },
+        modifier = Modifier
+            .width(36.dp) // Adjust width as needed
+            .height(36.dp) // Adjust height as needed
+            .padding(2.dp)
+            .clickable { onDateClick(date) },
+        colors = ButtonDefaults.buttonColors(
+            containerColor = if (isSelected) Color(0xFFFFA500) else Color.White
+        ),
+        shape = CircleShape
+    ) {
+        Text(
+            text = date.dayOfMonth.toString(),
+            modifier = Modifier.padding(2.dp),
+            color = if (isSelected) Color.White else Color.Black
+        )
+    }
+}