Add DonationDialog

This commit is contained in:
Shinokuni 2024-08-06 17:40:28 +02:00
parent a2e2c04142
commit 22913aa129
5 changed files with 137 additions and 2 deletions

View File

@ -0,0 +1,113 @@
package com.readrops.app.more
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import com.readrops.app.R
import com.readrops.app.util.components.dialog.BaseDialog
import com.readrops.app.util.theme.MediumSpacer
import com.readrops.app.util.theme.spacing
@Composable
fun DonationDialog(
onDismiss: () -> Unit
) {
val uriHandler = LocalUriHandler.current
val clipboardManager = LocalClipboardManager.current
val context = LocalContext.current
BaseDialog(
title = stringResource(id = R.string.make_donation),
icon = painterResource(id = R.drawable.ic_donation),
onDismiss = onDismiss
) {
Column {
Text(
text = stringResource(R.string.donation_text)
)
MediumSpacer()
Box(
modifier = Modifier
.fillMaxWidth()
.clickable {
uriHandler.openUri(context.getString(R.string.paypal_url))
onDismiss()
}
) {
Text(
text = stringResource(R.string.paypal),
style = MaterialTheme.typography.titleMedium,
modifier = Modifier.padding(
horizontal = MaterialTheme.spacing.mediumSpacing,
vertical = MaterialTheme.spacing.shortSpacing
)
)
}
Box(
modifier = Modifier
.fillMaxWidth()
.clickable {
clipboardManager.setText(AnnotatedString(context.getString(R.string.bitcoin_address)))
Toast
.makeText(
context,
context.getString(R.string.bitcoin_address),
Toast.LENGTH_SHORT
)
.show()
onDismiss()
}
) {
Text(
text = stringResource(R.string.bitcoin_copy_address),
style = MaterialTheme.typography.titleMedium,
modifier = Modifier.padding(
horizontal = MaterialTheme.spacing.mediumSpacing,
vertical = MaterialTheme.spacing.shortSpacing
)
)
}
Box(
modifier = Modifier
.fillMaxWidth()
.clickable {
clipboardManager.setText(AnnotatedString(context.getString(R.string.litecoin_address)))
Toast
.makeText(
context,
context.getString(R.string.litecoin_address),
Toast.LENGTH_SHORT
)
.show()
onDismiss()
}
) {
Text(
text = stringResource(R.string.litecoin_copy_address),
style = MaterialTheme.typography.titleMedium,
modifier = Modifier.padding(
horizontal = MaterialTheme.spacing.mediumSpacing,
vertical = MaterialTheme.spacing.shortSpacing
)
)
}
}
}
}

View File

@ -13,6 +13,10 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
@ -52,6 +56,14 @@ object MoreTab : Tab, KoinComponent {
val navigator = LocalNavigator.currentOrThrow
val context = LocalContext.current
var showDonationDialog by remember { mutableStateOf(false) }
if (showDonationDialog) {
DonationDialog(
onDismiss = { showDonationDialog = false }
)
}
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
@ -159,7 +171,7 @@ object MoreTab : Tab, KoinComponent {
spacing = MaterialTheme.spacing.largeSpacing,
padding = MaterialTheme.spacing.mediumSpacing,
tint = MaterialTheme.colorScheme.primary,
onClick = { }
onClick = { showDonationDialog = true }
)
}
}

View File

@ -60,7 +60,7 @@ class CrashActivity : ComponentActivity() {
} catch (e: Exception) {
Log.e("CrashActivity", "Unable to get crash exception")
null
throwable?.let { it::class.simpleName + it.message }
}
setContent {

View File

@ -213,4 +213,7 @@
<string name="report_error_github">Signaler l\'erreur sur Github</string>
<string name="copy_error_clipboard">Copier l\'erreur dans le presse-papier</string>
<string name="copied">Copié !</string>
<string name="bitcoin_copy_address">Bitcoin (copier l\'adresse)</string>
<string name="litecoin_copy_address">Litecoin (copier l\'adresse)</string>
<string name="donation_text">"Si vous considérez que mon travail vous est utile et si vous souhaitez me soutenir, vous pouvez me faire une donation. "</string>
</resources>

View File

@ -222,4 +222,11 @@
<string name="report_error_github">Report the error on Github</string>
<string name="copy_error_clipboard">Copy error to clipboard</string>
<string name="copied">Copied!</string>
<string name="paypal" translatable="false">Paypal</string>
<string name="paypal_url" translatable="false">https://paypal.me/readropsapp</string>
<string name="bitcoin_address" translatable="false">bc1qlkzlcsvvtn3y6mek5umv5tc4ln09l64x6y42hr</string>
<string name="litecoin_address" translatable="false">MTuf45ZvxhMWWo4v8YBbFDTLsFcGtpcPNT</string>
<string name="bitcoin_copy_address">Bitcoin (copy address)</string>
<string name="litecoin_copy_address">Litecoin (copy address)</string>
<string name="donation_text">I you find my work useful and you would like to support me, you can consider making me a donation.</string>
</resources>