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