Skip to content

Commit

Permalink
함수 분리 + 주석 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
plgafhd committed Oct 13, 2024
1 parent cb38959 commit 1b65151
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,43 @@ object SNUTTStringUtils {
return "$yearString-$semesterString"
}

// 간소화된 강의 시간
fun getSimplifiedClassTime(lectureDto: LectureDto): String {
/**
* 강의의 모든 classTime을 text로 변환
* ex) 월, 수 09:30 ~ 10:45 이면 -> "월(09:30 ~ 10:45), 수(09:30 ~ 10:45)"
*/
fun getSimplifiedClassTimeForLecture(lectureDto: LectureDto): String {
val texts = StringBuilder()
lectureDto.class_time_json.forEachIndexed { index, classTimeDto ->
texts.append(getClassTimeText(classTimeDto, isSingleClassTime = false))
texts.append(getClassTimeTextForLecture(classTimeDto))
if (index != lectureDto.class_time_json.size - 1) texts.append(", ")
}
if (texts.isEmpty()) texts.append("(없음)")
return texts.toString()
}

fun getClassTimeText(classTime: ClassTimeDto, isSingleClassTime: Boolean = true): String {
return when (isSingleClassTime) {
true -> StringBuilder()
.append(SNUTTUtils.numberToWday(classTime.day))
.append(" %02d:%02d".format(classTime.startTimeHour, classTime.startTimeMinute))
.append("~")
.append("%02d:%02d".format(classTime.endTimeHour, classTime.endTimeMinute))
.toString()
false -> StringBuilder()
.append(SNUTTUtils.numberToWday(classTime.day))
.append("(")
.append("%02d:%02d".format(classTime.startTimeHour, classTime.startTimeMinute))
.append("~")
.append("%02d:%02d".format(classTime.endTimeHour, classTime.endTimeMinute))
.append(")")
.toString()
}
}
/**
* 하나의 classTime을 텍스트로 변환, 강의 내의 모든 classTime에 대해 필요할 때
* ex) 월 09:30 ~ 10:45 이면 -> "월(09:30 ~ 10:45)"
*/
private fun getClassTimeTextForLecture(classTime: ClassTimeDto): String = StringBuilder()
.append(SNUTTUtils.numberToWday(classTime.day))
.append("(")
.append("%02d:%02d".format(classTime.startTimeHour, classTime.startTimeMinute))
.append("~")
.append("%02d:%02d".format(classTime.endTimeHour, classTime.endTimeMinute))
.append(")")
.toString()

/**
* 하나의 classTime을 텍스트로 변환, 하나의 classTime에 대해 필요할 때
* ex) 월 09:30 ~ 10:45 이면 -> "월 09:30~10:45"
*/
fun getSingleClassTimeText(classTime: ClassTimeDto): String = StringBuilder()
.append(SNUTTUtils.numberToWday(classTime.day))
.append(" %02d:%02d".format(classTime.startTimeHour, classTime.startTimeMinute))
.append("~")
.append("%02d:%02d".format(classTime.endTimeHour, classTime.endTimeMinute))
.toString()

fun getSimplifiedLocation(lectureDto: LectureDto): String {
val text = StringBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun LazyItemScope.LectureListItem(
)
val remarkText = lectureDataWithState.item.remark
val tagText = SNUTTStringUtils.getLectureTagText(lectureDataWithState.item)
val classTimeText = SNUTTStringUtils.getSimplifiedClassTime(lectureDataWithState.item)
val classTimeText = SNUTTStringUtils.getSimplifiedClassTimeForLecture(lectureDataWithState.item)
val backgroundColor = if (selected) SNUTTColors.Dim2 else SNUTTColors.Transparent

Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fun LectureDetailPage(
)
editingLectureDetail.class_time_json.forEachIndexed { idx, classTime ->
LectureDetailTimeAndLocation(
timeText = SNUTTStringUtils.getClassTimeText(classTime),
timeText = SNUTTStringUtils.getSingleClassTimeText(classTime),
locationText = classTime.place,
editTime = {
bottomSheet.setSheetContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private fun TableLectureItem(
onClickLecture: (lecture: LectureDto) -> Unit,
) {
val tagText = SNUTTStringUtils.getLectureTagText(lecture)
val classTimeText = SNUTTStringUtils.getSimplifiedClassTime(lecture)
val classTimeText = SNUTTStringUtils.getSimplifiedClassTimeForLecture(lecture)
val locationText = SNUTTStringUtils.getSimplifiedLocation(lecture)

Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun LazyItemScope.VacancyListItem(
lectureDto.quota,
)
val tagText = SNUTTStringUtils.getLectureTagText(lectureDto)
val classTimeText = SNUTTStringUtils.getSimplifiedClassTime(lectureDto)
val classTimeText = SNUTTStringUtils.getSimplifiedClassTimeForLecture(lectureDto)
val backgroundColor = if (hasVacancy) SNUTTColors.VacancyRedBg else SNUTTColors.White900

Row(
Expand Down

0 comments on commit 1b65151

Please sign in to comment.