Skip to content

Commit

Permalink
fix csv with quotes export
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Oct 19, 2024
1 parent 2fbe2af commit 5e1d7f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,16 @@ class CsvRepoImpl @Inject constructor(
return if (recordType != null) {
String.format(
"\"%s\",%s,%s,\"%s\",\"%s\",\"%s\",%s,%s\n",
recordType.name,
recordType.name.cleanText(),
formatDateTime(record.timeStarted),
formatDateTime(record.timeEnded),
record.comment,
categories.takeUnless { it.isEmpty() }?.joinToString(separator = ", ") { it.name }.orEmpty(),
recordTags.takeUnless { it.isEmpty() }?.joinToString(separator = ", ") { it.name }.orEmpty(),
record.comment.cleanText(),
categories.takeUnless { it.isEmpty() }
?.joinToString(separator = ", ", transform = { it.name })
.orEmpty().cleanText(),
recordTags.takeUnless { it.isEmpty() }
?.joinToString(separator = ", ", transform = { it.name })
.orEmpty().cleanText(),
formatDuration(record.duration),
formatDurationMinutes(record.duration),
)
Expand Down Expand Up @@ -239,6 +243,10 @@ class CsvRepoImpl @Inject constructor(
}
}

private fun String.cleanText(): String {
return this.replace("\"", "\"\"")
}

companion object {
private const val CSV_HEADER = "activity name,time started,time ended,comment,categories,record tags,duration,duration minutes\n"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RemoteViews
import com.example.util.simpletimetracker.core.extension.allowDiskRead
import com.example.util.simpletimetracker.core.interactor.FilterGoalsByDayOfWeekInteractor
import com.example.util.simpletimetracker.core.interactor.GetCurrentRecordsDurationInteractor
import com.example.util.simpletimetracker.core.interactor.RecordRepeatInteractor
Expand Down Expand Up @@ -39,6 +40,7 @@ import com.example.util.simpletimetracker.feature_views.viewData.RecordTypeIcon
import com.example.util.simpletimetracker.feature_widget.R
import com.example.util.simpletimetracker.navigation.params.screen.RecordTagSelectionParams
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -115,20 +117,22 @@ class WidgetSingleProvider : AppWidgetProvider() {
}
}

@OptIn(DelicateCoroutinesApi::class)
override fun onDeleted(context: Context?, appWidgetIds: IntArray?) {
GlobalScope.launch(Dispatchers.Main) {
allowDiskRead { GlobalScope }.launch(Dispatchers.Main) {
appWidgetIds?.forEach { prefsInteractor.removeWidget(it) }
}
}

@OptIn(DelicateCoroutinesApi::class)
private fun updateAppWidget(
context: Context?,
appWidgetManager: AppWidgetManager?,
appWidgetId: Int,
) {
if (context == null || appWidgetManager == null) return

GlobalScope.launch(Dispatchers.Main) {
allowDiskRead { GlobalScope }.launch(Dispatchers.Main) {
val view: View
val recordTypeId = prefsInteractor.getWidget(appWidgetId)
val backgroundTransparency = prefsInteractor.getWidgetBackgroundTransparencyPercent()
Expand Down

0 comments on commit 5e1d7f4

Please sign in to comment.