|
| 1 | +package org.osservatorionessuno.bugbane |
| 2 | + |
| 3 | +import android.content.Intent |
| 4 | +import android.net.Uri |
| 5 | +import android.os.Bundle |
| 6 | +import androidx.activity.ComponentActivity |
| 7 | +import androidx.activity.compose.setContent |
| 8 | +import androidx.activity.enableEdgeToEdge |
| 9 | +import androidx.compose.foundation.layout.* |
| 10 | +import androidx.compose.foundation.rememberScrollState |
| 11 | +import androidx.compose.foundation.verticalScroll |
| 12 | +import androidx.compose.material.icons.Icons |
| 13 | +import androidx.compose.material.icons.automirrored.filled.ArrowBack |
| 14 | +import androidx.compose.material.icons.filled.Email |
| 15 | +import androidx.compose.material.icons.filled.Favorite |
| 16 | +import androidx.compose.material3.* |
| 17 | +import androidx.compose.runtime.* |
| 18 | +import androidx.compose.ui.Alignment |
| 19 | +import androidx.compose.ui.Modifier |
| 20 | +import androidx.compose.ui.platform.LocalContext |
| 21 | +import androidx.compose.ui.res.stringResource |
| 22 | +import androidx.compose.ui.text.font.FontWeight |
| 23 | +import androidx.compose.ui.unit.dp |
| 24 | +import org.osservatorionessuno.bugbane.ui.theme.Theme |
| 25 | + |
| 26 | +class AboutActivity : ComponentActivity() { |
| 27 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 28 | + super.onCreate(savedInstanceState) |
| 29 | + |
| 30 | + enableEdgeToEdge() |
| 31 | + setContent { |
| 32 | + Theme { |
| 33 | + AboutContent() |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +@OptIn(ExperimentalMaterial3Api::class) |
| 40 | +@Composable |
| 41 | +fun AboutContent() { |
| 42 | + val context = LocalContext.current |
| 43 | + |
| 44 | + val contactUrl = stringResource(R.string.about_contact_url) |
| 45 | + val donateUrl = stringResource(R.string.about_donate_url) |
| 46 | + |
| 47 | + Scaffold( |
| 48 | + topBar = { |
| 49 | + TopAppBar( |
| 50 | + title = { Text(stringResource(R.string.about_title)) }, |
| 51 | + navigationIcon = { |
| 52 | + IconButton(onClick = { (context as? ComponentActivity)?.finish() }) { |
| 53 | + Icon( |
| 54 | + imageVector = Icons.AutoMirrored.Filled.ArrowBack, |
| 55 | + contentDescription = "Back" |
| 56 | + ) |
| 57 | + } |
| 58 | + }, |
| 59 | + colors = TopAppBarDefaults.topAppBarColors( |
| 60 | + containerColor = MaterialTheme.colorScheme.primary, |
| 61 | + titleContentColor = MaterialTheme.colorScheme.onPrimary, |
| 62 | + navigationIconContentColor = MaterialTheme.colorScheme.onPrimary |
| 63 | + ) |
| 64 | + ) |
| 65 | + } |
| 66 | + ) { padding -> |
| 67 | + Column( |
| 68 | + modifier = Modifier |
| 69 | + .fillMaxSize() |
| 70 | + .padding(padding) |
| 71 | + .padding(16.dp) |
| 72 | + .verticalScroll(rememberScrollState()), |
| 73 | + verticalArrangement = Arrangement.spacedBy(16.dp) |
| 74 | + ) { |
| 75 | + Card( |
| 76 | + modifier = Modifier.fillMaxWidth(), |
| 77 | + elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) |
| 78 | + ) { |
| 79 | + Column( |
| 80 | + modifier = Modifier.padding(20.dp) |
| 81 | + ) { |
| 82 | + Text( |
| 83 | + text = stringResource(R.string.about_organization_title), |
| 84 | + style = MaterialTheme.typography.headlineSmall, |
| 85 | + fontWeight = FontWeight.Bold |
| 86 | + ) |
| 87 | + Spacer(modifier = Modifier.height(8.dp)) |
| 88 | + Text( |
| 89 | + text = stringResource(R.string.about_organization_description), |
| 90 | + style = MaterialTheme.typography.bodyMedium, |
| 91 | + lineHeight = MaterialTheme.typography.bodyMedium.lineHeight * 1.2 |
| 92 | + ) |
| 93 | + Spacer(modifier = Modifier.height(12.dp)) |
| 94 | + Button( |
| 95 | + onClick = { |
| 96 | + val intent = Intent(Intent.ACTION_VIEW).apply { |
| 97 | + data = Uri.parse(contactUrl) |
| 98 | + } |
| 99 | + context.startActivity(intent) |
| 100 | + }, |
| 101 | + modifier = Modifier.fillMaxWidth(), |
| 102 | + colors = ButtonDefaults.buttonColors( |
| 103 | + containerColor = MaterialTheme.colorScheme.secondary, |
| 104 | + contentColor = MaterialTheme.colorScheme.onSecondary |
| 105 | + ) |
| 106 | + ) { |
| 107 | + Icon( |
| 108 | + imageVector = Icons.Default.Email, |
| 109 | + contentDescription = null, |
| 110 | + modifier = Modifier.size(20.dp) |
| 111 | + ) |
| 112 | + Spacer(modifier = Modifier.width(8.dp)) |
| 113 | + Text( |
| 114 | + text = stringResource(R.string.about_contact_button), |
| 115 | + style = MaterialTheme.typography.bodyLarge.copy( |
| 116 | + fontWeight = FontWeight.Medium |
| 117 | + ) |
| 118 | + ) |
| 119 | + } |
| 120 | + Button( |
| 121 | + onClick = { |
| 122 | + val intent = Intent(Intent.ACTION_VIEW).apply { |
| 123 | + data = Uri.parse(donateUrl) |
| 124 | + } |
| 125 | + context.startActivity(intent) |
| 126 | + }, |
| 127 | + modifier = Modifier.fillMaxWidth(), |
| 128 | + colors = ButtonDefaults.buttonColors( |
| 129 | + containerColor = MaterialTheme.colorScheme.error, |
| 130 | + contentColor = MaterialTheme.colorScheme.onError |
| 131 | + ) |
| 132 | + ) { |
| 133 | + Icon( |
| 134 | + imageVector = Icons.Default.Favorite, |
| 135 | + contentDescription = null, |
| 136 | + modifier = Modifier.size(20.dp) |
| 137 | + ) |
| 138 | + Spacer(modifier = Modifier.width(8.dp)) |
| 139 | + Text( |
| 140 | + text = stringResource(R.string.about_donate_button), |
| 141 | + style = MaterialTheme.typography.bodyLarge.copy( |
| 142 | + fontWeight = FontWeight.Medium |
| 143 | + ) |
| 144 | + ) |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | +} |
0 commit comments