Skip to content

Commit 4637acd

Browse files
authored
feat: provide text selection action (#410)
1 parent 4bfc838 commit 4637acd

File tree

7 files changed

+82
-0
lines changed

7 files changed

+82
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
android:supportsRtl="false"
3030
android:theme="@style/Theme.App"
3131
tools:targetApi="tiramisu">
32+
3233
<activity
3334
android:name=".MainActivity"
3435
android:exported="true"
@@ -44,6 +45,17 @@
4445
</intent-filter>
4546
</activity>
4647

48+
<activity
49+
android:name=".ProcessTextActivity"
50+
android:exported="true"
51+
android:label="@string/process_text_action_name">
52+
<intent-filter>
53+
<action android:name="android.intent.action.PROCESS_TEXT" />
54+
<category android:name="android.intent.category.DEFAULT" />
55+
<data android:mimeType="text/plain" />
56+
</intent-filter>
57+
</activity>
58+
4759
<!-- Handle browser intents. -->
4860
<!-- Disabled by default. Needs to be enabled in app settings. -->
4961
<activity-alias
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Léon - The URL Cleaner
3+
* Copyright (C) 2024 Sven Jacobs
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.svenjacobs.app.leon
20+
21+
import android.content.Intent
22+
import android.os.Build
23+
import android.os.Bundle
24+
import androidx.activity.ComponentActivity
25+
import androidx.annotation.RequiresApi
26+
import com.svenjacobs.app.leon.core.domain.CleanerService
27+
import kotlinx.coroutines.runBlocking
28+
29+
@RequiresApi(Build.VERSION_CODES.M)
30+
class ProcessTextActivity : ComponentActivity() {
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
35+
val text = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)?.toString()
36+
val readonly = intent.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false)
37+
38+
when {
39+
// If readonly, delegate to MainActivity
40+
readonly -> startActivity(
41+
Intent(this, MainActivity::class.java).apply {
42+
action = Intent.ACTION_SEND
43+
type = "text/plain"
44+
putExtra(Intent.EXTRA_TEXT, text)
45+
},
46+
)
47+
48+
text.isNullOrBlank() -> setResult(RESULT_CANCELED)
49+
50+
// Needs to run with runBlocking or else setResult() won't work
51+
else -> runBlocking {
52+
val result = CleanerService().clean(text)
53+
54+
setResult(
55+
RESULT_OK,
56+
Intent().apply {
57+
putExtra(Intent.EXTRA_PROCESS_TEXT, result.cleanedText)
58+
},
59+
)
60+
}
61+
}
62+
63+
finish()
64+
}
65+
}

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@
4343
<string name="open_share_menu">Teilenmenü öffnen</string>
4444
<string name="open_url">URL öffnen</string>
4545
<string name="copy_to_clipboard">In Zwischenablage kopieren</string>
46+
<string name="process_text_action_name">URL säubern (Léon)</string>
4647
</resources>

app/src/main/res/values-pl/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@
4343
<string name="open_share_menu">Open share menu</string> <!-- TODO: translate -->
4444
<string name="open_url">Open URL</string> <!-- TODO: translate -->
4545
<string name="copy_to_clipboard">Copy to clipboard</string> <!-- TODO: translate -->
46+
<string name="process_text_action_name">Clean URL (Léon)</string> <!-- TODO: translate -->
4647
</resources>

app/src/main/res/values-ru/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@
4343
<string name="open_share_menu">Open share menu</string> <!-- TODO: translate -->
4444
<string name="open_url">Open URL</string> <!-- TODO: translate -->
4545
<string name="copy_to_clipboard">Copy to clipboard</string> <!-- TODO: translate -->
46+
<string name="process_text_action_name">Clean URL (Léon)</string> <!-- TODO: translate -->
4647
</resources>

app/src/main/res/values-vi/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@
4444
<string name="open_share_menu">Mở menu chia sẻ</string>
4545
<string name="open_url">Mở URL</string>
4646
<string name="copy_to_clipboard">Sao chép vào clipboard</string>
47+
<string name="process_text_action_name">Clean URL (Léon)</string> <!-- TODO: translate -->
4748
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@
4444
<string name="open_share_menu">Open share menu</string>
4545
<string name="open_url">Open URL</string>
4646
<string name="copy_to_clipboard">Copy to clipboard</string>
47+
<string name="process_text_action_name">Clean URL (Léon)</string>
4748
</resources>

0 commit comments

Comments
 (0)