-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#35 timetable component #55
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c508305
chore: design-system core:model ์์กด์ฑ ์ถ๊ฐ
jinukeu 735dd4a
chore: `@Stable` ์ด๋
ธํ
์ด์
์ถ๊ฐ ๋ฐ startTime, endTime ํ์
๋ณ๊ฒฝ
jinukeu 2c0775e
design: TimetableCellColor ์ถ๊ฐ
jinukeu 173cdac
refactor: Timetable property ํ์
๋ณ๊ฒฝ
jinukeu da44d53
design: TimetableCell ์ปดํฌ๋ํธ ์ถ๊ฐ
jinukeu a2d0f8f
design: TimetableCell ํ
ํฌ๋ฆฌ ์ถ๊ฐ
jinukeu 81f2508
rename: TimetableCell -> TimetableClassCell
jinukeu 338575c
rename: TimetableEmptyCell ์ถ๊ฐ
jinukeu 80196d2
feat: TimetableDay ์ถ๊ฐ
jinukeu 0702546
feat: TimetableCellColumn ์ถ๊ฐ
jinukeu 97c1c7a
refactor: TimetableCellColumn ํจ์ ๋ถ๋ฆฌ
jinukeu c7ca182
refactor/#35: TimetableCellColumn ๋ฆฌํฉํ ๋ง
jinukeu 07d6e2c
Merge branch 'develop' into feature/timetable-component
jinukeu 65b85dd
design/#35: design system ์ ์ฉ
jinukeu c212840
feat/#35: Timetable Component ์ถ๊ฐ
jinukeu c4a6011
refactor/#35: Timetable Component ๋ฆฌํฉํ ๋ง
jinukeu 5b98a3c
chore/#35: ktlint Format
jinukeu a3025ce
refactor/#35: TimetableCellColor.toHex() ๋ฉ์๋์Cyclomatic Complexity 21โฆ
jinukeu 9e39161
docs/#35: Timetable.kt TODO ์ฃผ์ ์ถ๊ฐ
jinukeu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ android { | |
} | ||
|
||
dependencies { | ||
implementation(projects.core.model) | ||
implementation(projects.core.ui) | ||
} |
27 changes: 27 additions & 0 deletions
27
core/designsystem/src/main/java/com/suwiki/core/designsystem/component/timetable/Common.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.suwiki.core.designsystem.component.timetable | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.suwiki.core.designsystem.R | ||
import com.suwiki.core.model.timetable.TimetableDay | ||
|
||
internal val timetableHeightPerHour = 48.dp | ||
|
||
internal val timetableBorderWidth = 0.5.dp | ||
|
||
const val MINUTE60 = 60 | ||
const val MINUTE10 = 10 | ||
|
||
@Composable | ||
internal fun TimetableDay.toText(): String { | ||
return when (this) { | ||
TimetableDay.MON -> stringResource(R.string.word_mon) | ||
TimetableDay.TUE -> stringResource(R.string.word_tue) | ||
TimetableDay.WED -> stringResource(R.string.word_wed) | ||
TimetableDay.THU -> stringResource(R.string.word_thu) | ||
TimetableDay.FRI -> stringResource(R.string.word_fri) | ||
TimetableDay.SAT -> stringResource(R.string.word_sat) | ||
TimetableDay.E_LEARNING -> stringResource(R.string.word_elearning) | ||
} | ||
} |
259 changes: 259 additions & 0 deletions
259
.../designsystem/src/main/java/com/suwiki/core/designsystem/component/timetable/Timetable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,259 @@ | ||
package com.suwiki.core.designsystem.component.timetable | ||
|
||
import androidx.compose.foundation.ScrollState | ||
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.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.suwiki.core.designsystem.R | ||
import com.suwiki.core.designsystem.component.timetable.cell.ELearningCell | ||
import com.suwiki.core.designsystem.component.timetable.cell.TimetableCellType | ||
import com.suwiki.core.designsystem.component.timetable.column.ClassColumn | ||
import com.suwiki.core.designsystem.component.timetable.column.TimeColumn | ||
import com.suwiki.core.designsystem.theme.Black | ||
import com.suwiki.core.designsystem.theme.Gray95 | ||
import com.suwiki.core.designsystem.theme.GrayF6 | ||
import com.suwiki.core.designsystem.theme.SuwikiTheme | ||
import com.suwiki.core.model.timetable.Timetable | ||
import com.suwiki.core.model.timetable.TimetableCell | ||
import com.suwiki.core.model.timetable.TimetableCellColor | ||
import com.suwiki.core.model.timetable.TimetableDay | ||
import com.suwiki.core.ui.extension.suwikiClickable | ||
import kotlin.math.max | ||
|
||
private const val MIN_MAX_PERIOD = 8 | ||
|
||
internal fun List<TimetableCell>.maxPeriod(): Int { | ||
return max((maxOfOrNull { it.endPeriod }?.plus(1)) ?: MIN_MAX_PERIOD, MIN_MAX_PERIOD) | ||
} | ||
|
||
@Composable | ||
fun Timetable( | ||
modifier: Modifier = Modifier, | ||
type: TimetableCellType = TimetableCellType.CLASSNAME_PROFESSOR_LOCATION, | ||
timetable: Timetable, | ||
onClickAdd: () -> Unit = {}, | ||
onClickHamburger: () -> Unit = {}, | ||
onClickSetting: () -> Unit = {}, | ||
onClickClassCell: (TimetableCell) -> Unit = { _ -> }, | ||
) { | ||
val scrollState = rememberScrollState() | ||
val maxPeriod by remember { | ||
derivedStateOf { timetable.cellList.maxPeriod() } | ||
} | ||
|
||
// TODO ๋ฆฌ์ปดํฌ์ง์ ์ต์ ํ ํ์ | ||
val cellGroupedByDay = timetable.cellList.groupBy { it.day } | ||
|
||
Column( | ||
modifier = modifier.fillMaxSize(), | ||
verticalArrangement = Arrangement.spacedBy(12.dp), | ||
) { | ||
Header( | ||
name = timetable.name, | ||
onClickAdd = onClickAdd, | ||
onClickHamburger = onClickHamburger, | ||
onClickSetting = onClickSetting, | ||
) | ||
|
||
Body( | ||
scrollState = scrollState, | ||
type = type, | ||
maxPeriod = maxPeriod, | ||
cellGroupedByDay = cellGroupedByDay, | ||
onClickClassCell = onClickClassCell, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Header( | ||
modifier: Modifier = Modifier, | ||
name: String, | ||
onClickAdd: () -> Unit = {}, | ||
onClickHamburger: () -> Unit = {}, | ||
onClickSetting: () -> Unit = {}, | ||
) { | ||
Row( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(start = 24.dp, end = 20.dp), | ||
verticalAlignment = Alignment.Bottom, | ||
horizontalArrangement = Arrangement.spacedBy(18.dp), | ||
) { | ||
Text( | ||
modifier = Modifier.weight(1f), | ||
overflow = TextOverflow.Ellipsis, | ||
text = name, | ||
style = SuwikiTheme.typography.header1, | ||
color = Black, | ||
maxLines = 1, | ||
) | ||
|
||
Icon( | ||
modifier = Modifier.suwikiClickable(onClick = onClickHamburger), | ||
painter = painterResource(id = R.drawable.ic_timetable_add), | ||
contentDescription = "", | ||
tint = Gray95, | ||
) | ||
|
||
Icon( | ||
modifier = Modifier.suwikiClickable(onClick = onClickAdd), | ||
painter = painterResource(id = R.drawable.ic_timetable_hamburger), | ||
contentDescription = "", | ||
tint = Gray95, | ||
) | ||
|
||
Icon( | ||
modifier = Modifier.suwikiClickable(onClick = onClickSetting), | ||
painter = painterResource(id = R.drawable.ic_timetable_setting), | ||
contentDescription = "", | ||
tint = Gray95, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Body( | ||
modifier: Modifier = Modifier, | ||
type: TimetableCellType = TimetableCellType.CLASSNAME_PROFESSOR_LOCATION, | ||
scrollState: ScrollState, | ||
maxPeriod: Int, | ||
cellGroupedByDay: Map<TimetableDay, List<TimetableCell>>, | ||
onClickClassCell: (TimetableCell) -> Unit, | ||
) { | ||
Column( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.border(width = timetableBorderWidth, color = GrayF6) | ||
.verticalScroll(scrollState), | ||
) { | ||
Row { | ||
TimeColumn( | ||
modifier = Modifier.weight(1f), | ||
maxPeriod = maxPeriod, | ||
) | ||
|
||
TimetableDay.entries | ||
.sortedBy { it.idx } | ||
.filter { it !in listOf(TimetableDay.SAT, TimetableDay.E_LEARNING) } | ||
.forEach { day -> | ||
ClassColumn( | ||
modifier = Modifier.weight(1f), | ||
type = type, | ||
day = day, | ||
cellList = cellGroupedByDay[day] ?: emptyList(), | ||
lastPeriod = maxPeriod, | ||
onClickClassCell = onClickClassCell, | ||
) | ||
} | ||
} | ||
|
||
cellGroupedByDay | ||
.filter { it.key in listOf(TimetableDay.SAT, TimetableDay.E_LEARNING) } | ||
.flatMap { it.value } | ||
.forEach { cell -> | ||
ELearningCell( | ||
onClickClassCell = onClickClassCell, | ||
cell = cell, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview(showSystemUi = true) | ||
@Composable | ||
fun TimetablePreview() { | ||
SuwikiTheme { | ||
Timetable( | ||
timetable = Timetable( | ||
createTime = 0L, | ||
year = "", | ||
semester = "", | ||
name = "ํ๋ฆฌ๋ทฐ์ ๋๋ค ํ๋ฆฌ๋ทฐ์ ๋๋ค ํ๋ฆฌ๋ทฐ์ ๋๋ค", | ||
cellList = listOf( | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.E_LEARNING, | ||
startPeriod = 7, | ||
endPeriod = 8, | ||
color = TimetableCellColor.GREEN, | ||
), | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.SAT, | ||
startPeriod = 7, | ||
endPeriod = 8, | ||
color = TimetableCellColor.GREEN, | ||
), | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.E_LEARNING, | ||
startPeriod = 0, | ||
endPeriod = 0, | ||
color = TimetableCellColor.GREEN, | ||
), | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.MON, | ||
startPeriod = 7, | ||
endPeriod = 8, | ||
color = TimetableCellColor.GREEN, | ||
), | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.FRI, | ||
startPeriod = 1, | ||
endPeriod = 2, | ||
color = TimetableCellColor.GREEN, | ||
), | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.FRI, | ||
startPeriod = 3, | ||
endPeriod = 4, | ||
color = TimetableCellColor.PINK, | ||
), | ||
TimetableCell( | ||
name = "๋์ ๊ณผ ์ฐฝ์กฐ", | ||
professor = "๊น์๋ฏธ", | ||
location = "๋ฏธ๋ํ์ ๊ดB202", | ||
day = TimetableDay.FRI, | ||
startPeriod = 6, | ||
endPeriod = 6, | ||
color = TimetableCellColor.BROWN, | ||
), | ||
), | ||
), | ||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
derivedStateOf
์ฌ์ฉํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timetable.cellList์ ๊ฐ์ด ๋ณ๊ฒฝ๋์ด๋ maxPeriod์ ๊ฐ์ ๋ณ๊ฒฝ๋์ง ์๋ ๊ฒฝ์ฐ๊ฐ ์์ด์ derivedStateOf๋ฅผ ์ฌ์ฉํ์ด์~! derivedStateOf๋ฅผ ์ฌ์ฉํ๋ฉด timetable.cellList.maxPeriod์ ๊ฐ์ด ์ค์ ๋ก ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ์๋ง val maxPeriod์ ๊ฐ์ด ๋ฐ๋๊ฑฐ๋ผ ์๊ฐํ์ต๋๋ค.
์ฌ์ค ์์ง ํ ์คํธ๋ฅผ ํด๋ณธ๊ฑด ์๋๋ผ์ ... ์ง๊ธ์ TODO ์ฃผ์๋ง ๋ฌ์๋๊ณ ๋ฐ๋ก ๋ค์ Refactor ์์ ๋ ํ ์คํธ ํด๋ณด๊ฒ ์ต๋๋ค!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ํ ์๊ฒ ์ต๋๋ค~!