Skip to content

Commit

Permalink
[feat] 환자 홈화면 구현
Browse files Browse the repository at this point in the history
description: api 미연결
  • Loading branch information
seunghee17 committed May 16, 2024
1 parent 9afc141 commit e05b8c5
Show file tree
Hide file tree
Showing 15 changed files with 1,035 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.remind.core.common.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
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.text.PlatformTextStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.remind.core.designsystem.theme.Pretendard
import com.example.remind.core.designsystem.theme.RemindTheme

@Composable
fun BasicTextButton(
modifier: Modifier = Modifier,
backgroundColor: Color,
text: String,
textColor: Color,
onClick: () -> Unit,
verticalPadding: Dp,
enable: Boolean
) {
Box(
modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(color = backgroundColor)
.clickable(
enabled = enable,
onClick = onClick
)
) {
Text(
modifier = modifier
.padding(vertical = verticalPadding),
text = text,
textAlign = TextAlign.Center,
style = RemindTheme.typography.c1Medium.copy(color = textColor)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.example.remind.core.common.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.remind.R
import com.example.remind.core.designsystem.theme.RemindTheme

@Composable
fun MedicineItem(
modifier: Modifier = Modifier,
time: String,
score: Float,
doseClick: () -> Unit,
unadministeredClick: () -> Unit,
) {
Box(
modifier = modifier
.background(color = RemindTheme.colors.slate_50, shape = RoundedCornerShape(12.dp))
) {
Column(
horizontalAlignment = Alignment.Start,
) {
Text(
modifier = modifier.padding(start = 12.dp, top = 7.dp),
text = time,
style = RemindTheme.typography.b3Bold.copy(color = RemindTheme.colors.slate_600)
)
Row(
modifier = modifier.padding(
start = 12.dp,
end = 12.dp,
top = 2.dp,
bottom = 4.dp
)
) {
Text(
text = stringResource(id = R.string.중요도),
style = RemindTheme.typography.c3Medium.copy(color = RemindTheme.colors.slate_400)
)
Spacer(modifier = modifier.width(6.dp))
StarRatingBar(
rating = score,
onRatingChanged = {}
)
}
Spacer(modifier = modifier.height(4.dp))
Row() {
//시간이 정해져있을 경우 바꿔지도록 하기
Text(
modifier = modifier
.weight(0.5f)
.background(
color = RemindTheme.colors.main_6,
shape = RoundedCornerShape(bottomStart = 12.dp)
)
.clickable { doseClick },
text = stringResource(id = R.string.복용),
textAlign= TextAlign.Center,
style = RemindTheme.typography.c1Bold.copy(
color = RemindTheme.colors.white,
lineHeight = 20.sp
)
)
Spacer(modifier = modifier.width(2.dp))
Text(
modifier = modifier
.weight(0.5f)
.background(
color = RemindTheme.colors.main_5,
shape = RoundedCornerShape(bottomEnd = 12.dp)
)
.clickable { unadministeredClick },
text = stringResource(id = R.string.미복용),
textAlign= TextAlign.Center,
style = RemindTheme.typography.c1Bold.copy(
color = RemindTheme.colors.white,
lineHeight = 20.sp
)
)
}
}
}
}

@Preview
@Composable
fun ItemPreview() {
//MedicineItem(time = "아침", score= 2.0, doseClick = {}, unadministeredClick = {})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.example.remind.core.common.component

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.example.remind.R
import com.example.remind.core.designsystem.theme.RemindTheme

@Composable
fun StarRatingBar(
maxStars: Int = 3,
rating: Float,
onRatingChanged: (Float) -> Unit
) {
val density = LocalDensity.current.density
val starSize = (12f * density).dp
val starSpacing = (0.5f * density).dp

Row(
modifier = Modifier.selectableGroup(),
verticalAlignment = Alignment.CenterVertically
) {
for (i in 1..maxStars) {
val isSelected = i <= rating
val icon = if (isSelected) R.drawable.ic_star_fill else R.drawable.ic_star_unfill
val iconTintColor = if (isSelected) RemindTheme.colors.main_4 else RemindTheme.colors.slate_200
Icon(
painter = painterResource(id = icon),
contentDescription = null,
tint = iconTintColor,
modifier = Modifier
.selectable(
selected = isSelected,
onClick = {
onRatingChanged(i.toFloat())
}
)
.width(starSize)
.height(starSize)
)

if (i < maxStars) {
Spacer(modifier = Modifier.width(starSpacing))
}
}
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/example/remind/data/model/CalendarUiModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.remind.data.model

import android.os.Build
import androidx.annotation.RequiresApi
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Date

data class CalendarUiModel(
val selectedDate: Date,
val visibleDates: List<Date>
) {
val startDate: Date = visibleDates.first()
val endDate: Date = visibleDates.last()

data class Date(
val date: LocalDate,
val isSelected: Boolean,
val isToday: Boolean
) {
@RequiresApi(Build.VERSION_CODES.O)
val day: String = date.format(DateTimeFormatter.ofPattern("E"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.remind.data.repository

import android.os.Build
import androidx.annotation.RequiresApi
import com.example.remind.data.model.CalendarUiModel
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.temporal.ChronoUnit
import java.util.stream.Collectors
import java.util.stream.Stream

class CalendarDataSource {
val today: LocalDate
@RequiresApi(Build.VERSION_CODES.O)
get() {
return LocalDate.now()
}
@RequiresApi(Build.VERSION_CODES.O)
fun getData(startDate: LocalDate = today, lastSelectedDate: LocalDate): CalendarUiModel {
val firstDayOfWeek = startDate.with(DayOfWeek.MONDAY)
val endDayOfWeek = firstDayOfWeek.plusDays(7)
val visibleDates = getDateBetween(firstDayOfWeek,endDayOfWeek)
return toUiModel(visibleDates, lastSelectedDate)
}

@RequiresApi(Build.VERSION_CODES.O)
private fun getDateBetween(startDate: LocalDate, endDate: LocalDate): List<LocalDate> {
val numOfDays = ChronoUnit.DAYS.between(startDate, endDate)
return Stream.iterate(startDate) { date ->
date.plusDays(1)
}
.limit(numOfDays)
.collect(Collectors.toList())
}

@RequiresApi(Build.VERSION_CODES.O)
private fun toUiModel(
dateList: List<LocalDate>,
lastSelectedDate: LocalDate
): CalendarUiModel {
return CalendarUiModel(
selectedDate = toItemUiModel(lastSelectedDate, true),
visibleDates = dateList.map {
toItemUiModel(it, it.isEqual(lastSelectedDate))
}
)
}

@RequiresApi(Build.VERSION_CODES.O)
private fun toItemUiModel(date: LocalDate, isSelectedDate: Boolean) = CalendarUiModel.Date(
isSelected = isSelectedDate,
isToday = date.isEqual(today),
date = date
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.remind.feature.screens.patience

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.example.remind.R
import com.example.remind.core.designsystem.theme.RemindTheme

@Composable
fun CheeringScreen(){
RemindTheme {
Image(
modifier = Modifier.fillMaxSize(),
painter = painterResource(id = R.drawable.img_example_cheer),
contentDescription = null
)
}
}

@Preview
@Composable
fun CheeringPreview() {
CheeringScreen()
}
Loading

0 comments on commit e05b8c5

Please sign in to comment.