|
| 1 | +@file:OptIn(ExperimentalMaterial3Api::class) |
| 2 | + |
| 3 | +package org.stypox.dicio.ui.about |
| 4 | + |
| 5 | +import androidx.annotation.StringRes |
| 6 | +import androidx.compose.foundation.Image |
| 7 | +import androidx.compose.foundation.clickable |
| 8 | +import androidx.compose.foundation.layout.Arrangement |
| 9 | +import androidx.compose.foundation.layout.Column |
| 10 | +import androidx.compose.foundation.layout.PaddingValues |
| 11 | +import androidx.compose.foundation.layout.Row |
| 12 | +import androidx.compose.foundation.layout.Spacer |
| 13 | +import androidx.compose.foundation.layout.fillMaxSize |
| 14 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 15 | +import androidx.compose.foundation.layout.height |
| 16 | +import androidx.compose.foundation.layout.padding |
| 17 | +import androidx.compose.foundation.layout.size |
| 18 | +import androidx.compose.foundation.layout.wrapContentSize |
| 19 | +import androidx.compose.foundation.lazy.LazyColumn |
| 20 | +import androidx.compose.material.icons.Icons |
| 21 | +import androidx.compose.material.icons.filled.BugReport |
| 22 | +import androidx.compose.material.icons.filled.Code |
| 23 | +import androidx.compose.material.icons.filled.ContentCopy |
| 24 | +import androidx.compose.material.icons.filled.Group |
| 25 | +import androidx.compose.material.icons.filled.Policy |
| 26 | +import androidx.compose.material3.ExperimentalMaterial3Api |
| 27 | +import androidx.compose.material3.Icon |
| 28 | +import androidx.compose.material3.MaterialTheme |
| 29 | +import androidx.compose.material3.Scaffold |
| 30 | +import androidx.compose.material3.Text |
| 31 | +import androidx.compose.material3.TopAppBar |
| 32 | +import androidx.compose.runtime.Composable |
| 33 | +import androidx.compose.ui.Alignment |
| 34 | +import androidx.compose.ui.Modifier |
| 35 | +import androidx.compose.ui.graphics.vector.ImageVector |
| 36 | +import androidx.compose.ui.platform.LocalContext |
| 37 | +import androidx.compose.ui.res.stringResource |
| 38 | +import androidx.compose.ui.text.font.FontWeight |
| 39 | +import androidx.compose.ui.text.style.TextAlign |
| 40 | +import androidx.compose.ui.tooling.preview.Preview |
| 41 | +import androidx.compose.ui.unit.dp |
| 42 | +import org.stypox.dicio.BuildConfig |
| 43 | +import org.stypox.dicio.R |
| 44 | +import org.stypox.dicio.error.ErrorActivity |
| 45 | +import org.stypox.dicio.settings.ui.SettingsItem |
| 46 | +import org.stypox.dicio.ui.theme.AppTheme |
| 47 | +import org.stypox.dicio.util.ShareUtils |
| 48 | + |
| 49 | +@Composable |
| 50 | +fun AboutScreen( |
| 51 | + navigationIcon: @Composable () -> Unit, |
| 52 | +) { |
| 53 | + val context = LocalContext.current |
| 54 | + |
| 55 | + Scaffold( |
| 56 | + topBar = { |
| 57 | + TopAppBar( |
| 58 | + title = { Text(stringResource(R.string.about)) }, |
| 59 | + navigationIcon = navigationIcon, |
| 60 | + ) |
| 61 | + }, |
| 62 | + ) { paddingValues -> |
| 63 | + LazyColumn( |
| 64 | + contentPadding = PaddingValues(bottom = 4.dp), |
| 65 | + modifier = Modifier.padding(paddingValues) |
| 66 | + ) { |
| 67 | + item { |
| 68 | + Column( |
| 69 | + modifier = Modifier |
| 70 | + .padding(start = 16.dp, end = 16.dp, bottom = 16.dp) |
| 71 | + .fillMaxWidth() |
| 72 | + .wrapContentSize(Alignment.Center), |
| 73 | + horizontalAlignment = Alignment.CenterHorizontally |
| 74 | + ) { |
| 75 | + Image( |
| 76 | + imageVector = DicioSquircleIcon, |
| 77 | + contentDescription = stringResource(R.string.app_name), |
| 78 | + modifier = Modifier.size(64.dp) |
| 79 | + ) |
| 80 | + Spacer(Modifier.height(4.dp)) |
| 81 | + Text( |
| 82 | + text = stringResource(R.string.app_name), |
| 83 | + style = MaterialTheme.typography.titleLarge, |
| 84 | + textAlign = TextAlign.Center |
| 85 | + ) |
| 86 | + val versionTextSizeUnit = MaterialTheme.typography.titleMedium.fontSize.value.dp |
| 87 | + Row( |
| 88 | + verticalAlignment = Alignment.CenterVertically, |
| 89 | + horizontalArrangement = Arrangement.spacedBy(versionTextSizeUnit * 0.25f), |
| 90 | + modifier = Modifier.clickable( |
| 91 | + onClickLabel = stringResource(R.string.about_version_copy) |
| 92 | + ) { ShareUtils.copyToClipboard(context, getVersionInfoString()) } |
| 93 | + ) { |
| 94 | + Text( |
| 95 | + text = stringResource( |
| 96 | + R.string.about_version, |
| 97 | + BuildConfig.VERSION_NAME, |
| 98 | + BuildConfig.VERSION_CODE |
| 99 | + ), |
| 100 | + style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Light), |
| 101 | + textAlign = TextAlign.Center |
| 102 | + ) |
| 103 | + Icon( |
| 104 | + imageVector = Icons.Default.ContentCopy, |
| 105 | + contentDescription = null, |
| 106 | + modifier = Modifier.size(versionTextSizeUnit * 0.8f) |
| 107 | + ) |
| 108 | + } |
| 109 | + Text( |
| 110 | + modifier = Modifier.fillMaxWidth(), |
| 111 | + text = stringResource(R.string.about_description), |
| 112 | + textAlign = TextAlign.Center |
| 113 | + ) |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + item { |
| 118 | + AboutItem( |
| 119 | + title = R.string.about_repository_title, |
| 120 | + icon = Icons.Default.Code, |
| 121 | + description = R.string.about_repository_description, |
| 122 | + link = R.string.about_repository_link |
| 123 | + ) |
| 124 | + } |
| 125 | + |
| 126 | + item { |
| 127 | + AboutItem( |
| 128 | + title = R.string.about_issues_title, |
| 129 | + icon = Icons.Default.BugReport, |
| 130 | + description = R.string.about_issues_description, |
| 131 | + link = R.string.about_issues_link |
| 132 | + ) |
| 133 | + } |
| 134 | + |
| 135 | + item { |
| 136 | + AboutItem( |
| 137 | + title = R.string.about_contributing_title, |
| 138 | + icon = Icons.Default.Group, |
| 139 | + description = R.string.about_contributing_description, |
| 140 | + link = R.string.about_contributing_link |
| 141 | + ) |
| 142 | + } |
| 143 | + |
| 144 | + item { |
| 145 | + AboutItem( |
| 146 | + title = R.string.about_privacy_title, |
| 147 | + icon = Icons.Default.Policy, |
| 148 | + description = R.string.about_privacy_description, |
| 149 | + link = R.string.about_privacy_link |
| 150 | + ) |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +@Composable |
| 157 | +fun AboutItem( |
| 158 | + @StringRes title: Int, |
| 159 | + icon: ImageVector, |
| 160 | + @StringRes description: Int, |
| 161 | + @StringRes link: Int |
| 162 | +) { |
| 163 | + val context = LocalContext.current |
| 164 | + SettingsItem( |
| 165 | + title = stringResource(title), |
| 166 | + icon = icon, |
| 167 | + description = stringResource(description), |
| 168 | + modifier = Modifier.clickable { |
| 169 | + ShareUtils.openUrlInBrowser(context, context.getString(link)) |
| 170 | + }, |
| 171 | + ) |
| 172 | +} |
| 173 | + |
| 174 | +private fun getVersionInfoString(): String { |
| 175 | + return "${BuildConfig.APPLICATION_ID} ${BuildConfig.VERSION_NAME} (" + |
| 176 | + "${BuildConfig.VERSION_CODE}) running on ${ErrorActivity.getOsInfo()}" |
| 177 | +} |
| 178 | + |
| 179 | +@Preview |
| 180 | +@Composable |
| 181 | +private fun AboutScreenPreview() { |
| 182 | + AppTheme { |
| 183 | + AboutScreen( |
| 184 | + navigationIcon = {}, |
| 185 | + ) |
| 186 | + } |
| 187 | +} |
0 commit comments