Skip to content

Commit 51af955

Browse files
committed
refactor: migrate from material icons to drawable resources
1 parent ed83037 commit 51af955

45 files changed

Lines changed: 257 additions & 138 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.androidvip.sysctlgui.core.navigation
22

3-
import androidx.compose.ui.graphics.vector.ImageVector
3+
import androidx.annotation.DrawableRes
4+
import androidx.compose.runtime.Immutable
45

56
/**
67
* Represents a top-level destination in the application's navigation.
@@ -9,12 +10,13 @@ import androidx.compose.ui.graphics.vector.ImageVector
910
* route information to be associated with the top-level destination.
1011
* @property name The human-readable name of the top-level destination, used for labels.
1112
* @property route The actual [UiRoute] object that defines the navigation destination.
12-
* @property selectedIcon The icon to display when this top-level route is currently selected.
13-
* @property unselectedIcon The icon to display when this top-level route is not selected.
13+
* @property selectedIconRes The icon to display when this top-level route is currently selected.
14+
* @property unselectedIconRes The icon to display when this top-level route is not selected.
1415
*/
16+
@Immutable
1517
data class TopLevelRoute<T : UiRoute>(
1618
val name: String,
1719
val route: T,
18-
val selectedIcon: ImageVector,
19-
val unselectedIcon: ImageVector
20+
@param:DrawableRes val selectedIconRes: Int,
21+
@param:DrawableRes val unselectedIconRes: Int
2022
)

app/src/main/kotlin/com/androidvip/sysctlgui/core/navigation/UiRoute.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.androidvip.sysctlgui.core.navigation
22

3+
import androidx.compose.runtime.Immutable
34
import kotlinx.serialization.Serializable
45

56
/**
67
* Represents the different routes in the application's UI.
78
* This is used for navigation purposes.
89
*/
10+
@Immutable
911
@Serializable
1012
sealed interface UiRoute {
1113
@Serializable
1214
data object BrowseParams : UiRoute
1315
@Serializable
16+
@Immutable
1417
data class EditParam(val paramName: String) : UiRoute
1518
@Serializable
1619
data object Presets : UiRoute

app/src/main/kotlin/com/androidvip/sysctlgui/models/UiKernelParam.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ data class UiKernelParam(
5656
name.substringAfterLast('.', name)
5757
}
5858
}
59+
60+
fun KernelParam.toUiKernelParam(): UiKernelParam {
61+
return UiKernelParam(
62+
name = this.name,
63+
path = this.path,
64+
value = this.value,
65+
isFavorite = this.isFavorite,
66+
isTaskerParam = this.isTaskerParam,
67+
taskerList = this.taskerList
68+
)
69+
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/components/ErrorContainer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import androidx.compose.foundation.layout.Row
1010
import androidx.compose.foundation.layout.fillMaxWidth
1111
import androidx.compose.foundation.layout.padding
1212
import androidx.compose.foundation.layout.size
13-
import androidx.compose.material.icons.Icons
14-
import androidx.compose.material.icons.rounded.Close
1513
import androidx.compose.material3.Card
1614
import androidx.compose.material3.CardDefaults
1715
import androidx.compose.material3.Icon
@@ -26,6 +24,7 @@ import androidx.compose.runtime.remember
2624
import androidx.compose.runtime.setValue
2725
import androidx.compose.ui.Alignment
2826
import androidx.compose.ui.Modifier
27+
import androidx.compose.ui.res.painterResource
2928
import androidx.compose.ui.res.stringResource
3029
import androidx.compose.ui.unit.dp
3130
import com.androidvip.sysctlgui.R
@@ -76,7 +75,7 @@ internal fun ErrorContainer(message: String, onAnimationEnd: () -> Unit) {
7675
) {
7776
Icon(
7877
modifier = Modifier.size(40.dp),
79-
imageVector = Icons.Rounded.Close,
78+
painter = painterResource(R.drawable.ic_close),
8079
contentDescription = null,
8180
tint = MaterialTheme.colorScheme.onErrorContainer
8281
)

app/src/main/kotlin/com/androidvip/sysctlgui/ui/main/MainNavBar.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.runtime.getValue
1010
import androidx.compose.runtime.remember
1111
import androidx.compose.ui.platform.LocalContext
12+
import androidx.compose.ui.res.painterResource
1213
import androidx.compose.ui.text.style.TextOverflow
1314
import androidx.compose.ui.tooling.preview.PreviewDynamicColors
1415
import androidx.compose.ui.tooling.preview.PreviewLightDark
@@ -37,12 +38,13 @@ internal fun MainNavBar(navController: NavHostController = rememberNavController
3738
NavigationBarItem(
3839
icon = {
3940
AnimatedContent(targetState = selected) { selectedState ->
41+
val iconRes = if (selectedState) {
42+
route.selectedIconRes
43+
} else {
44+
route.unselectedIconRes
45+
}
4046
Icon(
41-
imageVector = if (selectedState) {
42-
route.selectedIcon
43-
} else {
44-
route.unselectedIcon
45-
},
47+
painter = painterResource(iconRes),
4648
contentDescription = route.name,
4749
)
4850
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/main/MainNavRail.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.runtime.getValue
1010
import androidx.compose.runtime.remember
1111
import androidx.compose.ui.platform.LocalContext
12+
import androidx.compose.ui.res.painterResource
1213
import androidx.compose.ui.text.style.TextOverflow
1314
import androidx.compose.ui.tooling.preview.PreviewLightDark
1415
import androidx.navigation.NavDestination.Companion.hasRoute
@@ -36,12 +37,13 @@ internal fun MainNavRail(navController: NavHostController = rememberNavControlle
3637
NavigationRailItem(
3738
icon = {
3839
AnimatedContent(targetState = selected) { selectedState ->
40+
val iconRes = if (selectedState) {
41+
route.selectedIconRes
42+
} else {
43+
route.unselectedIconRes
44+
}
3945
Icon(
40-
imageVector = if (selectedState) {
41-
route.selectedIcon
42-
} else {
43-
route.unselectedIcon
44-
},
46+
painterResource(iconRes),
4547
contentDescription = route.name,
4648
)
4749
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/main/MainTopBar.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import androidx.compose.animation.expandHorizontally
55
import androidx.compose.animation.fadeIn
66
import androidx.compose.animation.fadeOut
77
import androidx.compose.animation.shrinkHorizontally
8-
import androidx.compose.material.icons.Icons
9-
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
10-
import androidx.compose.material.icons.rounded.Search
118
import androidx.compose.material3.ExperimentalMaterial3Api
129
import androidx.compose.material3.Icon
1310
import androidx.compose.material3.IconButton
1411
import androidx.compose.material3.Text
1512
import androidx.compose.material3.TopAppBar
1613
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.res.painterResource
1715
import androidx.compose.ui.res.stringResource
1816
import androidx.compose.ui.text.style.TextOverflow
1917
import androidx.compose.ui.tooling.preview.PreviewLightDark
@@ -34,7 +32,7 @@ fun MainTopBar(
3432
AnimatedVisibility(visible = showBack) {
3533
IconButton(onClick = onBackPressed) {
3634
Icon(
37-
imageVector = Icons.AutoMirrored.Rounded.ArrowBack,
35+
painter = painterResource(R.drawable.ic_arrow_back),
3836
contentDescription = stringResource(R.string.go_back)
3937
)
4038
}
@@ -51,7 +49,7 @@ fun MainTopBar(
5149
) {
5250
IconButton(onClick = onSearchPressed) {
5351
Icon(
54-
imageVector = Icons.Rounded.Search,
52+
painter = painterResource(R.drawable.ic_search),
5553
contentDescription = stringResource(R.string.search)
5654
)
5755
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/main/TopLevelRouteProvider.kt

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
package com.androidvip.sysctlgui.ui.main
22

33
import android.content.Context
4-
import androidx.compose.material.icons.Icons
5-
import androidx.compose.material.icons.outlined.Build
6-
import androidx.compose.material.icons.outlined.FavoriteBorder
7-
import androidx.compose.material.icons.outlined.Home
8-
import androidx.compose.material.icons.outlined.Settings
9-
import androidx.compose.material.icons.rounded.Build
10-
import androidx.compose.material.icons.rounded.Favorite
11-
import androidx.compose.material.icons.rounded.Home
12-
import androidx.compose.material.icons.rounded.Settings
134
import com.androidvip.sysctlgui.R
145
import com.androidvip.sysctlgui.core.navigation.TopLevelRoute
156
import com.androidvip.sysctlgui.core.navigation.UiRoute
@@ -20,26 +11,26 @@ object TopLevelRouteProvider {
2011
TopLevelRoute(
2112
name = context.getString(R.string.browse),
2213
route = UiRoute.BrowseParams,
23-
selectedIcon = Icons.Rounded.Home,
24-
unselectedIcon = Icons.Outlined.Home
14+
selectedIconRes = R.drawable.ic_home_filled,
15+
unselectedIconRes = R.drawable.ic_home
2516
),
2617
TopLevelRoute(
2718
name = context.getString(R.string.presets),
2819
route = UiRoute.Presets,
29-
selectedIcon = Icons.Rounded.Build,
30-
unselectedIcon = Icons.Outlined.Build
20+
selectedIconRes = R.drawable.ic_build_filled,
21+
unselectedIconRes = R.drawable.ic_build
3122
),
3223
TopLevelRoute(
3324
name = context.getString(R.string.favorites),
3425
route = UiRoute.Favorites,
35-
selectedIcon = Icons.Rounded.Favorite,
36-
unselectedIcon = Icons.Outlined.FavoriteBorder
26+
selectedIconRes = R.drawable.ic_favorite,
27+
unselectedIconRes = R.drawable.ic_favorite_outlined
3728
),
3829
TopLevelRoute(
3930
name = context.getString(R.string.settings),
4031
route = UiRoute.Settings,
41-
selectedIcon = Icons.Rounded.Settings,
42-
unselectedIcon = Icons.Outlined.Settings
32+
selectedIconRes = R.drawable.ic_settings_filled,
33+
unselectedIconRes = R.drawable.ic_settings
4334
)
4435
)
4536
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/params/browse/ParamFileRow.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import androidx.compose.foundation.layout.Row
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.layout.size
1111
import androidx.compose.foundation.shape.CircleShape
12-
import androidx.compose.material.icons.Icons
13-
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowRight
14-
import androidx.compose.material.icons.rounded.Favorite
1512
import androidx.compose.material3.Icon
1613
import androidx.compose.material3.MaterialTheme
1714
import androidx.compose.material3.Text
@@ -124,14 +121,14 @@ private fun ParamIcon(param: UiKernelParam) {
124121
private fun TrailingIcon(param: UiKernelParam, showFavoriteIcon: Boolean) {
125122
if (param.isDirectory) {
126123
Icon(
127-
imageVector = Icons.AutoMirrored.Rounded.KeyboardArrowRight,
124+
painter = painterResource(R.drawable.ic_keyboard_arrow_right),
128125
contentDescription = stringResource(R.string.acessibility_davegate_to_directory_description),
129126
modifier = Modifier.size(24.dp),
130127
tint = MaterialTheme.colorScheme.onSurfaceVariant
131128
)
132129
} else if (param.isFavorite && showFavoriteIcon) {
133130
Icon(
134-
imageVector = Icons.Rounded.Favorite,
131+
painter = painterResource(R.drawable.ic_favorite),
135132
contentDescription = stringResource(R.string.favorites),
136133
tint = MaterialTheme.colorScheme.primary,
137134
modifier = Modifier.size(18.dp)

app/src/main/kotlin/com/androidvip/sysctlgui/ui/params/browse/ParamRow.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import androidx.compose.foundation.layout.fillMaxWidth
99
import androidx.compose.foundation.layout.heightIn
1010
import androidx.compose.foundation.layout.padding
1111
import androidx.compose.foundation.layout.size
12-
import androidx.compose.material.icons.Icons
13-
import androidx.compose.material.icons.rounded.Favorite
1412
import androidx.compose.material3.Icon
1513
import androidx.compose.material3.MaterialTheme
1614
import androidx.compose.material3.Text
1715
import androidx.compose.runtime.Composable
1816
import androidx.compose.ui.Alignment
1917
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.res.painterResource
2019
import androidx.compose.ui.res.stringResource
2120
import androidx.compose.ui.semantics.contentDescription
2221
import androidx.compose.ui.semantics.semantics
@@ -82,7 +81,7 @@ fun ParamRow(
8281

8382
if (param.isFavorite) {
8483
Icon(
85-
imageVector = Icons.Rounded.Favorite,
84+
painter = painterResource(R.drawable.ic_favorite),
8685
contentDescription = null,
8786
tint = MaterialTheme.colorScheme.secondary,
8887
modifier = Modifier

0 commit comments

Comments
 (0)