From 67a4de612bcfa9501fcbfaa4e97dc83202eab40e Mon Sep 17 00:00:00 2001 From: Mathis Dirksen-Thedens Date: Sun, 3 Mar 2024 21:50:44 +0100 Subject: [PATCH] update data model: include "image" and "imageRotation" which could soon be included in SDB2 data (which is consumed by this app) also see https://github.com/mathisdt/sdb2/issues/232 --- .../sdbviewer/db/DatabaseAccess.java | 12 +++++++-- .../org/zephyrsoft/sdbviewer/model/Song.java | 26 ++++++++++++++++++- .../sdbviewer/fetch/SDBFetcherTest.java | 18 ++++++++++++- songs.xml | 6 +++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/zephyrsoft/sdbviewer/db/DatabaseAccess.java b/app/src/main/java/org/zephyrsoft/sdbviewer/db/DatabaseAccess.java index 06d91f1..f96c70b 100644 --- a/app/src/main/java/org/zephyrsoft/sdbviewer/db/DatabaseAccess.java +++ b/app/src/main/java/org/zephyrsoft/sdbviewer/db/DatabaseAccess.java @@ -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; @@ -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); @@ -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); } @@ -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; } diff --git a/app/src/main/java/org/zephyrsoft/sdbviewer/model/Song.java b/app/src/main/java/org/zephyrsoft/sdbviewer/model/Song.java index 0be8a0d..420f56a 100644 --- a/app/src/main/java/org/zephyrsoft/sdbviewer/model/Song.java +++ b/app/src/main/java/org/zephyrsoft/sdbviewer/model/Song.java @@ -21,6 +21,8 @@ public class Song implements Serializable, Comparable, Parcelable { private String uuid; private String chordSequence; private String lyrics; + private String image; + private String imageRotation; public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override @@ -59,6 +61,8 @@ private Song(Parcel in) { uuid = in.readString(); chordSequence = in.readString(); lyrics = in.readString(); + image = in.readString(); + imageRotation = in.readString(); } @Override @@ -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 @@ -118,6 +124,14 @@ public String getLyrics() { return lyrics; } + public String getImage() { + return image; + } + + public String getImageRotation() { + return imageRotation; + } + public String getTonality() { return tonality; } @@ -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; } @@ -227,6 +249,8 @@ && isEmpty(getLanguage()) && isEmpty(getSongNotes()) && isEmpty(getLyrics()) && isEmpty(getTonality()) - && isEmpty(getChordSequence()); + && isEmpty(getChordSequence()) + && isEmpty(getImage()) + && isEmpty(getImageRotation()); } } diff --git a/app/src/test/java/org/zephyrsoft/sdbviewer/fetch/SDBFetcherTest.java b/app/src/test/java/org/zephyrsoft/sdbviewer/fetch/SDBFetcherTest.java index d652818..96aef8b 100644 --- a/app/src/test/java/org/zephyrsoft/sdbviewer/fetch/SDBFetcherTest.java +++ b/app/src/test/java/org/zephyrsoft/sdbviewer/fetch/SDBFetcherTest.java @@ -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; @@ -26,6 +27,10 @@ public class SDBFetcherTest { "T&M That GuyText AuthorTranslation AuthorPublisherAdditional Copyright NotesENGLISHSong NotesCC F G CThese are a test song's lyrics.\n" + "With multiple lines.\n" + "With exactly three lines.Test Song1e48767c-6cd8-48ea-917a-e6e4d93c149b\n" + + "Test Image\n" + + "2c44c9ac-226a-4478-b2fe-0e8dde3062cf\n" + + "/some/weird/path/to/a/file.jpg\n" + + "270\n" + ""; private SDBFetcher fetcher; @@ -55,8 +60,19 @@ public void deserializeFromXml() { List 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()); } } \ No newline at end of file diff --git a/songs.xml b/songs.xml index ea362c9..4f44d72 100644 --- a/songs.xml +++ b/songs.xml @@ -61,4 +61,10 @@ https://zephyrsoft.org/contact-about-me How This App Is Used 1e48767c-6cc8-48ea-917a-e894d93c149b + + Test Image + 2c44c9ac-226a-4478-b2fe-0e8dde3062cf + /a/path/to/a/file.jpg + 270 +