Skip to content

Commit

Permalink
update data model: include "image" and "imageRotation" which could so…
Browse files Browse the repository at this point in the history
…on be included in SDB2 data (which is consumed by this app)

also see mathisdt/sdb2#232
  • Loading branch information
mathisdt committed Mar 3, 2024
1 parent d939e3e commit 67a4de6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/org/zephyrsoft/sdbviewer/db/DatabaseAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public class DatabaseAccess {
private static final String COL_UUID = "UUID";
private static final String COL_CHORD_SEQUENCE = "CHORD_SEQUENCE";
private static final String COL_LYRICS = "LYRICS";
private static final String COL_IMAGE = "IMAGE";
private static final String COL_IMAGE_ROTATION = "IMAGE_ROTATION";

private static final String DATABASE = "SDBVIEWER";
private static final String TABLE = "SONGS";
private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 2;

private final DatabaseOpenHelper databaseOpenHelper;

Expand All @@ -58,7 +60,9 @@ private static class DatabaseOpenHelper extends SQLiteOpenHelper {
COL_TONALITY + ", " +
COL_UUID + ", " +
COL_CHORD_SEQUENCE + ", " +
COL_LYRICS + ")";
COL_LYRICS + ", " +
COL_IMAGE + ", " +
COL_IMAGE_ROTATION + ")";

DatabaseOpenHelper(Context context) {
super(context, DATABASE, null, DATABASE_VERSION);
Expand Down Expand Up @@ -112,6 +116,8 @@ private void insert(Song song) {
values.put(COL_UUID, song.getUUID());
values.put(COL_CHORD_SEQUENCE, song.getChordSequence());
values.put(COL_LYRICS, song.getLyrics());
values.put(COL_IMAGE, song.getImage());
values.put(COL_IMAGE_ROTATION, song.getImageRotation());

database.insert(TABLE, null, values);
}
Expand Down Expand Up @@ -166,6 +172,8 @@ private Song mapSingle(Cursor cursor) {
song.setTonality(cursor.getString(cursor.getColumnIndex(COL_TONALITY)));
song.setChordSequence(cursor.getString(cursor.getColumnIndex(COL_CHORD_SEQUENCE)));
song.setLyrics(cursor.getString(cursor.getColumnIndex(COL_LYRICS)));
song.setImage(cursor.getString(cursor.getColumnIndex(COL_IMAGE)));
song.setImageRotation(cursor.getString(cursor.getColumnIndex(COL_IMAGE_ROTATION)));

return song;
}
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/java/org/zephyrsoft/sdbviewer/model/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class Song implements Serializable, Comparable<Song>, Parcelable {
private String uuid;
private String chordSequence;
private String lyrics;
private String image;
private String imageRotation;

public static final Parcelable.Creator<Song> CREATOR = new Parcelable.Creator<Song>() {
@Override
Expand Down Expand Up @@ -59,6 +61,8 @@ private Song(Parcel in) {
uuid = in.readString();
chordSequence = in.readString();
lyrics = in.readString();
image = in.readString();
imageRotation = in.readString();
}

@Override
Expand All @@ -75,6 +79,8 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(uuid);
dest.writeString(chordSequence);
dest.writeString(lyrics);
dest.writeString(image);
dest.writeString(imageRotation);
}

@Override
Expand Down Expand Up @@ -118,6 +124,14 @@ public String getLyrics() {
return lyrics;
}

public String getImage() {
return image;
}

public String getImageRotation() {
return imageRotation;
}

public String getTonality() {
return tonality;
}
Expand Down Expand Up @@ -162,6 +176,14 @@ public void setLyrics(String lyrics) {
this.lyrics = lyrics;
}

public void setImage(String image) {
this.image = image;
}

public void setImageRotation(String imageRotation) {
this.imageRotation = imageRotation;
}

public void setTonality(String tonality) {
this.tonality = tonality;
}
Expand Down Expand Up @@ -227,6 +249,8 @@ && isEmpty(getLanguage())
&& isEmpty(getSongNotes())
&& isEmpty(getLyrics())
&& isEmpty(getTonality())
&& isEmpty(getChordSequence());
&& isEmpty(getChordSequence())
&& isEmpty(getImage())
&& isEmpty(getImageRotation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;

Expand All @@ -26,6 +27,10 @@ public class SDBFetcherTest {
"<song><composer>T&amp;M That Guy</composer><authorText>Text Author</authorText><authorTranslation>Translation Author</authorTranslation><publisher>Publisher</publisher><additionalCopyrightNotes>Additional Copyright Notes</additionalCopyrightNotes><language>ENGLISH</language><songNotes>Song Notes</songNotes><tonality>C</tonality><chordSequence>C F G C</chordSequence><lyrics>These are a test song's lyrics.\n" +
"With multiple lines.\n" +
"With exactly three lines.</lyrics><title>Test Song</title><uuid>1e48767c-6cd8-48ea-917a-e6e4d93c149b</uuid></song>\n" +
"<song><title>Test Image</title>\n" +
"<uuid>2c44c9ac-226a-4478-b2fe-0e8dde3062cf</uuid>\n" +
"<image>/some/weird/path/to/a/file.jpg</image>\n" +
"<imageRotation>270</imageRotation></song>\n" +
"</songs>";

private SDBFetcher fetcher;
Expand Down Expand Up @@ -55,8 +60,19 @@ public void deserializeFromXml() {
List<Song> songs = fetcher.deserializeFromXml(EXAMPLE_XML);

assertNotNull(songs);
assertEquals(2, songs.size());
assertEquals(3, songs.size());

assertNotNull(songs.get(0).getLyrics());
assertNull(songs.get(0).getImage());
assertNull(songs.get(0).getImageRotation());

assertNotNull(songs.get(1).getLyrics());
assertTrue(songs.get(1).getLyrics().contains("\n"));
assertNull(songs.get(1).getImage());
assertNull(songs.get(1).getImageRotation());

assertNotNull(songs.get(2).getTitle());
assertNotNull(songs.get(2).getImage());
assertNotNull(songs.get(2).getImageRotation());
}
}
6 changes: 6 additions & 0 deletions songs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ https://zephyrsoft.org/contact-about-me</lyrics>
<title>How This App Is Used</title>
<uuid>1e48767c-6cc8-48ea-917a-e894d93c149b</uuid>
</song>
<song>
<title>Test Image</title>
<uuid>2c44c9ac-226a-4478-b2fe-0e8dde3062cf</uuid>
<image>/a/path/to/a/file.jpg</image>
<imageRotation>270</imageRotation>
</song>
</songs>

0 comments on commit 67a4de6

Please sign in to comment.