Skip to content

Commit e6a0ef5

Browse files
authored
Merge pull request #761 from qonversion/kamo/dev-464-preload-images
2 parents 1a8373c + 206d9ab commit e6a0ef5

21 files changed

Lines changed: 401 additions & 23 deletions

File tree

config/detekt/baseline.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
<ID>MagicNumber:ApiErrorMapper.kt$ApiErrorMapper$20303</ID>
5252
<ID>MagicNumber:ApiErrorMapper.kt$ApiErrorMapper$20399</ID>
5353
<ID>MagicNumber:ApiInteractorImpl.kt$418</ID>
54+
<ID>MagicNumber:ImagePreloaderImpl.kt$ImagePreloaderImpl$200</ID>
55+
<ID>MagicNumber:ImagePreloaderImpl.kt$ImagePreloaderImpl$299</ID>
5456
<ID>MagicNumber:LogLevel.kt$LogLevel.Error$30</ID>
5557
<ID>MagicNumber:LogLevel.kt$LogLevel.Info$10</ID>
5658
<ID>MagicNumber:LogLevel.kt$LogLevel.Warning$20</ID>
@@ -146,6 +148,7 @@
146148
<ID>SwallowedException:ExceptionHandler.kt$ExceptionHandler$catch (e: Exception) { "" }</ID>
147149
<ID>SwallowedException:FacebookAttribution.kt$FacebookAttribution$catch (e: Exception) { null }</ID>
148150
<ID>SwallowedException:FallbackUtils.kt$FallbackUtils$catch (e: Exception) { false }</ID>
151+
<ID>SwallowedException:ImagePreloaderImpl.kt$ImagePreloaderImpl$catch (e: Exception) { urlString to null }</ID>
149152
<ID>SwallowedException:OtherFragment.kt$OtherFragment$catch (e: Exception) { binding.progressBar.visibility = View.GONE Toast.makeText(context, getString(R.string.error_checking_fallback), Toast.LENGTH_SHORT).show() }</ID>
150153
<ID>SwallowedException:PurchasesCache.kt$PurchasesCache$catch (e: IOException) { setOf() }</ID>
151154
<ID>SwallowedException:RemoteConfigsAdapter.kt$RemoteConfigsAdapter$catch (e: Exception) { payloadJson.toString() }</ID>
@@ -164,6 +167,7 @@
164167
<ID>TooGenericExceptionCaught:FacebookAttribution.kt$FacebookAttribution$e: Exception</ID>
165168
<ID>TooGenericExceptionCaught:FallbackServiceImpl.kt$FallbackServiceImpl$e: Exception</ID>
166169
<ID>TooGenericExceptionCaught:FallbackUtils.kt$FallbackUtils$e: Exception</ID>
170+
<ID>TooGenericExceptionCaught:ImagePreloaderImpl.kt$ImagePreloaderImpl$e: Exception</ID>
167171
<ID>TooGenericExceptionCaught:JsonSerializer.kt$JsonSerializer$cause: NullPointerException</ID>
168172
<ID>TooGenericExceptionCaught:NetworkClientImpl.kt$NetworkClientImpl$cause: Exception</ID>
169173
<ID>TooGenericExceptionCaught:NoCodesInternal.kt$NoCodesInternal$e: Exception</ID>

nocodes/src/main/java/io/qonversion/nocodes/NoCodes.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.qonversion.nocodes
22

33
import android.util.Log
44
import io.qonversion.nocodes.dto.LogLevel
5+
import io.qonversion.nocodes.dto.NoCodesTheme
56
import io.qonversion.nocodes.interfaces.NoCodesDelegate
67
import io.qonversion.nocodes.interfaces.PurchaseDelegate
78
import io.qonversion.nocodes.interfaces.PurchaseDelegateWithCallbacks
@@ -145,4 +146,16 @@ interface NoCodes {
145146
* @param locale the custom locale code, or null to use system default.
146147
*/
147148
fun setLocale(locale: String?)
149+
150+
/**
151+
* Set the theme mode for No-Code screens.
152+
* Controls how screens adapt to light/dark themes.
153+
*
154+
* You may set theme both *after* Qonversion No-Codes SDK initializing with [NoCodes.setTheme]
155+
* and *while* Qonversion No-Codes initializing via [NoCodesConfig.Builder.setTheme]
156+
*
157+
* @param theme the desired theme mode. Use [NoCodesTheme.Auto] to follow device settings,
158+
* [NoCodesTheme.Light] to force light theme, or [NoCodesTheme.Dark] to force dark theme.
159+
*/
160+
fun setTheme(theme: NoCodesTheme)
148161
}

