Skip to content

Commit

Permalink
[FIX] 코드리뷰 내용 반영
Browse files Browse the repository at this point in the history
- url링크 유효성 검증시 조건 단순화
- SDK 27 이하일 때 클립보드 초기화 누락 수정
  • Loading branch information
l5x5l committed Sep 30, 2024
1 parent 8785dcd commit cb98dc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/pokitmons/pokit/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pokitmons.pokit

import android.content.ClipData
import android.content.ClipboardManager
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -73,6 +74,9 @@ class MainActivity : ComponentActivity() {
ClipboardLinkManager.setClipboardLink(clipboardTextData)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
clipboardManager.clearPrimaryClip()
} else {
val emptyClip = ClipData.newPlainText("", "")
clipboardManager.setPrimaryClip(emptyClip)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package pokitmons.pokit.home.model

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import pokitmons.pokit.core.feature.flow.EventFlow
import pokitmons.pokit.core.feature.flow.MutableEventFlow
import pokitmons.pokit.core.feature.flow.asEventFlow
import java.util.Locale
import java.util.regex.Pattern

object ClipboardLinkManager {
private val _clipboardLinkUrl: MutableEventFlow<String> = MutableEventFlow()
val clipboardLinkUrl: EventFlow<String> = _clipboardLinkUrl.asEventFlow()
private val _clipboardLinkUrl: MutableSharedFlow<String> = MutableSharedFlow()
val clipboardLinkUrl: SharedFlow<String> = _clipboardLinkUrl.asSharedFlow()

fun setClipboardLink(linkUrl: String) {
CoroutineScope(Dispatchers.IO).launch {
Expand All @@ -20,14 +18,7 @@ object ClipboardLinkManager {
}

fun checkUrlIsValid(url: String): Boolean {
val urlPattern = (
"^(http://|https://)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}" +
"(:[0-9]{1,5})?(/.*)?$"
)

val pattern = Pattern.compile(urlPattern)
val matcher = pattern.matcher(url.lowercase(Locale.getDefault()))

return matcher.matches()
val isValidUrl = url.startsWith("http://") || url.startsWith("https://")
return isValidUrl
}
}

0 comments on commit cb98dc8

Please sign in to comment.