mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
@@ -19,6 +19,8 @@
|
||||
|
||||
package org.isoron.uhabits.io;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.models.CheckmarkList;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
@@ -64,7 +66,10 @@ public class HabitsCSVExporter
|
||||
|
||||
for(Habit h : habits)
|
||||
{
|
||||
String habitDirName = String.format("%03d %s/", h.position + 1, h.name);
|
||||
String sane = sanitizeFilename(h.name);
|
||||
String habitDirName = String.format("%03d %s", h.position + 1, sane);
|
||||
habitDirName = habitDirName.trim() + "/";
|
||||
|
||||
new File(exportDirName + habitDirName).mkdirs();
|
||||
generateDirs.add(habitDirName);
|
||||
|
||||
@@ -73,6 +78,13 @@ public class HabitsCSVExporter
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String sanitizeFilename(String name)
|
||||
{
|
||||
String s = name.replaceAll("[^a-zA-Z0-9\\._-]+", "");
|
||||
return s.substring(0, Math.min(s.length(), 100));
|
||||
}
|
||||
|
||||
private void writeScores(String habitDirName, ScoreList scores) throws IOException
|
||||
{
|
||||
String path = habitDirName + "Scores.csv";
|
||||
|
||||
@@ -489,7 +489,7 @@ public class Habit extends Model
|
||||
*/
|
||||
public static void writeCSV(List<Habit> habits, Writer out) throws IOException
|
||||
{
|
||||
String header[] = { "Name", "Description", "NumRepetitions", "Interval", "Color" };
|
||||
String header[] = { "Position", "Name", "Description", "NumRepetitions", "Interval", "Color" };
|
||||
|
||||
CSVWriter csv = new CSVWriter(out);
|
||||
csv.writeNext(header, false);
|
||||
@@ -498,6 +498,7 @@ public class Habit extends Model
|
||||
{
|
||||
String[] cols =
|
||||
{
|
||||
String.format("%03d", habit.position + 1),
|
||||
habit.name,
|
||||
habit.description,
|
||||
Integer.toString(habit.freqNum),
|
||||
|
||||
Reference in New Issue
Block a user