Skip to content

Commit

Permalink
#18 [FIX] entity 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeulzzang committed Jan 9, 2025
1 parent 48842ad commit 2f1deff
Show file tree
Hide file tree
Showing 11 changed files with 456 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,127 +26,127 @@ import com.sopt.domain.entity.TimeEntity
import com.sopt.domain.entity.TimeTableEntity
import java.sql.Time

@Composable
fun NoostakEditableTimeTable(
data: TimeTableEntity,
modifier: Modifier = Modifier,
onSelectionChange: (List<TimeEntity>) -> Unit
) {
val days = data.timeEntity.size
val timeSlots = TimeTable().calculateTimeSlots(data.startTime, data.endTime)
val selectedCells = remember { mutableStateListOf<Pair<Int, Int>>() } // Row, Column 저장
//@Composable
//fun NoostakEditableTimeTable(
// data: TimeTableEntity,
// modifier: Modifier = Modifier,
// onSelectionChange: (List<TimeEntity>) -> Unit
//) {
// val days = data.timeEntity.size
// val timeSlots = TimeTable().calculateTimeSlots(data.startTime, data.endTime)
// val selectedCells = remember { mutableStateListOf<Pair<Int, Int>>() } // Row, Column 저장
//
// LazyVerticalGrid(
// modifier = modifier
// .border(
// width = 1.dp,
// color = NoostakTheme.colors.gray200,
// shape = RoundedCornerShape(8.dp)
// ),
// columns = GridCells.Fixed(days + 1)
// ) {
// items((days + 1) * (timeSlots + 1)) { index ->
// val (rowIndex, columnIndex) = index / (days + 1) to index % (days + 1)
// val cellType = TimeTable().determineCellType(rowIndex, columnIndex)
// val isSelected = selectedCells.contains(rowIndex to columnIndex)
// val backgroundColor =
// getEditableBackgroundColor(cellType, isSelected)
// val text = TimeTable().getCellText(cellType, rowIndex, columnIndex, data)
//
// NoostakEditableTimeTableBox(
// index = index,
// days = days,
// timeSlots = timeSlots,
// backgroundColor = backgroundColor,
// text = text,
// onClick = {
// if (cellType == CellType.Data) {
// val cell = rowIndex to columnIndex
// if (selectedCells.contains(cell)) {
// selectedCells.remove(cell)
// } else {
// selectedCells.add(cell)
// }
// onSelectionChange(
// selectedCells.toTimeEntities(
// data.startTime,
// data.timeEntity
// )
// )
// }
// }
// )
// }
// }
//}

LazyVerticalGrid(
modifier = modifier
.border(
width = 1.dp,
color = NoostakTheme.colors.gray200,
shape = RoundedCornerShape(8.dp)
),
columns = GridCells.Fixed(days + 1)
) {
items((days + 1) * (timeSlots + 1)) { index ->
val (rowIndex, columnIndex) = index / (days + 1) to index % (days + 1)
val cellType = TimeTable().determineCellType(rowIndex, columnIndex)
val isSelected = selectedCells.contains(rowIndex to columnIndex)
val backgroundColor =
getEditableBackgroundColor(cellType, isSelected)
val text = TimeTable().getCellText(cellType, rowIndex, columnIndex, data)

NoostakEditableTimeTableBox(
index = index,
days = days,
timeSlots = timeSlots,
backgroundColor = backgroundColor,
text = text,
onClick = {
if (cellType == CellType.Data) {
val cell = rowIndex to columnIndex
if (selectedCells.contains(cell)) {
selectedCells.remove(cell)
} else {
selectedCells.add(cell)
}
onSelectionChange(
selectedCells.toTimeEntities(
data.startTime,
data.timeEntity
)
)
}
}
)
}
}
}

@Composable
fun getEditableBackgroundColor(
cellType: CellType,
isSelected: Boolean
): Color = when (cellType) {
CellType.Blank, CellType.DateHeader, CellType.TimeHeader -> Color.Transparent
CellType.Data -> if (isSelected) NoostakTheme.colors.blue400 else Color.Transparent
}

