issue 68 not yet completed

pull/114/head
PKompis 9 years ago
parent cba089407b
commit b0b4c739ba

@ -62,6 +62,18 @@ public class HabitsCSVExporter
Habit.writeCSV(habits, out); Habit.writeCSV(habits, out);
out.close(); out.close();
//my contribution
String filename2 = "AllCheckmarks.csv";
new File(exportDirName).mkdirs();
FileWriter out2 = new FileWriter(exportDirName + filename2);
generateFilenames.add(filename2);
CheckmarkList check = new CheckmarkList();
check.writeCSVMultipleHabits (habits, out2);
out2.close();
//until here
for(Habit h : habits) for(Habit h : habits)
{ {
String habitDirName = String.format("%03d %s/", h.position + 1, h.name); String habitDirName = String.format("%03d %s/", h.position + 1, h.name);

@ -19,6 +19,7 @@
package org.isoron.uhabits.models; package org.isoron.uhabits.models;
import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteStatement;
@ -28,6 +29,7 @@ import android.support.annotation.Nullable;
import com.activeandroid.Cache; import com.activeandroid.Cache;
import com.activeandroid.query.Delete; import com.activeandroid.query.Delete;
import com.activeandroid.query.Select; import com.activeandroid.query.Select;
import com.opencsv.CSVWriter;
import org.isoron.uhabits.helpers.DateHelper; import org.isoron.uhabits.helpers.DateHelper;
import org.isoron.uhabits.helpers.UIHelper; import org.isoron.uhabits.helpers.UIHelper;
@ -42,6 +44,10 @@ public class CheckmarkList
{ {
private Habit habit; private Habit habit;
public CheckmarkList()
{
}
public CheckmarkList(Habit habit) public CheckmarkList(Habit habit)
{ {
this.habit = habit; this.habit = habit;
@ -299,4 +305,59 @@ public class CheckmarkList
cursor.close(); cursor.close();
out.close(); out.close();
} }
//my contribution
/**
* Writes the checkmark of all habits for each date to the given writer, in CSV format. There is one
* line for each date. Each line contains two fields: timestamp and value.
*
* @param habits the list of habits to write
* @param out the writer where the CSV will be output
* @throws IOException in case write operations fail
*/
public void writeCSVMultipleHabits(List<Habit> habits, Writer out) throws IOException
{
SimpleDateFormat dateFormat = DateHelper.getCSVDateFormat();
String query = "select DISTINCT timestamp from checkmarks order by timestamp";
SQLiteDatabase db = Cache.openDatabase();
Cursor cursor = db.rawQuery(query, null);
if(!cursor.moveToFirst()) return;
out.write(String.format("%s", "Date"));
for(Habit habit : habits)
{
out.write(String.format(",%s", habit.name));
}
do
{
String timestamp = dateFormat.format(new Date(cursor.getLong(0)));
out.write(String.format("\n%s", timestamp));
for(Habit habit : habits)
{
out.write(String.format(",%s", getHabitValue(habit.name, timestamp)));
}
} while(cursor.moveToNext());
cursor.close();
out.close();
}
public String getHabitValue(String name, String date)
{
String query = "select value from checkmarks where timestamp ="+date+" and habit ='"+name+"'";
SQLiteDatabase db2 = Cache.openDatabase();
Cursor cursor2 = db2.rawQuery(query, null);
String habitValue = " ";
if(cursor2 != null && cursor2.moveToFirst()) {
habitValue = Integer.toString(cursor2.getInt(0));
cursor2.close();
}
return habitValue;
}//until here
} }

@ -4,7 +4,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-alpha3' classpath 'com.android.tools.build:gradle:2.0.0'
} }
} }

Loading…
Cancel
Save