Skip to content

Commit 02ee44b

Browse files
committed
nit: access modifiers and comments
1 parent 985181b commit 02ee44b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/src/androidTest/java/com/amrdeveloper/linkhub/ShareLinkTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ShareLinkTest {
1717
@get:Rule
1818
val intentsTestRule = IntentsTestRule(MainActivity::class.java, true, false)
1919

20-
fun runCaseFor(sharedLink: String, title: String, subTitle: String) {
20+
private fun runCaseFor(sharedLink: String, title: String, subTitle: String) {
2121
val intent = Intent(Intent.ACTION_SEND).apply {
2222
putExtra(Intent.EXTRA_TEXT, sharedLink)
2323
}
@@ -43,6 +43,7 @@ class ShareLinkTest {
4343

4444
@Test
4545
fun linkContainsSpace() {
46+
// not a valid URI, skip generation
4647
runCaseFor("https://www.example.com/hello world", "", "")
4748
}
4849
}

app/src/main/java/com/amrdeveloper/linkhub/ui/link/LinkViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ class LinkViewModel @Inject constructor(
7373
}
7474
}
7575

76+
private fun isValidURI(url: String) =
77+
URLUtil.isValidUrl(url) && runCatching { URI(url) }.isSuccess
78+
7679
fun generateLinkTitleAndSubTitle(url: String) {
7780
viewModelScope.launch(Dispatchers.IO) {
78-
val isValidLink = URLUtil.isValidUrl(url) && runCatching { URI(url) }.isSuccess
79-
if (isValidLink.not()) return@launch
81+
if (isValidURI(url).not()) return@launch
8082
val linkInfo = generateLinkInfo(url)
8183
withContext(Dispatchers.Main) {
8284
linkInfoLiveData.value = linkInfo

0 commit comments

Comments
 (0)