Skip to content

Commit

Permalink
feat: provide text selection action (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenjacobs authored Jun 1, 2024
1 parent 4bfc838 commit 4637acd
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:supportsRtl="false"
android:theme="@style/Theme.App"
tools:targetApi="tiramisu">

<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -44,6 +45,17 @@
</intent-filter>
</activity>

<activity
android:name=".ProcessTextActivity"
android:exported="true"
android:label="@string/process_text_action_name">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<!-- Handle browser intents. -->
<!-- Disabled by default. Needs to be enabled in app settings. -->
<activity-alias
Expand Down
65 changes: 65 additions & 0 deletions app/src/main/kotlin/com/svenjacobs/app/leon/ProcessTextActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Léon - The URL Cleaner
* Copyright (C) 2024 Sven Jacobs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.svenjacobs.app.leon

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.annotation.RequiresApi
import com.svenjacobs.app.leon.core.domain.CleanerService
import kotlinx.coroutines.runBlocking

@RequiresApi(Build.VERSION_CODES.M)
class ProcessTextActivity : ComponentActivity() {

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

val text = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)?.toString()
val readonly = intent.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false)

when {
// If readonly, delegate to MainActivity
readonly -> startActivity(
Intent(this, MainActivity::class.java).apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, text)
},
)

text.isNullOrBlank() -> setResult(RESULT_CANCELED)

// Needs to run with runBlocking or else setResult() won't work
else -> runBlocking {
val result = CleanerService().clean(text)

setResult(
RESULT_OK,
Intent().apply {
putExtra(Intent.EXTRA_PROCESS_TEXT, result.cleanedText)
},
)
}
}

finish()
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
<string name="open_share_menu">Teilenmenü öffnen</string>
<string name="open_url">URL öffnen</string>
<string name="copy_to_clipboard">In Zwischenablage kopieren</string>
<string name="process_text_action_name">URL säubern (Léon)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
<string name="open_share_menu">Open share menu</string> <!-- TODO: translate -->
<string name="open_url">Open URL</string> <!-- TODO: translate -->
<string name="copy_to_clipboard">Copy to clipboard</string> <!-- TODO: translate -->
<string name="process_text_action_name">Clean URL (Léon)</string> <!-- TODO: translate -->
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
<string name="open_share_menu">Open share menu</string> <!-- TODO: translate -->
<string name="open_url">Open URL</string> <!-- TODO: translate -->
<string name="copy_to_clipboard">Copy to clipboard</string> <!-- TODO: translate -->
<string name="process_text_action_name">Clean URL (Léon)</string> <!-- TODO: translate -->
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
<string name="open_share_menu">Mở menu chia sẻ</string>
<string name="open_url">Mở URL</string>
<string name="copy_to_clipboard">Sao chép vào clipboard</string>
<string name="process_text_action_name">Clean URL (Léon)</string> <!-- TODO: translate -->
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
<string name="open_share_menu">Open share menu</string>
<string name="open_url">Open URL</string>
<string name="copy_to_clipboard">Copy to clipboard</string>
<string name="process_text_action_name">Clean URL (Léon)</string>
</resources>

0 comments on commit 4637acd

Please sign in to comment.