File tree Expand file tree Collapse file tree 6 files changed +48
-19
lines changed
java/co/adityarajput/fileflow Expand file tree Collapse file tree 6 files changed +48
-19
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,13 @@ import androidx.compose.ui.text.buildAnnotatedString
88import androidx.compose.ui.text.withStyle
99import co.adityarajput.fileflow.R
1010import co.adityarajput.fileflow.data.Verb
11+ import co.adityarajput.fileflow.utils.File
1112import co.adityarajput.fileflow.utils.FileSuperlative
1213import co.adityarajput.fileflow.utils.getGetDirectoryFromUri
1314import co.adityarajput.fileflow.utils.toShortHumanReadableTime
1415import kotlinx.serialization.Serializable
16+ import kotlin.uuid.ExperimentalUuidApi
17+ import kotlin.uuid.Uuid
1518
1619@Suppress(" ClassName" )
1720@Serializable
@@ -65,6 +68,19 @@ sealed class Action {
6568 withStyle(dullStyle) { append(" \n as " ) }
6669 append(destFileNameTemplate)
6770 }
71+
72+ @OptIn(ExperimentalUuidApi ::class )
73+ fun getDestFileName (srcFile : File ) =
74+ srcFile.name!! .replace(
75+ Regex (srcFileNamePattern),
76+ destFileNameTemplate.replace(
77+ $$" ${uuid} " ,
78+ Uuid .random().toString(),
79+ ).replace(
80+ $$" ${folder} " ,
81+ srcFile.parent?.name ? : " " ,
82+ ),
83+ )
6884 }
6985
7086 @Serializable
Original file line number Diff line number Diff line change @@ -52,13 +52,7 @@ class FlowExecutor(private val context: Context) {
5252 continue
5353 }
5454
55- val destFileName = srcFile.name!! .replace(
56- regex,
57- rule.action.destFileNameTemplate.replace(
58- $$" ${folder} " ,
59- srcFile.parent?.name ? : " " ,
60- ),
61- )
55+ val destFileName = rule.action.getDestFileName(srcFile)
6256 var destFile = destSubDir.listChildren(false )
6357 .firstOrNull { it.isFile && it.name == destFileName }
6458
Original file line number Diff line number Diff line change @@ -107,15 +107,9 @@ class UpsertRuleViewModel(
107107 ?.also { if (it.isEmpty()) warning = FormWarning .NO_MATCHES_IN_SRC }
108108
109109 if (matchingSrcFiles != null && values.destFileNameTemplate.isNotBlank()) {
110- predictedDestFileNames = matchingSrcFiles.map {
111- it.name!! .replace(
112- regex,
113- values.destFileNameTemplate.replace(
114- $$" ${folder} " ,
115- it.parent?.name ? : " " ,
116- ),
117- )
118- }.distinct()
110+ predictedDestFileNames = matchingSrcFiles
111+ .map { (values.toRule().action as Action .MOVE ).getDestFileName(it) }
112+ .distinct()
119113 }
120114 } catch (_: Exception ) {
121115 }
Original file line number Diff line number Diff line change 11package co.adityarajput.fileflow.views.screens
22
3- import android.annotation.SuppressLint
43import android.os.Handler
54import android.os.Looper
65import androidx.compose.foundation.layout.*
@@ -22,7 +21,6 @@ private val permissions = listOf(
2221 Permission .MANAGE_EXTERNAL_STORAGE ,
2322)
2423
25- @SuppressLint(" BatteryLife" )
2624@Composable
2725fun OnboardingScreen (goToRulesScreen : () -> Unit = {}) {
2826 val context = LocalContext .current
Original file line number Diff line number Diff line change @@ -324,14 +324,39 @@ private fun ColumnScope.ActionPage(viewModel: UpsertRuleViewModel) {
324324 label = { Text (stringResource(R .string.file_name_template)) },
325325 placeholder = { Text (stringResource(R .string.template_placeholder)) },
326326 supportingText = {
327- if (viewModel.state.values.predictedDestFileNames?.isNotEmpty() ? : false )
327+ if (viewModel.state.values.predictedDestFileNames.isNullOrEmpty()) {
328+ Text (
329+ buildAnnotatedString {
330+ append(stringResource(R .string.blank_template_supporting))
331+ if (viewModel.state.values.destFileNameTemplate != " $0" ) {
332+ withLink(
333+ LinkAnnotation .Clickable (
334+ " keep_name" ,
335+ TextLinkStyles (
336+ SpanStyle (
337+ MaterialTheme .colorScheme.primary,
338+ textDecoration = TextDecoration .Underline ,
339+ ),
340+ ),
341+ ) {
342+ viewModel.updateForm(
343+ context,
344+ viewModel.state.values.copy(destFileNameTemplate = " $0" ),
345+ )
346+ },
347+ ) { append(stringResource(R .string.keep_name)) }
348+ }
349+ },
350+ )
351+ } else {
328352 Text (
329353 stringResource(
330354 R .string.template_will_yield,
331355 viewModel.state.values.predictedDestFileNames!!
332356 .joinToString(stringResource(R .string.or ), limit = 3 ),
333357 ),
334358 )
359+ }
335360 },
336361 colors = OutlinedTextFieldDefaults .colors(
337362 focusedContainerColor = MaterialTheme .colorScheme.secondaryContainer,
Original file line number Diff line number Diff line change 109109 <string name =" preserve_structure" >Recreate source folder-structure in destination</string >
110110 <string name =" file_name_template" >File name template</string >
111111 <string name =" template_placeholder" >Enter a regex template</string >
112+ <string name =" blank_template_supporting" >"Template will be used to name the file in the destination. "</string >
113+ <string name =" keep_name" >Keep original name?</string >
112114 <string name =" template_will_yield" >Template will yield %1$s</string >
113115 <string name =" overwrite_existing" >Overwrite existing files in the destination, in case of conflict</string >
114116 <string name =" retention_days" >Mark stale if unmodified for</string >
You can’t perform that action at this time.
0 commit comments