Skip to content

Commit

Permalink
V1.0.4 - fix reading quoted multiline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fr3ts0n committed Oct 26, 2016
1 parent 46dba1b commit f333e30
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fr3ts0n.stagefever"
android:versionCode="010003"
android:versionName="1.0.3" >
android:versionCode="010004"
android:versionName="1.0.4" >

<uses-sdk
android:minSdkVersion="15"
Expand Down
36 changes: 26 additions & 10 deletions src/com/fr3ts0n/stagefever/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ public class Song {
String notes = "";
int bpm = 0;

/**
* CSV field ids
*/
public enum FID
{
TITLE,
ARTIST,
SETTINGS,
BPM,
NOTES
}

/**
* construct Song from array of elements
*
Expand All @@ -24,41 +36,45 @@ public Song(String[] elements)
{
try
{
title = elements[0];
artist = elements[1];
settings = elements[2];
title = elements[FID.TITLE.ordinal()];
artist = elements[FID.ARTIST.ordinal()];
settings = elements[FID.SETTINGS.ordinal()];
try
{
bpm = Integer.valueOf(elements[3]);
bpm = Integer.valueOf(elements[FID.BPM.ordinal()]);
}
catch (NumberFormatException ex)
{
bpm = 0;
}
notes = elements[4];
notes = elements[FID.NOTES.ordinal()];
}
catch (Exception ex)
{
Log.e(getClass().getName(), ex.getMessage() + Arrays.toString(elements));
}
}

/**
* Construct song from a CSV record
* @param record CSV data record
*/
public Song(CSVRecord record)
{
try
{
title = record.get(0);
artist = record.get(1);
settings = record.get(2);
title = record.get(FID.TITLE.ordinal());
artist = record.get(FID.ARTIST.ordinal());
settings = record.get(FID.SETTINGS.ordinal());
try
{
bpm = Integer.valueOf(record.get(3));
bpm = Integer.valueOf(record.get(FID.BPM.ordinal()));
}
catch (NumberFormatException ex)
{
bpm = 0;
}
notes = record.get(4);
notes = record.get(FID.NOTES.ordinal());
}
catch (Exception ex)
{
Expand Down
5 changes: 4 additions & 1 deletion src/com/fr3ts0n/stagefever/SongAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.csv.QuoteMode;

public class SongAdapter extends ArrayAdapter<Song>
{
Expand Down Expand Up @@ -39,7 +40,9 @@ public void importFromCsvFile(InputStream inStr, String fieldDelimiter)
try
{
rdr = new BufferedReader(new InputStreamReader(inStr));
for(CSVRecord record : CSVFormat.newFormat(fieldDelimiter.charAt(0)).parse(rdr))
for(CSVRecord record : CSVFormat.newFormat(fieldDelimiter.charAt(0))
.withQuote('"')
.withQuoteMode(QuoteMode.MINIMAL).parse(rdr))
{
add(new Song(record));
}
Expand Down

0 comments on commit f333e30

Please sign in to comment.