Skip to content

Commit

Permalink
Merge pull request #95 from Infomaniak/is-email-language-default
Browse files Browse the repository at this point in the history
Feature: Add specific Android and iOS code to set the default email language to match the phone's language
  • Loading branch information
tevincent authored Nov 15, 2024
2 parents d51671c + 61a89f0 commit d2c1862
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface AppSettings {
val validityPeriod: ValidityPeriod
val downloadLimit: DownloadLimit
val emailLanguage: EmailLanguage

val lastTransferType: TransferType
val lastAuthorEmail: String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.utils

import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import java.util.Locale

actual class EmailLanguageUtils actual constructor() {

actual fun getEmailLanguageFromLocal(): EmailLanguage {
return when (Locale.getDefault().language) {
"fr" -> EmailLanguage.FRENCH
"de" -> EmailLanguage.GERMAN
"it" -> EmailLanguage.ITALIAN
"es" -> EmailLanguage.SPANISH
else -> EmailLanguage.ENGLISH
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.utils

import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import platform.Foundation.NSLocale
import platform.Foundation.currentLocale
import platform.Foundation.languageCode

actual class EmailLanguageUtils actual constructor() {
actual fun getEmailLanguageFromLocal(): EmailLanguage {
val currentLocale = NSLocale.currentLocale
return when (currentLocale.languageCode) {
"fr" -> EmailLanguage.FRENCH
"de" -> EmailLanguage.GERMAN
"es" -> EmailLanguage.SPANISH
"it" -> EmailLanguage.ITALIAN
else -> EmailLanguage.ENGLISH
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.infomaniak.multiplatform_swisstransfer.managers.UploadManager
import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider
import com.infomaniak.multiplatform_swisstransfer.network.repositories.TransferRepository
import com.infomaniak.multiplatform_swisstransfer.network.repositories.UploadRepository
import com.infomaniak.multiplatform_swisstransfer.utils.EmailLanguageUtils

/**
* SwissTransferInjection is a class responsible for initializing all the classes needed
Expand Down Expand Up @@ -58,14 +59,24 @@ class SwissTransferInjection(
private val uploadController by lazy { UploadController(realmProvider) }
private val transferController by lazy { TransferController(realmProvider) }

private val emailLanguageUtils by lazy { EmailLanguageUtils() }

/** A manager used to orchestrate Transfers operations. */
val transferManager by lazy { TransferManager(apiClientProvider, transferController, transferRepository) }

/** A manager used to orchestrate AppSettings operations. */
val appSettingsManager by lazy { AppSettingsManager(appSettingsController) }

/** A manager used to orchestrate Accounts operations. */
val accountManager by lazy { AccountManager(appSettingsController, uploadController, transferController, realmProvider) }
val accountManager by lazy {
AccountManager(
appSettingsController = appSettingsController,
emailLanguageUtils = emailLanguageUtils,
uploadController = uploadController,
transferController = transferController,
realmProvider = realmProvider,
)
}

/** A manager used to orchestrate Uploads operations. */
val uploadManager by lazy { UploadManager(uploadController, uploadRepository, transferManager) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider
import com.infomaniak.multiplatform_swisstransfer.database.controllers.AppSettingsController
import com.infomaniak.multiplatform_swisstransfer.database.controllers.TransferController
import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController
import com.infomaniak.multiplatform_swisstransfer.utils.EmailLanguageUtils
import kotlin.coroutines.cancellation.CancellationException

/**
Expand All @@ -34,6 +35,7 @@ import kotlin.coroutines.cancellation.CancellationException
*/
class AccountManager internal constructor(
private val appSettingsController: AppSettingsController,
private val emailLanguageUtils: EmailLanguageUtils,
private val uploadController: UploadController,
private val transferController: TransferController,
private val realmProvider: RealmProvider,
Expand All @@ -44,7 +46,7 @@ class AccountManager internal constructor(
*/
@Throws(RealmException::class, CancellationException::class)
suspend fun loadUser(userId: Int) {
appSettingsController.initAppSettings()
appSettingsController.initAppSettings(emailLanguageUtils.getEmailLanguageFromLocal())
realmProvider.openRealmTransfers(userId)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.utils

import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage

expect class EmailLanguageUtils() {
fun getEmailLanguageFromLocal(): EmailLanguage
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class AppSettingsController(private val realmProvider: RealmProvider) {
private val appSettingsQuery get() = realm.query<AppSettingsDB>().first()

@Throws(RealmException::class, CancellationException::class)
suspend fun initAppSettings() = runThrowingRealm {
suspend fun initAppSettings(defaultEmailLanguage: EmailLanguage) = runThrowingRealm {
if (appSettingsQuery.find() == null) {
realm.write {
copyToRealm(AppSettingsDB(), UpdatePolicy.ALL)
copyToRealm(AppSettingsDB(defaultEmailLanguage), UpdatePolicy.ALL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ package com.infomaniak.multiplatform_swisstransfer.database.models.appSettings
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings
import com.infomaniak.multiplatform_swisstransfer.common.models.*
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.Ignore

class AppSettingsDB : RealmObject, AppSettings {
class AppSettingsDB(): RealmObject, AppSettings {

@Ignore
private var defaultEmailLanguage = EmailLanguage.ENGLISH

constructor(defaultEmailLanguage: EmailLanguage): this() {
this.defaultEmailLanguage = defaultEmailLanguage
}

//region Options available in App Settings
private var _theme: String = Theme.SYSTEM.value
override var theme: Theme
get() = Theme.entries.find { it.value == _theme } ?: DEFAULT_THEME
Expand All @@ -44,12 +53,13 @@ class AppSettingsDB : RealmObject, AppSettings {
_downloadLimit = value.value
}

private var _emailLanguage: String = DEFAULT_EMAIL_LANGUAGE.value
private var _emailLanguage: String = defaultEmailLanguage.value
override var emailLanguage: EmailLanguage
get() = EmailLanguage.entries.find { it.value == _emailLanguage } ?: DEFAULT_EMAIL_LANGUAGE
get() = EmailLanguage.entries.find { it.value == _emailLanguage } ?: defaultEmailLanguage
set(value) {
_emailLanguage = value.value
}
//endregion

private var _lastTransferType: String = DEFAULT_TRANSFER_TYPE.name
override var lastTransferType: TransferType
Expand All @@ -61,10 +71,10 @@ class AppSettingsDB : RealmObject, AppSettings {
override var lastAuthorEmail: String? = null

companion object {
private val DEFAULT_THEME = Theme.SYSTEM
val DEFAULT_VALIDITY_PERIOD = ValidityPeriod.THIRTY
val DEFAULT_DOWNLOAD_LIMIT = DownloadLimit.TWO_HUNDRED_FIFTY
private val DEFAULT_EMAIL_LANGUAGE = EmailLanguage.ENGLISH
private val DEFAULT_THEME = Theme.SYSTEM

private val DEFAULT_TRANSFER_TYPE = TransferType.QR_CODE
}
}

0 comments on commit d2c1862

Please sign in to comment.