diff --git a/app/build.gradle b/app/build.gradle index e3d59f5..0b01341 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.literacyapp" minSdkVersion 21 targetSdkVersion 23 - versionCode 1006005 - versionName "1.6.5" + versionCode 1006006 + versionName "1.6.6" // jackOptions { // enabled true @@ -56,7 +56,7 @@ android { } greendao { - schemaVersion 2000006 // Must match greendao.schemaVersion in contentprovider/build.gradle + schemaVersion 2000007 // Must match greendao.schemaVersion in contentprovider/build.gradle daoPackage 'org.literacyapp.contentprovider.dao' targetGenDir '../contentprovider/src/main/java' } diff --git a/app/src/main/java/org/literacyapp/dao/CustomDaoMaster.java b/app/src/main/java/org/literacyapp/dao/CustomDaoMaster.java index b02b541..94e605f 100644 --- a/app/src/main/java/org/literacyapp/dao/CustomDaoMaster.java +++ b/app/src/main/java/org/literacyapp/dao/CustomDaoMaster.java @@ -8,6 +8,7 @@ import org.literacyapp.contentprovider.dao.AllophoneDao; import org.literacyapp.contentprovider.dao.DaoMaster; import org.literacyapp.contentprovider.dao.JoinNumbersWithWordsDao; +import org.literacyapp.contentprovider.dao.LetterDao; import org.literacyapp.contentprovider.dao.StoryBookDao; import org.literacyapp.contentprovider.dao.WordDao; import org.literacyapp.contentprovider.model.JoinNumbersWithWords; @@ -69,6 +70,14 @@ public void onUpgrade(Database db, int oldVersion, int newVersion) { ); } + if (oldVersion < 2000007) { + // Add new tables and/or columns automatically (include only the DAO classes that have been modified) + DbMigrationHelper.migrate(db, + AllophoneDao.class, + LetterDao.class + ); + } + // if (oldVersion < ???) { // // Add new tables and/or columns automatically (include only the DAO classes that have been modified) // DbMigrationHelper.migrate(db, diff --git a/app/src/main/java/org/literacyapp/service/synchronization/DownloadContentAsyncTask.java b/app/src/main/java/org/literacyapp/service/synchronization/DownloadContentAsyncTask.java index 6ffc850..0d68f77 100644 --- a/app/src/main/java/org/literacyapp/service/synchronization/DownloadContentAsyncTask.java +++ b/app/src/main/java/org/literacyapp/service/synchronization/DownloadContentAsyncTask.java @@ -22,6 +22,7 @@ import org.literacyapp.contentprovider.dao.JoinImagesWithLettersDao; import org.literacyapp.contentprovider.dao.JoinImagesWithNumbersDao; import org.literacyapp.contentprovider.dao.JoinImagesWithWordsDao; +import org.literacyapp.contentprovider.dao.JoinLettersWithAllophonesDao; import org.literacyapp.contentprovider.dao.JoinVideosWithLettersDao; import org.literacyapp.contentprovider.dao.JoinVideosWithNumbersDao; import org.literacyapp.contentprovider.dao.JoinVideosWithWordsDao; @@ -30,6 +31,7 @@ import org.literacyapp.contentprovider.dao.StoryBookDao; import org.literacyapp.contentprovider.dao.VideoDao; import org.literacyapp.contentprovider.dao.WordDao; +import org.literacyapp.contentprovider.model.JoinLettersWithAllophones; import org.literacyapp.contentprovider.model.content.Allophone; import org.literacyapp.contentprovider.model.content.Letter; import org.literacyapp.contentprovider.model.content.Number; @@ -80,6 +82,8 @@ public class DownloadContentAsyncTask extends AsyncTask { private AudioDao audioDao; private ImageDao imageDao; private VideoDao videoDao; + + private JoinLettersWithAllophonesDao joinLettersWithAllophonesDao; private JoinVideosWithLettersDao joinVideosWithLettersDao; private JoinVideosWithNumbersDao joinVideosWithNumbersDao; @@ -105,6 +109,8 @@ public DownloadContentAsyncTask(Context context) { audioDao = literacyApplication.getDaoSession().getAudioDao(); imageDao = literacyApplication.getDaoSession().getImageDao(); videoDao = literacyApplication.getDaoSession().getVideoDao(); + + joinLettersWithAllophonesDao = literacyApplication.getDaoSession().getJoinLettersWithAllophonesDao(); joinVideosWithLettersDao = literacyApplication.getDaoSession().getJoinVideosWithLettersDao(); joinVideosWithNumbersDao = literacyApplication.getDaoSession().getJoinVideosWithNumbersDao(); @@ -181,9 +187,26 @@ protected String doInBackground(Void... voids) { if (existingLetter == null) { Log.i(getClass().getName(), "Storing Letter, id: " + letter.getId() + ", text: \"" + letter.getText() + "\", revisionNumber: " + letter.getRevisionNumber()); letterDao.insert(letter); + + for (AllophoneGson allophoneGson : letterGson.getAllophones()) { + Allophone allophone = allophoneDao.queryBuilder() + .where( + AllophoneDao.Properties.Locale.eq(allophoneGson.getLocale()), + AllophoneDao.Properties.ValueSampa.eq(allophoneGson.getValueSampa()) + ) + .unique(); + Log.i(getClass().getName(), "Storing Allophone, id: " + allophone.getId() + ", valueIpa: /" + allophone.getValueIpa() + "/, valueSampa: \"" + allophone.getValueSampa() + "\", for letter '" + letter.getText() + "'"); + + JoinLettersWithAllophones joinLettersWithAllophones = new JoinLettersWithAllophones(); + joinLettersWithAllophones.setLetterId(letter.getId()); + joinLettersWithAllophones.setAllophoneId(allophone.getId()); + joinLettersWithAllophonesDao.insert(joinLettersWithAllophones); + } } else if (existingLetter.getRevisionNumber() < letter.getRevisionNumber()) { Log.i(getClass().getName(), "Updating Letter with id " + existingLetter.getId() + " from revisionNumber " + existingLetter.getRevisionNumber() + " to revisionNumber " + letter.getRevisionNumber()); letterDao.update(letter); + + // TODO: update JoinLettersWithAllophones } else { Log.i(getClass().getName(), "Letter \"" + letter.getText() + "\" already exists in database with id " + letter.getId() + " (revision " + letter.getRevisionNumber() + ")"); } diff --git a/contentprovider/build.gradle b/contentprovider/build.gradle index d97c72b..6da2b04 100644 --- a/contentprovider/build.gradle +++ b/contentprovider/build.gradle @@ -8,8 +8,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 23 - versionCode 1000009 - versionName "1.0.9" + versionCode 1001000 + versionName "1.1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -26,7 +26,7 @@ android { } greendao { - schemaVersion 2000006 // Must match greendao.schemaVersion in app/build.gradle + schemaVersion 2000007 // Must match greendao.schemaVersion in app/build.gradle daoPackage 'org.literacyapp.contentprovider.dao' targetGenDir '../contentprovider/src/main/java' } @@ -49,7 +49,7 @@ dependencies { }) testCompile 'junit:junit:4.12' - compile 'org.literacyapp:literacyapp-model:1.1.53' + compile 'org.literacyapp:literacyapp-model:1.1.56' compile 'org.greenrobot:greendao:3.2.0' compile 'com.android.support:appcompat-v7:23.4.0' } diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/AllophoneDao.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/AllophoneDao.java index 8e10be1..b0bd74c 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/AllophoneDao.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/AllophoneDao.java @@ -1,5 +1,6 @@ package org.literacyapp.contentprovider.dao; +import java.util.List; import android.database.Cursor; import android.database.sqlite.SQLiteStatement; @@ -8,6 +9,8 @@ import org.greenrobot.greendao.internal.DaoConfig; import org.greenrobot.greendao.database.Database; import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.query.Query; +import org.greenrobot.greendao.query.QueryBuilder; import java.util.Calendar; import org.literacyapp.contentprovider.dao.converter.CalendarConverter; @@ -21,6 +24,7 @@ import org.literacyapp.contentprovider.dao.converter.VowelFrontnessConverter; import org.literacyapp.contentprovider.dao.converter.VowelHeightConverter; import org.literacyapp.contentprovider.dao.converter.VowelLengthConverter; +import org.literacyapp.contentprovider.model.JoinLettersWithAllophones; import org.literacyapp.model.enums.Locale; import org.literacyapp.model.enums.content.ContentStatus; import org.literacyapp.model.enums.content.allophone.ConsonantPlace; @@ -54,15 +58,16 @@ public static class Properties { public final static Property ContentStatus = new Property(4, String.class, "contentStatus", false, "CONTENT_STATUS"); public final static Property ValueIpa = new Property(5, String.class, "valueIpa", false, "VALUE_IPA"); public final static Property ValueSampa = new Property(6, String.class, "valueSampa", false, "VALUE_SAMPA"); - public final static Property SoundType = new Property(7, String.class, "soundType", false, "SOUND_TYPE"); - public final static Property VowelLength = new Property(8, String.class, "vowelLength", false, "VOWEL_LENGTH"); - public final static Property VowelHeight = new Property(9, String.class, "vowelHeight", false, "VOWEL_HEIGHT"); - public final static Property VowelFrontness = new Property(10, String.class, "vowelFrontness", false, "VOWEL_FRONTNESS"); - public final static Property LipRounding = new Property(11, String.class, "lipRounding", false, "LIP_ROUNDING"); - public final static Property ConsonantType = new Property(12, String.class, "consonantType", false, "CONSONANT_TYPE"); - public final static Property ConsonantPlace = new Property(13, String.class, "consonantPlace", false, "CONSONANT_PLACE"); - public final static Property ConsonantVoicing = new Property(14, String.class, "consonantVoicing", false, "CONSONANT_VOICING"); - public final static Property UsageCount = new Property(15, int.class, "usageCount", false, "USAGE_COUNT"); + public final static Property Diacritic = new Property(7, boolean.class, "diacritic", false, "DIACRITIC"); + public final static Property SoundType = new Property(8, String.class, "soundType", false, "SOUND_TYPE"); + public final static Property VowelLength = new Property(9, String.class, "vowelLength", false, "VOWEL_LENGTH"); + public final static Property VowelHeight = new Property(10, String.class, "vowelHeight", false, "VOWEL_HEIGHT"); + public final static Property VowelFrontness = new Property(11, String.class, "vowelFrontness", false, "VOWEL_FRONTNESS"); + public final static Property LipRounding = new Property(12, String.class, "lipRounding", false, "LIP_ROUNDING"); + public final static Property ConsonantType = new Property(13, String.class, "consonantType", false, "CONSONANT_TYPE"); + public final static Property ConsonantPlace = new Property(14, String.class, "consonantPlace", false, "CONSONANT_PLACE"); + public final static Property ConsonantVoicing = new Property(15, String.class, "consonantVoicing", false, "CONSONANT_VOICING"); + public final static Property UsageCount = new Property(16, int.class, "usageCount", false, "USAGE_COUNT"); } private final LocaleConverter localeConverter = new LocaleConverter(); @@ -76,6 +81,7 @@ public static class Properties { private final ConsonantTypeConverter consonantTypeConverter = new ConsonantTypeConverter(); private final ConsonantPlaceConverter consonantPlaceConverter = new ConsonantPlaceConverter(); private final ConsonantVoicingConverter consonantVoicingConverter = new ConsonantVoicingConverter(); + private Query letter_AllophonesQuery; public AllophoneDao(DaoConfig config) { super(config); @@ -96,15 +102,16 @@ public static void createTable(Database db, boolean ifNotExists) { "\"CONTENT_STATUS\" TEXT NOT NULL ," + // 4: contentStatus "\"VALUE_IPA\" TEXT NOT NULL ," + // 5: valueIpa "\"VALUE_SAMPA\" TEXT NOT NULL ," + // 6: valueSampa - "\"SOUND_TYPE\" TEXT," + // 7: soundType - "\"VOWEL_LENGTH\" TEXT," + // 8: vowelLength - "\"VOWEL_HEIGHT\" TEXT," + // 9: vowelHeight - "\"VOWEL_FRONTNESS\" TEXT," + // 10: vowelFrontness - "\"LIP_ROUNDING\" TEXT," + // 11: lipRounding - "\"CONSONANT_TYPE\" TEXT," + // 12: consonantType - "\"CONSONANT_PLACE\" TEXT," + // 13: consonantPlace - "\"CONSONANT_VOICING\" TEXT," + // 14: consonantVoicing - "\"USAGE_COUNT\" INTEGER NOT NULL );"); // 15: usageCount + "\"DIACRITIC\" INTEGER NOT NULL ," + // 7: diacritic + "\"SOUND_TYPE\" TEXT," + // 8: soundType + "\"VOWEL_LENGTH\" TEXT," + // 9: vowelLength + "\"VOWEL_HEIGHT\" TEXT," + // 10: vowelHeight + "\"VOWEL_FRONTNESS\" TEXT," + // 11: vowelFrontness + "\"LIP_ROUNDING\" TEXT," + // 12: lipRounding + "\"CONSONANT_TYPE\" TEXT," + // 13: consonantType + "\"CONSONANT_PLACE\" TEXT," + // 14: consonantPlace + "\"CONSONANT_VOICING\" TEXT," + // 15: consonantVoicing + "\"USAGE_COUNT\" INTEGER NOT NULL );"); // 16: usageCount } /** Drops the underlying database table. */ @@ -131,47 +138,48 @@ protected final void bindValues(DatabaseStatement stmt, Allophone entity) { stmt.bindString(5, contentStatusConverter.convertToDatabaseValue(entity.getContentStatus())); stmt.bindString(6, entity.getValueIpa()); stmt.bindString(7, entity.getValueSampa()); + stmt.bindLong(8, entity.getDiacritic() ? 1L: 0L); SoundType soundType = entity.getSoundType(); if (soundType != null) { - stmt.bindString(8, soundTypeConverter.convertToDatabaseValue(soundType)); + stmt.bindString(9, soundTypeConverter.convertToDatabaseValue(soundType)); } VowelLength vowelLength = entity.getVowelLength(); if (vowelLength != null) { - stmt.bindString(9, vowelLengthConverter.convertToDatabaseValue(vowelLength)); + stmt.bindString(10, vowelLengthConverter.convertToDatabaseValue(vowelLength)); } VowelHeight vowelHeight = entity.getVowelHeight(); if (vowelHeight != null) { - stmt.bindString(10, vowelHeightConverter.convertToDatabaseValue(vowelHeight)); + stmt.bindString(11, vowelHeightConverter.convertToDatabaseValue(vowelHeight)); } VowelFrontness vowelFrontness = entity.getVowelFrontness(); if (vowelFrontness != null) { - stmt.bindString(11, vowelFrontnessConverter.convertToDatabaseValue(vowelFrontness)); + stmt.bindString(12, vowelFrontnessConverter.convertToDatabaseValue(vowelFrontness)); } LipRounding lipRounding = entity.getLipRounding(); if (lipRounding != null) { - stmt.bindString(12, lipRoundingConverter.convertToDatabaseValue(lipRounding)); + stmt.bindString(13, lipRoundingConverter.convertToDatabaseValue(lipRounding)); } ConsonantType consonantType = entity.getConsonantType(); if (consonantType != null) { - stmt.bindString(13, consonantTypeConverter.convertToDatabaseValue(consonantType)); + stmt.bindString(14, consonantTypeConverter.convertToDatabaseValue(consonantType)); } ConsonantPlace consonantPlace = entity.getConsonantPlace(); if (consonantPlace != null) { - stmt.bindString(14, consonantPlaceConverter.convertToDatabaseValue(consonantPlace)); + stmt.bindString(15, consonantPlaceConverter.convertToDatabaseValue(consonantPlace)); } ConsonantVoicing consonantVoicing = entity.getConsonantVoicing(); if (consonantVoicing != null) { - stmt.bindString(15, consonantVoicingConverter.convertToDatabaseValue(consonantVoicing)); + stmt.bindString(16, consonantVoicingConverter.convertToDatabaseValue(consonantVoicing)); } - stmt.bindLong(16, entity.getUsageCount()); + stmt.bindLong(17, entity.getUsageCount()); } @Override @@ -192,47 +200,48 @@ protected final void bindValues(SQLiteStatement stmt, Allophone entity) { stmt.bindString(5, contentStatusConverter.convertToDatabaseValue(entity.getContentStatus())); stmt.bindString(6, entity.getValueIpa()); stmt.bindString(7, entity.getValueSampa()); + stmt.bindLong(8, entity.getDiacritic() ? 1L: 0L); SoundType soundType = entity.getSoundType(); if (soundType != null) { - stmt.bindString(8, soundTypeConverter.convertToDatabaseValue(soundType)); + stmt.bindString(9, soundTypeConverter.convertToDatabaseValue(soundType)); } VowelLength vowelLength = entity.getVowelLength(); if (vowelLength != null) { - stmt.bindString(9, vowelLengthConverter.convertToDatabaseValue(vowelLength)); + stmt.bindString(10, vowelLengthConverter.convertToDatabaseValue(vowelLength)); } VowelHeight vowelHeight = entity.getVowelHeight(); if (vowelHeight != null) { - stmt.bindString(10, vowelHeightConverter.convertToDatabaseValue(vowelHeight)); + stmt.bindString(11, vowelHeightConverter.convertToDatabaseValue(vowelHeight)); } VowelFrontness vowelFrontness = entity.getVowelFrontness(); if (vowelFrontness != null) { - stmt.bindString(11, vowelFrontnessConverter.convertToDatabaseValue(vowelFrontness)); + stmt.bindString(12, vowelFrontnessConverter.convertToDatabaseValue(vowelFrontness)); } LipRounding lipRounding = entity.getLipRounding(); if (lipRounding != null) { - stmt.bindString(12, lipRoundingConverter.convertToDatabaseValue(lipRounding)); + stmt.bindString(13, lipRoundingConverter.convertToDatabaseValue(lipRounding)); } ConsonantType consonantType = entity.getConsonantType(); if (consonantType != null) { - stmt.bindString(13, consonantTypeConverter.convertToDatabaseValue(consonantType)); + stmt.bindString(14, consonantTypeConverter.convertToDatabaseValue(consonantType)); } ConsonantPlace consonantPlace = entity.getConsonantPlace(); if (consonantPlace != null) { - stmt.bindString(14, consonantPlaceConverter.convertToDatabaseValue(consonantPlace)); + stmt.bindString(15, consonantPlaceConverter.convertToDatabaseValue(consonantPlace)); } ConsonantVoicing consonantVoicing = entity.getConsonantVoicing(); if (consonantVoicing != null) { - stmt.bindString(15, consonantVoicingConverter.convertToDatabaseValue(consonantVoicing)); + stmt.bindString(16, consonantVoicingConverter.convertToDatabaseValue(consonantVoicing)); } - stmt.bindLong(16, entity.getUsageCount()); + stmt.bindLong(17, entity.getUsageCount()); } @Override @@ -250,15 +259,16 @@ public Allophone readEntity(Cursor cursor, int offset) { contentStatusConverter.convertToEntityProperty(cursor.getString(offset + 4)), // contentStatus cursor.getString(offset + 5), // valueIpa cursor.getString(offset + 6), // valueSampa - cursor.isNull(offset + 7) ? null : soundTypeConverter.convertToEntityProperty(cursor.getString(offset + 7)), // soundType - cursor.isNull(offset + 8) ? null : vowelLengthConverter.convertToEntityProperty(cursor.getString(offset + 8)), // vowelLength - cursor.isNull(offset + 9) ? null : vowelHeightConverter.convertToEntityProperty(cursor.getString(offset + 9)), // vowelHeight - cursor.isNull(offset + 10) ? null : vowelFrontnessConverter.convertToEntityProperty(cursor.getString(offset + 10)), // vowelFrontness - cursor.isNull(offset + 11) ? null : lipRoundingConverter.convertToEntityProperty(cursor.getString(offset + 11)), // lipRounding - cursor.isNull(offset + 12) ? null : consonantTypeConverter.convertToEntityProperty(cursor.getString(offset + 12)), // consonantType - cursor.isNull(offset + 13) ? null : consonantPlaceConverter.convertToEntityProperty(cursor.getString(offset + 13)), // consonantPlace - cursor.isNull(offset + 14) ? null : consonantVoicingConverter.convertToEntityProperty(cursor.getString(offset + 14)), // consonantVoicing - cursor.getInt(offset + 15) // usageCount + cursor.getShort(offset + 7) != 0, // diacritic + cursor.isNull(offset + 8) ? null : soundTypeConverter.convertToEntityProperty(cursor.getString(offset + 8)), // soundType + cursor.isNull(offset + 9) ? null : vowelLengthConverter.convertToEntityProperty(cursor.getString(offset + 9)), // vowelLength + cursor.isNull(offset + 10) ? null : vowelHeightConverter.convertToEntityProperty(cursor.getString(offset + 10)), // vowelHeight + cursor.isNull(offset + 11) ? null : vowelFrontnessConverter.convertToEntityProperty(cursor.getString(offset + 11)), // vowelFrontness + cursor.isNull(offset + 12) ? null : lipRoundingConverter.convertToEntityProperty(cursor.getString(offset + 12)), // lipRounding + cursor.isNull(offset + 13) ? null : consonantTypeConverter.convertToEntityProperty(cursor.getString(offset + 13)), // consonantType + cursor.isNull(offset + 14) ? null : consonantPlaceConverter.convertToEntityProperty(cursor.getString(offset + 14)), // consonantPlace + cursor.isNull(offset + 15) ? null : consonantVoicingConverter.convertToEntityProperty(cursor.getString(offset + 15)), // consonantVoicing + cursor.getInt(offset + 16) // usageCount ); return entity; } @@ -272,15 +282,16 @@ public void readEntity(Cursor cursor, Allophone entity, int offset) { entity.setContentStatus(contentStatusConverter.convertToEntityProperty(cursor.getString(offset + 4))); entity.setValueIpa(cursor.getString(offset + 5)); entity.setValueSampa(cursor.getString(offset + 6)); - entity.setSoundType(cursor.isNull(offset + 7) ? null : soundTypeConverter.convertToEntityProperty(cursor.getString(offset + 7))); - entity.setVowelLength(cursor.isNull(offset + 8) ? null : vowelLengthConverter.convertToEntityProperty(cursor.getString(offset + 8))); - entity.setVowelHeight(cursor.isNull(offset + 9) ? null : vowelHeightConverter.convertToEntityProperty(cursor.getString(offset + 9))); - entity.setVowelFrontness(cursor.isNull(offset + 10) ? null : vowelFrontnessConverter.convertToEntityProperty(cursor.getString(offset + 10))); - entity.setLipRounding(cursor.isNull(offset + 11) ? null : lipRoundingConverter.convertToEntityProperty(cursor.getString(offset + 11))); - entity.setConsonantType(cursor.isNull(offset + 12) ? null : consonantTypeConverter.convertToEntityProperty(cursor.getString(offset + 12))); - entity.setConsonantPlace(cursor.isNull(offset + 13) ? null : consonantPlaceConverter.convertToEntityProperty(cursor.getString(offset + 13))); - entity.setConsonantVoicing(cursor.isNull(offset + 14) ? null : consonantVoicingConverter.convertToEntityProperty(cursor.getString(offset + 14))); - entity.setUsageCount(cursor.getInt(offset + 15)); + entity.setDiacritic(cursor.getShort(offset + 7) != 0); + entity.setSoundType(cursor.isNull(offset + 8) ? null : soundTypeConverter.convertToEntityProperty(cursor.getString(offset + 8))); + entity.setVowelLength(cursor.isNull(offset + 9) ? null : vowelLengthConverter.convertToEntityProperty(cursor.getString(offset + 9))); + entity.setVowelHeight(cursor.isNull(offset + 10) ? null : vowelHeightConverter.convertToEntityProperty(cursor.getString(offset + 10))); + entity.setVowelFrontness(cursor.isNull(offset + 11) ? null : vowelFrontnessConverter.convertToEntityProperty(cursor.getString(offset + 11))); + entity.setLipRounding(cursor.isNull(offset + 12) ? null : lipRoundingConverter.convertToEntityProperty(cursor.getString(offset + 12))); + entity.setConsonantType(cursor.isNull(offset + 13) ? null : consonantTypeConverter.convertToEntityProperty(cursor.getString(offset + 13))); + entity.setConsonantPlace(cursor.isNull(offset + 14) ? null : consonantPlaceConverter.convertToEntityProperty(cursor.getString(offset + 14))); + entity.setConsonantVoicing(cursor.isNull(offset + 15) ? null : consonantVoicingConverter.convertToEntityProperty(cursor.getString(offset + 15))); + entity.setUsageCount(cursor.getInt(offset + 16)); } @Override @@ -308,4 +319,19 @@ protected final boolean isEntityUpdateable() { return true; } + /** Internal query to resolve the "allophones" to-many relationship of Letter. */ + public List _queryLetter_Allophones(long letterId) { + synchronized (this) { + if (letter_AllophonesQuery == null) { + QueryBuilder queryBuilder = queryBuilder(); + queryBuilder.join(JoinLettersWithAllophones.class, JoinLettersWithAllophonesDao.Properties.AllophoneId) + .where(JoinLettersWithAllophonesDao.Properties.LetterId.eq(letterId)); + letter_AllophonesQuery = queryBuilder.build(); + } + } + Query query = letter_AllophonesQuery.forCurrentThread(); + query.setParameter(0, letterId); + return query.list(); + } + } diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoMaster.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoMaster.java index ab46fd4..6cf4a86 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoMaster.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoMaster.java @@ -14,10 +14,10 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** - * Master of DAO (schema version 2000006): knows all DAOs. + * Master of DAO (schema version 2000007): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { - public static final int SCHEMA_VERSION = 2000006; + public static final int SCHEMA_VERSION = 2000007; /** Creates underlying database table using DAOs. */ public static void createAllTables(Database db, boolean ifNotExists) { @@ -42,6 +42,7 @@ public static void createAllTables(Database db, boolean ifNotExists) { SyllableDao.createTable(db, ifNotExists); WordDao.createTable(db, ifNotExists); DeviceDao.createTable(db, ifNotExists); + JoinLettersWithAllophonesDao.createTable(db, ifNotExists); JoinNumbersWithWordsDao.createTable(db, ifNotExists); JoinStudentsWithDevicesDao.createTable(db, ifNotExists); StudentDao.createTable(db, ifNotExists); @@ -72,6 +73,7 @@ public static void dropAllTables(Database db, boolean ifExists) { SyllableDao.dropTable(db, ifExists); WordDao.dropTable(db, ifExists); DeviceDao.dropTable(db, ifExists); + JoinLettersWithAllophonesDao.dropTable(db, ifExists); JoinNumbersWithWordsDao.dropTable(db, ifExists); JoinStudentsWithDevicesDao.dropTable(db, ifExists); StudentDao.dropTable(db, ifExists); @@ -116,6 +118,7 @@ public DaoMaster(Database db) { registerDaoClass(SyllableDao.class); registerDaoClass(WordDao.class); registerDaoClass(DeviceDao.class); + registerDaoClass(JoinLettersWithAllophonesDao.class); registerDaoClass(JoinNumbersWithWordsDao.class); registerDaoClass(JoinStudentsWithDevicesDao.class); registerDaoClass(StudentDao.class); diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoSession.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoSession.java index e53eb81..a59390c 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoSession.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/DaoSession.java @@ -29,6 +29,7 @@ import org.literacyapp.contentprovider.model.content.Syllable; import org.literacyapp.contentprovider.model.content.Word; import org.literacyapp.contentprovider.model.Device; +import org.literacyapp.contentprovider.model.JoinLettersWithAllophones; import org.literacyapp.contentprovider.model.JoinNumbersWithWords; import org.literacyapp.contentprovider.model.JoinStudentsWithDevices; import org.literacyapp.contentprovider.model.Student; @@ -56,6 +57,7 @@ import org.literacyapp.contentprovider.dao.SyllableDao; import org.literacyapp.contentprovider.dao.WordDao; import org.literacyapp.contentprovider.dao.DeviceDao; +import org.literacyapp.contentprovider.dao.JoinLettersWithAllophonesDao; import org.literacyapp.contentprovider.dao.JoinNumbersWithWordsDao; import org.literacyapp.contentprovider.dao.JoinStudentsWithDevicesDao; import org.literacyapp.contentprovider.dao.StudentDao; @@ -92,6 +94,7 @@ public class DaoSession extends AbstractDaoSession { private final DaoConfig syllableDaoConfig; private final DaoConfig wordDaoConfig; private final DaoConfig deviceDaoConfig; + private final DaoConfig joinLettersWithAllophonesDaoConfig; private final DaoConfig joinNumbersWithWordsDaoConfig; private final DaoConfig joinStudentsWithDevicesDaoConfig; private final DaoConfig studentDaoConfig; @@ -119,6 +122,7 @@ public class DaoSession extends AbstractDaoSession { private final SyllableDao syllableDao; private final WordDao wordDao; private final DeviceDao deviceDao; + private final JoinLettersWithAllophonesDao joinLettersWithAllophonesDao; private final JoinNumbersWithWordsDao joinNumbersWithWordsDao; private final JoinStudentsWithDevicesDao joinStudentsWithDevicesDao; private final StudentDao studentDao; @@ -192,6 +196,9 @@ public DaoSession(Database db, IdentityScopeType type, Map { + + public static final String TABLENAME = "JOIN_LETTERS_WITH_ALLOPHONES"; + + /** + * Properties of entity JoinLettersWithAllophones.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property LetterId = new Property(1, long.class, "letterId", false, "LETTER_ID"); + public final static Property AllophoneId = new Property(2, long.class, "allophoneId", false, "ALLOPHONE_ID"); + } + + + public JoinLettersWithAllophonesDao(DaoConfig config) { + super(config); + } + + public JoinLettersWithAllophonesDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"JOIN_LETTERS_WITH_ALLOPHONES\" (" + // + "\"_id\" INTEGER PRIMARY KEY ," + // 0: id + "\"LETTER_ID\" INTEGER NOT NULL ," + // 1: letterId + "\"ALLOPHONE_ID\" INTEGER NOT NULL );"); // 2: allophoneId + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"JOIN_LETTERS_WITH_ALLOPHONES\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, JoinLettersWithAllophones entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + stmt.bindLong(2, entity.getLetterId()); + stmt.bindLong(3, entity.getAllophoneId()); + } + + @Override + protected final void bindValues(SQLiteStatement stmt, JoinLettersWithAllophones entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + stmt.bindLong(2, entity.getLetterId()); + stmt.bindLong(3, entity.getAllophoneId()); + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public JoinLettersWithAllophones readEntity(Cursor cursor, int offset) { + JoinLettersWithAllophones entity = new JoinLettersWithAllophones( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.getLong(offset + 1), // letterId + cursor.getLong(offset + 2) // allophoneId + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, JoinLettersWithAllophones entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setLetterId(cursor.getLong(offset + 1)); + entity.setAllophoneId(cursor.getLong(offset + 2)); + } + + @Override + protected final Long updateKeyAfterInsert(JoinLettersWithAllophones entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(JoinLettersWithAllophones entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(JoinLettersWithAllophones entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/LetterDao.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/LetterDao.java index b932329..6dc9173 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/LetterDao.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/dao/LetterDao.java @@ -46,6 +46,8 @@ public static class Properties { public final static Property UsageCount = new Property(6, int.class, "usageCount", false, "USAGE_COUNT"); } + private DaoSession daoSession; + private final LocaleConverter localeConverter = new LocaleConverter(); private final CalendarConverter timeLastUpdateConverter = new CalendarConverter(); private final ContentStatusConverter contentStatusConverter = new ContentStatusConverter(); @@ -59,6 +61,7 @@ public LetterDao(DaoConfig config) { public LetterDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); + this.daoSession = daoSession; } /** Creates the underlying database table. */ @@ -120,6 +123,12 @@ protected final void bindValues(SQLiteStatement stmt, Letter entity) { stmt.bindLong(7, entity.getUsageCount()); } + @Override + protected final void attachEntity(Letter entity) { + super.attachEntity(entity); + entity.__setDaoSession(daoSession); + } + @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/model/JoinLettersWithAllophones.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/model/JoinLettersWithAllophones.java index aa3ac2a..3796f2c 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/model/JoinLettersWithAllophones.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/model/JoinLettersWithAllophones.java @@ -1,8 +1,51 @@ package org.literacyapp.contentprovider.model; -/** - * Created by jogrimst on 26/06/2017. - */ +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Generated; +@Entity public class JoinLettersWithAllophones { + + @Id + private Long id; + + private long letterId; + + private long allophoneId; + + @Generated(hash = 249120739) + public JoinLettersWithAllophones(Long id, long letterId, long allophoneId) { + this.id = id; + this.letterId = letterId; + this.allophoneId = allophoneId; + } + + @Generated(hash = 246556632) + public JoinLettersWithAllophones() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public long getLetterId() { + return this.letterId; + } + + public void setLetterId(long letterId) { + this.letterId = letterId; + } + + public long getAllophoneId() { + return this.allophoneId; + } + + public void setAllophoneId(long allophoneId) { + this.allophoneId = allophoneId; + } } diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Allophone.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Allophone.java index 872650d..5749545 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Allophone.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Allophone.java @@ -58,6 +58,8 @@ public class Allophone { @NotNull private String valueSampa; // X-SAMPA - Extended Speech Assessment Methods Phonetic Alphabet + private boolean diacritic; + @Convert(converter = SoundTypeConverter.class, columnType = String.class) private SoundType soundType; @@ -84,13 +86,13 @@ public class Allophone { private int usageCount; - @Generated(hash = 405598671) + @Generated(hash = 1936568992) public Allophone(Long id, @NotNull Locale locale, Calendar timeLastUpdate, @NotNull Integer revisionNumber, @NotNull ContentStatus contentStatus, - @NotNull String valueIpa, @NotNull String valueSampa, SoundType soundType, - VowelLength vowelLength, VowelHeight vowelHeight, VowelFrontness vowelFrontness, - LipRounding lipRounding, ConsonantType consonantType, ConsonantPlace consonantPlace, - ConsonantVoicing consonantVoicing, int usageCount) { + @NotNull String valueIpa, @NotNull String valueSampa, boolean diacritic, + SoundType soundType, VowelLength vowelLength, VowelHeight vowelHeight, + VowelFrontness vowelFrontness, LipRounding lipRounding, ConsonantType consonantType, + ConsonantPlace consonantPlace, ConsonantVoicing consonantVoicing, int usageCount) { this.id = id; this.locale = locale; this.timeLastUpdate = timeLastUpdate; @@ -98,6 +100,7 @@ public Allophone(Long id, @NotNull Locale locale, Calendar timeLastUpdate, this.contentStatus = contentStatus; this.valueIpa = valueIpa; this.valueSampa = valueSampa; + this.diacritic = diacritic; this.soundType = soundType; this.vowelLength = vowelLength; this.vowelHeight = vowelHeight; @@ -240,4 +243,12 @@ public int getUsageCount() { public void setUsageCount(int usageCount) { this.usageCount = usageCount; } + + public boolean getDiacritic() { + return this.diacritic; + } + + public void setDiacritic(boolean diacritic) { + this.diacritic = diacritic; + } } diff --git a/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Letter.java b/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Letter.java index d7ca18e..244e6a8 100644 --- a/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Letter.java +++ b/contentprovider/src/main/java/org/literacyapp/contentprovider/model/content/Letter.java @@ -4,14 +4,22 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.JoinEntity; import org.greenrobot.greendao.annotation.NotNull; +import org.greenrobot.greendao.annotation.ToMany; import org.literacyapp.contentprovider.dao.converter.CalendarConverter; import org.literacyapp.contentprovider.dao.converter.ContentStatusConverter; import org.literacyapp.contentprovider.dao.converter.LocaleConverter; +import org.literacyapp.contentprovider.model.JoinLettersWithAllophones; import org.literacyapp.model.enums.Locale; import org.literacyapp.model.enums.content.ContentStatus; import java.util.Calendar; +import java.util.List; +import org.greenrobot.greendao.DaoException; +import org.literacyapp.contentprovider.dao.DaoSession; +import org.literacyapp.contentprovider.dao.AllophoneDao; +import org.literacyapp.contentprovider.dao.LetterDao; /** * Based on {@link org.literacyapp.model.gson.content.LetterGson} @@ -39,8 +47,20 @@ public class Letter { @NotNull private String text; + @ToMany + @JoinEntity(entity = JoinLettersWithAllophones.class, sourceProperty = "letterId", targetProperty = "allophoneId") + private List allophones; + private int usageCount; + /** Used to resolve relations */ + @Generated(hash = 2040040024) + private transient DaoSession daoSession; + + /** Used for active entity operations. */ + @Generated(hash = 1121207071) + private transient LetterDao myDao; + @Generated(hash = 1689266044) public Letter(Long id, @NotNull Locale locale, Calendar timeLastUpdate, @NotNull Integer revisionNumber, @NotNull ContentStatus contentStatus, @@ -113,4 +133,75 @@ public int getUsageCount() { public void setUsageCount(int usageCount) { this.usageCount = usageCount; } + + /** + * To-many relationship, resolved on first access (and after reset). + * Changes to to-many relations are not persisted, make changes to the target entity. + */ + @Generated(hash = 34341705) + public List getAllophones() { + if (allophones == null) { + final DaoSession daoSession = this.daoSession; + if (daoSession == null) { + throw new DaoException("Entity is detached from DAO context"); + } + AllophoneDao targetDao = daoSession.getAllophoneDao(); + List allophonesNew = targetDao._queryLetter_Allophones(id); + synchronized (this) { + if (allophones == null) { + allophones = allophonesNew; + } + } + } + return allophones; + } + + /** Resets a to-many relationship, making the next get call to query for a fresh result. */ + @Generated(hash = 634480446) + public synchronized void resetAllophones() { + allophones = null; + } + + /** + * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}. + * Entity must attached to an entity context. + */ + @Generated(hash = 128553479) + public void delete() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.delete(this); + } + + /** + * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}. + * Entity must attached to an entity context. + */ + @Generated(hash = 1942392019) + public void refresh() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.refresh(this); + } + + /** + * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}. + * Entity must attached to an entity context. + */ + @Generated(hash = 713229351) + public void update() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.update(this); + } + + /** called by internal mechanisms, do not call yourself. */ + @Generated(hash = 1062828531) + public void __setDaoSession(DaoSession daoSession) { + this.daoSession = daoSession; + myDao = daoSession != null ? daoSession.getLetterDao() : null; + } }