Skip to content

Commit e4390d1

Browse files
author
Lennoard
committed
refactor: created data and domain modules
1 parent 49d5468 commit e4390d1

77 files changed

Lines changed: 1426 additions & 882 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle.kts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
2+
import java.util.Properties
3+
4+
val devCycle = true
25

36
plugins {
47
id("com.android.application")
@@ -8,9 +11,8 @@ plugins {
811
}
912

1013
android {
11-
buildToolsVersion("29.0.3")
1214

13-
compileSdkVersion(29)
15+
compileSdk = 30
1416
compileOptions {
1517
sourceCompatibility = JavaVersion.VERSION_1_8
1618
targetCompatibility = JavaVersion.VERSION_1_8
@@ -20,26 +22,44 @@ android {
2022
jvmTarget = "1.8"
2123
}
2224

25+
signingConfigs {
26+
create("release") {
27+
val localPropFile = rootProject.file("local.properties")
28+
val keystoreProps = Properties().apply {
29+
load(localPropFile.inputStream())
30+
}
31+
32+
keyAlias = keystoreProps["keyAlias"] as? String ?: ""
33+
keyPassword = keystoreProps["keyPassword"] as? String ?: ""
34+
storeFile = file(keystoreProps["storeFile"] as? String ?: "/")
35+
storePassword = keystoreProps["storePassword"] as? String ?: ""
36+
}
37+
}
38+
2339
defaultConfig {
2440
applicationId = "com.androidvip.sysctlgui"
25-
minSdkVersion(19)
26-
targetSdkVersion(29)
41+
minSdk = 19
42+
targetSdk = 30
2743
versionCode = 9
2844
versionName = "1.0.8"
2945
vectorDrawables.useSupportLibrary = true
30-
resConfigs("en", "de", "pt-rBR")
46+
resourceConfigurations.addAll(listOf("en", "de", "pt-rBR"))
3147
javaCompileOptions {
3248
annotationProcessorOptions {
33-
arguments["room.incremental"] = "true"
49+
arguments += mapOf(
50+
"room.incremental" to "true",
51+
"room.schemaLocation" to "$projectDir/schemas"
52+
)
3453
}
3554
}
3655
}
3756

3857
buildTypes {
3958
getByName("release") {
40-
isMinifyEnabled = true
41-
isShrinkResources = true
42-
isDebuggable = false
59+
isMinifyEnabled = !devCycle
60+
isShrinkResources = !devCycle
61+
isDebuggable = devCycle
62+
signingConfig = signingConfigs.getByName("release")
4363
proguardFiles(
4464
getDefaultProguardFile("proguard-android-optimize.txt"),
4565
"proguard-rules.pro",
@@ -55,6 +75,8 @@ android {
5575

5676
sourceSets {
5777
maybeCreate("main").java.srcDir("src/main/kotlin")
78+
// Adds exported schema location as test app assets.
79+
getByName("androidTest").assets.srcDir("$projectDir/schemas")
5880
}
5981

6082
packagingOptions {
@@ -80,33 +102,33 @@ android.applicationVariants.forEach { variant ->
80102
}
81103

82104
kapt {
83-
//generateStubs = true
84105
correctErrorTypes = true
85106
}
86107

87108
dependencies {
109+
implementation(project(":domain"))
110+
implementation(project(":data"))
111+
88112
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
89113
implementation(kotlin("stdlib-jdk8", KotlinCompilerVersion.VERSION))
90-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1")
114+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2")
91115

92-
implementation("org.koin:koin-android:2.1.6")
93-
implementation("org.koin:koin-androidx-scope:2.1.6")
94-
implementation("org.koin:koin-androidx-viewmodel:2.1.6")
116+
implementation("io.insert-koin:koin-android:3.1.3")
95117

96-
implementation("androidx.appcompat:appcompat:1.2.0")
97-
implementation("androidx.constraintlayout:constraintlayout:2.0.4")
118+
implementation("androidx.appcompat:appcompat:1.3.1")
119+
implementation("androidx.constraintlayout:constraintlayout:2.1.1")
98120
implementation("androidx.core:core-ktx:1.3.2")
99-
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.3.0")
121+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.3.1")
100122
implementation("androidx.preference:preference-ktx:1.1.1")
101123
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
102-
implementation("androidx.room:room-ktx:2.2.6")
103-
implementation("androidx.room:room-runtime:2.2.6")
124+
implementation("androidx.room:room-ktx:2.3.0")
125+
implementation("androidx.room:room-runtime:2.3.0")
104126

105-
implementation("com.google.android.material:material:1.3.0")
127+
implementation("com.google.android.material:material:1.4.0")
106128
implementation("com.google.code.gson:gson:2.8.6")
107129

108-
implementation("com.getkeepsafe.taptargetview:taptargetview:1.11.0")
130+
implementation("com.getkeepsafe.taptargetview:taptargetview:1.13.3")
109131
implementation("com.github.topjohnwu.libsu:core:2.5.1")
110132

111-
kapt("androidx.room:room-compiler:2.2.6")
133+
kapt("androidx.room:room-compiler:2.3.0")
112134
}

app/proguard-rules.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@
3535
-keep class sun.misc.Unsafe { *; }
3636

3737
# Application classes that will be serialized/deserialized over Gson
38-
-keep class com.androidvip.sysctlgui.KernelParameter { *; }
38+
-keep class com.androidvip.sysctlgui.data.models.KernelParam { *; }
39+
-keep class com.androidvip.sysctlgui.data.models.RoomKernelParam { *; }
40+
-keep class com.androidvip.sysctlgui.domain.models.param.DomainKernelParam { *; }

app/src/main/kotlin/com/androidvip/sysctlgui/SysctlGuiApp.kt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
11
package com.androidvip.sysctlgui
22

33
import android.app.Application
4-
import androidx.preference.PreferenceManager
5-
import com.androidvip.sysctlgui.data.ParamDatabase
6-
import com.androidvip.sysctlgui.data.ParamDatabaseManager
7-
import com.androidvip.sysctlgui.data.repository.ParamRepository
8-
import com.androidvip.sysctlgui.ui.params.browse.BrowseParamsViewModel
9-
import com.androidvip.sysctlgui.ui.params.list.ListParamsViewModel
10-
import com.androidvip.sysctlgui.ui.params.user.UserParamsViewModel
11-
import com.androidvip.sysctlgui.widgets.FavoriteWidgetParamUpdater
4+
import com.androidvip.sysctlgui.data.di.dataModules
5+
import com.androidvip.sysctlgui.di.presentationModules
6+
import com.androidvip.sysctlgui.domain.di.domainModule
127
import org.koin.android.ext.koin.androidContext
13-
import org.koin.androidx.viewmodel.dsl.viewModel
148
import org.koin.core.context.startKoin
15-
import org.koin.dsl.module
169

1710
class SysctlGuiApp : Application() {
1811

19-
private val modules = module {
20-
viewModel { BrowseParamsViewModel(repository = get()) }
21-
viewModel { ListParamsViewModel(repository = get()) }
22-
viewModel { UserParamsViewModel(repository = get()) }
23-
single { PreferenceManager.getDefaultSharedPreferences(applicationContext) }
24-
single { ParamDatabaseManager.getInstance(applicationContext) }
25-
single { FavoriteWidgetParamUpdater(this@SysctlGuiApp).getListener() }
26-
single {
27-
val db: ParamDatabase = get()
28-
ParamRepository(paramDao = db.paramDao(), prefs = get(), changeListener = get())
29-
}
30-
}
31-
3212
override fun onCreate() {
3313
super.onCreate()
3414

3515
startKoin {
3616
androidContext(this@SysctlGuiApp)
37-
modules(modules)
17+
modules(dataModules + presentationModules + domainModule)
3818
}
3919
}
4020
}

app/src/main/kotlin/com/androidvip/sysctlgui/data/ParamDao.kt

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

app/src/main/kotlin/com/androidvip/sysctlgui/data/ParamDatabase.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.androidvip.sysctlgui.data.mapper
2+
3+
import com.androidvip.sysctlgui.data.models.KernelParam
4+
import com.androidvip.sysctlgui.domain.models.param.DomainKernelParam
5+
6+
object DomainParamMapper : Mapper<DomainKernelParam, KernelParam> {
7+
override fun map(from: DomainKernelParam): KernelParam = KernelParam().apply {
8+
id = from.id
9+
name = from.name
10+
path = from.path
11+
value = from.value
12+
favorite = from.favorite
13+
taskerParam = from.taskerParam
14+
taskerList = from.taskerList
15+
}
16+
17+
override fun unmap(from: KernelParam): DomainKernelParam = DomainKernelParam().apply {
18+
id = from.id
19+
name = from.name
20+
path = from.path
21+
value = from.value
22+
favorite = from.favorite
23+
taskerParam = from.taskerParam
24+
taskerList = from.taskerList
25+
}
26+
}

app/src/main/kotlin/com/androidvip/sysctlgui/data/models/KernelParam.kt

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,20 @@
11
package com.androidvip.sysctlgui.data.models
22

33
import android.os.Parcelable
4-
import androidx.room.ColumnInfo
5-
import androidx.room.Entity
6-
import androidx.room.PrimaryKey
7-
import com.androidvip.sysctlgui.receivers.TaskerReceiver
4+
import com.androidvip.sysctlgui.domain.Consts
5+
import com.androidvip.sysctlgui.domain.models.param.DomainKernelParam
86
import kotlinx.parcelize.Parcelize
97

10-
@Entity
118
@Parcelize
129
data class KernelParam(
13-
@PrimaryKey(autoGenerate = true) var id: Int = 0,
14-
@ColumnInfo(name = "name") var name: String = "",
15-
@ColumnInfo(name = "path") var path: String = "",
16-
@ColumnInfo(name = "value") var value: String = "",
17-
@ColumnInfo(name = "favorite") var favorite: Boolean = false,
18-
@ColumnInfo(name = "tasker_param") var taskerParam: Boolean = false,
19-
@ColumnInfo(name = "tasker_list") var taskerList: Int = TaskerReceiver.LIST_NUMBER_PRIMARY_TASKER
20-
): Parcelable {
21-
val shortName: String get() = name.split(".").last()
22-
23-
fun setNameFromPath(path: String) {
24-
if (path.trim().isEmpty() || !path.startsWith("/proc/sys/")) return
25-
if (path.contains(".")) return
26-
27-
name = path.removeSuffix("/")
28-
.removePrefix("/proc/sys/")
29-
.replace("/", ".")
30-
}
31-
32-
fun setPathFromName(kernelParam: String) {
33-
if (kernelParam.trim().isEmpty() || kernelParam.contains("/")) return
34-
if (kernelParam.startsWith(".") || kernelParam.endsWith(".")) return
35-
36-
path = "/proc/sys/${kernelParam.replace(".", "/")}"
37-
}
38-
39-
fun hasValidPath() : Boolean {
40-
if (path.trim().isEmpty() || !path.startsWith("/proc/sys/")) return false
41-
if (path.contains(".")) return false
42-
43-
return true
44-
}
45-
46-
fun hasValidName() : Boolean {
47-
if (name.trim().isEmpty() || name.contains("/")) return false
48-
if (name.startsWith(".") || name.endsWith(".")) return false
49-
50-
return true
51-
}
10+
override var id: Int = 0,
11+
override var name: String = "",
12+
override var path: String = "",
13+
override var value: String = "",
14+
override var favorite: Boolean = false,
15+
override var taskerParam: Boolean = false,
16+
override var taskerList: Int = Consts.LIST_NUMBER_PRIMARY_TASKER
17+
) : DomainKernelParam(), Parcelable {
5218

5319
override fun equals(other: Any?): Boolean {
5420
if (this === other) return true

app/src/main/kotlin/com/androidvip/sysctlgui/data/models/ViewState.kt

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

0 commit comments

Comments
 (0)