Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -392,7 +393,7 @@ private fun TopPartOfAddANewLinkDialogBox(
)
},
textStyle = MaterialTheme.typography.titleSmall,
singleLine = true,
singleLine = false,
shape = RoundedCornerShape(5.dp),
value = linkTextFieldValue.value,
onValueChange = {
Expand Down Expand Up @@ -890,37 +891,81 @@ 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) {
Constants.SAVED_LINKS_ID -> LinkType.SAVED_LINK
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ import kotlin.time.Clock
import kotlin.time.ExperimentalTime
import kotlin.time.Instant

fun extractUrls(text: String): List<String> {
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 <T> wrappedResultFlow(init: suspend (SendChannel<Result<T>>) -> T): Flow<Result<T>> {
return channelFlow {
send(Result.Loading())
Expand Down