From ec1215bf2a420c32d72b435fbc645f965a2dd885 Mon Sep 17 00:00:00 2001 From: Jo Grimstad Date: Sun, 25 Mar 2018 17:00:18 +0200 Subject: [PATCH] #198 Add minSdkVersion to ApplicationVersion --- app/build.gradle | 6 +-- .../appstore/dao/ApplicationVersionDao.java | 38 +++++++++++++------ .../elimu/appstore/dao/CustomDaoMaster.java | 5 +++ .../java/ai/elimu/appstore/dao/DaoMaster.java | 4 +- .../appstore/model/ApplicationVersion.java | 17 ++++++++- .../AppSynchronizationActivity.java | 2 + 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d62fbf56..094f6bee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "ai.elimu.appstore" minSdkVersion 21 targetSdkVersion 26 - versionCode 2002001 - versionName "2.2.1-SNAPSHOT" + versionCode 2002002 + versionName "2.2.2-SNAPSHOT" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -72,7 +72,7 @@ greendao { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'ai.elimu:model:1.1.69' + implementation 'ai.elimu:model:1.1.70' implementation "org.greenrobot:greendao:3.2.2" implementation 'commons-io:commons-io:2.5' implementation 'com.jakewharton.timber:timber:4.5.1' diff --git a/app/src/main/java/ai/elimu/appstore/dao/ApplicationVersionDao.java b/app/src/main/java/ai/elimu/appstore/dao/ApplicationVersionDao.java index 2914a8c5..4c6a3903 100644 --- a/app/src/main/java/ai/elimu/appstore/dao/ApplicationVersionDao.java +++ b/app/src/main/java/ai/elimu/appstore/dao/ApplicationVersionDao.java @@ -40,8 +40,9 @@ public static class Properties { public final static Property VersionCode = new Property(6, Integer.class, "versionCode", false, "VERSION_CODE"); public final static Property VersionName = new Property(7, String.class, "versionName", false, "VERSION_NAME"); public final static Property Label = new Property(8, String.class, "label", false, "LABEL"); - public final static Property StartCommand = new Property(9, String.class, "startCommand", false, "START_COMMAND"); - public final static Property TimeUploaded = new Property(10, long.class, "timeUploaded", false, "TIME_UPLOADED"); + public final static Property MinSdkVersion = new Property(9, Integer.class, "minSdkVersion", false, "MIN_SDK_VERSION"); + public final static Property StartCommand = new Property(10, String.class, "startCommand", false, "START_COMMAND"); + public final static Property TimeUploaded = new Property(11, long.class, "timeUploaded", false, "TIME_UPLOADED"); } private DaoSession daoSession; @@ -70,8 +71,9 @@ public static void createTable(Database db, boolean ifNotExists) { "\"VERSION_CODE\" INTEGER NOT NULL ," + // 6: versionCode "\"VERSION_NAME\" TEXT," + // 7: versionName "\"LABEL\" TEXT," + // 8: label - "\"START_COMMAND\" TEXT," + // 9: startCommand - "\"TIME_UPLOADED\" INTEGER NOT NULL );"); // 10: timeUploaded + "\"MIN_SDK_VERSION\" INTEGER," + // 9: minSdkVersion + "\"START_COMMAND\" TEXT," + // 10: startCommand + "\"TIME_UPLOADED\" INTEGER NOT NULL );"); // 11: timeUploaded } /** Drops the underlying database table. */ @@ -105,11 +107,16 @@ protected final void bindValues(DatabaseStatement stmt, ApplicationVersion entit stmt.bindString(9, label); } + Integer minSdkVersion = entity.getMinSdkVersion(); + if (minSdkVersion != null) { + stmt.bindLong(10, minSdkVersion); + } + String startCommand = entity.getStartCommand(); if (startCommand != null) { - stmt.bindString(10, startCommand); + stmt.bindString(11, startCommand); } - stmt.bindLong(11, timeUploadedConverter.convertToDatabaseValue(entity.getTimeUploaded())); + stmt.bindLong(12, timeUploadedConverter.convertToDatabaseValue(entity.getTimeUploaded())); } @Override @@ -137,11 +144,16 @@ protected final void bindValues(SQLiteStatement stmt, ApplicationVersion entity) stmt.bindString(9, label); } + Integer minSdkVersion = entity.getMinSdkVersion(); + if (minSdkVersion != null) { + stmt.bindLong(10, minSdkVersion); + } + String startCommand = entity.getStartCommand(); if (startCommand != null) { - stmt.bindString(10, startCommand); + stmt.bindString(11, startCommand); } - stmt.bindLong(11, timeUploadedConverter.convertToDatabaseValue(entity.getTimeUploaded())); + stmt.bindLong(12, timeUploadedConverter.convertToDatabaseValue(entity.getTimeUploaded())); } @Override @@ -167,8 +179,9 @@ public ApplicationVersion readEntity(Cursor cursor, int offset) { cursor.getInt(offset + 6), // versionCode cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // versionName cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // label - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // startCommand - timeUploadedConverter.convertToEntityProperty(cursor.getLong(offset + 10)) // timeUploaded + cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9), // minSdkVersion + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // startCommand + timeUploadedConverter.convertToEntityProperty(cursor.getLong(offset + 11)) // timeUploaded ); return entity; } @@ -184,8 +197,9 @@ public void readEntity(Cursor cursor, ApplicationVersion entity, int offset) { entity.setVersionCode(cursor.getInt(offset + 6)); entity.setVersionName(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLabel(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); - entity.setStartCommand(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setTimeUploaded(timeUploadedConverter.convertToEntityProperty(cursor.getLong(offset + 10))); + entity.setMinSdkVersion(cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9)); + entity.setStartCommand(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setTimeUploaded(timeUploadedConverter.convertToEntityProperty(cursor.getLong(offset + 11))); } @Override diff --git a/app/src/main/java/ai/elimu/appstore/dao/CustomDaoMaster.java b/app/src/main/java/ai/elimu/appstore/dao/CustomDaoMaster.java index 6000802c..24044a2a 100644 --- a/app/src/main/java/ai/elimu/appstore/dao/CustomDaoMaster.java +++ b/app/src/main/java/ai/elimu/appstore/dao/CustomDaoMaster.java @@ -59,6 +59,11 @@ public void onUpgrade(Database db, int oldVersion, int newVersion) { dropAllTables(db, true); onCreate(db); } + + if (oldVersion < 2002002) { + // Add minSdkVersion + DbMigrationHelper.migrate(db, ApplicationVersionDao.class); + } } } } diff --git a/app/src/main/java/ai/elimu/appstore/dao/DaoMaster.java b/app/src/main/java/ai/elimu/appstore/dao/DaoMaster.java index b6e67c63..8b13b0ed 100644 --- a/app/src/main/java/ai/elimu/appstore/dao/DaoMaster.java +++ b/app/src/main/java/ai/elimu/appstore/dao/DaoMaster.java @@ -14,10 +14,10 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** - * Master of DAO (schema version 2002001): knows all DAOs. + * Master of DAO (schema version 2002002): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { - public static final int SCHEMA_VERSION = 2002001; + public static final int SCHEMA_VERSION = 2002002; /** Creates underlying database table using DAOs. */ public static void createAllTables(Database db, boolean ifNotExists) { diff --git a/app/src/main/java/ai/elimu/appstore/model/ApplicationVersion.java b/app/src/main/java/ai/elimu/appstore/model/ApplicationVersion.java index 7ba49e6c..67100e4a 100644 --- a/app/src/main/java/ai/elimu/appstore/model/ApplicationVersion.java +++ b/app/src/main/java/ai/elimu/appstore/model/ApplicationVersion.java @@ -46,6 +46,9 @@ public class ApplicationVersion { // @NotNull private String label; +// @NotNull + private Integer minSdkVersion; + private String startCommand; @NotNull @@ -60,10 +63,11 @@ public class ApplicationVersion { @Generated(hash = 1339503542) private transient ApplicationVersionDao myDao; - @Generated(hash = 985154034) + @Generated(hash = 932028413) public ApplicationVersion(Long id, long applicationId, @NotNull Integer fileSizeInKb, @NotNull String fileUrl, @NotNull String checksumMd5, @NotNull String contentType, @NotNull Integer versionCode, - String versionName, String label, String startCommand, @NotNull Calendar timeUploaded) { + String versionName, String label, Integer minSdkVersion, String startCommand, + @NotNull Calendar timeUploaded) { this.id = id; this.applicationId = applicationId; this.fileSizeInKb = fileSizeInKb; @@ -73,6 +77,7 @@ public ApplicationVersion(Long id, long applicationId, @NotNull Integer fileSize this.versionCode = versionCode; this.versionName = versionName; this.label = label; + this.minSdkVersion = minSdkVersion; this.startCommand = startCommand; this.timeUploaded = timeUploaded; } @@ -248,4 +253,12 @@ public String getLabel() { public void setLabel(String label) { this.label = label; } + + public Integer getMinSdkVersion() { + return this.minSdkVersion; + } + + public void setMinSdkVersion(Integer minSdkVersion) { + this.minSdkVersion = minSdkVersion; + } } diff --git a/app/src/main/java/ai/elimu/appstore/synchronization/AppSynchronizationActivity.java b/app/src/main/java/ai/elimu/appstore/synchronization/AppSynchronizationActivity.java index 7c1092d6..1aa4a8cf 100644 --- a/app/src/main/java/ai/elimu/appstore/synchronization/AppSynchronizationActivity.java +++ b/app/src/main/java/ai/elimu/appstore/synchronization/AppSynchronizationActivity.java @@ -239,6 +239,7 @@ private void processAppListData(@NonNull Response response) { applicationVersion.setVersionCode(applicationVersionGson.getVersionCode()); applicationVersion.setVersionName(applicationVersionGson.getVersionName()); applicationVersion.setLabel(applicationVersionGson.getLabel()); + applicationVersion.setMinSdkVersion(applicationVersionGson.getMinSdkVersion()); applicationVersion.setStartCommand(applicationVersionGson.getStartCommand()); applicationVersion.setTimeUploaded(applicationVersionGson.getTimeUploaded()); long applicationVersionId = applicationVersionDao.insert(applicationVersion); @@ -277,6 +278,7 @@ private void processAppListData(@NonNull Response response) { applicationVersion.setVersionCode(applicationVersionGson.getVersionCode()); applicationVersion.setVersionName(applicationVersionGson.getVersionName()); applicationVersion.setLabel(applicationVersionGson.getLabel()); + applicationVersion.setMinSdkVersion(applicationVersionGson.getMinSdkVersion()); applicationVersion.setStartCommand(applicationVersionGson.getStartCommand()); applicationVersion.setTimeUploaded(applicationVersionGson.getTimeUploaded()); long applicationVersionId = applicationVersionDao.insert(applicationVersion);