File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed
androidTest/java/com/amrdeveloper/linkhub
main/java/com/amrdeveloper/linkhub/ui/link Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments