Skip to content

Commit 628c9c9

Browse files
committed
bugfix: import presets
1 parent 076aca2 commit 628c9c9

6 files changed

Lines changed: 34 additions & 14 deletions

File tree

app/src/main/kotlin/com/androidvip/sysctlgui/di/PresentationModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal val presentationModule = module {
1919
viewModelOf(::ParamBrowseViewModel)
2020
viewModelOf(::EditParamViewModel)
2121
viewModelOf(::SearchViewModel)
22-
viewModelOf(::PresetsViewModel)
22+
singleOf(::PresetsViewModel)
2323
viewModelOf(::UserParamsViewModel)
2424

2525
single { FavoriteWidgetParamUpdater(androidContext()).getListener() }

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class MainActivity : ComponentActivity() {
3737
)
3838

3939
setContent {
40+
// TODO: Make the switch dynamic with the view model
41+
// TODO: Test presets
42+
// TODO: Translations
43+
// TODO: Handle shortcuts / widgets
4044
SysctlGuiTheme(
4145
darkTheme = prefs.forceDark || isSystemInDarkTheme(),
4246
contrastLevel = prefs.contrastLevel,

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

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

3+
import androidx.compose.animation.AnimatedContent
34
import androidx.compose.material.icons.Icons
4-
import androidx.compose.material.icons.filled.Favorite
5-
import androidx.compose.material.icons.filled.Home
65
import androidx.compose.material.icons.outlined.Build
76
import androidx.compose.material.icons.outlined.FavoriteBorder
87
import androidx.compose.material.icons.outlined.Home
98
import androidx.compose.material.icons.outlined.Settings
109
import androidx.compose.material.icons.rounded.Build
10+
import androidx.compose.material.icons.rounded.Favorite
11+
import androidx.compose.material.icons.rounded.Home
1112
import androidx.compose.material.icons.rounded.Settings
1213
import androidx.compose.material3.Icon
1314
import androidx.compose.material3.NavigationBar
@@ -42,7 +43,7 @@ internal fun MainNavBar(navController: NavHostController = rememberNavController
4243
TopLevelRoute(
4344
name = browseParamsTitle,
4445
route = UiRoute.BrowseParams,
45-
selectedIcon = Icons.Filled.Home,
46+
selectedIcon = Icons.Rounded.Home,
4647
unselectedIcon = Icons.Outlined.Home
4748
),
4849
TopLevelRoute(
@@ -54,7 +55,7 @@ internal fun MainNavBar(navController: NavHostController = rememberNavController
5455
TopLevelRoute(
5556
name = favoritesTitle,
5657
route = UiRoute.Favorites,
57-
selectedIcon = Icons.Filled.Favorite,
58+
selectedIcon = Icons.Rounded.Favorite,
5859
unselectedIcon = Icons.Outlined.FavoriteBorder
5960
),
6061
TopLevelRoute(
@@ -77,10 +78,16 @@ internal fun MainNavBar(navController: NavHostController = rememberNavController
7778

7879
NavigationBarItem(
7980
icon = {
80-
Icon(
81-
imageVector = if (selected) route.selectedIcon else route.unselectedIcon,
82-
contentDescription = route.name,
83-
)
81+
AnimatedContent(targetState = selected) { selectedState ->
82+
Icon(
83+
imageVector = if (selectedState) {
84+
route.selectedIcon
85+
} else {
86+
route.unselectedIcon
87+
},
88+
contentDescription = route.name,
89+
)
90+
}
8491
},
8592
label = {
8693
Text(

app/src/main/kotlin/com/androidvip/sysctlgui/ui/presets/PresetsScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fun PresetsScreen(
6363
}
6464
)
6565
val createFileLauncher = rememberLauncherForActivityResult(
66-
contract = ActivityResultContracts.CreateDocument("text/plain"),
66+
contract = ActivityResultContracts.CreateDocument("*/*"),
6767
onResult = { uri ->
6868
viewModel.onEvent(PresetsViewEvent.BackUpFileCreated(uri))
6969
}

data/src/main/java/com/androidvip/sysctlgui/data/repository/UserRepositoryImpl.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,20 @@ class UserRepositoryImpl(
3838
paramDao.upsert(newParam)
3939
}
4040

41-
override suspend fun upsertUserParams(params: List<KernelParam>) =
42-
withContext(coroutineContext) {
43-
paramDao.upsertAll(params.map { KernelParamDTO.fromKernelParam(it) })
41+
override suspend fun upsertUserParams(
42+
params: List<KernelParam>
43+
) = withContext(coroutineContext) {
44+
val currentDatabaseParams = paramDao.getAll()
45+
val newParams = params.map { param ->
46+
val currentDatabaseParam = currentDatabaseParams.find { it.name == param.name }
47+
KernelParamDTO.fromKernelParam(param).copy(
48+
id = currentDatabaseParam?.id ?: 0
49+
)
4450
}
4551

52+
paramDao.upsertAll(newParams)
53+
}
54+
4655
override suspend fun removeUserParam(param: KernelParam) = withContext(coroutineContext) {
4756
paramDao.delete(KernelParamDTO.fromKernelParam(param))
4857
}

domain/src/main/java/com/androidvip/sysctlgui/domain/usecase/ApplyParamUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ class ApplyParamUseCase(
7171
CommitMode.SYSCTL -> "Failed to execute sysctl command for '${param.name}'"
7272
CommitMode.ECHO -> "Failed to write value '${param.value}' to '${param.path}'"
7373
}
74-
throw ApplyValueException(errorMessage)
74+
throw ApplyValueException(errorMessage + message)
7575
}
7676
}

0 commit comments

Comments
 (0)