feat(CON-171) : Summary consent screen
feat(CON-172) : Detail consent screen feat(-) : Send consent to BO to save them
This commit is contained in:
@ -3,10 +3,6 @@ package fr.openium.consentium.api
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.EntryPointAccessors
|
||||
import fr.openium.consentium.api.model.PurposeChoice
|
||||
import fr.openium.consentium.api.model.PurposeIdentifier
|
||||
import fr.openium.consentium.api.model.PurposeStatus
|
||||
import fr.openium.consentium.api.model.VendorIdentifier
|
||||
import fr.openium.consentium.api.model.VendorStatus
|
||||
import fr.openium.consentium.api.state.FetchConsentiumState
|
||||
import fr.openium.consentium.api.state.SetConsentiumState
|
||||
import fr.openium.consentium.domain.di.RepositoryEntryPoint
|
||||
@ -23,8 +19,8 @@ class Consentium(
|
||||
private val _fetchConsentState = MutableStateFlow<FetchConsentiumState>(FetchConsentiumState.Idle)
|
||||
val fetchConsentState by lazy { _fetchConsentState.asStateFlow() }
|
||||
|
||||
private val _setConsentState = MutableStateFlow<SetConsentiumState>(SetConsentiumState.Idle)
|
||||
val setConsentState by lazy { _setConsentState.asStateFlow() }
|
||||
private val _saveConsentState = MutableStateFlow<SetConsentiumState>(SetConsentiumState.Idle)
|
||||
val saveConsentState by lazy { _saveConsentState.asStateFlow() }
|
||||
|
||||
private val consentiumRepository: ConsentiumRepository by lazy {
|
||||
val appContext = context.applicationContext
|
||||
@ -32,34 +28,6 @@ class Consentium(
|
||||
entryPoint.provideConsentiumRepository()
|
||||
}
|
||||
|
||||
fun getConsentStatus(purpose: PurposeIdentifier): PurposeStatus {
|
||||
return when (val state = fetchConsentState.value) {
|
||||
is FetchConsentiumState.Valid -> {
|
||||
val purposeChoice = state.purposes.find { it.identifier == purpose }
|
||||
purposeChoice?.isAccepted ?: PurposeStatus.UNKNOWN
|
||||
}
|
||||
|
||||
else -> PurposeStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
fun getConsentStatus(purpose: PurposeIdentifier, vendorIdentifier: VendorIdentifier): VendorStatus {
|
||||
return when (val state = fetchConsentState.value) {
|
||||
is FetchConsentiumState.Valid -> {
|
||||
val vendorChoice = state.purposes.find { it.identifier == purpose }
|
||||
?.vendors?.find { it.identifier == vendorIdentifier }
|
||||
|
||||
when (vendorChoice?.isAccepted) {
|
||||
true -> VendorStatus.ACCEPTED
|
||||
false -> VendorStatus.REJECTED
|
||||
else -> VendorStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
else -> VendorStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fetchConsents() {
|
||||
_fetchConsentState.value = FetchConsentiumState.Loading
|
||||
try {
|
||||
@ -75,24 +43,27 @@ class Consentium(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
_fetchConsentState.value = FetchConsentiumState.Error
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setConsents(
|
||||
suspend fun saveConsents(
|
||||
consent: List<PurposeChoice>,
|
||||
) {
|
||||
_setConsentState.value = SetConsentiumState.Loading
|
||||
_saveConsentState.emit(SetConsentiumState.Loading)
|
||||
try {
|
||||
when (consentiumRepository.setConsents(applicationId, consent)) {
|
||||
ConsentiumRepositorySetResponse.Error -> _setConsentState.value = SetConsentiumState.Error
|
||||
ConsentiumRepositorySetResponse.SetConsentsSuccess -> _setConsentState.value = SetConsentiumState.Success
|
||||
}
|
||||
ConsentiumRepositorySetResponse.Error -> {
|
||||
_saveConsentState.emit(SetConsentiumState.Error)
|
||||
}
|
||||
|
||||
ConsentiumRepositorySetResponse.SetConsentsSuccess -> {
|
||||
_saveConsentState.emit(SetConsentiumState.Success)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
_setConsentState.value = SetConsentiumState.Error
|
||||
_saveConsentState.emit(SetConsentiumState.Error)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.Purpose
|
||||
import fr.openium.consentium.api.model.PurposeIdentifier
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
|
||||
internal fun GetConsent.PurposeDTO.toPurpose() = Purpose(
|
||||
identifier = PurposeIdentifier.fromString(identifier),
|
||||
identifier = identifier,
|
||||
isRequired = isRequired,
|
||||
isAccepted = isAccepted.toPurposeStatus(),
|
||||
vendors = vendors?.map { it.toVendor() } ?: emptyList(),
|
||||
|
@ -1,11 +1,10 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.Vendor
|
||||
import fr.openium.consentium.api.model.VendorIdentifier
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
|
||||
internal fun GetConsent.VendorDTO.toVendor() = Vendor(
|
||||
identifier = VendorIdentifier.fromString(identifier),
|
||||
identifier = identifier,
|
||||
isAccepted = isAccepted,
|
||||
isRequired = isRequired,
|
||||
)
|
@ -1,7 +1,7 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class Purpose(
|
||||
val identifier: PurposeIdentifier,
|
||||
val identifier: String,
|
||||
val isRequired: Boolean,
|
||||
val isAccepted: PurposeStatus,
|
||||
val vendors: List<Vendor>,
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class PurposeChoice(
|
||||
val purposeIdentifier: PurposeIdentifier,
|
||||
val purposeIdentifier: String,
|
||||
val isAccepted: Boolean,
|
||||
val vendors: List<VendorChoice>,
|
||||
)
|
@ -1,24 +0,0 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
enum class PurposeIdentifier {
|
||||
REQUIRED,
|
||||
AUDIENCE,
|
||||
ADS,
|
||||
UNKNOWN;
|
||||
|
||||
companion object {
|
||||
fun fromString(string: String): PurposeIdentifier = when (string) {
|
||||
"purpose-required" -> REQUIRED
|
||||
"purpose-audience" -> AUDIENCE
|
||||
"purpose-ads" -> ADS
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = when (this) {
|
||||
REQUIRED -> "purpose-required"
|
||||
AUDIENCE -> "purpose-audience"
|
||||
ADS -> "purpose-ads"
|
||||
else -> "purpose-unknown"
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class Vendor(
|
||||
val identifier: VendorIdentifier,
|
||||
val identifier: String,
|
||||
val isAccepted: Boolean,
|
||||
val isRequired: Boolean,
|
||||
)
|
@ -1,6 +1,6 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class VendorChoice(
|
||||
val vendorIdentifier: VendorIdentifier,
|
||||
val vendorIdentifier: String,
|
||||
val isAccepted: Boolean,
|
||||
)
|
@ -1,27 +0,0 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
enum class VendorIdentifier {
|
||||
CRASHLYTICS,
|
||||
MATOMO,
|
||||
GA4,
|
||||
CLARITY,
|
||||
UNKNOWN;
|
||||
|
||||
companion object {
|
||||
fun fromString(string: String): VendorIdentifier = when (string) {
|
||||
"vendor-clarity" -> CLARITY
|
||||
"vendor-crashlytics" -> CRASHLYTICS
|
||||
"vendor-matomo" -> MATOMO
|
||||
"vendor-ga4" -> GA4
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = when (this) {
|
||||
CLARITY -> "vendor-clarity"
|
||||
CRASHLYTICS -> "vendor-crashlytics"
|
||||
MATOMO -> "vendor-matomo"
|
||||
GA4 -> "vendor-ga4"
|
||||
else -> "vendor-unknown"
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import dagger.Reusable
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import fr.openium.consentium.BuildConfig
|
||||
import fr.openium.consentium.api.mock.ConsentiumMockApi
|
||||
import fr.openium.consentium.data.remote.mock.ConsentiumMockApi
|
||||
import fr.openium.consentium.data.remote.ConsentiumApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.Cache
|
||||
|
@ -1,4 +1,4 @@
|
||||
package fr.openium.consentium.api.mock
|
||||
package fr.openium.consentium.data.remote.mock
|
||||
|
||||
import fr.openium.consentium.data.remote.ConsentiumApi
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
@ -36,16 +36,16 @@ internal object ConsentiumMockApi : ConsentiumApi {
|
||||
vendors = null
|
||||
),
|
||||
),
|
||||
isValid = true
|
||||
isValid = false,
|
||||
)
|
||||
|
||||
override suspend fun getConsents(applicationId: String, installationId: String): Response<GetConsent.GetConsentPayloadDTO> {
|
||||
delay(500)
|
||||
delay(2000)
|
||||
return Response.success(consents)
|
||||
}
|
||||
|
||||
override suspend fun setConsents(applicationId: String, patchConsent: PatchConsent.PatchConsentPayloadDTO): Response<Any> {
|
||||
delay(500)
|
||||
delay(2000)
|
||||
return Response.success(Unit)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user