nocodes/src/main/java/io/qonversion/nocodes/NoCodesConfig.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.qonversion.nocodes
33
import android.app.Application
44
import android.content.Context
55
import io.qonversion.nocodes.dto.LogLevel
6+
import io.qonversion.nocodes.dto.NoCodesTheme
67
import io.qonversion.nocodes.interfaces.NoCodesDelegate
78
import io.qonversion.nocodes.interfaces.PurchaseDelegate
89
import io.qonversion.nocodes.interfaces.PurchaseDelegateWithCallbacks
@@ -32,6 +33,7 @@ class NoCodesConfig internal constructor(
3233
internal val purchaseDelegate: PurchaseDelegate?,
3334
internal val purchaseDelegateWithCallbacks: PurchaseDelegateWithCallbacks?,
3435
internal val locale: String?,
36+
internal val theme: NoCodesTheme,
3537
) {
3638

3739
/**
@@ -57,6 +59,7 @@ class NoCodesConfig internal constructor(
5759
private var logTag = DEFAULT_LOG_TAG
5860
private var customFallbackFileName: String? = null
5961
private var locale: String? = null
62+
private var theme: NoCodesTheme = NoCodesTheme.Auto
6063

6164
/**
6265
* Provide a delegate to be notified about the no-code screens events.
@@ -171,6 +174,18 @@ class NoCodesConfig internal constructor(
171174
this.locale = locale
172175
}
173176

177+
/**
178+
* Set the theme mode for No-Code screens.
179+
* Controls how screens adapt to light/dark themes.
180+
*
181+
* @param theme the desired theme mode. Use [NoCodesTheme.Auto] to follow device settings,
182+
* [NoCodesTheme.Light] to force light theme, or [NoCodesTheme.Dark] to force dark theme.
183+
* @return builder instance for chain calls.
184+
*/
185+
fun setTheme(theme: NoCodesTheme): Builder = apply {
186+
this.theme = theme
187+
}
188+
174189
/**
175190
* Generate [NoCodesConfig] instance with all the provided configurations.
176191
* This method also validates some of the provided data.
@@ -197,6 +212,7 @@ class NoCodesConfig internal constructor(
197212
purchaseDelegate,
198213
purchaseDelegateWithCallbacks,
199214
locale,
215+
theme,
200216
)
201217
}
202218
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.qonversion.nocodes.dto
2+
3+
/**
4+
* Enum representing the theme mode for No-Code screens.
5+
* Use this to control how screens adapt to light/dark themes.
6+
*/
7+
enum class NoCodesTheme(val value: String) {
8+
/**
9+
* Automatically follow the device's system appearance (default).
10+
* The screen will use light theme in light mode and dark theme in dark mode.
11+
*/
12+
Auto("auto"),
13+
14+
/**
15+
* Force light theme regardless of device settings.
16+
*/
17+
Light("light"),
18+
19+
/**
20+
* Force dark theme regardless of device settings.
21+
*/
22+
Dark("dark")
23+
}

nocodes/src/main/java/io/qonversion/nocodes/internal/NoCodesInternal.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.qonversion.nocodes.internal
22

33
import io.qonversion.nocodes.NoCodes
44
import io.qonversion.nocodes.dto.LogLevel
5+
import io.qonversion.nocodes.dto.NoCodesTheme
56
import io.qonversion.nocodes.interfaces.NoCodesDelegate
67
import io.qonversion.nocodes.interfaces.PurchaseDelegate
78
import io.qonversion.nocodes.interfaces.PurchaseDelegateWithCallbacks
@@ -73,4 +74,8 @@ internal class NoCodesInternal(
7374
override fun setLocale(locale: String?) {
7475
internalConfig.customLocale = locale
7576
}
77+
78+
override fun setTheme(theme: NoCodesTheme) {
79+
internalConfig.theme = theme
80+
}
7681
}

nocodes/src/main/java/io/qonversion/nocodes/internal/di/controllers/ControllersAssemblyImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ internal class ControllersAssemblyImpl(
3535
miscAssembly.noCodesDelegateProvider(),
3636
miscAssembly.jsonSerializer(),
3737
mappersAssembly.actionMapper(),
38-
{ miscAssembly.customLocale() }
38+
{ miscAssembly.customLocale() },
39+
{ miscAssembly.theme() }
3940
)
4041
}
4142
}

