Skip to content

Commit

Permalink
ThemeManager should not throw runtime exception if its not set, it sh…
Browse files Browse the repository at this point in the history
…ould initialize it self with the default values. Only if someone wants to override the default values can take control with the builder outside the ThemeManager.
  • Loading branch information
stzouvaras committed Oct 15, 2024
1 parent 9c5a49f commit 65519d1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import eu.europa.ec.analyticslogic.controller.AnalyticsController
import eu.europa.ec.assemblylogic.di.setupKoin
import eu.europa.ec.corelogic.config.WalletCoreConfig
import eu.europa.ec.eudi.wallet.EudiWallet
import eu.europa.ec.resourceslogic.theme.ThemeManager
import eu.europa.ec.resourceslogic.theme.templates.ThemeDimensTemplate
import eu.europa.ec.resourceslogic.theme.values.ThemeColors
import eu.europa.ec.resourceslogic.theme.values.ThemeShapes
import eu.europa.ec.resourceslogic.theme.values.ThemeTypography
import org.koin.android.ext.android.inject

class Application : Application() {
Expand All @@ -38,27 +33,12 @@ class Application : Application() {
setupKoin()
initializeReporting()
initializeEudiWallet()
initializeTheme()
}

private fun initializeReporting() {
analyticsController.initialize(this)
}

private fun initializeTheme() {
ThemeManager.Builder()
.withLightColors(ThemeColors.lightColors)
.withDarkColors(ThemeColors.darkColors)
.withTypography(ThemeTypography.typo)
.withShapes(ThemeShapes.shapes)
.withDimensions(
ThemeDimensTemplate(
screenPadding = 10.0
)
)
.build()
}

private fun initializeEudiWallet() {
EudiWallet.init(
applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin
import project.convention.logic.config.LibraryModule
import project.convention.logic.configureGradleManagedDevices
import project.convention.logic.libs

Expand Down Expand Up @@ -52,7 +51,6 @@ class AndroidTestConventionPlugin : Plugin<Project> {
add("api", libs.findLibrary("mockito-kotlin").get())
add("api", libs.findLibrary("mockito-inline").get())
add("api", libs.findLibrary("robolectric").get())
add("implementation", project(LibraryModule.ResourcesLogic.path))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import eu.europa.ec.eudi.iso18013.transfer.DocItem
import eu.europa.ec.eudi.iso18013.transfer.DocRequest
import eu.europa.ec.eudi.iso18013.transfer.ReaderAuth
import eu.europa.ec.eudi.iso18013.transfer.RequestDocument
import eu.europa.ec.eudi.wallet.issue.openid4vci.Offer
import eu.europa.ec.eudi.wallet.issue.openid4vci.Offer.TxCodeSpec
import eu.europa.ec.uilogic.component.AppIcons
import eu.europa.ec.uilogic.component.InfoTextWithNameAndImageData
Expand Down Expand Up @@ -506,7 +505,7 @@ object TestsData {

val mockedOfferTxCodeSpecFourDigits =
TxCodeSpec(
inputMode = Offer.TxCodeSpec.InputMode.NUMERIC,
inputMode = TxCodeSpec.InputMode.NUMERIC,
length = mockedTxCodeSpecFourDigits
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class TestDocumentOfferInteractor {
issuerName = mockedIssuerName,
offeredDocuments = mockedOfferedDocumentsList,
txCodeSpec = mockOfferTxCodeSpec(
inputMode = Offer.TxCodeSpec.InputMode.NUMERIC,
inputMode = TxCodeSpec.InputMode.NUMERIC,
length = mockedTxCodeSpecLength
)
)
Expand Down Expand Up @@ -1057,7 +1057,7 @@ class TestDocumentOfferInteractor {
}

private fun mockOfferTxCodeSpec(
inputMode: TxCodeSpec.InputMode = Offer.TxCodeSpec.InputMode.NUMERIC,
inputMode: TxCodeSpec.InputMode = TxCodeSpec.InputMode.NUMERIC,
length: Int? = mockedTxCodeSpecFourDigits,
description: String? = null
): TxCodeSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import eu.europa.ec.resourceslogic.theme.templates.ThemeShapesTemplate
import eu.europa.ec.resourceslogic.theme.templates.ThemeShapesTemplate.Companion.toShapes
import eu.europa.ec.resourceslogic.theme.templates.ThemeTypographyTemplate
import eu.europa.ec.resourceslogic.theme.templates.ThemeTypographyTemplate.Companion.toTypography
import eu.europa.ec.resourceslogic.theme.values.ThemeColors
import eu.europa.ec.resourceslogic.theme.values.ThemeShapes
import eu.europa.ec.resourceslogic.theme.values.ThemeTypography

class ThemeManager {
/**
Expand Down Expand Up @@ -106,9 +109,16 @@ class ThemeManager {
val instance: ThemeManager
get() {
if (this::_instance.isInitialized.not()) {
throw RuntimeException(
"Theme manager not initialized. Initialize via ThemeManager builder first."
)
_instance = Builder()
.withLightColors(ThemeColors.lightColors)
.withDarkColors(ThemeColors.darkColors)
.withTypography(ThemeTypography.typo)
.withShapes(ThemeShapes.shapes)
.withDimensions(
ThemeDimensTemplate(
screenPadding = 10.0
)
).build()
}

return _instance
Expand All @@ -120,7 +130,7 @@ class ThemeManager {
*/
fun ThemeManager.build(builder: Builder): ThemeManager {
set = ThemeSet(
isInDarkMode = builder.isInDarkMode ?: false,
isInDarkMode = builder.isInDarkMode == true,
lightColors = builder.lightColors.toColorScheme(),
darkColors = builder.darkColors.toColorScheme(),
typo = builder.typography.toTypography(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,5 @@
package eu.europa.ec.testlogic.base

import android.app.Application
import eu.europa.ec.resourceslogic.theme.ThemeManager
import eu.europa.ec.resourceslogic.theme.templates.ThemeDimensTemplate
import eu.europa.ec.resourceslogic.theme.values.ThemeColors
import eu.europa.ec.resourceslogic.theme.values.ThemeShapes
import eu.europa.ec.resourceslogic.theme.values.ThemeTypography

class TestApplication : Application() {
override fun onCreate() {
super.onCreate()
initializeTheme()
}

private fun initializeTheme() {
ThemeManager.Builder()
.withLightColors(ThemeColors.lightColors)
.withDarkColors(ThemeColors.darkColors)
.withTypography(ThemeTypography.typo)
.withShapes(ThemeShapes.shapes)
.withDimensions(
ThemeDimensTemplate(
screenPadding = 10.0
)
)
.build()
}
}
class TestApplication : Application()
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,10 @@ package eu.europa.ec.uilogic.component.preview

import androidx.compose.runtime.Composable
import eu.europa.ec.resourceslogic.theme.ThemeManager
import eu.europa.ec.resourceslogic.theme.templates.ThemeDimensTemplate
import eu.europa.ec.resourceslogic.theme.values.ThemeColors
import eu.europa.ec.resourceslogic.theme.values.ThemeShapes
import eu.europa.ec.resourceslogic.theme.values.ThemeTypography

@Composable
fun PreviewTheme(
content: @Composable () -> Unit
) {
ThemeManager.Builder()
.withLightColors(ThemeColors.lightColors)
.withDarkColors(ThemeColors.darkColors)
.withTypography(ThemeTypography.typo)
.withShapes(ThemeShapes.shapes)
.withDimensions(
ThemeDimensTemplate(
screenPadding = 10.0
)
)
.build()
ThemeManager.instance.Theme { content() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.material3.CardDefaults
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package eu.europa.ec.uilogic.component.wrap

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
Expand Down

0 comments on commit 65519d1

Please sign in to comment.