Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad2c9d43c5 | ||
|
|
91067833a4 |
+2
-2
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId "com.folderredirect.app"
|
applicationId "com.folderredirect.app"
|
||||||
minSdk 26
|
minSdk 26
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 1
|
versionCode 3
|
||||||
versionName "1.0.1"
|
versionName "1.1.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class FileMoveWorker(appContext: Context, params: WorkerParameters) : CoroutineW
|
|||||||
val totalFiles = filesToProcess.size
|
val totalFiles = filesToProcess.size
|
||||||
|
|
||||||
if (totalFiles == 0) {
|
if (totalFiles == 0) {
|
||||||
|
deleteEmptyFoldersRecursively(sourceDir)
|
||||||
rulesManager.updateImmichRuleProgress(rule.id, 100)
|
rulesManager.updateImmichRuleProgress(rule.id, 100)
|
||||||
sendProgressUpdate()
|
sendProgressUpdate()
|
||||||
return@withContext 0
|
return@withContext 0
|
||||||
@@ -140,7 +141,7 @@ class FileMoveWorker(appContext: Context, params: WorkerParameters) : CoroutineW
|
|||||||
}
|
}
|
||||||
|
|
||||||
val relativePath = file.absolutePath.substringAfter(sourceDir.absolutePath.trimEnd('/'), "").trimStart('/')
|
val relativePath = file.absolutePath.substringAfter(sourceDir.absolutePath.trimEnd('/'), "").trimStart('/')
|
||||||
val albumName = getAlbumNameFromRelativePathImmich(relativePath)
|
val albumName = if (rule.useFolderAsAlbum) getAlbumNameFromRelativePathImmich(relativePath) else null
|
||||||
|
|
||||||
var retries = 3
|
var retries = 3
|
||||||
var success = false
|
var success = false
|
||||||
@@ -175,6 +176,8 @@ class FileMoveWorker(appContext: Context, params: WorkerParameters) : CoroutineW
|
|||||||
sendProgressUpdate()
|
sendProgressUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteEmptyFoldersRecursively(sourceDir)
|
||||||
|
|
||||||
return@withContext count
|
return@withContext count
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error procesando regla Immich: ${e.message}")
|
Log.e(TAG, "Error procesando regla Immich: ${e.message}")
|
||||||
@@ -186,6 +189,9 @@ class FileMoveWorker(appContext: Context, params: WorkerParameters) : CoroutineW
|
|||||||
private fun deleteEmptyParentFoldersImmich(folder: File?, baseFolder: File) =
|
private fun deleteEmptyParentFoldersImmich(folder: File?, baseFolder: File) =
|
||||||
FileUtils.deleteEmptyParentFolders(folder, baseFolder)
|
FileUtils.deleteEmptyParentFolders(folder, baseFolder)
|
||||||
|
|
||||||
|
private fun deleteEmptyFoldersRecursively(baseFolder: File) =
|
||||||
|
FileUtils.deleteEmptyFoldersRecursively(baseFolder)
|
||||||
|
|
||||||
private fun getAllFilesRecursively(dir: File): List<File> =
|
private fun getAllFilesRecursively(dir: File): List<File> =
|
||||||
FileUtils.getAllFilesRecursively(dir)
|
FileUtils.getAllFilesRecursively(dir)
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,20 @@ object FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteEmptyFoldersRecursively(baseFolder: File) {
|
||||||
|
if (!baseFolder.exists() || !baseFolder.isDirectory) return
|
||||||
|
val children = baseFolder.listFiles() ?: return
|
||||||
|
for (child in children) {
|
||||||
|
if (child.isDirectory) {
|
||||||
|
deleteEmptyFoldersRecursively(child)
|
||||||
|
if (child.exists() && child.listFiles()?.isEmpty() == true) {
|
||||||
|
child.delete()
|
||||||
|
Log.d(TAG, "Carpeta vacía eliminada: ${child.absolutePath}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getAllFilesRecursively(dir: File): List<File> {
|
fun getAllFilesRecursively(dir: File): List<File> {
|
||||||
val files = mutableListOf<File>()
|
val files = mutableListOf<File>()
|
||||||
dir.listFiles()?.forEach { file ->
|
dir.listFiles()?.forEach { file ->
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ data class ImmichUploadRule(
|
|||||||
var isEnabled: Boolean = true,
|
var isEnabled: Boolean = true,
|
||||||
var fileTypeCategory: String = FileTypeCategory.IMAGES.name,
|
var fileTypeCategory: String = FileTypeCategory.IMAGES.name,
|
||||||
var namePattern: String? = null,
|
var namePattern: String? = null,
|
||||||
|
var useFolderAsAlbum: Boolean = true,
|
||||||
var progress: Int = 0
|
var progress: Int = 0
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
|
|
||||||
|
|||||||
@@ -399,6 +399,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
editApiKey = view.findViewById(R.id.editApiKey)
|
editApiKey = view.findViewById(R.id.editApiKey)
|
||||||
radioGroupFileType = view.findViewById(R.id.radioGroupFileType)
|
radioGroupFileType = view.findViewById(R.id.radioGroupFileType)
|
||||||
editNamePattern = view.findViewById(R.id.editNamePattern)
|
editNamePattern = view.findViewById(R.id.editNamePattern)
|
||||||
|
val switchUseFolderAsAlbum = view.findViewById<com.google.android.material.switchmaterial.SwitchMaterial>(R.id.switchUseFolderAsAlbum)
|
||||||
val btnSelectSource = view.findViewById<Button>(R.id.btnSelectSource)
|
val btnSelectSource = view.findViewById<Button>(R.id.btnSelectSource)
|
||||||
|
|
||||||
editRuleName?.setText(rule?.name ?: "")
|
editRuleName?.setText(rule?.name ?: "")
|
||||||
@@ -407,6 +408,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
editImmichUrl?.setText(rule?.immichUrl ?: "")
|
editImmichUrl?.setText(rule?.immichUrl ?: "")
|
||||||
editApiKey?.setText(rule?.apiKey ?: "")
|
editApiKey?.setText(rule?.apiKey ?: "")
|
||||||
editNamePattern?.setText(currentPattern)
|
editNamePattern?.setText(currentPattern)
|
||||||
|
switchUseFolderAsAlbum.isChecked = rule?.useFolderAsAlbum ?: true
|
||||||
|
|
||||||
when (currentCategory) {
|
when (currentCategory) {
|
||||||
FileTypeCategory.IMAGES -> view.findViewById<RadioButton>(R.id.radioImages).isChecked = true
|
FileTypeCategory.IMAGES -> view.findViewById<RadioButton>(R.id.radioImages).isChecked = true
|
||||||
@@ -460,6 +462,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
immichUrl = immichUrl,
|
immichUrl = immichUrl,
|
||||||
apiKey = apiKey
|
apiKey = apiKey
|
||||||
)
|
)
|
||||||
|
newRule.useFolderAsAlbum = switchUseFolderAsAlbum.isChecked
|
||||||
newRule.setCategory(fileTypeCategory)
|
newRule.setCategory(fileTypeCategory)
|
||||||
if (namePattern.isNotEmpty()) {
|
if (namePattern.isNotEmpty()) {
|
||||||
newRule.setPattern(namePattern)
|
newRule.setPattern(namePattern)
|
||||||
@@ -471,6 +474,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
rule.sourcePath = sourcePath
|
rule.sourcePath = sourcePath
|
||||||
rule.immichUrl = immichUrl
|
rule.immichUrl = immichUrl
|
||||||
rule.apiKey = apiKey
|
rule.apiKey = apiKey
|
||||||
|
rule.useFolderAsAlbum = switchUseFolderAsAlbum.isChecked
|
||||||
rule.setCategory(fileTypeCategory)
|
rule.setCategory(fileTypeCategory)
|
||||||
if (namePattern.isNotEmpty()) {
|
if (namePattern.isNotEmpty()) {
|
||||||
rule.setPattern(namePattern)
|
rule.setPattern(namePattern)
|
||||||
|
|||||||
@@ -175,6 +175,43 @@
|
|||||||
android:textSize="11sp"
|
android:textSize="11sp"
|
||||||
android:textColor="@android:color/darker_gray" />
|
android:textColor="@android:color/darker_gray" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Usar carpetas como álbum"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Al desactivar, todos los archivos se suben sin álbum"
|
||||||
|
android:textSize="11sp"
|
||||||
|
android:textColor="@android:color/darker_gray" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
android:id="@+id/switchUseFolderAsAlbum"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:checked="true" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -199,7 +236,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:text="Las subcarpetas dentro de la carpeta monitoreada se usarán como nombres de álbum en Immich. Los archivos sin subcarpeta se subirán sin álbum."
|
android:text="Las subcarpetas dentro de la carpeta monitoreada se usarán como nombres de álbum en Immich. Puedes desactivar esta opción para subir todo sin álbum."
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:textColor="?attr/colorOnPrimaryContainer" />
|
android:textColor="?attr/colorOnPrimaryContainer" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user