From 526e438708d873b377005f7cb750d456ca2cb1de Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Fri, 1 Dec 2023 19:44:45 +0700 Subject: [PATCH] feat: Download sounds for letter-sound correspondence close #117 --- .../26.json | 683 ++++++++++++++++++ .../room/dao/LetterSound_SoundDao.java | 17 + .../content_provider/room/db/RoomDb.java | 20 +- .../room/entity/LetterSound_Sound.java | 33 + .../ui/letter_sound/LetterSoundsFragment.java | 16 +- 5 files changed, 766 insertions(+), 3 deletions(-) create mode 100644 app/schemas/ai.elimu.content_provider.room.db.RoomDb/26.json create mode 100644 app/src/main/java/ai/elimu/content_provider/room/dao/LetterSound_SoundDao.java create mode 100644 app/src/main/java/ai/elimu/content_provider/room/entity/LetterSound_Sound.java diff --git a/app/schemas/ai.elimu.content_provider.room.db.RoomDb/26.json b/app/schemas/ai.elimu.content_provider.room.db.RoomDb/26.json new file mode 100644 index 0000000..e4efe9e --- /dev/null +++ b/app/schemas/ai.elimu.content_provider.room.db.RoomDb/26.json @@ -0,0 +1,683 @@ +{ + "formatVersion": 1, + "database": { + "version": 26, + "identityHash": "59e65b275fee9665d0c18eb2d49f6a3a", + "entities": [ + { + "tableName": "Letter", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`text` TEXT, `diacritic` INTEGER, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "text", + "columnName": "text", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "diacritic", + "columnName": "diacritic", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Sound", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`valueIpa` TEXT, `diacritic` INTEGER, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "valueIpa", + "columnName": "valueIpa", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "diacritic", + "columnName": "diacritic", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "LetterSound", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "LetterSound_Letter", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`LetterSound_id` INTEGER NOT NULL, `letters_id` INTEGER NOT NULL, PRIMARY KEY(`LetterSound_id`, `letters_id`))", + "fields": [ + { + "fieldPath": "LetterSound_id", + "columnName": "LetterSound_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "letters_id", + "columnName": "letters_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "LetterSound_id", + "letters_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "LetterSound_Sound", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`LetterSound_id` INTEGER NOT NULL, `sounds_id` INTEGER NOT NULL, PRIMARY KEY(`LetterSound_id`, `sounds_id`))", + "fields": [ + { + "fieldPath": "LetterSound_id", + "columnName": "LetterSound_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "sounds_id", + "columnName": "sounds_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "LetterSound_id", + "sounds_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Word", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`text` TEXT NOT NULL, `wordType` TEXT, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "text", + "columnName": "text", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "wordType", + "columnName": "wordType", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Number", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` INTEGER NOT NULL, `symbol` TEXT, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "value", + "columnName": "value", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "symbol", + "columnName": "symbol", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Emoji", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`glyph` TEXT NOT NULL, `unicodeVersion` REAL NOT NULL, `unicodeEmojiVersion` REAL NOT NULL, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "glyph", + "columnName": "glyph", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "unicodeVersion", + "columnName": "unicodeVersion", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "unicodeEmojiVersion", + "columnName": "unicodeEmojiVersion", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Emoji_Word", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`Emoji_id` INTEGER NOT NULL, `words_id` INTEGER NOT NULL, PRIMARY KEY(`Emoji_id`, `words_id`))", + "fields": [ + { + "fieldPath": "Emoji_id", + "columnName": "Emoji_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "words_id", + "columnName": "words_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "Emoji_id", + "words_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Image", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `imageFormat` TEXT NOT NULL, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "imageFormat", + "columnName": "imageFormat", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Image_Word", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`Image_id` INTEGER NOT NULL, `words_id` INTEGER NOT NULL, PRIMARY KEY(`Image_id`, `words_id`))", + "fields": [ + { + "fieldPath": "Image_id", + "columnName": "Image_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "words_id", + "columnName": "words_id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "Image_id", + "words_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Audio", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `transcription` TEXT NOT NULL, `audioFormat` TEXT NOT NULL, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "transcription", + "columnName": "transcription", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "audioFormat", + "columnName": "audioFormat", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "StoryBook", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT, `coverImageId` INTEGER NOT NULL, `readingLevel` TEXT, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "coverImageId", + "columnName": "coverImageId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "readingLevel", + "columnName": "readingLevel", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "StoryBookChapter", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`storyBookId` INTEGER NOT NULL, `sortOrder` INTEGER NOT NULL, `imageId` INTEGER NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "storyBookId", + "columnName": "storyBookId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "sortOrder", + "columnName": "sortOrder", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "imageId", + "columnName": "imageId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "StoryBookParagraph", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`storyBookChapterId` INTEGER NOT NULL, `sortOrder` INTEGER NOT NULL, `originalText` TEXT NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "storyBookChapterId", + "columnName": "storyBookChapterId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "sortOrder", + "columnName": "sortOrder", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "originalText", + "columnName": "originalText", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "StoryBookParagraph_Word", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`StoryBookParagraph_id` INTEGER NOT NULL, `words_id` INTEGER NOT NULL, `words_ORDER` INTEGER NOT NULL, PRIMARY KEY(`StoryBookParagraph_id`, `words_ORDER`))", + "fields": [ + { + "fieldPath": "StoryBookParagraph_id", + "columnName": "StoryBookParagraph_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "words_id", + "columnName": "words_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "words_ORDER", + "columnName": "words_ORDER", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "StoryBookParagraph_id", + "words_ORDER" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Video", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `videoFormat` TEXT NOT NULL, `revisionNumber` INTEGER NOT NULL, `usageCount` INTEGER, `id` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "videoFormat", + "columnName": "videoFormat", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "revisionNumber", + "columnName": "revisionNumber", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "usageCount", + "columnName": "usageCount", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '59e65b275fee9665d0c18eb2d49f6a3a')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/ai/elimu/content_provider/room/dao/LetterSound_SoundDao.java b/app/src/main/java/ai/elimu/content_provider/room/dao/LetterSound_SoundDao.java new file mode 100644 index 0000000..9bd6016 --- /dev/null +++ b/app/src/main/java/ai/elimu/content_provider/room/dao/LetterSound_SoundDao.java @@ -0,0 +1,17 @@ +package ai.elimu.content_provider.room.dao; + +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.Query; + +import ai.elimu.content_provider.room.entity.LetterSound_Sound; + +@Dao +public interface LetterSound_SoundDao { + + @Insert + void insert(LetterSound_Sound letterSound_Sound); + + @Query("DELETE FROM LetterSound_Sound") + void deleteAll(); +} diff --git a/app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java b/app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java index 0988e89..53ffa41 100644 --- a/app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java +++ b/app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java @@ -15,6 +15,7 @@ import ai.elimu.content_provider.room.dao.LetterSoundDao; import ai.elimu.content_provider.room.dao.LetterSound_LetterDao; +import ai.elimu.content_provider.room.dao.LetterSound_SoundDao; import ai.elimu.content_provider.room.dao.SoundDao; import ai.elimu.content_provider.room.dao.AudioDao; import ai.elimu.content_provider.room.dao.EmojiDao; @@ -31,6 +32,7 @@ import ai.elimu.content_provider.room.dao.WordDao; import ai.elimu.content_provider.room.entity.LetterSound; import ai.elimu.content_provider.room.entity.LetterSound_Letter; +import ai.elimu.content_provider.room.entity.LetterSound_Sound; import ai.elimu.content_provider.room.entity.Sound; import ai.elimu.content_provider.room.entity.Audio; import ai.elimu.content_provider.room.entity.Emoji; @@ -46,7 +48,7 @@ import ai.elimu.content_provider.room.entity.Video; import ai.elimu.content_provider.room.entity.Word; -@Database(version = 25, entities = {Letter.class, Sound.class, LetterSound.class, LetterSound_Letter.class, Word.class, Number.class, Emoji.class, Emoji_Word.class, Image.class, Image_Word.class, Audio.class, StoryBook.class, StoryBookChapter.class, StoryBookParagraph.class, StoryBookParagraph_Word.class, Video.class}) +@Database(version = 26, entities = {Letter.class, Sound.class, LetterSound.class, LetterSound_Letter.class, LetterSound_Sound.class, Word.class, Number.class, Emoji.class, Emoji_Word.class, Image.class, Image_Word.class, Audio.class, StoryBook.class, StoryBookChapter.class, StoryBookParagraph.class, StoryBookParagraph_Word.class, Video.class}) @TypeConverters({Converters.class}) public abstract class RoomDb extends RoomDatabase { @@ -58,6 +60,8 @@ public abstract class RoomDb extends RoomDatabase { public abstract LetterSound_LetterDao letterSound_LetterDao(); + public abstract LetterSound_SoundDao letterSound_SoundDao(); + public abstract WordDao wordDao(); public abstract NumberDao numberDao(); @@ -115,7 +119,8 @@ public static RoomDb getDatabase(final Context context) { MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, - MIGRATION_24_25 + MIGRATION_24_25, + MIGRATION_25_26 ) .build(); } @@ -346,4 +351,15 @@ public void migrate(SupportSQLiteDatabase database) { database.execSQL(sql); } }; + + private static final Migration MIGRATION_25_26 = new Migration(25, 26) { + @Override + public void migrate(SupportSQLiteDatabase database) { + Log.i(getClass().getName(), "migrate (25 --> 26)"); + + String sql = "CREATE TABLE IF NOT EXISTS `LetterSound_Sound` (`LetterSound_id` INTEGER NOT NULL, `sounds_id` INTEGER NOT NULL, PRIMARY KEY(`LetterSound_id`, `sounds_id`))"; + Log.i(getClass().getName(), "sql: " + sql); + database.execSQL(sql); + } + }; } diff --git a/app/src/main/java/ai/elimu/content_provider/room/entity/LetterSound_Sound.java b/app/src/main/java/ai/elimu/content_provider/room/entity/LetterSound_Sound.java new file mode 100644 index 0000000..7eb91fa --- /dev/null +++ b/app/src/main/java/ai/elimu/content_provider/room/entity/LetterSound_Sound.java @@ -0,0 +1,33 @@ +package ai.elimu.content_provider.room.entity; + +import androidx.annotation.NonNull; +import androidx.room.Entity; + +/** + * For documentation, see https://github.com/elimu-ai/webapp/tree/main/src/main/java/ai/elimu/model + */ +@Entity(primaryKeys = {"LetterSound_id", "sounds_id"}) +public class LetterSound_Sound { + + @NonNull + private Long LetterSound_id; + + @NonNull + private Long sounds_id; + + public Long getLetterSound_id() { + return LetterSound_id; + } + + public void setLetterSound_id(Long letterSound_id) { + LetterSound_id = letterSound_id; + } + + public Long getSounds_id() { + return sounds_id; + } + + public void setSounds_id(Long sounds_id) { + this.sounds_id = sounds_id; + } +} diff --git a/app/src/main/java/ai/elimu/content_provider/ui/letter_sound/LetterSoundsFragment.java b/app/src/main/java/ai/elimu/content_provider/ui/letter_sound/LetterSoundsFragment.java index 866c7ff..ff4680f 100644 --- a/app/src/main/java/ai/elimu/content_provider/ui/letter_sound/LetterSoundsFragment.java +++ b/app/src/main/java/ai/elimu/content_provider/ui/letter_sound/LetterSoundsFragment.java @@ -26,11 +26,14 @@ import ai.elimu.content_provider.room.GsonToRoomConverter; import ai.elimu.content_provider.room.dao.LetterSoundDao; import ai.elimu.content_provider.room.dao.LetterSound_LetterDao; +import ai.elimu.content_provider.room.dao.LetterSound_SoundDao; import ai.elimu.content_provider.room.db.RoomDb; import ai.elimu.content_provider.room.entity.LetterSound; import ai.elimu.content_provider.room.entity.LetterSound_Letter; +import ai.elimu.content_provider.room.entity.LetterSound_Sound; import ai.elimu.model.v2.gson.content.LetterGson; import ai.elimu.model.v2.gson.content.LetterSoundGson; +import ai.elimu.model.v2.gson.content.SoundGson; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -122,9 +125,11 @@ public void run() { RoomDb roomDb = RoomDb.getDatabase(getContext()); LetterSoundDao letterSoundDao = roomDb.letterSoundDao(); LetterSound_LetterDao letterSound_LetterDao = roomDb.letterSound_LetterDao(); + LetterSound_SoundDao letterSound_SoundDao = roomDb.letterSound_SoundDao(); // Empty the database table before downloading up-to-date content letterSound_LetterDao.deleteAll(); + letterSound_SoundDao.deleteAll(); letterSoundDao.deleteAll(); for (LetterSoundGson letterSoundGson : letterSoundGsons) { @@ -148,7 +153,16 @@ public void run() { } // Store all the LetterSound's sounds in the database - // TODO + List soundGsons = letterSoundGson.getSounds(); + Log.i(getClass().getName(), "soundGsons.size():" + soundGsons.size()); + for (SoundGson soundGson : soundGsons) { + Log.i(getClass().getName(), "soundGson.getId(): " + soundGson.getId()); + LetterSound_Sound letterSound_Sound = new LetterSound_Sound(); + letterSound_Sound.setLetterSound_id(letterSoundGson.getId()); + letterSound_Sound.setSounds_id(soundGson.getId()); + letterSound_SoundDao.insert(letterSound_Sound); + Log.i(getClass().getName(), "Stored LetterSound_Sound in database. LetterSound_id: " + letterSound_Sound.getLetterSound_id() + ", sounds_id: " + letterSound_Sound.getSounds_id()); + } } // Update the UI