Added IntEnum support for UserSettings

This commit is contained in:
Jorge Martín
2021-09-20 17:12:30 +02:00
parent e5061c7dfc
commit 5fc2de6837
12 changed files with 116 additions and 50 deletions
+8
View File
@@ -1,3 +1,11 @@
## User Settings [1.15.1]
Sep 20, 2021
### New Features
- Added IntEnum support for UserSettings.
## Test Android Instrumented [1.15.1]
Sep 12, 2021
+1 -1
View File
@@ -23,7 +23,7 @@ plugins {
kotlin("android")
}
libVersion = Version(1, 15, 0)
libVersion = Version(1, 15, 1)
android()
+1 -1
View File
@@ -24,7 +24,7 @@ plugins {
kotlin("plugin.serialization")
}
libVersion = Version(1, 15, 0)
libVersion = Version(1, 15, 1)
android()
@@ -37,6 +37,7 @@ import me.proton.core.usersettings.domain.entity.RecoverySetting
import me.proton.core.usersettings.domain.entity.TwoFASetting
import me.proton.core.usersettings.domain.entity.U2FKeySetting
import me.proton.core.usersettings.domain.entity.UserSettings
import me.proton.core.usersettings.domain.entity.UserSettings.*
import me.proton.core.util.kotlin.toBoolean
import me.proton.core.util.kotlin.toInt
@@ -50,14 +51,14 @@ internal fun UserSettingsResponse.fromResponse(userId: UserId) = UserSettings(
twoFA = twoFA?.fromResponse(),
news = news,
locale = locale,
logAuth = logAuth,
logAuth = LogAuth.enumOf(logAuth),
invoiceText = invoiceText,
density = density,
density = Density.enumOf(density),
theme = theme,
themeType = themeType,
weekStart = weekStart,
dateFormat = dateFormat,
timeFormat = timeFormat,
weekStart = WeekStart.enumOf(weekStart),
dateFormat = DateFormat.enumOf(dateFormat),
timeFormat = TimeFormat.enumOf(timeFormat),
welcome = welcome.toBoolean(),
earlyAccess = earlyAccess.toBoolean(),
flags = flags?.fromResponse()
@@ -83,14 +84,14 @@ internal fun UserSettingsEntity.fromEntity() = UserSettings(
twoFA = twoFA?.fromEntity(),
news = news,
locale = locale,
logAuth = logAuth,
logAuth = LogAuth.enumOf(logAuth),
invoiceText = invoiceText,
density = density,
density = Density.enumOf(density),
theme = theme,
themeType = themeType,
weekStart = weekStart,
dateFormat = dateFormat,
timeFormat = timeFormat,
weekStart = WeekStart.enumOf(weekStart),
dateFormat = DateFormat.enumOf(dateFormat),
timeFormat = TimeFormat.enumOf(timeFormat),
welcome = welcome,
earlyAccess = earlyAccess,
flags = flags?.fromEntity()
@@ -104,14 +105,14 @@ internal fun UserSettings.toEntity() = UserSettingsEntity(
twoFA = twoFA?.toEntity(),
news = news,
locale = locale,
logAuth = logAuth,
logAuth = logAuth?.value,
invoiceText = invoiceText,
density = density,
density = density?.value,
theme = theme,
themeType = themeType,
weekStart = weekStart,
dateFormat = dateFormat,
timeFormat = timeFormat,
weekStart = weekStart?.value,
dateFormat = dateFormat?.value,
timeFormat = timeFormat?.value,
welcome = welcome,
earlyAccess = earlyAccess,
flags = flags?.toEntity()
+1 -1
View File
@@ -23,7 +23,7 @@ plugins {
kotlin("jvm")
}
libVersion = Version(1, 15, 0)
libVersion = Version(1, 15, 1)
dependencies {
@@ -19,6 +19,7 @@
package me.proton.core.usersettings.domain.entity
import me.proton.core.domain.entity.UserId
import me.proton.core.domain.type.IntEnum
data class UserSettings(
val userId: UserId,
@@ -28,18 +29,74 @@ data class UserSettings(
val twoFA: TwoFASetting?,
val news: Int?,
val locale: String?,
val logAuth: Int?,
val logAuth: IntEnum<LogAuth>?,
val invoiceText: String?,
val density: Int?,
val density: IntEnum<Density>?,
val theme: String?,
val themeType: Int?,
val weekStart: Int?,
val dateFormat: Int?,
val timeFormat: Int?,
val weekStart: IntEnum<WeekStart>?,
val dateFormat: IntEnum<DateFormat>?,
val timeFormat: IntEnum<TimeFormat>?,
val welcome: Boolean?,
val earlyAccess: Boolean?,
val flags: Flags?
)
) {
enum class LogAuth(val value: Int) {
Disabled(0),
Basic(1),
Advanced(2);
companion object {
val map = values().associateBy { it.value }
fun enumOf(value: Int?) = value?.let { IntEnum(it, map[it]) }
}
}
enum class Density(val value: Int) {
Comfortable(0),
Compact(1);
companion object {
val map = values().associateBy { it.value }
fun enumOf(value: Int?) = value?.let { IntEnum(it, map[it]) }
}
}
enum class WeekStart(val value: Int) {
Default(0),
Monday(1),
Saturday(6),
Sunday(7);
companion object {
val map = values().associateBy { it.value }
fun enumOf(value: Int?) = value?.let { IntEnum(it, map[it]) }
}
}
enum class DateFormat(val value: Int) {
Default(0),
DayMonthYear(1),
MonthDayYear(2),
YearMonthDay(3);
companion object {
val map = values().associateBy { it.value }
fun enumOf(value: Int?) = value?.let { IntEnum(it, map[it]) }
}
}
enum class TimeFormat(val value: Int) {
Default(0),
TwentyFourHours(1),
TwelveHours(2);
companion object {
val map = values().associateBy { it.value }
fun enumOf(value: Int?) = value?.let { IntEnum(it, map[it]) }
}
}
}
data class RecoverySetting(
val value: String?,
@@ -50,13 +50,13 @@ class GetSettingsTest {
password = PasswordSetting(mode = 1, expirationTime = null),
news = 0,
locale = "en",
logAuth = 1,
density = 1,
logAuth = UserSettings.LogAuth.enumOf(1),
density = UserSettings.Density.enumOf(1),
invoiceText = "",
dateFormat = 1,
timeFormat = 2,
dateFormat = UserSettings.DateFormat.enumOf(1),
timeFormat = UserSettings.TimeFormat.enumOf(2),
themeType = 1,
weekStart = 7,
weekStart = UserSettings.WeekStart.enumOf(7),
welcome = true,
earlyAccess = true,
theme = "test-theme",
@@ -104,13 +104,13 @@ class PerformUpdateLoginPasswordTest {
password = PasswordSetting(mode = 1, expirationTime = null),
news = 0,
locale = "en",
logAuth = 1,
density = 1,
logAuth = UserSettings.LogAuth.enumOf(1),
density = UserSettings.Density.enumOf(1),
invoiceText = "",
dateFormat = 1,
timeFormat = 2,
dateFormat = UserSettings.DateFormat.enumOf(1),
timeFormat = UserSettings.TimeFormat.enumOf(2),
themeType = 1,
weekStart = 7,
weekStart = UserSettings.WeekStart.enumOf(7),
welcome = true,
earlyAccess = true,
theme = "test-theme",
@@ -69,13 +69,13 @@ class PerformUpdateRecoveryEmailTest {
password = PasswordSetting(mode = 1, expirationTime = null),
news = 0,
locale = "en",
logAuth = 1,
density = 1,
logAuth = UserSettings.LogAuth.enumOf(1),
density = UserSettings.Density.enumOf(1),
invoiceText = "",
dateFormat = 1,
timeFormat = 2,
dateFormat = UserSettings.DateFormat.enumOf(1),
timeFormat = UserSettings.TimeFormat.enumOf(2),
themeType = 1,
weekStart = 7,
weekStart = UserSettings.WeekStart.enumOf(7),
welcome = true,
earlyAccess = true,
theme = "test-theme",
+1 -1
View File
@@ -27,7 +27,7 @@ plugins {
id("dagger.hilt.android.plugin")
}
libVersion = Version(1, 15, 0)
libVersion = Version(1, 15, 1)
android(useDataBinding = true)
@@ -67,13 +67,13 @@ class PasswordManagementViewModelTest : ArchTest, CoroutinesTest {
password = PasswordSetting(mode = 1, expirationTime = null),
news = 0,
locale = "en",
logAuth = 1,
density = 1,
logAuth = UserSettings.LogAuth.enumOf(1),
density = UserSettings.Density.enumOf(1),
invoiceText = "",
dateFormat = 1,
timeFormat = 2,
dateFormat = UserSettings.DateFormat.enumOf(1),
timeFormat = UserSettings.TimeFormat.enumOf(2),
themeType = 1,
weekStart = 7,
weekStart = UserSettings.WeekStart.enumOf(7),
welcome = true,
earlyAccess = true,
theme = "test-theme",
@@ -65,13 +65,13 @@ class UpdateRecoveryEmailViewModelTest : ArchTest, CoroutinesTest {
password = PasswordSetting(mode = 1, expirationTime = null),
news = 0,
locale = "en",
logAuth = 1,
density = 1,
logAuth = UserSettings.LogAuth.enumOf(1),
density = UserSettings.Density.enumOf(1),
invoiceText = "",
dateFormat = 1,
timeFormat = 2,
dateFormat = UserSettings.DateFormat.enumOf(1),
timeFormat = UserSettings.TimeFormat.enumOf(2),
themeType = 1,
weekStart = 7,
weekStart = UserSettings.WeekStart.enumOf(7),
welcome = true,
earlyAccess = true,
theme = "test-theme",