mirror of
https://github.com/revanced/revanced-manager-compose-old.git
synced 2025-04-29 22:14:28 +02:00
feat: migrate to using Any for parameter types
This commit is contained in:
parent
6949e9718d
commit
5cce6c7e41
@ -1,5 +1,6 @@
|
||||
package app.revanced.manager.ui.component
|
||||
|
||||
import android.media.Image
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
@ -15,11 +16,13 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import java.security.InvalidParameterException
|
||||
|
||||
@Composable
|
||||
fun ButtonRow(
|
||||
@ -43,8 +46,9 @@ fun ButtonRow(
|
||||
|
||||
@Composable
|
||||
fun RowScope.ButtonRowItem(
|
||||
icon: ImageVector,
|
||||
@StringRes label: Int,
|
||||
label: String,
|
||||
icon: Any,
|
||||
contentDescription: String? = null,
|
||||
onClick: (() -> Unit)? = null
|
||||
) {
|
||||
Column(
|
||||
@ -60,16 +64,30 @@ fun RowScope.ButtonRowItem(
|
||||
}
|
||||
.fillMaxSize()
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = label),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
when (icon) {
|
||||
is ImageVector -> {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = contentDescription,
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
is Painter -> {
|
||||
Icon(
|
||||
painter = icon,
|
||||
contentDescription = contentDescription,
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
throw InvalidParameterException()
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = label,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package app.revanced.manager.ui.component
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@ -9,48 +8,45 @@ import androidx.compose.material3.ListItem
|
||||
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.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import java.security.InvalidParameterException
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SocialItem(
|
||||
@StringRes label: Int,
|
||||
imageVector: ImageVector? = null,
|
||||
label: String,
|
||||
icon: Any,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
ListItem(
|
||||
modifier = Modifier.clickable { onClick() },
|
||||
leadingContent = {
|
||||
if (imageVector != null) {
|
||||
Icon(
|
||||
imageVector = imageVector,
|
||||
contentDescription = stringResource(label)
|
||||
)
|
||||
}
|
||||
},
|
||||
headlineText = { Text(stringResource(label)) }
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SocialItem(
|
||||
@StringRes label: Int,
|
||||
@DrawableRes painterResource: Int? = null,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
ListItem(
|
||||
modifier = Modifier.clickable { onClick() },
|
||||
leadingContent = {
|
||||
if (painterResource != null) {
|
||||
Icon(
|
||||
painter = painterResource(painterResource),
|
||||
contentDescription = stringResource(label)
|
||||
)
|
||||
}
|
||||
},
|
||||
headlineText = { Text(stringResource(label)) }
|
||||
)
|
||||
when (icon) {
|
||||
is ImageVector -> {
|
||||
ListItem(
|
||||
modifier = Modifier.clickable { onClick() },
|
||||
leadingContent = {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = label
|
||||
)
|
||||
},
|
||||
headlineText = { Text(text = label) }
|
||||
)
|
||||
}
|
||||
is Painter -> {
|
||||
ListItem(
|
||||
modifier = Modifier.clickable { onClick() },
|
||||
leadingContent = {
|
||||
Icon(
|
||||
painter = icon,
|
||||
contentDescription = label
|
||||
)
|
||||
},
|
||||
headlineText = { Text(label) }
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
throw InvalidParameterException()
|
||||
}
|
||||
}
|
||||
}
|
@ -119,9 +119,9 @@ fun SettingsScreen(
|
||||
Switch(checked = prefs.sentry, onCheckedChange = { prefs.sentry = it })
|
||||
})
|
||||
Divider()
|
||||
SocialItem(R.string.github, R.drawable.ic_github, vm::openGitHub)
|
||||
SocialItem(R.string.opensource_licenses, Icons.Default.LibraryBooks, onClickLicenses)
|
||||
SocialItem(R.string.screen_contributors_title, Icons.Default.Group, onClickContributors)
|
||||
SocialItem(stringResource(id = R.string.github), R.drawable.ic_github, vm::openGitHub)
|
||||
SocialItem(stringResource(id = R.string.opensource_licenses), Icons.Default.LibraryBooks, onClickLicenses)
|
||||
SocialItem(stringResource(id = R.string.screen_contributors_title), Icons.Default.Group, onClickContributors)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ fun AppInfoSubscreen(
|
||||
)
|
||||
Text(patchedApp.appVersion)
|
||||
ButtonRow {
|
||||
ButtonRowItem(icon = Icons.Outlined.Launch, label = R.string.launch)
|
||||
ButtonRowItem(icon = Icons.Outlined.Launch, label = stringResource(id = R.string.launch))
|
||||
Divider(
|
||||
modifier = Modifier
|
||||
.width(.5.dp)
|
||||
@ -87,7 +87,7 @@ fun AppInfoSubscreen(
|
||||
.padding(vertical = 16.dp),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
)
|
||||
ButtonRowItem(icon = Icons.Outlined.Delete, label = R.string.uninstall)
|
||||
ButtonRowItem(icon = Icons.Outlined.Delete, label = stringResource(id = R.string.uninstall))
|
||||
Divider(
|
||||
modifier = Modifier
|
||||
.width(.5.dp)
|
||||
@ -95,7 +95,7 @@ fun AppInfoSubscreen(
|
||||
.padding(vertical = 16.dp),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
)
|
||||
ButtonRowItem(icon = Icons.Outlined.Build, label = R.string.patch)
|
||||
ButtonRowItem(icon = Icons.Outlined.Build, label = stringResource(id = R.string.patch))
|
||||
}
|
||||
ListItem(
|
||||
headlineText = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user