Skip to content

Commit

Permalink
Modularize a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
erikeelde committed Sep 29, 2023
1 parent a337899 commit b46b013
Show file tree
Hide file tree
Showing 72 changed files with 544 additions and 167 deletions.
2 changes: 1 addition & 1 deletion build-logic/conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ java {

dependencies {
// implementation("gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.2")
implementation("se.premex:ownership-gradle-plugin:0.0.7")
implementation("se.premex:ownership-gradle-plugin:0.0.11")
implementation(libs.io.gitlab.arturbosch.detekt.detekt.gradle.plugin)
implementation(libs.com.android.tools.build.gradle)
implementation(libs.org.jetbrains.kotlin.kotlin.gradle.plugin)
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ plugins {
// https://github.com/Kotlin/KEEP/blob/master/proposals/explicit-api-mode.md
alias(libs.plugins.com.github.triplet.play) apply (false)
id("toggles.ownership-conventions")
alias(libs.plugins.com.android.library) apply false
alias(libs.plugins.org.jetbrains.kotlin.android) apply false
}

fun isNonStable(version: String): Boolean {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ android.enableJetifier=false
#kotlin.parallel.tasks.in.project=true

org.gradle.caching=true
org.gradle.configuration-cache=false
org.gradle.configuration-cache=true
org.gradle.configuration-cache.max-problems=5
12 changes: 12 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ com-squareup-moshi = "1.15.0"
dokka = "1.8.20"
kotlin = "1.9.10"
org-jetbrains-kotlinx = "1.7.1"
agp = "8.1.2"
org-jetbrains-kotlin-android = "1.9.0"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
material = "1.9.0"

[libraries]
androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-activity" }
Expand Down Expand Up @@ -177,6 +183,10 @@ org-robolectric = "org.robolectric:robolectric:4.10.3"
se-eelde-toggles-toggles-core = { module = "se.eelde.toggles:toggles-core" }
se-eelde-toggles-toggles-flow = { module = "se.eelde.toggles:toggles-flow" }
se-eelde-toggles-toggles-prefs = { module = "se.eelde.toggles:toggles-prefs" }
junit-junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-test-ext-junit115 = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
#se-eelde-toggles-toggles-core = "se.eelde.toggles:toggles-core:0.0.2"
#se-eelde-toggles-toggles-flow = "se.eelde.toggles:toggles-flow:0.0.1"
#se-eelde-toggles-toggles-prefs = "se.eelde.toggles:toggles-prefs:0.0.1"
Expand All @@ -193,3 +203,5 @@ dagger-hilt-android-plugin = "dagger.hilt.android.plugin:2.47"
nl-littlerobots-version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.1"
org-jetbrains-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
org-jetbrains-kotlinx-binary-compatibility-validator = "org.jetbrains.kotlinx.binary-compatibility-validator:0.13.2"
com-android-library = { id = "com.android.library", version.ref = "agp" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "org-jetbrains-kotlin-android" }
Empty file.
21 changes: 0 additions & 21 deletions modules/applications/proguard-rules.pro

This file was deleted.

1 change: 1 addition & 0 deletions modules/booleanconfiguration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
4 changes: 4 additions & 0 deletions modules/booleanconfiguration/OWNERSHIP.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = 1

[owner]
user = "@erikeelde"
33 changes: 33 additions & 0 deletions modules/booleanconfiguration/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id("toggles.android.module-conventions")
id("toggles.ownership-conventions")
}

android {
namespace = "se.eelde.toggles.booleanconfiguration"
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}
}

dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(projects.modules.composeTheme)
implementation(projects.modules.database)
implementation(projects.modules.provider)
implementation(libs.androidx.core.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.navigation.navigation.compose)
implementation(libs.androidx.hilt.hilt.navigation.compose)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.material3)
debugImplementation(libs.androidx.compose.ui.ui.tooling)
implementation(libs.androidx.compose.ui.ui.tooling.preview)
implementation(libs.androidx.startup.startup.runtime)
implementation(libs.com.google.dagger.hilt.android)
implementation(libs.se.eelde.toggles.toggles.core)
kapt(libs.com.google.dagger.hilt.compiler)
}
4 changes: 4 additions & 0 deletions modules/booleanconfiguration/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.1.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.1.2)" variant="all" version="8.1.2">