nocodes/src/main/java/io/qonversion/nocodes/internal/di/misc/MiscAssembly.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.qonversion.nocodes.internal.di.misc
22

3+
import io.qonversion.nocodes.dto.NoCodesTheme
34
import io.qonversion.nocodes.internal.common.serializers.Serializer
45
import io.qonversion.nocodes.internal.logger.Logger
56
import io.qonversion.nocodes.internal.networkLayer.retryDelayCalculator.RetryDelayCalculator
@@ -19,6 +20,11 @@ internal interface MiscAssembly {
1920
*/
2021
fun customLocale(): String?
2122

23+
/**
24+
* Returns the current theme setting for No-Code screens.
25+
*/
26+
fun theme(): NoCodesTheme
27+
2228
fun jsonSerializer(): Serializer
2329

2430
fun exponentialDelayCalculator(): RetryDelayCalculator

nocodes/src/main/java/io/qonversion/nocodes/internal/di/misc/MiscAssemblyImpl.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.qonversion.nocodes.internal.di.misc
22

33
import android.app.Application
4+
import io.qonversion.nocodes.dto.NoCodesTheme
45
import io.qonversion.nocodes.internal.common.serializers.JsonSerializer
56
import io.qonversion.nocodes.internal.common.serializers.Serializer
67
import io.qonversion.nocodes.internal.dto.config.InternalConfig
@@ -39,6 +40,8 @@ internal class MiscAssemblyImpl(
3940

4041
override fun customLocale(): String? = internalConfig.customLocale
4142

43+
override fun theme(): NoCodesTheme = internalConfig.theme
44+
4245
override fun jsonSerializer(): Serializer = JsonSerializer()
4346

4447
override fun exponentialDelayCalculator(): RetryDelayCalculator =
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.qonversion.nocodes.internal.di.services
22

33
import io.qonversion.nocodes.internal.screen.service.FallbackService
4+
import io.qonversion.nocodes.internal.screen.service.ImagePreloader
45
import io.qonversion.nocodes.internal.screen.service.ScreenService
56

67
internal interface ServicesAssembly {
78

89
fun screenService(): ScreenService
910

1011
fun fallbackService(): FallbackService?
12+
13+
fun imagePreloader(): ImagePreloader
1114
}

nocodes/src/main/java/io/qonversion/nocodes/internal/di/services/ServicesAssemblyImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import io.qonversion.nocodes.internal.di.misc.MiscAssembly
66
import io.qonversion.nocodes.internal.di.network.NetworkAssembly
77
import io.qonversion.nocodes.internal.screen.service.FallbackService
88
import io.qonversion.nocodes.internal.screen.service.FallbackServiceImpl
9+
import io.qonversion.nocodes.internal.screen.service.ImagePreloader
10+
import io.qonversion.nocodes.internal.screen.service.ImagePreloaderImpl
911
import io.qonversion.nocodes.internal.screen.service.ScreenService
1012
import io.qonversion.nocodes.internal.screen.service.ScreenServiceImpl
1113
import io.qonversion.nocodes.internal.utils.FallbackUtils
@@ -18,12 +20,17 @@ internal class ServicesAssemblyImpl(
1820
private val effectiveFallbackFileName: String
1921
) : ServicesAssembly {
2022

23+
private val imagePreloaderInstance by lazy {
24+
ImagePreloaderImpl()
25+
}
26+
2127
private val screenServiceInstance by lazy {
2228
ScreenServiceImpl(
2329
networkAssembly.requestConfigurator(),
2430
networkAssembly.exponentialApiInteractor(),
2531
mappersAssembly.screenMapper(),
2632
fallbackService(),
33+
imagePreloader(),
2734
miscAssembly.logger()
2835
)
2936
}
@@ -45,4 +52,8 @@ internal class ServicesAssemblyImpl(
4552
miscAssembly.logger()
4653
)
4754
}
55+
56+
override fun imagePreloader(): ImagePreloader {
57+
return imagePreloaderInstance
58+
}
4859
}

0 commit comments

Comments
 (0)