Skip to content

Commit

Permalink
Merge pull request #423 from jogrimst/master
Browse files Browse the repository at this point in the history
#418 ContentProvider release 1.0.8
  • Loading branch information
literacyapp authored Jun 22, 2017
2 parents 4f9b7dd + 006a6c9 commit 1b7289a
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 6 deletions.
4 changes: 2 additions & 2 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 1006003
versionName "1.6.3"
versionCode 1006004
versionName "1.6.4"

// jackOptions {
// enabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
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.SyllableGson;
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 @@ -228,6 +229,41 @@ protected String doInBackground(Void... voids) {
}


publishProgress("Downloading Syllables");
url = EnvironmentSettings.getRestUrl() + "/content/syllable/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("syllables");
for (int i = 0; i < jsonArray.length(); i++) {
Type type = new TypeToken<SyllableGson>(){}.getType();
SyllableGson syllableGson = new Gson().fromJson(jsonArray.getString(i), type);
// Syllable syllable = GsonToGreenDaoConverter.getSyllable(syllableGson);
// Syllable existingSyllable = syllableDao.queryBuilder()
// .where(SyllableDao.Properties.Id.eq(syllable.getId()))
// .unique();
// if (existingSyllable == null) {
// Log.i(getClass().getName(), "Storing Syllable, id: " + syllable.getId() + ", text: \"" + syllable.getText() + "\", revisionNumber: " + syllable.getRevisionNumber());
// syllableDao.insert(syllable);
// } else if (existingSyllable.getRevisionNumber() < syllable.getRevisionNumber()) {
// Log.i(getClass().getName(), "Updating Syllable with id " + existingSyllable.getId() + " from revisionNumber " + existingSyllable.getRevisionNumber() + " to revisionNumber " + syllable.getRevisionNumber());
// syllableDao.update(syllable);
// } else {
// Log.i(getClass().getName(), "Syllable \"" + syllable.getText() + "\" already exists in database with id " + syllable.getId() + " (revision " + syllable.getRevisionNumber() + ")");
// }
}
}
} catch (JSONException e) {
Log.e(getClass().getName(), null, e);
}


