|
|
@ -23,22 +23,14 @@ class SharedReceiverActivity : AppCompatActivity() { |
|
|
|
when { |
|
|
|
when { |
|
|
|
Intent.ACTION_SEND == intent.action && intent.type == receivingType -> { |
|
|
|
Intent.ACTION_SEND == intent.action && intent.type == receivingType -> { |
|
|
|
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { |
|
|
|
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { |
|
|
|
if (openUrl(it)) { |
|
|
|
dispose(it) |
|
|
|
startActivity<SearchActivity> { |
|
|
|
|
|
|
|
putExtra("key", it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M |
|
|
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M |
|
|
|
&& Intent.ACTION_PROCESS_TEXT == intent.action |
|
|
|
&& Intent.ACTION_PROCESS_TEXT == intent.action |
|
|
|
&& intent.type == receivingType -> { |
|
|
|
&& intent.type == receivingType -> { |
|
|
|
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { |
|
|
|
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { |
|
|
|
if (openUrl(it)) { |
|
|
|
dispose(it) |
|
|
|
startActivity<SearchActivity> { |
|
|
|
|
|
|
|
putExtra("key", it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
intent.getStringExtra("action") == "readAloud" -> { |
|
|
|
intent.getStringExtra("action") == "readAloud" -> { |
|
|
@ -47,9 +39,9 @@ class SharedReceiverActivity : AppCompatActivity() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun openUrl(text: String): Boolean { |
|
|
|
private fun dispose(text: String) { |
|
|
|
if (text.isBlank()) { |
|
|
|
if (text.isBlank()) { |
|
|
|
return false |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
val urls = text.split("\\s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() |
|
|
|
val urls = text.split("\\s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() |
|
|
|
val result = StringBuilder() |
|
|
|
val result = StringBuilder() |
|
|
@ -57,11 +49,10 @@ class SharedReceiverActivity : AppCompatActivity() { |
|
|
|
if (url.matches("http.+".toRegex())) |
|
|
|
if (url.matches("http.+".toRegex())) |
|
|
|
result.append("\n").append(url.trim { it <= ' ' }) |
|
|
|
result.append("\n").append(url.trim { it <= ' ' }) |
|
|
|
} |
|
|
|
} |
|
|
|
return if (result.length > 1) { |
|
|
|
if (result.length > 1) { |
|
|
|
startActivity<MainActivity>() |
|
|
|
startActivity<MainActivity>() |
|
|
|
false |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
true |
|
|
|
SearchActivity.start(this, text) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |