Skip to content

Commit

Permalink
feat: Implementing "Edit" & "Retry" features (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne authored Dec 24, 2024
2 parents 52057ef + 3892f8b commit 70a62d4
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,30 @@ sealed class NewTransferNavigation : NavigationDestination() {

@Serializable
data object ImportFilesDestination : NewTransferNavigation()

@Serializable
data object ValidateUserEmailDestination : NewTransferNavigation()

@Serializable
data class UploadProgressDestination(
val transferType: TransferTypeUi,
val totalSize: Long,
val recipients: List<String>,
) : NewTransferNavigation()

@Serializable
data class UploadSuccessDestination(
val transferType: TransferTypeUi,
val transferUrl: String,
val recipients: List<String>,
) : NewTransferNavigation()

@Serializable
data object UploadErrorDestination : NewTransferNavigation()
data class UploadErrorDestination(
val transferType: TransferTypeUi,
val totalSize: Long,
val recipients: List<String>,
) : NewTransferNavigation()

companion object {
val startDestination = ImportFilesDestination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ class ImportFilesViewModel @Inject constructor(
viewModelScope.launch(ioDispatcher) {
if (isFirstViewModelCreation) {
isFirstViewModelCreation = false
// Remove old imported files in case it would've crashed or similar to start with a clean slate. This is required
// for already imported files restoration to not pick up old files in some extreme cases.

// Remove old imported files in case it would've crashed (or similar) to start with a clean slate.
// This is required for already imported files restoration to not pick up old files in some extreme cases.
removeOldData()

// Set default values to advanced transfer options. This need to be done here in the `init`,
// because we only want to do it once. If we come back from a cancelled or edited transfer,
// we don't want to erase user's choices about advanced transfer options.
initTransferOptionsValues()

} else {
importationFilesManager.restoreAlreadyImportedFiles()
}
Expand Down Expand Up @@ -233,7 +240,7 @@ class ImportFilesViewModel @Inject constructor(
)
}

fun initTransferOptionsValues() {
private fun initTransferOptionsValues() {
viewModelScope.launch(ioDispatcher) {
appSettingsManager.getAppSettings()?.let {
selectTransferValidityPeriod(it.validityPeriod.toTransferOption())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.ValidateUs
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.UploadErrorScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.UploadProgressScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.UploadSuccessScreen
import io.sentry.Sentry
import io.sentry.SentryLevel

@Composable
fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Unit) {
Expand All @@ -52,7 +54,11 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
navigateToUploadSuccess = { transferUrl ->
navController.navigate(UploadSuccessDestination(args.transferType, transferUrl, args.recipients))
},
navigateToUploadError = { navController.navigate(UploadErrorDestination) },
navigateToUploadError = {
navController.navigate(
UploadErrorDestination(args.transferType, args.totalSize, args.recipients),
)
},
navigateBackToImportFiles = { navController.popBackStack(route = ImportFilesDestination, inclusive = false) },
)
}
Expand All @@ -66,7 +72,29 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
)
}
composable<UploadErrorDestination> {
UploadErrorScreen(navigateToImportFiles = { navController.navigate(ImportFilesDestination) })
val args = it.toRoute<UploadErrorDestination>()
UploadErrorScreen(
navigateBackToUploadProgress = {
val hasPoppedBack = navController.popBackStack(
route = UploadProgressDestination(args.transferType, args.totalSize, args.recipients),
inclusive = false,
)
if (!hasPoppedBack) {
navController.navigate(UploadProgressDestination(args.transferType, args.totalSize, args.recipients))
Sentry.captureMessage(
"PopBackStack to retry transfer after error has failed",
SentryLevel.ERROR,
) { scope ->
scope.setExtra("transferType", args.transferType.toString())
scope.setExtra("totalSize", args.totalSize.toString())
scope.setExtra("recipients.count", args.recipients.count().toString())
}
}
},
navigateBackToImportFiles = {
navController.popBackStack(route = ImportFilesDestination, inclusive = false)
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ fun ImportFilesScreen(
resetSendActionResult = importFilesViewModel::resetSendActionResult,
)

LaunchedEffect(Unit) { importFilesViewModel.initTransferOptionsValues() }

val transferOptionsCallbacks = importFilesViewModel.getTransferOptionsCallbacks(
transferOptionsStates = {
buildList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,36 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer.upload
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.BottomStickyButtonScaffold
import com.infomaniak.swisstransfer.ui.components.BrandTopAppBar
import com.infomaniak.swisstransfer.ui.components.EmptyState
import com.infomaniak.swisstransfer.ui.components.LargeButton
import com.infomaniak.swisstransfer.ui.components.*
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.uploadError.GhostMagnifyingGlassQuestionMark
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import com.infomaniak.core2.R as RCore2

@Composable
fun UploadErrorScreen(navigateToImportFiles: () -> Unit) {
fun UploadErrorScreen(
navigateBackToUploadProgress: () -> Unit,
navigateBackToImportFiles: () -> Unit,
uploadProgressViewModel: UploadProgressViewModel = hiltViewModel<UploadProgressViewModel>(),
) {
BottomStickyButtonScaffold(
topBar = { BrandTopAppBar() },
bottomButton = {
topButton = {
LargeButton(
modifier = it,
title = stringResource(RCore2.string.buttonRetry),
onClick = navigateToImportFiles,
onClick = { uploadProgressViewModel.resendLastTransfer(onCompletion = navigateBackToUploadProgress) },
)
},
bottomButton = {
LargeButton(
modifier = it,
title = stringResource(R.string.buttonEditTransfer),
style = ButtonType.SECONDARY,
onClick = { uploadProgressViewModel.removeAllUploadSession(onCompletion = navigateBackToImportFiles) },
)
}
) {
Expand All @@ -56,7 +66,7 @@ fun UploadErrorScreen(navigateToImportFiles: () -> Unit) {
private fun UploadErrorScreenPreview() {
SwissTransferTheme {
Surface {
UploadErrorScreen({})
UploadErrorScreen({}, {})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ import com.infomaniak.multiplatform_swisstransfer.managers.UploadManager
import com.infomaniak.network.NetworkAvailability
import com.infomaniak.sentry.SentryLog
import com.infomaniak.swisstransfer.di.IoDispatcher
import com.infomaniak.swisstransfer.di.MainDispatcher
import com.infomaniak.swisstransfer.ui.screen.newtransfer.TransferSendManager
import com.infomaniak.swisstransfer.workers.UploadWorker
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
class UploadProgressViewModel @Inject constructor(
@ApplicationContext private val appContext: Context,
private val uploadWorkerScheduler: UploadWorker.Scheduler,
private val uploadManager: UploadManager,
private val transferSendManager: TransferSendManager,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
) : ViewModel() {

val isNetworkAvailable = NetworkAvailability(appContext).isNetworkAvailable
Expand Down Expand Up @@ -91,6 +96,20 @@ class UploadProgressViewModel @Inject constructor(
}
}

fun removeAllUploadSession(onCompletion: () -> Unit) {
viewModelScope.launch(ioDispatcher) {
uploadManager.removeAllUploadSession()
withContext(mainDispatcher) { onCompletion() }
}
}

fun resendLastTransfer(onCompletion: () -> Unit) {
viewModelScope.launch(ioDispatcher) {
transferSendManager.resendLastTransfer()
withContext(mainDispatcher) { onCompletion() }
}
}

companion object {
private val TAG = UploadProgressViewModel::class.java.simpleName
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="buttonCopyLink">Link kopieren</string>
<string name="buttonDownload">Download</string>
<string name="buttonDownloadSelected">Auswahl herunterladen</string>
<string name="buttonEditTransfer">Meine Übertragung bearbeiten</string>
<string name="buttonFinished">Beenden</string>
<string name="buttonShare">Teilen</string>
<string name="buttonStart">Starten</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="buttonCopyLink">Copiar enlace</string>
<string name="buttonDownload">Descargar</string>
<string name="buttonDownloadSelected">Descargar la selección</string>
<string name="buttonEditTransfer">Editar mi transferencia</string>
<string name="buttonFinished">Acabado</string>
<string name="buttonShare">Compartir</string>
<string name="buttonStart">Inicio</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="buttonCopyLink">Copier le lien</string>
<string name="buttonDownload">Télécharger</string>
<string name="buttonDownloadSelected">Télécharger la sélection</string>
<string name="buttonEditTransfer">Modifier mon transfert</string>
<string name="buttonFinished">Terminer</string>
<string name="buttonShare">Partager</string>
<string name="buttonStart">Démarrer</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="buttonCopyLink">Copia link</string>
<string name="buttonDownload">Scaricare</string>
<string name="buttonDownloadSelected">Scarica la selezione</string>
<string name="buttonEditTransfer">Modifica mio trasferimento</string>
<string name="buttonFinished">Finisci</string>
<string name="buttonShare">Condividi</string>
<string name="buttonStart">Inizio</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<string name="buttonCopyLink">Copy link</string>
<string name="buttonDownload">Download</string>
<string name="buttonDownloadSelected">Download selection</string>
<string name="buttonEditTransfer">Edit my transfer</string>
<string name="buttonFinished">Finish</string>
<string name="buttonShare">Share</string>
<string name="buttonStart">Start</string>
Expand Down

0 comments on commit 70a62d4

Please sign in to comment.