Skip to content

Commit a6fdcc7

Browse files
author
Jan Guegel
committed
rename function to getAvailablePath and using getDoesFilePathExist make it compatible with external filestorage
1 parent 166a788 commit a6fdcc7

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SaveAsActivity : SimpleActivity() {
5858
?: filename.getMimeType()
5959
val inputStream = contentResolver.openInputStream(source)
6060

61-
val destinationPath = setAvailablePath("$destination/$filename")
61+
val destinationPath = getAvailablePath("$destination/$filename")
6262
val outputStream = getFileOutputStreamSync(destinationPath, mimeType, null)!!
6363
inputStream!!.copyTo(outputStream)
6464
rescanPaths(arrayListOf(destinationPath))
@@ -87,17 +87,16 @@ class SaveAsActivity : SimpleActivity() {
8787
.takeIf { it.isNotBlank() } ?: "unnamed_file"
8888
}
8989

90-
private fun setAvailablePath(path: String): String {
91-
val file = File(path)
92-
93-
return if (!file.exists()) {
94-
path
95-
} else {
96-
findAvailableNameForExistingFile(file)
90+
private fun getAvailablePath(destinationPath: String): String {
91+
if (!getDoesFilePathExist(destinationPath)) {
92+
return destinationPath
9793
}
94+
95+
val file = File(destinationPath)
96+
return findAvailableName(file)
9897
}
9998

100-
private fun findAvailableNameForExistingFile(file: File): String {
99+
private fun findAvailableName(file: File): String {
101100
val parent = file.parent ?: return file.absolutePath
102101
val name = file.nameWithoutExtension
103102
val ext = if (file.extension.isNotEmpty()) ".${file.extension}" else ""

0 commit comments

Comments
 (0)