Skip to content

Commit

Permalink
Refactor: if -> when, buildAnnotated 함수 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
Guri999 committed Jan 10, 2025
1 parent f9874aa commit 1dda89d
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions feature/explore/src/main/java/kr/co/explore/ExploreScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -95,35 +96,7 @@ private fun ExploreScreen(
color = Theme.colors.text
)
Text(
text = buildAnnotatedString {
val relativePath = state.path.replace(
DEFAULT_STORAGE,
stringResource(R.string.feature_explore_local_storage)
)
val pathSegments = relativePath.split("/")

if (pathSegments.isEmpty()) {
return@buildAnnotatedString
}

if (pathSegments.size == 1) {
withStyle(
Theme.typography.caption1r.copy(color = Theme.colors.highlight).toSpanStyle()
) {
append("> ${pathSegments.first()}")
}
} else {
append("> ")
pathSegments.dropLast(1).forEach { segment ->
append("$segment/")
}
withStyle(
Theme.typography.caption1r.copy(color = Theme.colors.highlight).toSpanStyle()
) {
append(pathSegments.last())
}
}
},
text = buildPath(state.path),
style = Theme.typography.caption1r,
color = Theme.colors.grayText,
)
Expand Down Expand Up @@ -151,6 +124,37 @@ private fun ExploreScreen(
}
}

@Composable
private fun buildPath(path: String): AnnotatedString =
buildAnnotatedString {
val relativePath = path.replace(
DEFAULT_STORAGE,
stringResource(R.string.feature_explore_local_storage)
)
val pathSegments = relativePath.split("/")

when {
pathSegments.isEmpty() -> return@buildAnnotatedString
pathSegments.size == 1 -> withStyle(
Theme.typography.caption1r.copy(color = Theme.colors.highlight).toSpanStyle()
) {
append("> ${pathSegments.first()}")
}
else -> {
append("> ")
pathSegments.dropLast(1).forEach { segment ->
append("$segment/")
}
withStyle(
Theme.typography.caption1r.copy(color = Theme.colors.highlight).toSpanStyle()
) {
append(pathSegments.last())
}
}
}
}


@Preview
@Composable
private fun Preview() {
Expand Down

0 comments on commit 1dda89d

Please sign in to comment.