diff --git a/composeApp/src/androidMain/kotlin/com/sakethh/linkora/ShareToSaveActivity.kt b/composeApp/src/androidMain/kotlin/com/sakethh/linkora/ShareToSaveActivity.kt index c797c6501..c24f50437 100644 --- a/composeApp/src/androidMain/kotlin/com/sakethh/linkora/ShareToSaveActivity.kt +++ b/composeApp/src/androidMain/kotlin/com/sakethh/linkora/ShareToSaveActivity.kt @@ -157,6 +157,32 @@ class ShareToSaveActivity : ComponentActivity() { colorScheme = colors, preferredFont = preferences.selectedFont ) { + var sharedUrls = this@ShareToSaveActivity.intent?.getStringExtra( + Intent.EXTRA_TEXT + ).toString().lines(); + + var url = "" + var title = "" + + if(sharedUrls.size > 1) { + var urlStringForDialogBox = sharedUrls[0].toString() + + for (i in 1 until sharedUrls.size) { + urlStringForDialogBox += "\n\n" + urlStringForDialogBox += sharedUrls[i].toString() + } + + url = urlStringForDialogBox + preferences.forceSaveWithoutFetchingAnyMetaData = true + }else{ + url = this@ShareToSaveActivity.intent?.getStringExtra( + Intent.EXTRA_TEXT + ).toString() + title = this@ShareToSaveActivity.intent?.getStringExtra( + Intent.EXTRA_SUBJECT + ) ?: "" + } + AddANewLinkDialogBox( preferences = preferences, addNewLinkDialogParams = AddNewLinkDialogParams( @@ -180,12 +206,8 @@ class ShareToSaveActivity : ComponentActivity() { foldersSearchQueryResult = collectionsScreenVM.foldersSearchQueryResult, rootRegularFolders = collectionsScreenVM.rootRegularFolders, performAction = collectionsScreenVM::performAction, - url = this@ShareToSaveActivity.intent?.getStringExtra( - Intent.EXTRA_TEXT - ).toString(), - title = this@ShareToSaveActivity.intent?.getStringExtra( - Intent.EXTRA_SUBJECT - ) ?: "" + url = url, + title = title ), ) } diff --git a/composeApp/src/commonMain/kotlin/com/sakethh/linkora/domain/AppPreferences.kt b/composeApp/src/commonMain/kotlin/com/sakethh/linkora/domain/AppPreferences.kt index 765d2dafa..fb1969b97 100644 --- a/composeApp/src/commonMain/kotlin/com/sakethh/linkora/domain/AppPreferences.kt +++ b/composeApp/src/commonMain/kotlin/com/sakethh/linkora/domain/AppPreferences.kt @@ -34,7 +34,7 @@ data class AppPreferences( val showTitleInLinkGridView: Boolean = true, val showHostInLinkListView: Boolean = true, val enableFadedEdgeForNonListViews: Boolean = true, - val forceSaveWithoutFetchingAnyMetaData: Boolean = false, + var forceSaveWithoutFetchingAnyMetaData: Boolean = false, val skipSavingExistingLink: Boolean = true, val useProxy: Boolean = platform == Platform.Web, val proxyUrl: String = Constants.PROXY_SERVER_URL, diff --git a/composeApp/src/commonMain/kotlin/com/sakethh/linkora/ui/components/AddANewLinkDialogBox.kt b/composeApp/src/commonMain/kotlin/com/sakethh/linkora/ui/components/AddANewLinkDialogBox.kt index 25d02411b..54ffea94a 100644 --- a/composeApp/src/commonMain/kotlin/com/sakethh/linkora/ui/components/AddANewLinkDialogBox.kt +++ b/composeApp/src/commonMain/kotlin/com/sakethh/linkora/ui/components/AddANewLinkDialogBox.kt @@ -134,6 +134,7 @@ import com.sakethh.linkora.utils.booleanPreferencesKey import com.sakethh.linkora.utils.defaultFolderIds import com.sakethh.linkora.utils.defaultImpLinksFolder import com.sakethh.linkora.utils.defaultSavedLinksFolder +import com.sakethh.linkora.utils.extractUrls import com.sakethh.linkora.utils.getLocalizedString import com.sakethh.linkora.utils.pushSnackbarOnFailure import com.sakethh.linkora.utils.rememberLocalizedString @@ -392,7 +393,7 @@ private fun TopPartOfAddANewLinkDialogBox( ) }, textStyle = MaterialTheme.typography.titleSmall, - singleLine = true, + singleLine = false, shape = RoundedCornerShape(5.dp), value = linkTextFieldValue.value, onValueChange = { @@ -890,6 +891,10 @@ private fun BottomPartOfAddANewLinkDialogBox( end = 20.dp, top = 10.dp, start = 20.dp ).fillMaxWidth().pressScaleEffect(), onClick = { + + val splitLinkTextFieldValue = linkTextFieldValue.value.split("\n"); + val numUrls = splitLinkTextFieldValue.size + isDataExtractingForTheLink.value = true val linkType = when (currentFolder?.localId ?: selectedFolderForSavingTheLink.value.localId) { @@ -897,30 +902,70 @@ private fun BottomPartOfAddANewLinkDialogBox( Constants.IMPORTANT_LINKS_ID -> LinkType.IMPORTANT_LINK else -> LinkType.FOLDER_LINK } - performAction( - AddANewLinkDialogBoxAction.AddANewLink( - link = Link( - linkType = linkType, - title = titleTextFieldValue.value.trim(), - url = linkTextFieldValue.value.trim(), - imgURL = imgUrlTextFieldValue.value.trim(), - note = noteTextFieldValue.value, - idOfLinkedFolder = currentFolder?.localId - ?: selectedFolderForSavingTheLink.value.localId, - userAgent = preferences.primaryJsoupUserAgent - ), - linkSaveConfig = LinkSaveConfig( - forceAutoDetectTitle = isAutoDetectTitleEnabled.value || preferences.isAutoDetectTitleForLinksEnabled, - forceSaveWithoutRetrievingData = isForceSaveWithoutFetchingMetaDataEnabled.value || preferences.forceSaveWithoutFetchingAnyMetaData, - useProxy = preferences.useProxy, - skipSavingIfExists = preferences.skipSavingExistingLink, - forceSaveIfRetrievalFails = preferences.forceSaveIfRetrievalFails - ), - onCompletion = onDismiss, - selectedTags = selectedTags, - pushSnackbarOnSuccess = true + if(numUrls == 1){ + performAction( + AddANewLinkDialogBoxAction.AddANewLink( + link = Link( + linkType = linkType, + title = titleTextFieldValue.value.trim(), + url = linkTextFieldValue.value.trim(), + imgURL = imgUrlTextFieldValue.value.trim(), + note = noteTextFieldValue.value, + idOfLinkedFolder = currentFolder?.localId + ?: selectedFolderForSavingTheLink.value.localId, + userAgent = preferences.primaryJsoupUserAgent + ), + linkSaveConfig = LinkSaveConfig( + forceAutoDetectTitle = isAutoDetectTitleEnabled.value || preferences.isAutoDetectTitleForLinksEnabled, + forceSaveWithoutRetrievingData = isForceSaveWithoutFetchingMetaDataEnabled.value || preferences.forceSaveWithoutFetchingAnyMetaData, + useProxy = preferences.useProxy, + skipSavingIfExists = preferences.skipSavingExistingLink, + forceSaveIfRetrievalFails = preferences.forceSaveIfRetrievalFails + ), + onCompletion = onDismiss, + selectedTags = selectedTags, + pushSnackbarOnSuccess = true + ) ) - ) + } + else { + for (linkTextField in splitLinkTextFieldValue) { + if (linkTextField == "") { + continue; + } + + var extractedUrls = extractUrls(linkTextField) + + for (extractedUrl in extractedUrls) { + var url = extractedUrl.trim() + + performAction( + AddANewLinkDialogBoxAction.AddANewLink( + link = Link( + linkType = linkType, + title = titleTextFieldValue.value.trim(), + url = url, + imgURL = imgUrlTextFieldValue.value.trim(), + note = noteTextFieldValue.value, + idOfLinkedFolder = currentFolder?.localId + ?: selectedFolderForSavingTheLink.value.localId, + userAgent = preferences.primaryJsoupUserAgent + ), + linkSaveConfig = LinkSaveConfig( + forceAutoDetectTitle = false, + forceSaveWithoutRetrievingData = true, + useProxy = preferences.useProxy, + skipSavingIfExists = preferences.skipSavingExistingLink, + forceSaveIfRetrievalFails = preferences.forceSaveIfRetrievalFails + ), + onCompletion = onDismiss, + selectedTags = selectedTags, + pushSnackbarOnSuccess = true + ) + ) + } + } + } }) { Text( text = Localization.rememberLocalizedString(Localization.Key.Save), diff --git a/composeApp/src/commonMain/kotlin/com/sakethh/linkora/utils/RegularFunctions.kt b/composeApp/src/commonMain/kotlin/com/sakethh/linkora/utils/RegularFunctions.kt index 7e6b1e7d0..31fa118c3 100644 --- a/composeApp/src/commonMain/kotlin/com/sakethh/linkora/utils/RegularFunctions.kt +++ b/composeApp/src/commonMain/kotlin/com/sakethh/linkora/utils/RegularFunctions.kt @@ -33,6 +33,17 @@ import kotlin.time.Clock import kotlin.time.ExperimentalTime import kotlin.time.Instant +fun extractUrls(text: String): List { + if (text.isBlank()) return emptyList() + + val urlPattern = Regex( + "(https?|ftp)://[\\w-]+(\\.[\\w-]+)+([\\w.,@?^=%&:/~+#-]*)?", + RegexOption.IGNORE_CASE + ) + + return urlPattern.findAll(text).map { it.value }.toList() +} + fun wrappedResultFlow(init: suspend (SendChannel>) -> T): Flow> { return channelFlow { send(Result.Loading())