-
Notifications
You must be signed in to change notification settings - Fork 1
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/250 링크 하이라이팅 #251
Merged
Merged
Feature/250 링크 하이라이팅 #251
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b19a4cf
feat : [공연 상세] 전체 내용 화면에서 url 하이라이팅 처리
HamBP 6c95ec1
refactor : [공연 상세] url 파싱 로직 추출
HamBP 4e308c2
feat : [공연 상세] url 상세 페이지 하이라이팅 적용
HamBP 0d74254
test : url parser 테스트 작성
HamBP 7c4e5a4
fix : url parser 배킹 프로퍼티 + 방어적 복사
HamBP 63fb6fd
fix : url parser, 패턴을 인자로 추가
HamBP adf9eb5
fix : url parser, 방어적 복사 버그 수정
HamBP 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
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
44 changes: 44 additions & 0 deletions
44
presentation/src/main/java/com/nexters/boolti/presentation/util/UrlParser.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,44 @@ | ||
package com.nexters.boolti.presentation.util | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.buildAnnotatedString | ||
import androidx.compose.ui.text.style.TextDecoration | ||
|
||
class UrlParser( | ||
url: String, | ||
urlRegex: Regex = "(https?://\\S+\\b)".toRegex(), | ||
) { | ||
val annotatedString: AnnotatedString | ||
|
||
private val _urlOffsets = mutableListOf<UrlOffset>() | ||
val urlOffsets get() = _urlOffsets.toList() | ||
|
||
init { | ||
val linkMatch = urlRegex.toPattern().matcher(url) | ||
|
||
while (linkMatch.find()) { | ||
_urlOffsets.add(UrlOffset(linkMatch.start(), linkMatch.end())) | ||
} | ||
|
||
annotatedString = buildAnnotatedString { | ||
append(url) | ||
_urlOffsets.forEach { (start, end) -> | ||
addStyle( | ||
SpanStyle( | ||
textDecoration = TextDecoration.Underline, | ||
color = Color(0xFF46A6FF) | ||
), | ||
start, | ||
end, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
data class UrlOffset( | ||
val start: Int, | ||
val end: Int | ||
) |
17 changes: 0 additions & 17 deletions
17
presentation/src/test/java/com/nexters/boolti/presentation/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
presentation/src/test/java/com/nexters/boolti/presentation/util/UrlParserTest.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,24 @@ | ||
package com.nexters.boolti.presentation.util | ||
|
||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class UrlParserTest : BehaviorSpec() { | ||
init { | ||
given("url이 포함된 문자열이 주어지고") { | ||
val targetString = "https://www.naver.com 적당한https://www.naver.com 문자열 http://www.naver.com" | ||
|
||
`when`("이 문자열을 파싱하면") { | ||
val urlParser = UrlParser(targetString) | ||
val urlOffsets = urlParser.urlOffsets | ||
|
||
then("문자열 내 url의 start, end offset을 확인할 수 있다") { | ||
urlOffsets.size shouldBe 3 | ||
urlOffsets[0] shouldBe UrlOffset(0, 21) | ||
urlOffsets[1] shouldBe UrlOffset(25, 46) | ||
urlOffsets[2] shouldBe UrlOffset(51, 71) | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
ㅋㅋ 새로운 문법 바로 써버리기
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.
오잉 ..으로 한 줄 알았는데 ..< 였네 ㅋㅋㅋㅋ
사실 IDE가 고쳐준 거거등