Skip to content

Commit

Permalink
Add "copy to clipboard" functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
svenjacobs committed Jun 5, 2022
1 parent 6131e0f commit f6c9a02
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ android {
applicationId = "com.svenjacobs.app.leon"
minSdk = 21
targetSdk = 32
versionCode = 231
versionName = "0.8.0"
versionCode = 232
versionName = "0.9.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.svenjacobs.app.leon.ui.theme.AppTheme
fun HomeScreen(
result: CleaningResult,
onShareButtonClick: (CleaningResult.Success) -> Unit,
onCopyToClipboardClick: (CleaningResult.Success) -> Unit,
onVerifyButtonClick: (CleaningResult.Success) -> Unit,
) {
Column(
Expand Down Expand Up @@ -67,6 +68,7 @@ fun HomeScreen(
result = res,
onShareButtonClick = onShareButtonClick,
onVerifyButtonClick = onVerifyButtonClick,
onCopyToClipboardClick = onCopyToClipboardClick,
)
is CleaningResult.Failure -> FailureBody()
}
Expand All @@ -92,6 +94,7 @@ private fun Statistics(result: CleaningResult.Success) {
private fun SuccessBody(
result: CleaningResult.Success,
onShareButtonClick: (CleaningResult.Success) -> Unit,
onCopyToClipboardClick: (CleaningResult.Success) -> Unit,
onVerifyButtonClick: (CleaningResult.Success) -> Unit,
) {
Column {
Expand Down Expand Up @@ -121,11 +124,23 @@ private fun SuccessBody(
text = stringResource(R.string.share),
)
}

TextButton(
modifier = Modifier
.weight(1f)
.padding(8.dp),
onClick = { onCopyToClipboardClick(result) },
) {
Text(
text = stringResource(R.string.copy),
)
}

TextButton(
modifier = Modifier
.weight(1f)
.padding(8.dp),
onClick = { onVerifyButtonClick(result) }
onClick = { onVerifyButtonClick(result) },
) {
Text(
text = stringResource(R.string.verify),
Expand Down Expand Up @@ -184,6 +199,7 @@ private fun SuccessBodyPreview() {
),
onShareButtonClick = {},
onVerifyButtonClick = {},
onCopyToClipboardClick = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
Expand All @@ -52,6 +52,7 @@ import com.svenjacobs.app.leon.ui.screens.main.model.Screen
import com.svenjacobs.app.leon.ui.screens.settings.SettingsParametersScreen
import com.svenjacobs.app.leon.ui.screens.settings.SettingsScreen
import com.svenjacobs.app.leon.ui.theme.AppTheme
import kotlinx.coroutines.launch

@Composable
@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -71,13 +72,17 @@ fun MainScreen(
intent.launchUrl(context, Uri.parse(result.urls.first()))
}

val navController = rememberNavController()
val isBackVisible by viewModel.isBackVisible.collectAsState()
val navController = rememberNavController()
val snackbarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
val clipboard = LocalClipboardManager.current

AppTheme {
Scaffold(
topBar = { MyTopAppBar(isBackVisible, navController) },
bottomBar = { MyBottomBar(navController) },
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
content = { padding ->
Box(
modifier = Modifier.padding(
Expand All @@ -98,6 +103,12 @@ fun MainScreen(
HomeScreen(
result = result,
onShareButtonClick = ::onShareButtonClick,
onCopyToClipboardClick = { result ->
clipboard.setText(AnnotatedString(result.cleanedText))
coroutineScope.launch {
snackbarHostState.showSnackbar(context.getString(R.string.clipboard_message))
}
},
onVerifyButtonClick = ::onVerifyButtonClick,
)
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/play/release-notes/de-DE/default.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Reiniger für Flipkart hinzugefügt
- "In Zwischenablage kopieren" Funktion hinzugefügt
- Material You Design
3 changes: 2 additions & 1 deletion app/src/main/play/release-notes/en-US/default.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Add sanitizer for Flipkart
- Add "copy to clipboard" functionality
- Material You design
20 changes: 20 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
<!--
~ Léon - The URL Cleaner
~ Copyright (C) 2022 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/>.
-->

<resources>
<string name="screen_home">Start</string>
<string name="screen_settings">Einstellungen</string>
<string name="scaffold_title">Léon – Der URL Cleaner (Beta)</string>
<string name="share">Teilen</string>
<string name="verify">Überprüfen</string>
<string name="copy">Kopieren</string>
<string name="clipboard_message">Link in Zwischenablage kopiert</string>
<string name="how_to_title">Anleitung</string>
<string name="how_to_text">Wähle die App \"URL Cleaner\" beim Teilen von Text aus. Klicke anschließend in dieser App auf \"Teilen\", um den Text an die Ziel-App zu schicken.</string>
<plurals name="statistics_parameters">
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
<!--
~ Léon - The URL Cleaner
~ Copyright (C) 2022 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/>.
-->

<resources>
<string name="app_name" translatable="false">URL Cleaner</string>
<string name="screen_home">Home</string>
<string name="screen_settings">Settings</string>
<string name="scaffold_title">Léon – The URL Cleaner (Beta)</string>
<string name="share">Share</string>
<string name="verify">Verify</string>
<string name="copy">Copy</string>
<string name="clipboard_message">Link copied to clipboard</string>
<string name="how_to_title">How-to</string>
<string name="how_to_text">When sharing text, choose \"URL Cleaner\". Then click on \"Share\" in this app to send text to target app.</string>
<plurals name="statistics_parameters">
Expand Down

0 comments on commit f6c9a02

Please sign in to comment.