</issues>
4 changes: 4 additions & 0 deletions modules/booleanconfiguration/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.eelde.toggles.dialogs.booleanvalue
package se.eelde.toggles.booleanconfiguration

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -19,7 +19,7 @@ import kotlinx.coroutines.launch

@Composable
@Suppress("LongParameterList")
internal fun BooleanValueView(
fun BooleanValueView(
uiState: ViewState,
popBackStack: () -> Unit,
setBooleanValue: (Boolean) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.eelde.toggles.dialogs.booleanvalue
package se.eelde.toggles.booleanconfiguration

import android.app.Application
import androidx.lifecycle.SavedStateHandle
Expand All @@ -19,7 +19,7 @@ import se.eelde.toggles.provider.notifyUpdate
import java.util.Date
import javax.inject.Inject

internal data class ViewState(
data class ViewState(
val title: String? = null,
val checked: Boolean? = null,
val saving: Boolean = false,
Expand All @@ -44,7 +44,7 @@ class FragmentBooleanValueViewModel @Inject internal constructor(

private val _state = MutableStateFlow(reduce(ViewState(), PartialViewState.Empty))

internal val state: StateFlow<ViewState>
val state: StateFlow<ViewState>
get() = _state

private val configurationId: Long = savedStateHandle.get<Long>("configurationId")!!
Expand All @@ -63,7 +63,10 @@ class FragmentBooleanValueViewModel @Inject internal constructor(
if (it != null) {
selectedConfigurationValue = it
// viewEffects.value = Event(ViewEffect.CheckedChanged(it.value!!.toBoolean()))
_state.value = reduce(state.value, PartialViewState.NewConfigurationValue(it.value!!.toBoolean()))
_state.value = reduce(
state.value,
PartialViewState.NewConfigurationValue(it.value!!.toBoolean())
)
}
}
}
Expand Down Expand Up @@ -92,12 +95,12 @@ class FragmentBooleanValueViewModel @Inject internal constructor(
}
}

internal suspend fun saveClick() {
suspend fun saveClick() {
_state.value = reduce(state.value, PartialViewState.Saving)
updateConfigurationValue(state.value.checked.toString()).join()
}

internal suspend fun revertClick() {
suspend fun revertClick() {
_state.value = reduce(state.value, PartialViewState.Reverting)
deleteConfigurationValue().join()
}
Expand Down
1 change: 1 addition & 0 deletions modules/configurations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
4 changes: 4 additions & 0 deletions modules/configurations/OWNERSHIP.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = 1

[owner]
user = "@erikeelde"
34 changes: 34 additions & 0 deletions modules/configurations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id("toggles.android.module-conventions")
id("toggles.ownership-conventions")
}

android {
namespace = "se.eelde.toggles.configurations"
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}
}

dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(projects.modules.composeTheme)
implementation(projects.modules.database)
implementation(libs.se.eelde.toggles.toggles.core)
implementation(libs.androidx.core.core.ktx)
implementation(libs.androidx.lifecycle.lifecycle.runtime.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.navigation.navigation.compose)
implementation(libs.androidx.hilt.hilt.navigation.compose)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.material3)
debugImplementation(libs.androidx.compose.ui.ui.tooling)
implementation(libs.androidx.compose.material.material.icons.extended)
implementation(libs.androidx.compose.ui.ui.tooling.preview)
implementation(libs.androidx.startup.startup.runtime)
implementation(libs.com.google.dagger.hilt.android)
kapt(libs.com.google.dagger.hilt.compiler)
}
4 changes: 4 additions & 0 deletions modules/configurations/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.1.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.1.2)" variant="all" version="8.1.2">

</issues>
4 changes: 4 additions & 0 deletions modules/configurations/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.eelde.toggles.configurationlist
package se.eelde.toggles.configurations

import android.text.TextUtils
import android.util.Log
Expand All @@ -18,16 +18,18 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import kotlinx.coroutines.ExperimentalCoroutinesApi
import se.eelde.toggles.core.Toggle
import se.eelde.toggles.database.WrenchConfigurationValue
import se.eelde.toggles.database.WrenchConfigurationWithValues
import se.eelde.toggles.database.WrenchScope

