Skip to content

Commit

Permalink
Merge pull request #410 from jogrimst/master
Browse files Browse the repository at this point in the history
#409 Add StoryBooks
  • Loading branch information
literacyapp authored Jun 2, 2017
2 parents 6d50f1b + a1fe903 commit 2442025
Show file tree
Hide file tree
Showing 11 changed files with 671 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.literacyapp"
minSdkVersion 21
targetSdkVersion 23
versionCode 1006002
versionName "1.6.2"
versionCode 1006003
versionName "1.6.3"

// jackOptions {
// enabled true
Expand Down Expand Up @@ -56,7 +56,7 @@ android {
}

greendao {
schemaVersion 2000003 // Must match greendao.schemaVersion in contentprovider/build.gradle
schemaVersion 2000004 // Must match greendao.schemaVersion in contentprovider/build.gradle
daoPackage 'org.literacyapp.contentprovider.dao'
targetGenDir '../contentprovider/src/main/java'
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/org/literacyapp/dao/CustomDaoMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.StoryBookDao;
import org.literacyapp.contentprovider.model.JoinNumbersWithWords;

public class CustomDaoMaster extends DaoMaster {
Expand Down Expand Up @@ -53,6 +54,13 @@ public void onUpgrade(Database db, int oldVersion, int newVersion) {
);
}

if (oldVersion < 2000004) {
// Add new tables and/or columns automatically (include only the DAO classes that have been modified)
DbMigrationHelper.migrate(db,
StoryBookDao.class
);
}

// if (oldVersion < ???) {
// // Add new tables and/or columns automatically (include only the DAO classes that have been modified)
// DbMigrationHelper.migrate(db,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.literacyapp.contentprovider.dao.JoinVideosWithWordsDao;
import org.literacyapp.contentprovider.dao.LetterDao;
import org.literacyapp.contentprovider.dao.NumberDao;
import org.literacyapp.contentprovider.dao.StoryBookDao;
import org.literacyapp.contentprovider.dao.VideoDao;
import org.literacyapp.contentprovider.dao.WordDao;
import org.literacyapp.contentprovider.model.content.Allophone;
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.StoryBook;
import org.literacyapp.contentprovider.model.content.Word;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.contentprovider.model.content.multimedia.Image;
Expand All @@ -48,6 +50,7 @@
import org.literacyapp.model.gson.content.AllophoneGson;
import org.literacyapp.model.gson.content.LetterGson;
import org.literacyapp.model.gson.content.NumberGson;
import org.literacyapp.model.gson.content.StoryBookGson;
import org.literacyapp.model.gson.content.WordGson;
import org.literacyapp.model.gson.content.multimedia.AudioGson;
import org.literacyapp.model.gson.content.multimedia.ImageGson;
Expand All @@ -72,6 +75,7 @@ public class DownloadContentAsyncTask extends AsyncTask<Void, String, String> {
private NumberDao numberDao;
private LetterDao letterDao;
private WordDao wordDao;
private StoryBookDao storyBookDao;
private AudioDao audioDao;
private ImageDao imageDao;
private VideoDao videoDao;
Expand All @@ -96,6 +100,7 @@ public DownloadContentAsyncTask(Context context) {
numberDao = literacyApplication.getDaoSession().getNumberDao();
letterDao = literacyApplication.getDaoSession().getLetterDao();
wordDao = literacyApplication.getDaoSession().getWordDao();
storyBookDao = literacyApplication.getDaoSession().getStoryBookDao();
audioDao = literacyApplication.getDaoSession().getAudioDao();
imageDao = literacyApplication.getDaoSession().getImageDao();
videoDao = literacyApplication.getDaoSession().getVideoDao();
Expand Down Expand Up @@ -258,6 +263,41 @@ protected String doInBackground(Void... voids) {
}


publishProgress("Downloading StoryBooks");
url = EnvironmentSettings.getRestUrl() + "/content/storybook/list" +
"?deviceId=" + DeviceInfoHelper.getDeviceId(context) +
"&locale=" + DeviceInfoHelper.getLocale(context);
jsonResponse = JsonLoader.loadJson(url);
Log.i(getClass().getName(), "jsonResponse: " + jsonResponse);
try {
JSONObject jsonObject = new JSONObject(jsonResponse);
if (!"success".equals(jsonObject.getString("result"))) {
Log.w(getClass().getName(), "Download failed");
} else {
JSONArray jsonArray = jsonObject.getJSONArray("storyBooks");
for (int i = 0; i < jsonArray.length(); i++) {
Type type = new TypeToken<StoryBookGson>(){}.getType();
StoryBookGson storyBookGson = new Gson().fromJson(jsonArray.getString(i), type);
StoryBook storyBook = GsonToGreenDaoConverter.getStoryBook(storyBookGson);
StoryBook existingStoryBook = storyBookDao.queryBuilder()
.where(StoryBookDao.Properties.Id.eq(storyBook.getId()))
.unique();
if (existingStoryBook == null) {
Log.i(getClass().getName(), "Storing StoryBook, id: " + storyBook.getId() + ", title: \"" + storyBook.getTitle() + "\", revisionNumber: " + storyBook.getRevisionNumber());
storyBookDao.insert(storyBook);
} else if (existingStoryBook.getRevisionNumber() < storyBook.getRevisionNumber()) {
Log.i(getClass().getName(), "Updating StoryBook with id " + existingStoryBook.getId() + " from revisionNumber " + existingStoryBook.getRevisionNumber() + " to revisionNumber " + storyBook.getRevisionNumber());
storyBookDao.update(storyBook);
} else {
Log.i(getClass().getName(), "StoryBook \"" + storyBook.getTitle() + "\" already exists in database with id " + storyBook.getId() + " (revision " + storyBook.getRevisionNumber() + ")");
}
}
}
} catch (JSONException e) {
Log.e(getClass().getName(), null, e);
}



publishProgress("Downloading Audios");
url = EnvironmentSettings.getRestUrl() + "/content/multimedia/audio/list" +
Expand Down
8 changes: 4 additions & 4 deletions contentprovider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
versionCode 1000006
versionName "1.0.6"
versionCode 1000007
versionName "1.0.7"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand All @@ -26,7 +26,7 @@ android {
}

greendao {
schemaVersion 2000003 // Must match greendao.schemaVersion in app/build.gradle
schemaVersion 2000004 // Must match greendao.schemaVersion in app/build.gradle
daoPackage 'org.literacyapp.contentprovider.dao'
targetGenDir '../contentprovider/src/main/java'
}
Expand All @@ -49,7 +49,7 @@ dependencies {
})
testCompile 'junit:junit:4.12'

compile 'org.literacyapp:literacyapp-model:1.1.41'
compile 'org.literacyapp:literacyapp-model:1.1.47'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.android.support:appcompat-v7:23.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
import org.literacyapp.contentprovider.dao.ImageDao;
import org.literacyapp.contentprovider.dao.LetterDao;
import org.literacyapp.contentprovider.dao.NumberDao;
import org.literacyapp.contentprovider.dao.StoryBookDao;
import org.literacyapp.contentprovider.dao.VideoDao;
import org.literacyapp.contentprovider.dao.WordDao;
import org.literacyapp.contentprovider.model.Student;
import org.literacyapp.contentprovider.model.content.Allophone;
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.StoryBook;
import org.literacyapp.contentprovider.model.content.Word;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.contentprovider.model.content.multimedia.Image;
import org.literacyapp.contentprovider.model.content.multimedia.Video;
import org.literacyapp.model.enums.GradeLevel;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -231,7 +234,30 @@ public static List<Word> getAllWordsOrderedByFrequency() {

// TODO: getUnlockedStoryBooks()

// TODO: getAllStoryBooks()
public static List<StoryBook> getStoryBooks(GradeLevel... gradeLevels) {
Log.i(ContentProvider.class.getName(), "getAllStoryBooks");

StoryBookDao storyBookDao = daoSession.getStoryBookDao();

List<StoryBook> storyBooks = storyBookDao.queryBuilder()
.where(StoryBookDao.Properties.GradeLevel.in(gradeLevels))
.orderAsc(StoryBookDao.Properties.Title)
.list();

return storyBooks;
}

public static List<StoryBook> getAllStoryBooks() {
Log.i(ContentProvider.class.getName(), "getAllStoryBooks");

StoryBookDao wordDao = daoSession.getStoryBookDao();

List<StoryBook> words = wordDao.queryBuilder()
.orderAsc(StoryBookDao.Properties.Title)
.list();

return words;
}

public static List<Audio> getAllAudios() {
Log.i(ContentProvider.class.getName(), "getAllAudios");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 2000003): knows all DAOs.
* Master of DAO (schema version 2000004): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 2000003;
public static final int SCHEMA_VERSION = 2000004;

/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
Expand All @@ -38,6 +38,7 @@ public static void createAllTables(Database db, boolean ifNotExists) {
JoinVideosWithWordsDao.createTable(db, ifNotExists);
VideoDao.createTable(db, ifNotExists);
NumberDao.createTable(db, ifNotExists);
StoryBookDao.createTable(db, ifNotExists);
WordDao.createTable(db, ifNotExists);
DeviceDao.createTable(db, ifNotExists);
JoinNumbersWithWordsDao.createTable(db, ifNotExists);
Expand Down Expand Up @@ -66,6 +67,7 @@ public static void dropAllTables(Database db, boolean ifExists) {
JoinVideosWithWordsDao.dropTable(db, ifExists);
VideoDao.dropTable(db, ifExists);
NumberDao.dropTable(db, ifExists);
StoryBookDao.dropTable(db, ifExists);
WordDao.dropTable(db, ifExists);
DeviceDao.dropTable(db, ifExists);
JoinNumbersWithWordsDao.dropTable(db, ifExists);
Expand Down Expand Up @@ -108,6 +110,7 @@ public DaoMaster(Database db) {
registerDaoClass(JoinVideosWithWordsDao.class);
registerDaoClass(VideoDao.class);
registerDaoClass(NumberDao.class);
registerDaoClass(StoryBookDao.class);
registerDaoClass(WordDao.class);
registerDaoClass(DeviceDao.class);
registerDaoClass(JoinNumbersWithWordsDao.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.literacyapp.contentprovider.model.content.multimedia.JoinVideosWithWords;
import org.literacyapp.contentprovider.model.content.multimedia.Video;
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.StoryBook;
import org.literacyapp.contentprovider.model.content.Word;
import org.literacyapp.contentprovider.model.Device;
import org.literacyapp.contentprovider.model.JoinNumbersWithWords;
Expand All @@ -50,6 +51,7 @@
import org.literacyapp.contentprovider.dao.JoinVideosWithWordsDao;
import org.literacyapp.contentprovider.dao.VideoDao;
import org.literacyapp.contentprovider.dao.NumberDao;
import org.literacyapp.contentprovider.dao.StoryBookDao;
import org.literacyapp.contentprovider.dao.WordDao;
import org.literacyapp.contentprovider.dao.DeviceDao;
import org.literacyapp.contentprovider.dao.JoinNumbersWithWordsDao;
Expand Down Expand Up @@ -84,6 +86,7 @@ public class DaoSession extends AbstractDaoSession {
private final DaoConfig joinVideosWithWordsDaoConfig;
private final DaoConfig videoDaoConfig;
private final DaoConfig numberDaoConfig;
private final DaoConfig storyBookDaoConfig;
private final DaoConfig wordDaoConfig;
private final DaoConfig deviceDaoConfig;
private final DaoConfig joinNumbersWithWordsDaoConfig;
Expand All @@ -109,6 +112,7 @@ public class DaoSession extends AbstractDaoSession {
private final JoinVideosWithWordsDao joinVideosWithWordsDao;
private final VideoDao videoDao;
private final NumberDao numberDao;
private final StoryBookDao storyBookDao;
private final WordDao wordDao;
private final DeviceDao deviceDao;
private final JoinNumbersWithWordsDao joinNumbersWithWordsDao;
Expand Down Expand Up @@ -172,6 +176,9 @@ public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends Abstr
numberDaoConfig = daoConfigMap.get(NumberDao.class).clone();
numberDaoConfig.initIdentityScope(type);

storyBookDaoConfig = daoConfigMap.get(StoryBookDao.class).clone();
storyBookDaoConfig.initIdentityScope(type);

wordDaoConfig = daoConfigMap.get(WordDao.class).clone();
wordDaoConfig.initIdentityScope(type);

Expand Down Expand Up @@ -210,6 +217,7 @@ public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends Abstr
joinVideosWithWordsDao = new JoinVideosWithWordsDao(joinVideosWithWordsDaoConfig, this);
videoDao = new VideoDao(videoDaoConfig, this);
numberDao = new NumberDao(numberDaoConfig, this);
storyBookDao = new StoryBookDao(storyBookDaoConfig, this);
wordDao = new WordDao(wordDaoConfig, this);
deviceDao = new DeviceDao(deviceDaoConfig, this);
joinNumbersWithWordsDao = new JoinNumbersWithWordsDao(joinNumbersWithWordsDaoConfig, this);
Expand All @@ -235,6 +243,7 @@ public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends Abstr
registerDao(JoinVideosWithWords.class, joinVideosWithWordsDao);
registerDao(Video.class, videoDao);
registerDao(Number.class, numberDao);
registerDao(StoryBook.class, storyBookDao);
registerDao(Word.class, wordDao);
registerDao(Device.class, deviceDao);
registerDao(JoinNumbersWithWords.class, joinNumbersWithWordsDao);
Expand Down Expand Up @@ -262,6 +271,7 @@ public void clear() {
joinVideosWithWordsDaoConfig.clearIdentityScope();
videoDaoConfig.clearIdentityScope();
numberDaoConfig.clearIdentityScope();
storyBookDaoConfig.clearIdentityScope();
wordDaoConfig.clearIdentityScope();
deviceDaoConfig.clearIdentityScope();
joinNumbersWithWordsDaoConfig.clearIdentityScope();
Expand Down Expand Up @@ -339,6 +349,10 @@ public NumberDao getNumberDao() {
return numberDao;
}

public StoryBookDao getStoryBookDao() {
return storyBookDao;
}

public WordDao getWordDao() {
return wordDao;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.literacyapp.contentprovider.model.content.Allophone;
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.StoryBook;
import org.literacyapp.contentprovider.model.content.Word;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.contentprovider.model.content.multimedia.Image;
Expand All @@ -14,6 +15,7 @@
import org.literacyapp.model.gson.content.AllophoneGson;
import org.literacyapp.model.gson.content.LetterGson;
import org.literacyapp.model.gson.content.NumberGson;
import org.literacyapp.model.gson.content.StoryBookGson;
import org.literacyapp.model.gson.content.WordGson;
import org.literacyapp.model.gson.content.multimedia.AudioGson;
import org.literacyapp.model.gson.content.multimedia.ImageGson;
Expand Down Expand Up @@ -111,6 +113,29 @@ public static Word getWord(WordGson wordGson) {
}
}

public static StoryBook getStoryBook(StoryBookGson storyBookGson) {
if (storyBookGson == null) {
return null;
} else {
StoryBook storyBook = new StoryBook();

storyBook.setId(storyBookGson.getId());

storyBook.setLocale(storyBookGson.getLocale());
storyBook.setTimeLastUpdate(storyBookGson.getTimeLastUpdate());
storyBook.setRevisionNumber(storyBookGson.getRevisionNumber());
storyBook.setContentStatus(storyBookGson.getContentStatus());

storyBook.setTitle(storyBookGson.getTitle());
storyBook.setCoverImage(getImage(storyBookGson.getCoverImage()));
storyBook.setGradeLevel(storyBookGson.getGradeLevel());

// TODO: pages

return storyBook;
}
}

public static Audio getAudio(AudioGson audioGson) {
if (audioGson == null) {
return null;
Expand Down
Loading

0 comments on commit 2442025

Please sign in to comment.