publishProgress("Downloading Words");
url = EnvironmentSettings.getRestUrl() + "/content/word/list" +
"?deviceId=" + DeviceInfoHelper.getDeviceId(context) +
Expand Down
4 changes: 2 additions & 2 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 1000007
versionName "1.0.7"
versionCode 1000008
versionName "1.0.8"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static List<Letter> getUnlockedLetters() {

LetterDao letterDao = daoSession.getLetterDao();

// Copied from CurriculumHelper.java:
// Copied from app/CurriculumHelper.java:

List<Letter> letters = new ArrayList<>();

Expand Down Expand Up @@ -144,7 +144,7 @@ public static List<Number> getUnlockedNumbers() {

NumberDao numberDao = daoSession.getNumberDao();

// Copied from CurriculumHelper.java:
// Copied from app/CurriculumHelper.java:

List<Number> numbers = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static void createAllTables(Database db, boolean ifNotExists) {
VideoDao.createTable(db, ifNotExists);
NumberDao.createTable(db, ifNotExists);
StoryBookDao.createTable(db, ifNotExists);
SyllableDao.createTable(db, ifNotExists);
WordDao.createTable(db, ifNotExists);
DeviceDao.createTable(db, ifNotExists);
JoinNumbersWithWordsDao.createTable(db, ifNotExists);
Expand Down Expand Up @@ -68,6 +69,7 @@ public static void dropAllTables(Database db, boolean ifExists) {
VideoDao.dropTable(db, ifExists);
NumberDao.dropTable(db, ifExists);
StoryBookDao.dropTable(db, ifExists);
SyllableDao.dropTable(db, ifExists);
WordDao.dropTable(db, ifExists);
DeviceDao.dropTable(db, ifExists);
JoinNumbersWithWordsDao.dropTable(db, ifExists);
Expand Down Expand Up @@ -111,6 +113,7 @@ public DaoMaster(Database db) {
registerDaoClass(VideoDao.class);
registerDaoClass(NumberDao.class);
registerDaoClass(StoryBookDao.class);
registerDaoClass(SyllableDao.class);
registerDaoClass(WordDao.class);
registerDaoClass(DeviceDao.class);
registerDaoClass(JoinNumbersWithWordsDao.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.Syllable;
import org.literacyapp.contentprovider.model.content.Word;
import org.literacyapp.contentprovider.model.Device;
import org.literacyapp.contentprovider.model.JoinNumbersWithWords;
Expand All @@ -52,6 +53,7 @@
import org.literacyapp.contentprovider.dao.VideoDao;
import org.literacyapp.contentprovider.dao.NumberDao;
import org.literacyapp.contentprovider.dao.StoryBookDao;
import org.literacyapp.contentprovider.dao.SyllableDao;
import org.literacyapp.contentprovider.dao.WordDao;
import org.literacyapp.contentprovider.dao.DeviceDao;
import org.literacyapp.contentprovider.dao.JoinNumbersWithWordsDao;
Expand Down Expand Up @@ -87,6 +89,7 @@ public class DaoSession extends AbstractDaoSession {
private final DaoConfig videoDaoConfig;
private final DaoConfig numberDaoConfig;
private final DaoConfig storyBookDaoConfig;
private final DaoConfig syllableDaoConfig;
private final DaoConfig wordDaoConfig;
private final DaoConfig deviceDaoConfig;
private final DaoConfig joinNumbersWithWordsDaoConfig;
Expand All @@ -113,6 +116,7 @@ public class DaoSession extends AbstractDaoSession {
private final VideoDao videoDao;
private final NumberDao numberDao;
private final StoryBookDao storyBookDao;
private final SyllableDao syllableDao;
private final WordDao wordDao;
private final DeviceDao deviceDao;
private final JoinNumbersWithWordsDao joinNumbersWithWordsDao;
Expand Down Expand Up @@ -179,6 +183,9 @@ public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends Abstr
storyBookDaoConfig = daoConfigMap.get(StoryBookDao.class).clone();
storyBookDaoConfig.initIdentityScope(type);

syllableDaoConfig = daoConfigMap.get(SyllableDao.class).clone();
syllableDaoConfig.initIdentityScope(type);

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

Expand Down Expand Up @@ -218,6 +225,7 @@ public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends Abstr
videoDao = new VideoDao(videoDaoConfig, this);
numberDao = new NumberDao(numberDaoConfig, this);
storyBookDao = new StoryBookDao(storyBookDaoConfig, this);
syllableDao = new SyllableDao(syllableDaoConfig, this);
wordDao = new WordDao(wordDaoConfig, this);
deviceDao = new DeviceDao(deviceDaoConfig, this);
joinNumbersWithWordsDao = new JoinNumbersWithWordsDao(joinNumbersWithWordsDaoConfig, this);
Expand All @@ -244,6 +252,7 @@ public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends Abstr
registerDao(Video.class, videoDao);
registerDao(Number.class, numberDao);
registerDao(StoryBook.class, storyBookDao);
registerDao(Syllable.class, syllableDao);
registerDao(Word.class, wordDao);
registerDao(Device.class, deviceDao);
registerDao(JoinNumbersWithWords.class, joinNumbersWithWordsDao);
Expand Down Expand Up @@ -272,6 +281,7 @@ public void clear() {
videoDaoConfig.clearIdentityScope();
numberDaoConfig.clearIdentityScope();
storyBookDaoConfig.clearIdentityScope();
syllableDaoConfig.clearIdentityScope();
wordDaoConfig.clearIdentityScope();
deviceDaoConfig.clearIdentityScope();
joinNumbersWithWordsDaoConfig.clearIdentityScope();
Expand Down Expand Up @@ -353,6 +363,10 @@ public StoryBookDao getStoryBookDao() {
return storyBookDao;
}

public SyllableDao getSyllableDao() {
return syllableDao;
}

public WordDao getWordDao() {
return wordDao;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package org.literacyapp.contentprovider.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import java.util.Calendar;
import org.literacyapp.contentprovider.dao.converter.CalendarConverter;
import org.literacyapp.contentprovider.dao.converter.ContentStatusConverter;
import org.literacyapp.contentprovider.dao.converter.LocaleConverter;
import org.literacyapp.model.enums.Locale;
import org.literacyapp.model.enums.content.ContentStatus;

import org.literacyapp.contentprovider.model.content.Syllable;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "SYLLABLE".
*/
public class SyllableDao extends AbstractDao<Syllable, Long> {

public static final String TABLENAME = "SYLLABLE";

/**
* Properties of entity Syllable.<br/>
* 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 Locale = new Property(1, String.class, "locale", false, "LOCALE");
public final static Property TimeLastUpdate = new Property(2, Long.class, "timeLastUpdate", false, "TIME_LAST_UPDATE");
public final static Property RevisionNumber = new Property(3, Integer.class, "revisionNumber", false, "REVISION_NUMBER");
public final static Property ContentStatus = new Property(4, String.class, "contentStatus", false, "CONTENT_STATUS");
public final static Property Text = new Property(5, String.class, "text", false, "TEXT");
public final static Property UsageCount = new Property(6, int.class, "usageCount", false, "USAGE_COUNT");
}

private final LocaleConverter localeConverter = new LocaleConverter();
private final CalendarConverter timeLastUpdateConverter = new CalendarConverter();
private final ContentStatusConverter contentStatusConverter = new ContentStatusConverter();

public SyllableDao(DaoConfig config) {
super(config);
}

public SyllableDao(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 + "\"SYLLABLE\" (" + //
"\"_id\" INTEGER PRIMARY KEY ," + // 0: id
"\"LOCALE\" TEXT NOT NULL ," + // 1: locale
"\"TIME_LAST_UPDATE\" INTEGER," + // 2: timeLastUpdate
"\"REVISION_NUMBER\" INTEGER NOT NULL ," + // 3: revisionNumber
"\"CONTENT_STATUS\" TEXT NOT NULL ," + // 4: contentStatus
"\"TEXT\" TEXT NOT NULL ," + // 5: text
"\"USAGE_COUNT\" INTEGER NOT NULL );"); // 6: usageCount
}

/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SYLLABLE\"";
db.execSQL(sql);
}

@Override
protected final void bindValues(DatabaseStatement stmt, Syllable entity) {
stmt.clearBindings();

Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
stmt.bindString(2, localeConverter.convertToDatabaseValue(entity.getLocale()));

Calendar timeLastUpdate = entity.getTimeLastUpdate();
if (timeLastUpdate != null) {
stmt.bindLong(3, timeLastUpdateConverter.convertToDatabaseValue(timeLastUpdate));
}
stmt.bindLong(4, entity.getRevisionNumber());
stmt.bindString(5, contentStatusConverter.convertToDatabaseValue(entity.getContentStatus()));
stmt.bindString(6, entity.getText());
stmt.bindLong(7, entity.getUsageCount());
}

@Override
protected final void bindValues(SQLiteStatement stmt, Syllable entity) {
stmt.clearBindings();

Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
stmt.bindString(2, localeConverter.convertToDatabaseValue(entity.getLocale()));

Calendar timeLastUpdate = entity.getTimeLastUpdate();
if (timeLastUpdate != null) {
stmt.bindLong(3, timeLastUpdateConverter.convertToDatabaseValue(timeLastUpdate));
}
stmt.bindLong(4, entity.getRevisionNumber());
stmt.bindString(5, contentStatusConverter.convertToDatabaseValue(entity.getContentStatus()));
stmt.bindString(6, entity.getText());
stmt.bindLong(7, entity.getUsageCount());
}

@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}

@Override
public Syllable readEntity(Cursor cursor, int offset) {
Syllable entity = new Syllable( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
localeConverter.convertToEntityProperty(cursor.getString(offset + 1)), // locale
cursor.isNull(offset + 2) ? null : timeLastUpdateConverter.convertToEntityProperty(cursor.getLong(offset + 2)), // timeLastUpdate
cursor.getInt(offset + 3), // revisionNumber
contentStatusConverter.convertToEntityProperty(cursor.getString(offset + 4)), // contentStatus
cursor.getString(offset + 5), // text
cursor.getInt(offset + 6) // usageCount
);
return entity;
}

@Override
public void readEntity(Cursor cursor, Syllable entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setLocale(localeConverter.convertToEntityProperty(cursor.getString(offset + 1)));
entity.setTimeLastUpdate(cursor.isNull(offset + 2) ? null : timeLastUpdateConverter.convertToEntityProperty(cursor.getLong(offset + 2)));
entity.setRevisionNumber(cursor.getInt(offset + 3));
entity.setContentStatus(contentStatusConverter.convertToEntityProperty(cursor.getString(offset + 4)));
entity.setText(cursor.getString(offset + 5));
entity.setUsageCount(cursor.getInt(offset + 6));
}

@Override
protected final Long updateKeyAfterInsert(Syllable entity, long rowId) {
entity.setId(rowId);
return rowId;
}

@Override
public Long getKey(Syllable entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}

@Override
public boolean hasKey(Syllable entity) {
return entity.getId() != null;
}

@Override
protected final boolean isEntityUpdateable() {
return true;
}

}
Loading

0 comments on commit 1b7289a

Please sign in to comment.