@Composable
@Suppress("LongParameterList")
internal fun ConfigurationListView(
navController: NavController,
navigateToBooleanConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToIntegerConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToStringConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToEnumConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
uiState: State<ViewState>,
modifier: Modifier = Modifier,
) {
Expand All @@ -46,7 +48,10 @@ internal fun ConfigurationListView(
.clickable {
Log.w("Clicked configuration", "")
configurationClicked(
navController = navController,
navigateToBooleanConfiguration = navigateToBooleanConfiguration,
navigateToIntegerConfiguration = navigateToIntegerConfiguration,
navigateToStringConfiguration = navigateToStringConfiguration,
navigateToEnumConfiguration = navigateToEnumConfiguration,
configuration = configuration,
selectedScope = uiState.value.selectedScope
)
Expand Down Expand Up @@ -107,10 +112,12 @@ private fun getItemForScope(
return null
}

@Suppress("LongMethod")
@OptIn(ExperimentalCoroutinesApi::class)
@Suppress("LongMethod", "LongParameterList")
fun configurationClicked(
navController: NavController,
navigateToBooleanConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToIntegerConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToStringConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToEnumConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
configuration: WrenchConfigurationWithValues,
selectedScope: WrenchScope?
) {
Expand All @@ -124,25 +131,25 @@ fun configurationClicked(
configuration.type
) || TextUtils.equals(Toggle.TYPE.STRING, configuration.type)
) {
navController.navigate("configuration/${configuration.id}/${selectedScope!!.id}/string")
navigateToStringConfiguration(selectedScope!!.id, configuration.id)
} else if (TextUtils.equals(Int::class.java.name, configuration.type) || TextUtils.equals(
Toggle.TYPE.INTEGER,
configuration.type
)
) {
navController.navigate("configuration/${configuration.id}/${selectedScope!!.id}/integer")
navigateToIntegerConfiguration(selectedScope!!.id, configuration.id)
} else if (TextUtils.equals(
Boolean::class.java.name,
configuration.type
) || TextUtils.equals(Toggle.TYPE.BOOLEAN, configuration.type)
) {
navController.navigate("configuration/${configuration.id}/${selectedScope!!.id}/boolean")
navigateToBooleanConfiguration(selectedScope!!.id, configuration.id)
} else if (TextUtils.equals(Enum::class.java.name, configuration.type) || TextUtils.equals(
Toggle.TYPE.ENUM,
configuration.type
)
) {
navController.navigate("configuration/${configuration.id}/${selectedScope!!.id}/enum")
navigateToEnumConfiguration(selectedScope!!.id, configuration.id)
} else {
// Snackbar.make(
// binding.animator,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.eelde.toggles.configurationlist
package se.eelde.toggles.configurations

import android.app.ActivityManager
import android.content.Context
Expand Down Expand Up @@ -107,7 +107,6 @@ class ConfigurationViewModel @Inject internal constructor(
is PartialViewState.Configurations -> viewState.copy(
configurations = partialViewState.configurations
)

PartialViewState.Empty -> viewState
is PartialViewState.DefaultScope -> viewState.copy(defaultScope = partialViewState.scope)
is PartialViewState.SelectedScope -> viewState.copy(selectedScope = partialViewState.scope)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.eelde.toggles.configurationlist
package se.eelde.toggles.configurations

import android.content.Intent
import android.net.Uri
Expand All @@ -23,7 +23,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
Expand All @@ -32,7 +31,10 @@ import androidx.navigation.navArgument
@Suppress("LongMethod")
@OptIn(ExperimentalMaterial3Api::class)
fun NavGraphBuilder.configurationsNavigations(
navController: NavController,
navigateToBooleanConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToIntegerConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToStringConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
navigateToEnumConfiguration: (scopeId: Long, configurationId: Long) -> Unit,
back: () -> Unit,
) {
composable(
Expand Down Expand Up @@ -124,7 +126,10 @@ fun NavGraphBuilder.configurationsNavigations(
},
) { paddingValues ->
ConfigurationListView(
navController = navController,
navigateToBooleanConfiguration = navigateToBooleanConfiguration,
navigateToIntegerConfiguration = navigateToIntegerConfiguration,
navigateToStringConfiguration = navigateToStringConfiguration,
navigateToEnumConfiguration = navigateToEnumConfiguration,
uiState = uiState,
modifier = Modifier.padding(paddingValues),
)
Expand Down
Empty file.
1 change: 1 addition & 0 deletions modules/enumconfiguration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit b46b013

Please sign in to comment.