@@ -0,0 +1,2939 @@
+package com.github.keaume.amigo.export;%0A%0Aimport android.os.Environment;%0A%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Date;%0Aimport java.util.List;%0Aimport java.util.Locale;%0A%0Aimport com.github.zeroxfelix.obd2fun.sql.ObdData;%0Aimport timber.log.Timber;%0A%0Apublic class CsvExport%7B%0A%0A    private static final String EXTERNAL_STORAGE_EXPORT_DIRECTORY = %22export%22;%0A    private static final String EXTERNAL_STORAGE_MAIN_DIRECTORY = %22obd2fun%22;%0A    private final String fileName;%0A    private final ArrayList%3CObdData%3E obdDataList;%0A%0A    public CsvExport(ArrayList%3CObdData%3E obdDataList, Date startDate, Date endDate)%7B%0A%0A        SimpleDateFormat dateFormat = new SimpleDateFormat(%22dd_MM_yyyy_HHmm%22, Locale.GERMANY);%0A        String startDateString = dateFormat.format(startDate);%0A        String endDateString = dateFormat.format(endDate);%0A%0A        this.fileName = startDateString + %22-%22 + endDateString + %22.csv%22;%0A        this.obdDataList = obdDataList;%0A%0A    %7D%0A%0A    public CsvExport(ArrayList%3CObdData%3E obdDataList, String sessionId)%7B%0A%0A        long sessionLong =  Long.parseLong(sessionId);%0A        Date date = new Date(sessionLong);%0A        SimpleDateFormat dateFormat = new SimpleDateFormat(%22dd_MM_yyyy_HHmm%22, Locale.GERMANY);%0A%0A        this.fileName = dateFormat.format(date) + %22.csv%22;%0A        this.obdDataList = obdDataList;%0A%0A    %7D%0A%0A    public void writeFileToExternalStorage() %7B%0A        List%3CString%3E csvData = new ArrayList%3C%3E();%0A        csvData.add(%22SessionId;Date;ObdCommand;Result;Unit;VIN%22);%0A        for(ObdData obdData : this.obdDataList)%7B%0A            csvData.add(obdData.getSessionId() + %22;%22 + obdData.getRecordingDate().toString() + %22;%22 + obdData.getObdCommandType().getNameForValue() + %22;%22 + obdData.getCalculatedResult() + %22;%22 + obdData.getResultUnit() + %22;%22 + obdData.getVin());%0A        %7D%0A%0A        Timber.d(%22Writing file to external storage%22);%0A        File externalStorageDirectory = Environment.getExternalStorageDirectory();%0A        File externalStorageSaveDirectory = new File(externalStorageDirectory.getAbsolutePath() + %22/%22 + EXTERNAL_STORAGE_MAIN_DIRECTORY + %22/%22 + EXTERNAL_STORAGE_EXPORT_DIRECTORY);%0A        //noinspection ResultOfMethodCallIgnored%0A        externalStorageSaveDirectory.mkdirs();%0A        if (externalStorageSaveDirectory.isDirectory()) %7B%0A            File file = new File(externalStorageSaveDirectory, this.fileName);%0A            try %7B%0A                FileWriter fileWriter = new FileWriter(file);%0A                for (int i = 0; i %3C csvData.size(); i++) %7B%0A                    fileWriter.write( csvData.get(i) + %22%5Cn%22);%0A                %7D%0A                fileWriter.close();%0A%0A            %7D catch (Exception e) %7B%0A                Timber.e(e, %22Writing to file %25s failed%22, file.getAbsolutePath());%0A            %7D%0A        %7D else %7B%0A            Timber.e(%22Failed to create directory %25s%22, externalStorageSaveDirectory.getAbsolutePath());%0A        %7D%0A    %7D%0A%0A%7D%0A

Create CsvExport.java