@Composable
fun NoostakEditableTimeTableBox(
index: Int,
days: Int,
timeSlots: Int,
backgroundColor: Color,
text: String,
onClick: () -> Unit
) {
val shape = when (index) {
0 -> RoundedCornerShape(topStart = 10.dp)
days -> RoundedCornerShape(topEnd = 10.dp)
(days + 1) * timeSlots -> RoundedCornerShape(bottomStart = 10.dp)
(days + 1) * (timeSlots + 1) - 1 -> RoundedCornerShape(bottomEnd = 10.dp)
else -> RoundedCornerShape(0.dp)
}

Box(
modifier = Modifier
.border(
width = 0.5.dp,
color = NoostakTheme.colors.gray200,
shape = shape
)
.background(
color = backgroundColor,
shape = shape
)
.defaultMinSize(minWidth = 42.dp, minHeight = 36.dp)
.noRippleClickable { onClick() },
contentAlignment = Alignment.Center
) {
Text(
modifier = Modifier.padding(horizontal = 5.dp, vertical = 3.dp),
text = text,
color = NoostakTheme.colors.gray600,
style = NoostakTheme.typography.c4Regular,
textAlign = TextAlign.Center,
maxLines = 2
)
}
}

fun List<Pair<Int, Int>>.toTimeEntities(
startTime: String,
timeEntityList: List<TimeEntity>
): List<TimeEntity> {
val startHour = startTime.split(":")[0].toInt()

return this.groupBy { it.second }.mapNotNull { (columnIndex, rowIndex) ->
val date = timeEntityList.getOrNull(columnIndex - 1)?.date ?: return@mapNotNull null
val times = rowIndex.map { row ->
val hour = startHour + (row.first - 1)
AvailableTimeEntity(
startTime = "%02d:00".format(hour),
endTime = "%02d:00".format(hour + 1)
)
}
TimeEntity(date = date, times = times)
}
}
//@Composable
//fun getEditableBackgroundColor(
// cellType: CellType,
// isSelected: Boolean
//): Color = when (cellType) {
// CellType.Blank, CellType.DateHeader, CellType.TimeHeader -> Color.Transparent
// CellType.Data -> if (isSelected) NoostakTheme.colors.blue400 else Color.Transparent
//}
//
//@Composable
//fun NoostakEditableTimeTableBox(
// index: Int,
// days: Int,
// timeSlots: Int,
// backgroundColor: Color,
// text: String,
// onClick: () -> Unit
//) {
// val shape = when (index) {
// 0 -> RoundedCornerShape(topStart = 10.dp)
// days -> RoundedCornerShape(topEnd = 10.dp)
// (days + 1) * timeSlots -> RoundedCornerShape(bottomStart = 10.dp)
// (days + 1) * (timeSlots + 1) - 1 -> RoundedCornerShape(bottomEnd = 10.dp)
// else -> RoundedCornerShape(0.dp)
// }
//
// Box(
// modifier = Modifier
// .border(
// width = 0.5.dp,
// color = NoostakTheme.colors.gray200,
// shape = shape
// )
// .background(
// color = backgroundColor,
// shape = shape
// )
// .defaultMinSize(minWidth = 42.dp, minHeight = 36.dp)
// .noRippleClickable { onClick() },
// contentAlignment = Alignment.Center
// ) {
// Text(
// modifier = Modifier.padding(horizontal = 5.dp, vertical = 3.dp),
// text = text,
// color = NoostakTheme.colors.gray600,
// style = NoostakTheme.typography.c4Regular,
// textAlign = TextAlign.Center,
// maxLines = 2
// )
// }
//}
//
//fun List<Pair<Int, Int>>.toTimeEntities(
// startTime: String,
// timeEntityList: List<TimeEntity>
//): List<TimeEntity> {
// val startHour = startTime.split(":")[0].toInt()
//
// return this.groupBy { it.second }.mapNotNull { (columnIndex, rowIndex) ->
// val date = timeEntityList.getOrNull(columnIndex - 1)?.date ?: return@mapNotNull null
// val times = rowIndex.map { row ->
// val hour = startHour + (row.first - 1)
// AvailableTimeEntity(
// startTime = "%02d:00".format(hour),
// endTime = "%02d:00".format(hour + 1)
// )
// }
// TimeEntity(date = date, times = times)
// }
//}
Loading

0 comments on commit 2f1deff

Please sign in to comment.