diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2ca759f4..30231283 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,6 +29,7 @@ android:supportsRtl="false" android:theme="@style/Theme.App" tools:targetApi="tiramisu"> + + + + + + + + + . + */ + +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() + } +} diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0ce8d0e5..5b59b973 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -43,4 +43,5 @@ Teilenmenü öffnen URL öffnen In Zwischenablage kopieren + URL säubern (Léon) diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 734f9c52..0c0db30e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -43,4 +43,5 @@ Open share menu Open URL Copy to clipboard + Clean URL (Léon) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 28f4fda1..c627ce97 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -43,4 +43,5 @@ Open share menu Open URL Copy to clipboard + Clean URL (Léon) diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 0f238807..fddb8248 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -44,4 +44,5 @@ Mở menu chia sẻ Mở URL Sao chép vào clipboard + Clean URL (Léon) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ebe5f0bd..6737b0f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,4 +44,5 @@ Open share menu Open URL Copy to clipboard + Clean URL (Léon)