Skip to content

Commit

Permalink
Remove texts shared/copied along with links before copy to clipboard
Browse files Browse the repository at this point in the history
Now remove additional text (usually from the marketplace) to just copy the link to the clipboard.

Example:

> Look at this incredible product I found: https:/market/product

To:

> https:/market/product
  • Loading branch information
WSTxda committed Nov 3, 2024
1 parent b714994 commit fa96460
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import com.wstxda.clippy.R
import com.wstxda.clippy.cleaner.tools.TextCleaner

abstract class ClipboardLinkActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val action = intent.action
val sharedLink = when {
action == Intent.ACTION_PROCESS_TEXT -> intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)
?.trim()

action == Intent.ACTION_SEND -> intent.getStringExtra(Intent.EXTRA_TEXT)?.trim()
val sharedLink = when (action) {
Intent.ACTION_PROCESS_TEXT -> intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.trim()
Intent.ACTION_SEND -> intent.getStringExtra(Intent.EXTRA_TEXT)?.trim()
?: intent.getStringExtra(Intent.EXTRA_SUBJECT)?.trim()

else -> null
Expand All @@ -29,8 +28,10 @@ abstract class ClipboardLinkActivity : AppCompatActivity() {
}

private fun handleLink(sharedLink: String?) {
if (!sharedLink.isNullOrEmpty()) {
processLink(sharedLink)
val extractedLink = sharedLink?.let { TextCleaner.extractUrl(it) }

if (!extractedLink.isNullOrEmpty()) {
processLink(extractedLink)
} else {
showToast(getString(R.string.copy_failure))
finishActivity()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wstxda.clippy.cleaner.provider

object TextRegexProvider {
val urlRegex = """(https?://\S+)""".toRegex()
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/wstxda/clippy/cleaner/tools/TextCleaner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wstxda.clippy.cleaner.tools

import com.wstxda.clippy.cleaner.provider.TextRegexProvider

object TextCleaner {

fun extractUrl(text: String): String? {
return TextRegexProvider.urlRegex.find(text)?.value
}
}

0 comments on commit fa96460

Please sign in to comment.