Skip to content

Commit

Permalink
Rename variables and classes
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Oct 21, 2024
1 parent f6558cf commit c5f41a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class TransferFilesManager @Inject constructor(@ApplicationContext private val appContext: Context) {
class ImportationFilesManager @Inject constructor(@ApplicationContext private val appContext: Context) {

private val filesToImport: TransferCountChannel = TransferCountChannel()
val filesToImportCount: StateFlow<Int> = filesToImport.count
Expand All @@ -51,8 +51,8 @@ class TransferFilesManager @Inject constructor(@ApplicationContext private val a
private val _failedFiles = MutableSharedFlow<PickedFile>()
val failedFiles = _failedFiles.asSharedFlow()

// Importing a file locally can take up time. We can't base the list of already used names on _files because a new import with
// the same name could occur while the file is not finished importing yet.
// Importing a file locally can take up time. We can't base the list of already used names on _importedFiles's value because a
// new import with the same name could occur while the file is still importing. This would lead to a name collision.
// This list needs to mark a name as "taken" as soon as the file is queued to be imported and until the file is removed from
// the list of already imported files we listen to in the LazyRow.
private val alreadyUsedFileNames = AlreadyUsedFileNamesSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ import javax.inject.Inject

@HiltViewModel
class NewTransferViewModel @Inject constructor(
private val transferFilesManager: TransferFilesManager,
private val importationFilesManager: ImportationFilesManager,
private val savedStateHandle: SavedStateHandle,
) : ViewModel() {

@OptIn(FlowPreview::class)
val filesDebounced = transferFilesManager.importedFiles
val importedFilesDebounced = importationFilesManager.importedFiles
.debounce(50)
.stateIn(
scope = viewModelScope,
started = SharingStarted.Lazily,
initialValue = emptyList(),
)

val failedFiles = transferFilesManager.failedFiles
val filesToImportCount = transferFilesManager.filesToImportCount
val currentSessionTotalUploadedFiles = transferFilesManager.currentSessionTotalUploadedFiles
val failedFiles = importationFilesManager.failedFiles
val filesToImportCount = importationFilesManager.filesToImportCount
val currentSessionTotalUploadedFiles = importationFilesManager.currentSessionTotalUploadedFiles

private var isFirstViewModelCreation: Boolean
get() = savedStateHandle.get<Boolean>(IS_VIEW_MODEL_RESTORED_KEY) ?: true
Expand All @@ -61,24 +61,24 @@ class NewTransferViewModel @Inject constructor(
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.
transferFilesManager.removeLocalCopyFolder()
importationFilesManager.removeLocalCopyFolder()
} else {
transferFilesManager.restoreAlreadyImportedFiles()
importationFilesManager.restoreAlreadyImportedFiles()
}

transferFilesManager.copyPickedFilesToLocalStorage()
importationFilesManager.copyPickedFilesToLocalStorage()
}
}

fun addFiles(uris: List<Uri>) {
viewModelScope.launch(Dispatchers.IO) {
transferFilesManager.addFiles(uris)
importationFilesManager.addFiles(uris)
}
}

fun removeFileByUid(uid: String) {
viewModelScope.launch(Dispatchers.IO) {
transferFilesManager.removeFileByUid(uid)
importationFilesManager.removeFileByUid(uid)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun ImportFilesScreen(
newTransferViewModel: NewTransferViewModel = hiltViewModel<NewTransferViewModel>(),
closeActivity: () -> Unit,
) {
val files by newTransferViewModel.filesDebounced.collectAsStateWithLifecycle()
val files by newTransferViewModel.importedFilesDebounced.collectAsStateWithLifecycle()
val filesToImportCount by newTransferViewModel.filesToImportCount.collectAsStateWithLifecycle()
val currentSessionTotalUploadedFiles by newTransferViewModel.currentSessionTotalUploadedFiles.collectAsStateWithLifecycle()
ImportFilesScreen(
Expand Down

0 comments on commit c5f41a8

Please sign in to comment.