compose: Pass painter instead of drawables
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -29,7 +29,7 @@ import com.aurora.store.R
|
||||
/**
|
||||
* Composable to show error message when no apps are available for a request
|
||||
* @param modifier The modifier to be applied to the composable
|
||||
* @param icon Drawable for error
|
||||
* @param painter Painter to draw the icon
|
||||
* @param message Message for error
|
||||
* @param actionMessage Message to show on action button; defaults to null with button not visible
|
||||
* @param onAction Callback when action button is clicked
|
||||
@@ -37,7 +37,7 @@ import com.aurora.store.R
|
||||
@Composable
|
||||
fun ErrorComposable(
|
||||
modifier: Modifier = Modifier,
|
||||
icon: Painter,
|
||||
painter: Painter,
|
||||
message: String,
|
||||
actionMessage: String? = null,
|
||||
onAction: () -> Unit = {}
|
||||
@@ -53,7 +53,7 @@ fun ErrorComposable(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Icon(
|
||||
painter = icon,
|
||||
painter = painter,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.requiredSize(dimensionResource(R.dimen.icon_size))
|
||||
)
|
||||
@@ -79,7 +79,7 @@ fun ErrorComposable(
|
||||
@Composable
|
||||
private fun ErrorComposablePreview() {
|
||||
ErrorComposable(
|
||||
icon = painterResource(R.drawable.ic_updates),
|
||||
painter = painterResource(R.drawable.ic_updates),
|
||||
message = stringResource(R.string.details_no_updates),
|
||||
actionMessage = stringResource(R.string.check_updates)
|
||||
)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package com.aurora.store.compose.composables
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -18,6 +17,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -35,7 +35,7 @@ import com.aurora.store.compose.preview.AppPreviewProvider
|
||||
* @param modifier The modifier to be applied to the composable
|
||||
* @param title Title of the information
|
||||
* @param description Information to show
|
||||
* @param icon Optional icon representing the information
|
||||
* @param painter Optional painter to draw the icon
|
||||
* @param onClick Callback when this composable is clicked
|
||||
*/
|
||||
@Composable
|
||||
@@ -43,7 +43,7 @@ fun InfoComposable(
|
||||
modifier: Modifier = Modifier,
|
||||
title: AnnotatedString,
|
||||
description: AnnotatedString? = null,
|
||||
@DrawableRes icon: Int? = null,
|
||||
painter: Painter? = null,
|
||||
onClick: (() -> Unit)? = null
|
||||
) {
|
||||
Row(
|
||||
@@ -57,7 +57,7 @@ fun InfoComposable(
|
||||
horizontalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.margin_normal)),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (icon != null) Icon(painter = painterResource(icon), contentDescription = null)
|
||||
if (painter != null) Icon(painter = painter, contentDescription = null)
|
||||
Column(modifier = Modifier.weight(1F)) {
|
||||
Text(
|
||||
text = title,
|
||||
@@ -82,6 +82,6 @@ private fun InfoComposablePreview(@PreviewParameter(AppPreviewProvider::class) a
|
||||
InfoComposable(
|
||||
title = AnnotatedString(text = stringResource(R.string.details_dev_website)),
|
||||
description = AnnotatedString.fromHtml(htmlString = app.developerWebsite),
|
||||
icon = R.drawable.ic_network
|
||||
painter = painterResource(R.drawable.ic_network)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -33,11 +33,7 @@ import com.aurora.store.R
|
||||
* @param currentPage Currently displayed page number
|
||||
*/
|
||||
@Composable
|
||||
fun PageIndicatorComposable(
|
||||
modifier: Modifier = Modifier,
|
||||
totalPages: Int,
|
||||
currentPage: Int = 0,
|
||||
) {
|
||||
fun PageIndicatorComposable(modifier: Modifier = Modifier, totalPages: Int, currentPage: Int = 0) {
|
||||
Row(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
||||
@@ -5,49 +5,46 @@
|
||||
|
||||
package com.aurora.store.compose.composables.app
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.compose.preview.AppPreviewProvider
|
||||
|
||||
/**
|
||||
* Composable to show a tag related to an app
|
||||
* @param modifier The modifier to be applied to the composable
|
||||
* @param label Label of the tag
|
||||
* @param icon Icon of the tag
|
||||
* @param painter Painter to draw the icon
|
||||
* @param onClick Callback when this composable is clicked
|
||||
*/
|
||||
@Composable
|
||||
fun AppTagComposable(
|
||||
modifier: Modifier = Modifier,
|
||||
label: String,
|
||||
@DrawableRes icon: Int,
|
||||
painter: Painter,
|
||||
onClick: () -> Unit = {}
|
||||
) {
|
||||
FilterChip(
|
||||
modifier = modifier,
|
||||
onClick = onClick,
|
||||
label = { Text(text = label, style = MaterialTheme.typography.bodySmall) },
|
||||
leadingIcon = { Icon(painter = painterResource(icon), contentDescription = label) },
|
||||
leadingIcon = { Icon(painter = painter, contentDescription = label) },
|
||||
selected = true
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun AppTagComposablePreview(@PreviewParameter(AppPreviewProvider::class) app: App) {
|
||||
private fun AppTagComposablePreview() {
|
||||
AppTagComposable(
|
||||
label = stringResource(R.string.details_free),
|
||||
icon = R.drawable.ic_paid
|
||||
painter = painterResource(R.drawable.ic_paid)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ private fun ScreenContentError(onNavigateUp: () -> Unit = {}, message: String? =
|
||||
) { paddingValues ->
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_apps_outage),
|
||||
painter = painterResource(R.drawable.ic_apps_outage),
|
||||
message = message ?: stringResource(R.string.toast_app_unavailable)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.TextRange
|
||||
@@ -145,7 +146,7 @@ private fun ScreenContent(
|
||||
verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.margin_medium))
|
||||
) {
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_download_manager,
|
||||
painter = painterResource(R.drawable.ic_download_manager),
|
||||
title = AnnotatedString(text = stringResource(R.string.manual_download_hint))
|
||||
)
|
||||
OutlinedTextField(
|
||||
|
||||
@@ -116,7 +116,7 @@ private fun ScreenContent(
|
||||
is LoadState.Error -> {
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_disclaimer),
|
||||
painter = painterResource(R.drawable.ic_disclaimer),
|
||||
message = stringResource(R.string.error)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
@@ -32,7 +33,7 @@ fun Compatibility(needsGms: Boolean, plexusScores: Scores? = null) {
|
||||
|
||||
if (!needsGms) {
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_menu_about,
|
||||
painter = painterResource(R.drawable.ic_menu_about),
|
||||
title = AnnotatedString(
|
||||
text = stringResource(R.string.details_compatibility_gms_not_required_title)
|
||||
),
|
||||
@@ -46,7 +47,7 @@ fun Compatibility(needsGms: Boolean, plexusScores: Scores? = null) {
|
||||
}
|
||||
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_menu_about,
|
||||
painter = painterResource(R.drawable.ic_menu_about),
|
||||
title = AnnotatedString(
|
||||
text = stringResource(R.string.details_compatibility_gms_required_title)
|
||||
),
|
||||
@@ -61,7 +62,7 @@ fun Compatibility(needsGms: Boolean, plexusScores: Scores? = null) {
|
||||
)
|
||||
scoresStatus.forEach { (title, description) ->
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_android,
|
||||
painter = painterResource(R.drawable.ic_android),
|
||||
title = AnnotatedString(text = stringResource(title)),
|
||||
description = AnnotatedString(
|
||||
text = stringResource(description ?: R.string.details_compatibility_status_unknown)
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
@@ -44,7 +45,7 @@ fun DataSafety(report: Report, privacyPolicyUrl: String) {
|
||||
when (type) {
|
||||
EntryType.DATA_COLLECTED -> {
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_cloud_upload,
|
||||
painter = painterResource(R.drawable.ic_cloud_upload),
|
||||
title = AnnotatedString(
|
||||
text = stringResource(R.string.details_data_safety_collect)
|
||||
),
|
||||
@@ -59,7 +60,7 @@ fun DataSafety(report: Report, privacyPolicyUrl: String) {
|
||||
|
||||
EntryType.DATA_SHARED -> {
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_share,
|
||||
painter = painterResource(R.drawable.ic_share),
|
||||
title = AnnotatedString(
|
||||
text = stringResource(R.string.details_data_safety_shared)
|
||||
),
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.fromHtml
|
||||
@@ -41,7 +42,7 @@ fun DeveloperDetails(address: String, website: String, email: String) {
|
||||
InfoComposable(
|
||||
title = AnnotatedString(text = stringResource(R.string.details_dev_website)),
|
||||
description = AnnotatedString(text = website),
|
||||
icon = R.drawable.ic_network,
|
||||
painter = painterResource(R.drawable.ic_network),
|
||||
onClick = { context.browse(website) }
|
||||
)
|
||||
}
|
||||
@@ -50,7 +51,7 @@ fun DeveloperDetails(address: String, website: String, email: String) {
|
||||
InfoComposable(
|
||||
title = AnnotatedString(text = stringResource(R.string.details_dev_email)),
|
||||
description = AnnotatedString(text = email),
|
||||
icon = R.drawable.ic_mail,
|
||||
painter = painterResource(R.drawable.ic_mail),
|
||||
onClick = { context.mailTo(email) }
|
||||
)
|
||||
}
|
||||
@@ -59,7 +60,7 @@ fun DeveloperDetails(address: String, website: String, email: String) {
|
||||
InfoComposable(
|
||||
title = AnnotatedString(text = stringResource(R.string.details_dev_address)),
|
||||
description = AnnotatedString.fromHtml(htmlString = address),
|
||||
icon = R.drawable.ic_person_location,
|
||||
painter = painterResource(R.drawable.ic_person_location),
|
||||
onClick = { context.copyToClipBoard(address) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
@@ -42,7 +43,7 @@ fun Privacy(report: Report?, onNavigateToDetailsExodus: (() -> Unit)? = null) {
|
||||
}
|
||||
|
||||
InfoComposable(
|
||||
icon = R.drawable.ic_visibility,
|
||||
painter = painterResource(R.drawable.ic_visibility),
|
||||
title = AnnotatedString(text = reportStatus),
|
||||
description = AnnotatedString(text = stringResource(R.string.exodus_tracker_desc))
|
||||
)
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
@@ -61,7 +62,7 @@ fun Tags(app: App) {
|
||||
horizontalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_medium))
|
||||
) {
|
||||
items(items = tags.keys.toList()) { label ->
|
||||
AppTagComposable(label = label!!, icon = tags.getValue(label))
|
||||
AppTagComposable(label = label!!, painter = painterResource(tags.getValue(label)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
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
|
||||
@@ -43,7 +44,7 @@ fun Testing(isSubscribed: Boolean, onTestingSubscriptionChange: (subscribe: Bool
|
||||
) {
|
||||
InfoComposable(
|
||||
modifier = Modifier.weight(1F),
|
||||
icon = R.drawable.ic_experiment,
|
||||
painter = painterResource(R.drawable.ic_experiment),
|
||||
title = AnnotatedString(
|
||||
text = if (isSubscribed) {
|
||||
stringResource(R.string.details_beta_subscribed)
|
||||
|
||||
@@ -101,7 +101,7 @@ private fun ScreenContent(
|
||||
is LoadState.Error -> {
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_disclaimer),
|
||||
painter = painterResource(R.drawable.ic_disclaimer),
|
||||
message = stringResource(R.string.error)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ private fun ScreenContent(
|
||||
if (downloads.itemCount == 0) {
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_download_manager),
|
||||
painter = painterResource(R.drawable.ic_download_manager),
|
||||
message = stringResource(R.string.download_none)
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -144,7 +144,7 @@ private fun ScreenContent(
|
||||
if (favourites.itemCount == 0) {
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_favorite_unchecked),
|
||||
painter = painterResource(R.drawable.ic_favorite_unchecked),
|
||||
message = stringResource(R.string.details_no_favourites)
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -211,7 +211,7 @@ private fun ScreenContent(
|
||||
is LoadState.Error -> {
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_disclaimer),
|
||||
painter = painterResource(R.drawable.ic_disclaimer),
|
||||
message = stringResource(R.string.error)
|
||||
)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ private fun ScreenContent(
|
||||
if (isSearching && results.itemCount == 0) {
|
||||
ErrorComposable(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
icon = painterResource(R.drawable.ic_disclaimer),
|
||||
painter = painterResource(R.drawable.ic_disclaimer),
|
||||
message = stringResource(R.string.no_apps_available)
|
||||
)
|
||||
} else {
|
||||
@@ -262,7 +262,7 @@ private fun ScreenContent(
|
||||
else -> {
|
||||
if (isSearching && results.itemCount > 0) {
|
||||
ErrorComposable(
|
||||
icon = painterResource(R.drawable.ic_round_search),
|
||||
painter = painterResource(R.drawable.ic_round_search),
|
||||
message = stringResource(R.string.select_app_for_details)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user