diff --git a/sample/src/main/java/com/anggrayudi/storage/sample/activity/MainActivity.kt b/sample/src/main/java/com/anggrayudi/storage/sample/activity/MainActivity.kt index c789e8f..bf28522 100644 --- a/sample/src/main/java/com/anggrayudi/storage/sample/activity/MainActivity.kt +++ b/sample/src/main/java/com/anggrayudi/storage/sample/activity/MainActivity.kt @@ -282,7 +282,7 @@ class MainActivity : AppCompatActivity() { } Toast.makeText(this, "Copying...", Toast.LENGTH_SHORT).show() ioScope.launch { - sources.copyTo(applicationContext, targetFolder, callback = createMultipleFileCallback()) + sources.copyTo(applicationContext, targetFolder, onConflict = createMultipleFileCallback()) .onCompletion { if (it is CancellationException) { // maybe you want to show to the user that the operation was cancelled @@ -336,7 +336,7 @@ class MainActivity : AppCompatActivity() { } Toast.makeText(this, "Moving...", Toast.LENGTH_SHORT).show() ioScope.launch { - sources.moveTo(applicationContext, targetFolder, callback = createMultipleFileCallback()) + sources.moveTo(applicationContext, targetFolder, onConflict = createMultipleFileCallback()) .onCompletion { if (it is CancellationException) { // maybe you want to show to the user that the operation was cancelled @@ -403,7 +403,7 @@ class MainActivity : AppCompatActivity() { } Toast.makeText(this, "Copying...", Toast.LENGTH_SHORT).show() ioScope.launch { - folder.copyFolderTo(applicationContext, targetFolder, false, callback = createFolderCallback()) + folder.copyFolderTo(applicationContext, targetFolder, false, onConflict = createFolderCallback()) .onCompletion { if (it is CancellationException) { // maybe you want to show to the user that the operation was cancelled @@ -451,7 +451,7 @@ class MainActivity : AppCompatActivity() { } Toast.makeText(this, "Moving...", Toast.LENGTH_SHORT).show() ioScope.launch { - folder.moveFolderTo(applicationContext, targetFolder, false, callback = createFolderCallback()) + folder.moveFolderTo(applicationContext, targetFolder, false, onConflict = createFolderCallback()) .onCompletion { if (it is CancellationException) { // maybe you want to show to the user that the operation was cancelled @@ -513,7 +513,7 @@ class MainActivity : AppCompatActivity() { val targetFolder = binding.layoutCopyFileTargetFolder.tvFilePath.tag as DocumentFile Toast.makeText(this, "Copying...", Toast.LENGTH_SHORT).show() ioScope.launch { - file.copyFileTo(applicationContext, targetFolder, callback = createFileCallback()) + file.copyFileTo(applicationContext, targetFolder, onConflict = createFileCallback()) .onCompletion { if (it is CancellationException) { // maybe you want to show to the user that the operation was cancelled @@ -565,7 +565,7 @@ class MainActivity : AppCompatActivity() { var tvStatus: TextView? = null var progressBar: ProgressBar? = null - file.moveFileTo(applicationContext, targetFolder, callback = createFileCallback()) + file.moveFileTo(applicationContext, targetFolder, onConflict = createFileCallback()) .onCompletion { if (it is CancellationException) { // maybe you want to show to the user that the operation was cancelled diff --git a/storage/src/main/java/com/anggrayudi/storage/file/DocumentFileExt.kt b/storage/src/main/java/com/anggrayudi/storage/file/DocumentFileExt.kt index 03150b3..db5bda4 100644 --- a/storage/src/main/java/com/anggrayudi/storage/file/DocumentFileExt.kt +++ b/storage/src/main/java/com/anggrayudi/storage/file/DocumentFileExt.kt @@ -1451,9 +1451,9 @@ fun List.moveTo( skipEmptyFiles: Boolean = true, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: MultipleFileConflictCallback + onConflict: MultipleFileConflictCallback ): Flow { - return copyTo(context, targetParentFolder, skipEmptyFiles, true, updateInterval, isFileSizeAllowed, callback) + return copyTo(context, targetParentFolder, skipEmptyFiles, true, updateInterval, isFileSizeAllowed, onConflict) } @WorkerThread @@ -1463,9 +1463,9 @@ fun List.copyTo( skipEmptyFiles: Boolean = true, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: MultipleFileConflictCallback + onConflict: MultipleFileConflictCallback ): Flow { - return copyTo(context, targetParentFolder, skipEmptyFiles, false, updateInterval, isFileSizeAllowed, callback) + return copyTo(context, targetParentFolder, skipEmptyFiles, false, updateInterval, isFileSizeAllowed, onConflict) } @OptIn(DelicateCoroutinesApi::class) @@ -1476,15 +1476,15 @@ private fun List.copyTo( deleteSourceWhenComplete: Boolean, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: MultipleFileConflictCallback + onConflict: MultipleFileConflictCallback ): Flow = callbackFlow { send(MultipleFilesResult.Validating) - val pair = doesMeetCopyRequirements(context, targetParentFolder, this, callback) ?: return@callbackFlow + val pair = doesMeetCopyRequirements(context, targetParentFolder, this, onConflict) ?: return@callbackFlow send(MultipleFilesResult.Preparing) val validSources = pair.second val writableTargetParentFolder = pair.first - val conflictResolutions = validSources.handleParentFolderConflict(context, writableTargetParentFolder, this, callback) ?: return@callbackFlow + val conflictResolutions = validSources.handleParentFolderConflict(context, writableTargetParentFolder, this, onConflict) ?: return@callbackFlow validSources.removeAll(conflictResolutions.filter { it.solution == FolderConflictCallback.ConflictResolution.SKIP }.map { it.source }) if (validSources.isEmpty()) { return@callbackFlow @@ -1712,8 +1712,8 @@ private fun List.copyTo( } if (finalize()) return@callbackFlow - val solutions = awaitUiResultWithPending>(callback.uiScope) { - callback.onContentConflict(writableTargetParentFolder, conflictedFiles, FolderConflictCallback.FolderContentConflictAction(it)) + val solutions = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onContentConflict(writableTargetParentFolder, conflictedFiles, FolderConflictCallback.FolderContentConflictAction(it)) }.filter { // free up space first, by deleting some files if (it.solution == SingleFileConflictCallback.ConflictResolution.SKIP) { @@ -1761,7 +1761,7 @@ private fun List.doesMeetCopyRequirements( context: Context, targetParentFolder: DocumentFile, scope: ProducerScope, - callback: MultipleFileConflictCallback + onConflict: MultipleFileConflictCallback ): Pair>? { if (!targetParentFolder.isDirectory) { scope.trySend(MultipleFilesResult.Error(MultipleFilesErrorCode.INVALID_TARGET_FOLDER)) @@ -1786,8 +1786,8 @@ private fun List.doesMeetCopyRequirements( }.toMap() if (invalidSourceFiles.isNotEmpty()) { - val abort = awaitUiResultWithPending(callback.uiScope) { - callback.onInvalidSourceFilesFound(invalidSourceFiles, MultipleFileConflictCallback.InvalidSourceFilesAction(it)) + val abort = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onInvalidSourceFilesFound(invalidSourceFiles, MultipleFileConflictCallback.InvalidSourceFilesAction(it)) } if (abort) { scope.trySend(MultipleFilesResult.Error(MultipleFilesErrorCode.CANCELED)) @@ -1868,9 +1868,9 @@ fun DocumentFile.moveFolderTo( newFolderNameInTargetPath: String? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: FolderConflictCallback + onConflict: FolderConflictCallback ): Flow { - return copyFolderTo(context, targetParentFolder, skipEmptyFiles, newFolderNameInTargetPath, true, updateInterval, isFileSizeAllowed, callback) + return copyFolderTo(context, targetParentFolder, skipEmptyFiles, newFolderNameInTargetPath, true, updateInterval, isFileSizeAllowed, onConflict) } @WorkerThread @@ -1881,9 +1881,9 @@ fun DocumentFile.copyFolderTo( newFolderNameInTargetPath: String? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: FolderConflictCallback + onConflict: FolderConflictCallback ): Flow { - return copyFolderTo(context, targetParentFolder, skipEmptyFiles, newFolderNameInTargetPath, false, updateInterval, isFileSizeAllowed, callback) + return copyFolderTo(context, targetParentFolder, skipEmptyFiles, newFolderNameInTargetPath, false, updateInterval, isFileSizeAllowed, onConflict) } /** @@ -1898,14 +1898,14 @@ private fun DocumentFile.copyFolderTo( deleteSourceWhenComplete: Boolean, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: FolderConflictCallback + onConflict: FolderConflictCallback ): Flow = callbackFlow { val writableTargetParentFolder = doesMeetFolderCopyRequirements(context, targetParentFolder, newFolderNameInTargetPath, this) ?: return@callbackFlow send(FolderResult.Preparing) val targetFolderParentName = (newFolderNameInTargetPath ?: name.orEmpty()).removeForbiddenCharsFromFilename().trimFileSeparator() - val conflictResolution = handleParentFolderConflict(context, targetParentFolder, targetFolderParentName, this, callback) + val conflictResolution = handleParentFolderConflict(context, targetParentFolder, targetFolderParentName, this, onConflict) if (conflictResolution == FolderConflictCallback.ConflictResolution.SKIP) { return@callbackFlow } @@ -2092,8 +2092,8 @@ private fun DocumentFile.copyFolderTo( } if (finalize()) return@callbackFlow - val solutions = awaitUiResultWithPending>(callback.uiScope) { - callback.onContentConflict(targetFolder, conflictedFiles, FolderConflictCallback.FolderContentConflictAction(it)) + val solutions = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onContentConflict(targetFolder, conflictedFiles, FolderConflictCallback.FolderContentConflictAction(it)) }.filter { // free up space first, by deleting some files if (it.solution == SingleFileConflictCallback.ConflictResolution.SKIP) { @@ -2194,9 +2194,9 @@ fun DocumentFile.copyFileTo( fileDescription: FileDescription? = null, reportInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow { - return copyFileTo(context, targetFolder.absolutePath, fileDescription, reportInterval, isFileSizeAllowed, callback) + return copyFileTo(context, targetFolder.absolutePath, fileDescription, reportInterval, isFileSizeAllowed, onConflict) } /** @@ -2210,13 +2210,13 @@ fun DocumentFile.copyFileTo( fileDescription: FileDescription? = null, reportInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { val targetFolder = DocumentFileCompat.mkdirs(context, targetFolderAbsolutePath, true) if (targetFolder == null) { send(SingleFileResult.Error(SingleFileErrorCode.CANNOT_CREATE_FILE_IN_TARGET)) } else { - copyFileTo(context, targetFolder, fileDescription, reportInterval, this, isFileSizeAllowed, callback) + copyFileTo(context, targetFolder, fileDescription, reportInterval, this, isFileSizeAllowed, onConflict) } } @@ -2230,9 +2230,9 @@ fun DocumentFile.copyFileTo( fileDescription: FileDescription? = null, reportInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { - copyFileTo(context, targetFolder, fileDescription, reportInterval, this, isFileSizeAllowed, callback) + copyFileTo(context, targetFolder, fileDescription, reportInterval, this, isFileSizeAllowed, onConflict) } private fun DocumentFile.copyFileTo( @@ -2242,16 +2242,16 @@ private fun DocumentFile.copyFileTo( reportInterval: Long, scope: ProducerScope, isFileSizeAllowed: CheckFileSize, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ) { if (fileDescription?.subFolder.isNullOrEmpty()) { - copyFileTo(context, targetFolder, fileDescription?.name, fileDescription?.mimeType, reportInterval, scope, isFileSizeAllowed, callback) + copyFileTo(context, targetFolder, fileDescription?.name, fileDescription?.mimeType, reportInterval, scope, isFileSizeAllowed, onConflict) } else { val targetDirectory = targetFolder.makeFolder(context, fileDescription?.subFolder.orEmpty(), CreateMode.REUSE) if (targetDirectory == null) { scope.trySend(SingleFileResult.Error(SingleFileErrorCode.CANNOT_CREATE_FILE_IN_TARGET)) } else { - copyFileTo(context, targetDirectory, fileDescription?.name, fileDescription?.mimeType, reportInterval, scope, isFileSizeAllowed, callback) + copyFileTo(context, targetDirectory, fileDescription?.name, fileDescription?.mimeType, reportInterval, scope, isFileSizeAllowed, onConflict) } } } @@ -2264,7 +2264,7 @@ private fun DocumentFile.copyFileTo( updateInterval: Long, scope: ProducerScope, isFileSizeAllowed: CheckFileSize, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ) { val writableTargetFolder = doesMeetFileCopyRequirements(context, targetFolder, newFilenameInTargetPath, scope) ?: return @@ -2277,7 +2277,7 @@ private fun DocumentFile.copyFileTo( val cleanFileName = MimeType.getFullFileName(newFilenameInTargetPath ?: name.orEmpty(), newMimeTypeInTargetPath ?: mimeTypeByFileName) .removeForbiddenCharsFromFilename().trimFileSeparator() - val fileConflictResolution = handleFileConflict(context, writableTargetFolder, cleanFileName, scope, callback) + val fileConflictResolution = handleFileConflict(context, writableTargetFolder, cleanFileName, scope, onConflict) if (fileConflictResolution == SingleFileConflictCallback.ConflictResolution.SKIP) { return } @@ -2413,9 +2413,9 @@ fun DocumentFile.moveFileTo( fileDescription: FileDescription? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow { - return moveFileTo(context, targetFolder.absolutePath, fileDescription, updateInterval, isFileSizeAllowed, callback) + return moveFileTo(context, targetFolder.absolutePath, fileDescription, updateInterval, isFileSizeAllowed, onConflict) } /** @@ -2429,13 +2429,13 @@ fun DocumentFile.moveFileTo( fileDescription: FileDescription? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { val targetFolder = DocumentFileCompat.mkdirs(context, targetFolderAbsolutePath, true) if (targetFolder == null) { send(SingleFileResult.Error(SingleFileErrorCode.CANNOT_CREATE_FILE_IN_TARGET)) } else { - moveFileTo(context, targetFolder, fileDescription, updateInterval, this, isFileSizeAllowed, callback) + moveFileTo(context, targetFolder, fileDescription, updateInterval, this, isFileSizeAllowed, onConflict) } } @@ -2449,9 +2449,9 @@ fun DocumentFile.moveFileTo( fileDescription: FileDescription? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { - moveFileTo(context, targetFolder, fileDescription, updateInterval, this, isFileSizeAllowed, callback) + moveFileTo(context, targetFolder, fileDescription, updateInterval, this, isFileSizeAllowed, onConflict) } private fun DocumentFile.moveFileTo( @@ -2461,16 +2461,16 @@ private fun DocumentFile.moveFileTo( updateInterval: Long, scope: ProducerScope, isFileSizeAllowed: CheckFileSize, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ) { if (fileDescription?.subFolder.isNullOrEmpty()) { - moveFileTo(context, targetFolder, fileDescription?.name, fileDescription?.mimeType, updateInterval, scope, isFileSizeAllowed, callback) + moveFileTo(context, targetFolder, fileDescription?.name, fileDescription?.mimeType, updateInterval, scope, isFileSizeAllowed, onConflict) } else { val targetDirectory = targetFolder.makeFolder(context, fileDescription?.subFolder.orEmpty(), CreateMode.REUSE) if (targetDirectory == null) { scope.trySend(SingleFileResult.Error(SingleFileErrorCode.CANNOT_CREATE_FILE_IN_TARGET)) } else { - moveFileTo(context, targetDirectory, fileDescription?.name, fileDescription?.mimeType, updateInterval, scope, isFileSizeAllowed, callback) + moveFileTo(context, targetDirectory, fileDescription?.name, fileDescription?.mimeType, updateInterval, scope, isFileSizeAllowed, onConflict) } } } @@ -2483,7 +2483,7 @@ private fun DocumentFile.moveFileTo( updateInterval: Long, scope: ProducerScope, isFileSizeAllowed: CheckFileSize, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ) { val writableTargetFolder = doesMeetFileCopyRequirements(context, targetFolder, newFilenameInTargetPath, scope) ?: return @@ -2491,7 +2491,7 @@ private fun DocumentFile.moveFileTo( val cleanFileName = MimeType.getFullFileName(newFilenameInTargetPath ?: name.orEmpty(), newMimeTypeInTargetPath ?: mimeTypeByFileName) .removeForbiddenCharsFromFilename().trimFileSeparator() - val fileConflictResolution = handleFileConflict(context, writableTargetFolder, cleanFileName, scope, callback) + val fileConflictResolution = handleFileConflict(context, writableTargetFolder, cleanFileName, scope, onConflict) if (fileConflictResolution == SingleFileConflictCallback.ConflictResolution.SKIP) { return } @@ -2588,7 +2588,7 @@ private fun DocumentFile.copyFileToMedia( updateInterval: Long, scope: ProducerScope, isFileSizeAllowed: CheckFileSize, - callback: SingleFileConflictCallback, + onConflict: SingleFileConflictCallback, ) { if (simpleCheckSourceFile(scope)) return @@ -2610,9 +2610,9 @@ private fun DocumentFile.copyFileToMedia( } fileDescription.subFolder = "" if (deleteSourceFileWhenComplete) { - moveFileTo(context, publicFolder, fileDescription, updateInterval, isFileSizeAllowed, callback) + moveFileTo(context, publicFolder, fileDescription, updateInterval, isFileSizeAllowed, onConflict) } else { - copyFileTo(context, publicFolder, fileDescription, updateInterval, isFileSizeAllowed, callback) + copyFileTo(context, publicFolder, fileDescription, updateInterval, isFileSizeAllowed, onConflict) } } else { val validMode = if (mode == CreateMode.REUSE) CreateMode.CREATE_NEW else mode @@ -2637,9 +2637,9 @@ fun DocumentFile.copyFileToDownloadMedia( mode: CreateMode = CreateMode.CREATE_NEW, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback, + onConflict: SingleFileConflictCallback, ): Flow = callbackFlow { - copyFileToMedia(context, fileDescription, PublicDirectory.DOWNLOADS, false, mode, updateInterval, this, isFileSizeAllowed, callback) + copyFileToMedia(context, fileDescription, PublicDirectory.DOWNLOADS, false, mode, updateInterval, this, isFileSizeAllowed, onConflict) } @WorkerThread @@ -2650,9 +2650,9 @@ fun DocumentFile.copyFileToPictureMedia( mode: CreateMode = CreateMode.CREATE_NEW, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback, + onConflict: SingleFileConflictCallback, ): Flow = callbackFlow { - copyFileToMedia(context, fileDescription, PublicDirectory.PICTURES, false, mode, updateInterval, this, isFileSizeAllowed, callback) + copyFileToMedia(context, fileDescription, PublicDirectory.PICTURES, false, mode, updateInterval, this, isFileSizeAllowed, onConflict) } @WorkerThread @@ -2663,9 +2663,9 @@ fun DocumentFile.moveFileToDownloadMedia( mode: CreateMode = CreateMode.CREATE_NEW, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { - copyFileToMedia(context, fileDescription, PublicDirectory.DOWNLOADS, true, mode, updateInterval, this, isFileSizeAllowed, callback) + copyFileToMedia(context, fileDescription, PublicDirectory.DOWNLOADS, true, mode, updateInterval, this, isFileSizeAllowed, onConflict) } @WorkerThread @@ -2676,9 +2676,9 @@ fun DocumentFile.moveFileToPictureMedia( mode: CreateMode = CreateMode.CREATE_NEW, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { - copyFileToMedia(context, fileDescription, PublicDirectory.PICTURES, true, mode, updateInterval, this, isFileSizeAllowed, callback) + copyFileToMedia(context, fileDescription, PublicDirectory.PICTURES, true, mode, updateInterval, this, isFileSizeAllowed, onConflict) } /** @@ -2753,11 +2753,11 @@ private fun handleFileConflict( targetFolder: DocumentFile, targetFileName: String, scope: ProducerScope, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): SingleFileConflictCallback.ConflictResolution { targetFolder.child(context, targetFileName)?.let { targetFile -> - val resolution = awaitUiResultWithPending(callback.uiScope) { - callback.onFileConflict(targetFile, SingleFileConflictCallback.FileConflictAction(it)) + val resolution = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onFileConflict(targetFile, SingleFileConflictCallback.FileConflictAction(it)) } if (resolution == SingleFileConflictCallback.ConflictResolution.REPLACE) { scope.trySend(SingleFileResult.DeletingConflictedFile) @@ -2776,7 +2776,7 @@ private fun handleParentFolderConflict( targetParentFolder: DocumentFile, targetFolderParentName: String, scope: ProducerScope, - callback: FolderConflictCallback + onConflict: FolderConflictCallback ): FolderConflictCallback.ConflictResolution { targetParentFolder.child(context, targetFolderParentName)?.let { targetFolder -> val canMerge = targetFolder.isDirectory @@ -2784,8 +2784,8 @@ private fun handleParentFolderConflict( return FolderConflictCallback.ConflictResolution.MERGE } - val resolution = awaitUiResultWithPending(callback.uiScope) { - callback.onParentConflict(targetFolder, FolderConflictCallback.ParentFolderConflictAction(it), canMerge) + val resolution = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onParentConflict(targetFolder, FolderConflictCallback.ParentFolderConflictAction(it), canMerge) } when (resolution) { @@ -2834,7 +2834,7 @@ private fun List.handleParentFolderConflict( context: Context, targetParentFolder: DocumentFile, scope: ProducerScope, - callback: MultipleFileConflictCallback + onConflict: MultipleFileConflictCallback ): List? { val sourceFileNames = map { it.name } val conflictedFiles = targetParentFolder.listFiles().filter { it.name in sourceFileNames } @@ -2849,8 +2849,8 @@ private fun List.handleParentFolderConflict( if (unresolvedConflicts.isNotEmpty()) { val unresolvedFiles = unresolvedConflicts.filter { it.source.isFile }.toMutableList() val unresolvedFolders = unresolvedConflicts.filter { it.source.isDirectory }.toMutableList() - val resolution = awaitUiResultWithPending(callback.uiScope) { - callback.onParentConflict(targetParentFolder, unresolvedFolders, unresolvedFiles, MultipleFileConflictCallback.ParentFolderConflictAction(it)) + val resolution = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onParentConflict(targetParentFolder, unresolvedFolders, unresolvedFiles, MultipleFileConflictCallback.ParentFolderConflictAction(it)) } if (resolution.any { it.solution == FolderConflictCallback.ConflictResolution.REPLACE }) { scope.trySend(MultipleFilesResult.DeletingConflictedFiles) diff --git a/storage/src/main/java/com/anggrayudi/storage/media/MediaFile.kt b/storage/src/main/java/com/anggrayudi/storage/media/MediaFile.kt index 10b1e35..b966732 100644 --- a/storage/src/main/java/com/anggrayudi/storage/media/MediaFile.kt +++ b/storage/src/main/java/com/anggrayudi/storage/media/MediaFile.kt @@ -91,6 +91,7 @@ class MediaFile(context: Context, val uri: Uri) { /** * Some media files do not return file extension. This function helps you to fix this kind of issue. */ + @Suppress("DEPRECATION") val fullName: String get() = if (isRawFile) { toRawFile()?.name.orEmpty() @@ -103,6 +104,7 @@ class MediaFile(context: Context, val uri: Uri) { /** * @see [fullName] */ + @Suppress("DEPRECATION") val name: String? get() = toRawFile()?.name ?: getColumnInfoString(MediaStore.MediaColumns.DISPLAY_NAME) @@ -115,6 +117,7 @@ class MediaFile(context: Context, val uri: Uri) { /** * @see [mimeType] */ + @Suppress("DEPRECATION") val type: String? get() = toRawFile()?.name?.let { MimeType.getMimeTypeFromExtension(MimeType.getExtensionFromFileName(it)) } ?: getColumnInfoString(MediaStore.MediaColumns.MIME_TYPE) @@ -126,6 +129,7 @@ class MediaFile(context: Context, val uri: Uri) { get() = getColumnInfoString(MediaStore.MediaColumns.MIME_TYPE) ?: MimeType.getMimeTypeFromExtension(extension) + @Suppress("DEPRECATION") var length: Long get() = toRawFile()?.length() ?: getColumnInfoLong(MediaStore.MediaColumns.SIZE) set(value) { @@ -164,6 +168,7 @@ class MediaFile(context: Context, val uri: Uri) { val isRawFile: Boolean get() = uri.isRawFile + @Suppress("DEPRECATION") val lastModified: Long get() = toRawFile()?.lastModified() ?: getColumnInfoLong(MediaStore.MediaColumns.DATE_MODIFIED) @@ -187,6 +192,7 @@ class MediaFile(context: Context, val uri: Uri) { fun toDocumentFile() = absolutePath.let { if (it.isEmpty()) null else DocumentFileCompat.fromFullPath(context, it) } + @Suppress("DEPRECATION") val absolutePath: String @SuppressLint("InlinedApi") get() { @@ -224,6 +230,7 @@ class MediaFile(context: Context, val uri: Uri) { /** * @see MediaStore.MediaColumns.RELATIVE_PATH */ + @Suppress("DEPRECATION") val relativePath: String @SuppressLint("InlinedApi") get() { @@ -258,6 +265,7 @@ class MediaFile(context: Context, val uri: Uri) { } } + @Suppress("DEPRECATION") fun delete(): Boolean { val file = toRawFile() return if (file != null) { @@ -274,6 +282,7 @@ class MediaFile(context: Context, val uri: Uri) { * Please note that this function does not move file if you input `newName` as `Download/filename.mp4`. * If you want to move media files, please use [moveFileTo] instead. */ + @Suppress("DEPRECATION") fun renameTo(newName: String): Boolean { val file = toRawFile() val contentValues = ContentValues(1).apply { put(MediaStore.MediaColumns.DISPLAY_NAME, newName) } @@ -319,6 +328,7 @@ class MediaFile(context: Context, val uri: Uri) { /** * @param append if `false` and the file already exists, it will recreate the file. */ + @Suppress("DEPRECATION") @WorkerThread @JvmOverloads fun openOutputStream(append: Boolean = true): OutputStream? { @@ -334,6 +344,7 @@ class MediaFile(context: Context, val uri: Uri) { } } + @Suppress("DEPRECATION") @WorkerThread fun openInputStream(): InputStream? { return try { @@ -365,11 +376,11 @@ class MediaFile(context: Context, val uri: Uri) { fileDescription: FileDescription? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { val sourceFile = toDocumentFile() if (sourceFile != null) { - sourceFile.moveFileTo(context, targetFolder, fileDescription, updateInterval, isFileSizeAllowed, callback) + sourceFile.moveFileTo(context, targetFolder, fileDescription, updateInterval, isFileSizeAllowed, onConflict) return@callbackFlow } @@ -392,7 +403,7 @@ class MediaFile(context: Context, val uri: Uri) { val cleanFileName = MimeType.getFullFileName(fileDescription?.name ?: name.orEmpty(), fileDescription?.mimeType ?: type) .removeForbiddenCharsFromFilename().trimFileSeparator() - val conflictResolution = handleFileConflict(targetDirectory, cleanFileName, this, callback) + val conflictResolution = handleFileConflict(targetDirectory, cleanFileName, this, onConflict) if (conflictResolution == SingleFileConflictCallback.ConflictResolution.SKIP) { return@callbackFlow } @@ -418,11 +429,11 @@ class MediaFile(context: Context, val uri: Uri) { fileDescription: FileDescription? = null, updateInterval: Long = 500, isFileSizeAllowed: CheckFileSize = defaultFileSizeChecker, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): Flow = callbackFlow { val sourceFile = toDocumentFile() if (sourceFile != null) { - sourceFile.copyFileTo(context, targetFolder, fileDescription, updateInterval, isFileSizeAllowed, callback) + sourceFile.copyFileTo(context, targetFolder, fileDescription, updateInterval, isFileSizeAllowed, onConflict) return@callbackFlow } @@ -445,7 +456,7 @@ class MediaFile(context: Context, val uri: Uri) { val cleanFileName = MimeType.getFullFileName(fileDescription?.name ?: name.orEmpty(), fileDescription?.mimeType ?: type) .removeForbiddenCharsFromFilename().trimFileSeparator() - val conflictResolution = handleFileConflict(targetDirectory, cleanFileName, this, callback) + val conflictResolution = handleFileConflict(targetDirectory, cleanFileName, this, onConflict) if (conflictResolution == SingleFileConflictCallback.ConflictResolution.SKIP) { return@callbackFlow } @@ -559,11 +570,11 @@ class MediaFile(context: Context, val uri: Uri) { targetFolder: DocumentFile, fileName: String, scope: ProducerScope, - callback: SingleFileConflictCallback + onConflict: SingleFileConflictCallback ): SingleFileConflictCallback.ConflictResolution { targetFolder.child(context, fileName)?.let { targetFile -> - val resolution = awaitUiResultWithPending(callback.uiScope) { - callback.onFileConflict(targetFile, SingleFileConflictCallback.FileConflictAction(it)) + val resolution = awaitUiResultWithPending(onConflict.uiScope) { + onConflict.onFileConflict(targetFile, SingleFileConflictCallback.FileConflictAction(it)) } if (resolution == SingleFileConflictCallback.ConflictResolution.REPLACE) { if (!targetFile.forceDelete(context)) {