Skip to content

Commit 40a95b6

Browse files
committed
refactor: [WIP] updated data layer
1 parent 956751a commit 40a95b6

36 files changed

Lines changed: 1046 additions & 607 deletions

common/utils/src/main/kotlin/com/androidvip/sysctlgui/utils/BaseViewModel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.SharingStarted
88
import kotlinx.coroutines.flow.asStateFlow
99
import kotlinx.coroutines.flow.receiveAsFlow
1010
import kotlinx.coroutines.flow.shareIn
11+
import kotlinx.coroutines.flow.update
1112
import kotlinx.coroutines.launch
1213

1314
abstract class BaseViewModel<Event, State, Effect> : ViewModel() {
@@ -28,12 +29,12 @@ abstract class BaseViewModel<Event, State, Effect> : ViewModel() {
2829
abstract fun onEvent(event: Event)
2930

3031
protected fun setState(block: State.() -> State) {
31-
_uiState.value = currentState.block()
32+
_uiState.update(block)
3233
}
3334

3435
protected fun setEffect(block: () -> Effect) {
3536
viewModelScope.launch {
3637
_effect.send(block())
3738
}
3839
}
39-
}
40+
}

common/utils/src/main/kotlin/com/androidvip/sysctlgui/utils/Consts.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,4 @@ object Consts {
88
const val LIST_NUMBER_SECONDARY_TASKER: Int = 1
99
const val LIST_NUMBER_FAVORITES: Int = 2
1010
const val LIST_NUMBER_APPLY_ON_BOOT: Int = 3
11-
12-
object Prefs {
13-
const val LIST_FOLDERS_FIRST = "list_folders_first"
14-
const val GUESS_INPUT_TYPE = "guess_input_type"
15-
const val COMMIT_MODE = "commit_mode"
16-
const val ALLOW_BLANK = "allow_blank_values"
17-
const val USE_BUSYBOX = "use_busybox"
18-
const val RUN_ON_START_UP = "run_on_start_up"
19-
const val START_UP_DELAY = "startup_delay"
20-
const val SHOW_TASKER_TOAST = "show_tasker_toast"
21-
const val MIGRATION_COMPLETED = "migration_completed"
22-
const val FORCE_DARK_THEME = "force_dark_theme"
23-
const val DYNAMIC_COLORS = "dynamic_colors"
24-
const val ASKED_NOTIFICATION_PERMISSION = "asked_notification_permission"
25-
}
2611
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.androidvip.sysctlgui.utils
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import androidx.core.net.toUri
6+
7+
fun Context.browse(url: String) {
8+
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
9+
runCatching { startActivity(intent) }
10+
}
11+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.androidvip.sysctlgui.utils
2+
3+
import android.view.View
4+
import androidx.core.view.HapticFeedbackConstantsCompat
5+
import androidx.core.view.ViewCompat
6+
7+
/**
8+
* Checks if a string is a valid sysctl line.
9+
* A valid sysctl line must:
10+
* - Contain exactly one "=" character.
11+
* - Not have blank parts before or after the "=".
12+
* - Have a key that matches the pattern: `^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)+$`
13+
* (e.g., "vm.swappiness", "net.ipv4.tcp_congestion_control").
14+
*
15+
* @return `true` if the string is a valid sysctl line, `false` otherwise.
16+
*/
17+
fun String.isValidSysctlLine(): Boolean {
18+
val parts = this.split("=", limit = 2)
19+
if (parts.size != 2 || parts.any { it.isBlank() }) return false
20+
21+
val keyPattern = "^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)+$".toRegex()
22+
return keyPattern.matches(parts.first())
23+
}
24+
25+
fun performHapticFeedbackForToggle(newState: Boolean, view: View) {
26+
val feedbackConst = if (newState) {
27+
HapticFeedbackConstantsCompat.TOGGLE_ON
28+
} else {
29+
HapticFeedbackConstantsCompat.TOGGLE_OFF
30+
}
31+
ViewCompat.performHapticFeedback(view, feedbackConst)
32+
}

common/utils/src/main/kotlin/com/androidvip/sysctlgui/utils/ViewState.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

data/build.gradle.kts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ dependencies {
5050
implementation(libs.androidx.core.ktx)
5151
implementation(libs.androidx.preference)
5252

53-
// Room
54-
implementation(libs.androidx.room.runtime)
55-
implementation(libs.androidx.room.ktx)
56-
ksp(libs.androidx.room.compiler)
57-
5853
implementation(libs.kotlinx.coroutines.android)
5954
implementation(libs.kotlinx.serialization.json)
6055
implementation(libs.koin)
56+
implementation(libs.jsoup)
57+
implementation(libs.bundles.ktor.clients)
6158
implementation(libs.bundles.libsu)
62-
implementation(Google.gson)
59+
60+
// Room
61+
implementation(libs.androidx.room.runtime)
62+
implementation(libs.androidx.room.ktx)
63+
ksp(libs.androidx.room.compiler)
6364

6465
testImplementation(libs.junit)
6566
}

data/consumer-rules.pro

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.androidvip.sysctlgui.data
2+
3+
enum class Prefs(val key: String) {
4+
ListFoldersFirst("list_folders_first"),
5+
GuessInputType("guess_input_type"),
6+
CommitMode("commit_mode"),
7+
ALLOW_BLANK("allow_blank_values"),
8+
UseBusybox("use_busybox"),
9+
RunOnStartup("run_on_start_up"),
10+
StartupDelay("startup_delay"),
11+
ShowTaskerToast("show_tasker_toast"),
12+
ForceDarkTheme("force_dark_theme"),
13+
DynamicColors("dynamic_colors"),
14+
AskedNotificationPermission("asked_notification_permission"),
15+
UseOnlineDocs("use_online_docs"),
16+
ContrastLevel("contrast_level"),
17+
SearchHistory("search_history")
18+
}

data/src/main/java/com/androidvip/sysctlgui/data/datasource/JsonParamDataSource.kt

Lines changed: 0 additions & 93 deletions
This file was deleted.

data/src/main/java/com/androidvip/sysctlgui/data/datasource/RoomParamDataSource.kt

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)