-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide text selection action (#410)
- Loading branch information
1 parent
4bfc838
commit 4637acd
Showing
7 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/kotlin/com/svenjacobs/app/leon/ProcessTextActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters