Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mail-validation-ui
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt
  • Loading branch information
LunarX committed Jan 7, 2025
2 parents 1559c89 + 8b2e257 commit a4d536c
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 55 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ sentry {
}

dependencies {

implementation(project(":Core2"))
implementation(project(":Core2:Sentry"))
implementation(project(":Core2:AppIntegrity"))
implementation(project(":Core2:Compose:Core"))
implementation(project(":Core2:Matomo"))
implementation(project(":Core2:Network"))
implementation(project(":Core2:AppIntegrity"))
implementation(project(":Core2:Onboarding"))
implementation(project(":Core2:Compose:Core"))
implementation(project(":Core2:Sentry"))
implementation(project(":FileTypes"))

implementation(kotlin("reflect"))

implementation(libs.androidx.core.ktx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ package com.infomaniak.swisstransfer.di
import android.app.Application
import android.content.Context
import androidx.work.WorkManager
import com.infomaniak.core2.appintegrity.AppIntegrityManager
import com.infomaniak.core2.buildUserAgent
import com.infomaniak.swisstransfer.BuildConfig
import com.infomaniak.swisstransfer.ui.MainApplication
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import javax.inject.Singleton

@Module
Expand All @@ -39,11 +40,22 @@ object ApplicationModule {

@Provides
@Singleton
fun providesGlobalCoroutineScope(@DefaultDispatcher defaultDispatcher: CoroutineDispatcher): CoroutineScope {
return CoroutineScope(defaultDispatcher)
fun providesWorkManager(@ApplicationContext appContext: Context) = WorkManager.getInstance(appContext)

@UserAgent
@Provides
@Singleton
fun providesUserAgent(): String {
return buildUserAgent(
appId = BuildConfig.APPLICATION_ID,
appVersionCode = BuildConfig.VERSION_CODE,
appVersionName = BuildConfig.VERSION_NAME,
)
}

@Provides
@Singleton
fun providesWorkManager(@ApplicationContext context: Context) = WorkManager.getInstance(context)
fun providesAppIntegrityManager(application: Application, @UserAgent userAgent: String): AppIntegrityManager {
return AppIntegrityManager(application, userAgent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
Expand All @@ -39,4 +41,10 @@ object CoroutinesDispatchersModule {
@MainDispatcher
@Provides
fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main

@Provides
@Singleton
fun providesGlobalCoroutineScope(@DefaultDispatcher defaultDispatcher: CoroutineDispatcher): CoroutineScope {
return CoroutineScope(defaultDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
*/
package com.infomaniak.swisstransfer.di

import android.app.Application
import com.infomaniak.core2.appintegrity.AppIntegrityManager
import com.infomaniak.core2.buildUserAgent
import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection
import com.infomaniak.multiplatform_swisstransfer.common.utils.ApiEnvironment
import com.infomaniak.swisstransfer.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -33,17 +29,6 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
object SwissTransferInjectionModule {

@UserAgent
@Provides
@Singleton
fun providesUserAgent(): String {
return buildUserAgent(
appId = BuildConfig.APPLICATION_ID,
appVersionCode = BuildConfig.VERSION_CODE,
appVersionName = BuildConfig.VERSION_NAME,
)
}

@Provides
@Singleton
fun providesSwissTransferInjection(@UserAgent userAgent: String): SwissTransferInjection {
Expand All @@ -69,10 +54,4 @@ object SwissTransferInjectionModule {
@Provides
@Singleton
fun providesSharedApiUrlCreator(swissTransferInjection: SwissTransferInjection) = swissTransferInjection.sharedApiUrlCreator

@Provides
@Singleton
fun providesAppIntegrityManger(application: Application, @UserAgent userAgent: String): AppIntegrityManager {
return AppIntegrityManager(application, userAgent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ sealed class MainNavigation : NavigationDestination() {
private val TAG = MainNavigation::class.java.simpleName
val startDestination = SentDestination

// If these classes have to be renamed, they need to be renamed here too.
// Because of the minification, we can't directly use the classes names here. It won't work in production environment.
// So, if these classes have to be renamed, they need to be renamed here too.
// Don't worry if you forget, there's a unit test about that.
private const val sentDestinationName = "SentDestination"
private const val receivedDestinationName = "ReceivedDestination"
private const val settingsDestinationName = "SettingsDestination"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ class ImportFilesViewModel @Inject constructor(
private suspend fun generateNewUploadSession(): NewUploadSession {
return uploadManager.generateNewUploadSession(
duration = selectedValidityPeriodOption.value.apiValue,
authorEmail = if (selectedTransferType.value == TransferTypeUi.MAIL) transferAuthorEmail.trim() else "",
authorEmail = if (selectedTransferType.value == TransferTypeUi.Mail) transferAuthorEmail.trim() else "",
password = if (selectedPasswordOption.value == PasswordTransferOption.ACTIVATED) transferPassword else NO_PASSWORD,
message = transferMessage,
numberOfDownload = selectedDownloadLimitOption.value.apiValue,
language = selectedLanguageOption.value.apiValue,
recipientsEmails = if (selectedTransferType.value == TransferTypeUi.MAIL) validatedRecipientsEmails else emptySet(),
recipientsEmails = if (selectedTransferType.value == TransferTypeUi.Mail) validatedRecipientsEmails else emptySet(),
files = importationFilesManager.importedFiles.value.mapToList { fileUi ->
object : UploadFileSession {
override val path: String? = null
Expand All @@ -181,7 +181,7 @@ class ImportFilesViewModel @Inject constructor(
}

//region Transfer Type
val selectedTransferType = savedStateHandle.getStateFlow(SELECTED_TRANSFER_TYPE, TransferTypeUi.QR_CODE)
val selectedTransferType = savedStateHandle.getStateFlow(SELECTED_TRANSFER_TYPE, TransferTypeUi.QrCode)

fun selectTransferType(type: TransferTypeUi) {
savedStateHandle[SELECTED_TRANSFER_TYPE] = type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
closeActivity = closeActivity,
navigateBack = { navController.popBackStack() },
navigateToUploadInProgress = { totalSize ->
navController.navigate(UploadProgressDestination(TransferTypeUi.MAIL, totalSize, args.recipients))
navController.navigate(UploadProgressDestination(TransferTypeUi.Mail, totalSize, args.recipients))
},
emailToValidate = args.userEmail,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fun ImportFilesScreen(
)
)

if (selectedTransferType == TransferTypeUi.MAIL) {
if (selectedTransferType == TransferTypeUi.Mail) {
add(
TransferOptionState(
transferOptionType = TransferOptionType.LANGUAGE,
Expand Down Expand Up @@ -211,7 +211,7 @@ private fun ImportFilesScreen(
snackbarHostState: SnackbarHostState? = null,
) {

val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } }
val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.Mail } }
val areEmailsCorrects by remember {
derivedStateOf {
with(emailTextFieldCallbacks) {
Expand Down Expand Up @@ -539,7 +539,7 @@ private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files:
currentSessionFilesCount = { 0 },
emailTextFieldCallbacks = emailTextFieldCallbacks,
transferMessageCallbacks = GetSetCallbacks(get = { "" }, set = {}),
selectedTransferType = GetSetCallbacks(get = { TransferTypeUi.MAIL }, set = {}),
selectedTransferType = GetSetCallbacks(get = { TransferTypeUi.Mail }, set = {}),
transferOptionsCallbacks = transferOptionsCallbacks,
addFiles = {},
closeActivity = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,36 @@ fun TransferTypeButtons(horizontalPadding: Dp, transferType: GetSetCallbacks<Tra
}
}

// DO NOT RENAME THESE ENUMS. Their `.name` is used when sending Notifications.
enum class TransferTypeUi(
val buttonIcon: ImageVector,
@StringRes val buttonTextRes: Int,
@StringRes val titleRes: Int,
@StringRes @PluralsRes val descriptionRes: Int?,
val dbValue: TransferType,
) {
QR_CODE(
QrCode(
buttonIcon = AppIcons.QrCode,
buttonTextRes = R.string.transferTypeQrCode,
titleRes = R.string.uploadSuccessQrTitle,
descriptionRes = null,
dbValue = TransferType.QR_CODE,
),
MAIL(
Mail(
buttonIcon = AppIcons.Envelope,
buttonTextRes = R.string.transferTypeEmail,
titleRes = R.string.uploadSuccessEmailTitle,
descriptionRes = R.plurals.uploadSuccessEmailDescription,
dbValue = TransferType.MAIL,
),
LINK(
Link(
buttonIcon = AppIcons.Chain,
buttonTextRes = R.string.transferTypeLink,
titleRes = R.string.uploadSuccessLinkTitle,
descriptionRes = R.string.uploadSuccessLinkDescription,
dbValue = TransferType.LINK,
),
PROXIMITY(
Proximity(
buttonIcon = AppIcons.WifiWave,
buttonTextRes = R.string.transferTypeProximity,
titleRes = R.string.uploadSuccessLinkTitle,
Expand All @@ -103,10 +104,10 @@ enum class TransferTypeUi(

companion object {
fun TransferType.toTransferTypeUi() = when (this) {
TransferType.LINK -> LINK
TransferType.QR_CODE -> QR_CODE
TransferType.PROXIMITY -> PROXIMITY
TransferType.MAIL -> MAIL
TransferType.LINK -> Link
TransferType.QR_CODE -> QrCode
TransferType.PROXIMITY -> Proximity
TransferType.MAIL -> Mail
}
}
}
Expand All @@ -118,7 +119,7 @@ private fun TransferTypeButtonsPreview() {
Surface {
TransferTypeButtons(
horizontalPadding = Margin.Medium,
transferType = GetSetCallbacks(get = { TransferTypeUi.QR_CODE }, set = {}),
transferType = GetSetCallbacks(get = { TransferTypeUi.QrCode }, set = {}),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ fun UploadSuccessEmailScreen(emails: List<String>, closeActivity: () -> Unit) {

IllustratedMessageBlock(
icon = AppIllus.Beers.image(),
title = TransferTypeUi.MAIL.titleRes,
description = pluralStringResource(TransferTypeUi.MAIL.descriptionRes!!, emails.count()),
title = TransferTypeUi.Mail.titleRes,
description = pluralStringResource(TransferTypeUi.Mail.descriptionRes!!, emails.count()),
)

Spacer(Modifier.height(Margin.Medium))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private fun UploadSuccessQrScreenPreview() {
SwissTransferTheme {
Surface {
UploadSuccessQrScreen(
transferType = TransferTypeUi.QR_CODE,
transferType = TransferTypeUi.QrCode,
transferUrl = "https://chk.me/83azQOl",
closeActivity = {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun UploadSuccessScreen(
) {
BackHandler(onBack = closeActivity)

if (transferType == TransferTypeUi.MAIL) {
if (transferType == TransferTypeUi.Mail) {
UploadSuccessEmailScreen(emails = recipients, closeActivity = closeActivity)
} else {
UploadSuccessQrScreen(transferType, transferUrl, closeActivity)
Expand All @@ -46,7 +46,7 @@ private fun UploadSuccessScreenPreview() {
SwissTransferTheme {
Surface {
UploadSuccessScreen(
transferType = TransferTypeUi.QR_CODE,
transferType = TransferTypeUi.QrCode,
transferUrl = "https://chk.me/83azQOl",
recipients = emptyList(),
closeActivity = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class UploadWorker @AssistedInject constructor(
return Success(
uploadedSize = outputData.getLong(UPLOADED_BYTES_TAG, 0L),
transferUrl = outputData.getString(TRANSFER_UUID_TAG)
?.let { transferUuid -> sharedApiUrlCreator.shareTransferUrl(transferUuid) } ?: return null
?.let { transferUuid -> sharedApiUrlCreator.shareTransferUrl(transferUuid) } ?: return null,
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ dependencyResolutionManagement {
rootProject.name = "android-SwissTransfer"
include(":app")
include(":Core2")
include(":Core2:Sentry")
include(":Core2:AppIntegrity")
include(":Core2:Compose:Core")
include(":Core2:Matomo")
include(":Core2:Network")
include(":Core2:Onboarding")
include(":Core2:Compose:Core")
include(":Core2:AppIntegrity")
include(":Core2:Sentry")
include(":FileTypes")

0 comments on commit a4d536c

Please sign in to comment.