Skip to content

Commit a5dfc04

Browse files
committed
Handle folder selection errors #2
1 parent 081f75d commit a5dfc04

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

shared/src/androidMain/kotlin/com/module/notelycompose/export/domain/ExportSelectionInteractorImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ExportSelectionInteractorImpl(
8686
if(shouldExportTxt) {
8787
texts.forEachIndexed { index, text ->
8888
val timestampText = SimpleDateFormat(PATTERN_DATE_FORMAT, Locale.getDefault()).format(Date())
89-
val textTitle = titles[index].takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT
89+
val textTitle = (titles[index].takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT).take(20)
9090
val fileName = "${textTitle}-${timestampText}.txt"
9191
val textFile = exportFolder.createFile("text/plain", fileName)
9292
?: return@withContext Result.failure(Exception("Failed to create text file $index"))
@@ -99,7 +99,7 @@ class ExportSelectionInteractorImpl(
9999
// Update progress
100100
completedItems++
101101
val progress = completedItems.toFloat() / totalItems.toFloat()
102-
withContext(Dispatchers.Main) {
102+
kotlinx.coroutines.MainScope().launch {
103103
onProgress(progress)
104104
}
105105
}
@@ -114,7 +114,7 @@ class ExportSelectionInteractorImpl(
114114
return@withContext Result.failure(Exception("Audio file not found: $path"))
115115
}
116116

117-
val textTitle = titles[index].takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT
117+
val textTitle = (titles[index].takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT).take(20)
118118
val audioFileName = "${textTitle}-audio-${timestampAudio}.wav"
119119
val mimeType = getMimeType(audioFileName)
120120
val audioFile = exportFolder.createFile(mimeType, audioFileName)
@@ -130,7 +130,7 @@ class ExportSelectionInteractorImpl(
130130
// Update progress
131131
completedItems++
132132
val progress = completedItems.toFloat() / totalItems.toFloat()
133-
withContext(Dispatchers.Main) {
133+
kotlinx.coroutines.MainScope().launch {
134134
onProgress(progress)
135135
}
136136
}

shared/src/commonMain/kotlin/com/module/notelycompose/export/presentation/ExportSelectionViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ExportSelectionViewModel(
100100
when {
101101
result.isSuccess -> ExportingFileState.Success
102102
else -> {
103-
_exportingState.update { ExportingFileState.Idle }
103+
ExportingFileState.Idle
104104
if(result.exceptionOrNull() is NoFolderSelectedException) {
105105
ExportingFileState.NoFolderSelected
106106
} else {

shared/src/commonMain/kotlin/com/module/notelycompose/export/ui/ExportingFileStateHost.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal fun ExportingFileStateHost(
6868
}
6969
},
7070
title = { Text(stringResource(Res.string.error)) },
71-
text = { Text(stringResource(Res.string.batch_export_settings_error_occurred)) }
71+
text = { Text(state.message) }
7272
)
7373
}
7474
}

shared/src/iosMain/kotlin/com/module/notelycompose/export/domain/ExportSelectionInteractorImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ExportSelectionInteractorImpl : ExportSelectionInteractor {
136136
if (shouldExportTxt) {
137137
texts.forEachIndexed { index, text ->
138138
val timestampText = getFormattedDate(PATTERN_DATE_FORMAT)
139-
val textTitle = titles.getOrNull(index)?.takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT
139+
val textTitle = (titles[index].takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT).take(20)
140140
val fileName = "${textTitle}-${timestampText}.txt"
141141

142142
val fileUrl = exportFolderUrl.URLByAppendingPathComponent(fileName)
@@ -164,7 +164,7 @@ class ExportSelectionInteractorImpl : ExportSelectionInteractor {
164164
// Update progress
165165
completedItems++
166166
val progress = completedItems.toFloat() / totalItems.toFloat()
167-
withContext(Dispatchers.Main) {
167+
kotlinx.coroutines.MainScope().launch {
168168
onProgress(progress)
169169
}
170170
}
@@ -180,7 +180,7 @@ class ExportSelectionInteractorImpl : ExportSelectionInteractor {
180180
return@withContext Result.failure(Exception("Audio file not found: $path"))
181181
}
182182

183-
val textTitle = titles.getOrNull(index)?.takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT
183+
val textTitle = (titles[index].takeIf { it.isNotBlank() } ?: TEXT_BLANK_DEFAULT).take(20)
184184
val audioFileName = "${textTitle}-audio-${timestampAudio}.wav"
185185

186186
val destUrl = exportFolderUrl.URLByAppendingPathComponent(audioFileName)
@@ -206,7 +206,7 @@ class ExportSelectionInteractorImpl : ExportSelectionInteractor {
206206

207207
completedItems++
208208
val progress = completedItems.toFloat() / totalItems.toFloat()
209-
withContext(Dispatchers.Main) {
209+
kotlinx.coroutines.MainScope().launch {
210210
onProgress(progress)
211211
}
212212
}

0 commit comments

Comments
 (0)