From 83289e4e062b1fae1d588f26b35b4cd619011daa Mon Sep 17 00:00:00 2001 From: Jo Grimstad Date: Sun, 4 Jun 2017 13:37:03 +0200 Subject: [PATCH] #51 Add StoryBookLearningEvent --- app/build.gradle | 6 +- app/src/main/AndroidManifest.xml | 10 ++ .../analytics/dao/CustomDaoMaster.java | 6 + .../literacyapp/analytics/dao/DaoMaster.java | 7 +- .../literacyapp/analytics/dao/DaoSession.java | 14 ++ .../dao/StoryBookLearningEventDao.java | 165 ++++++++++++++++++ .../model/StoryBookLearningEvent.java | 26 +-- .../StoryBookLearningEventReceiver.java | 46 ++--- eventtracker/build.gradle | 6 +- .../analytics/eventtracker/EventTracker.java | 13 +- 10 files changed, 254 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/org/literacyapp/analytics/dao/StoryBookLearningEventDao.java diff --git a/app/build.gradle b/app/build.gradle index cf099bd..e0c95a2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { applicationId "org.literacyapp.analytics" minSdkVersion 21 targetSdkVersion 23 - versionCode 1000008 - versionName "1.0.8" + versionCode 1000009 + versionName "1.0.9" } buildTypes { @@ -50,7 +50,7 @@ dependencies { testCompile 'junit:junit:4.12' - compile 'org.literacyapp:literacyapp-model:1.1.45' + compile 'org.literacyapp:literacyapp-model:1.1.48' compile 'com.android.support:appcompat-v7:23.4.0' compile 'commons-io:commons-io:2.5' compile 'org.greenrobot:greendao:3.2.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 42bbd81..7ba0755 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -70,6 +70,16 @@ + + + + + + + >, DaoConfig> @@ -57,6 +61,9 @@ public DaoSession(Database db, IdentityScopeType type, Map { + + public static final String TABLENAME = "STORY_BOOK_LEARNING_EVENT"; + + /** + * Properties of entity StoryBookLearningEvent.
+ * 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 DeviceId = new Property(1, String.class, "deviceId", false, "DEVICE_ID"); + public final static Property Time = new Property(2, long.class, "time", false, "TIME"); + public final static Property PackageName = new Property(3, String.class, "packageName", false, "PACKAGE_NAME"); + public final static Property StudentId = new Property(4, String.class, "studentId", false, "STUDENT_ID"); + public final static Property StoryBookId = new Property(5, Long.class, "storyBookId", false, "STORY_BOOK_ID"); + } + + private final CalendarConverter timeConverter = new CalendarConverter(); + + public StoryBookLearningEventDao(DaoConfig config) { + super(config); + } + + public StoryBookLearningEventDao(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 + "\"STORY_BOOK_LEARNING_EVENT\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"DEVICE_ID\" TEXT NOT NULL ," + // 1: deviceId + "\"TIME\" INTEGER NOT NULL ," + // 2: time + "\"PACKAGE_NAME\" TEXT NOT NULL ," + // 3: packageName + "\"STUDENT_ID\" TEXT," + // 4: studentId + "\"STORY_BOOK_ID\" INTEGER);"); // 5: storyBookId + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"STORY_BOOK_LEARNING_EVENT\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, StoryBookLearningEvent entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + stmt.bindString(2, entity.getDeviceId()); + stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime())); + stmt.bindString(4, entity.getPackageName()); + + String studentId = entity.getStudentId(); + if (studentId != null) { + stmt.bindString(5, studentId); + } + + Long storyBookId = entity.getStoryBookId(); + if (storyBookId != null) { + stmt.bindLong(6, storyBookId); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, StoryBookLearningEvent entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + stmt.bindString(2, entity.getDeviceId()); + stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime())); + stmt.bindString(4, entity.getPackageName()); + + String studentId = entity.getStudentId(); + if (studentId != null) { + stmt.bindString(5, studentId); + } + + Long storyBookId = entity.getStoryBookId(); + if (storyBookId != null) { + stmt.bindLong(6, storyBookId); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public StoryBookLearningEvent readEntity(Cursor cursor, int offset) { + StoryBookLearningEvent entity = new StoryBookLearningEvent( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.getString(offset + 1), // deviceId + timeConverter.convertToEntityProperty(cursor.getLong(offset + 2)), // time + cursor.getString(offset + 3), // packageName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // studentId + cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5) // storyBookId + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, StoryBookLearningEvent entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setDeviceId(cursor.getString(offset + 1)); + entity.setTime(timeConverter.convertToEntityProperty(cursor.getLong(offset + 2))); + entity.setPackageName(cursor.getString(offset + 3)); + entity.setStudentId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setStoryBookId(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5)); + } + + @Override + protected final Long updateKeyAfterInsert(StoryBookLearningEvent entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(StoryBookLearningEvent entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(StoryBookLearningEvent entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/org/literacyapp/analytics/model/StoryBookLearningEvent.java b/app/src/main/java/org/literacyapp/analytics/model/StoryBookLearningEvent.java index 4239706..a1b7d2a 100644 --- a/app/src/main/java/org/literacyapp/analytics/model/StoryBookLearningEvent.java +++ b/app/src/main/java/org/literacyapp/analytics/model/StoryBookLearningEvent.java @@ -10,7 +10,7 @@ import java.util.Calendar; @Entity -public class VideoLearningEvent { +public class StoryBookLearningEvent { @Id(autoincrement = true) private Long id; @@ -30,23 +30,23 @@ public class VideoLearningEvent { // TODO: replace with Student? private String studentId; - // TODO: replace with Video? - private Long videoId; + // TODO: replace with StoryBook? + private Long storyBookId; - @Generated(hash = 1150493777) - public VideoLearningEvent(Long id, @NotNull String deviceId, + @Generated(hash = 1450632809) + public StoryBookLearningEvent(Long id, @NotNull String deviceId, @NotNull Calendar time, @NotNull String packageName, String studentId, - Long videoId) { + Long storyBookId) { this.id = id; this.deviceId = deviceId; this.time = time; this.packageName = packageName; this.studentId = studentId; - this.videoId = videoId; + this.storyBookId = storyBookId; } - @Generated(hash = 934937089) - public VideoLearningEvent() { + @Generated(hash = 333305170) + public StoryBookLearningEvent() { } public Long getId() { @@ -89,11 +89,11 @@ public void setStudentId(String studentId) { this.studentId = studentId; } - public Long getVideoId() { - return this.videoId; + public Long getStoryBookId() { + return this.storyBookId; } - public void setVideoId(Long videoId) { - this.videoId = videoId; + public void setStoryBookId(Long storyBookId) { + this.storyBookId = storyBookId; } } diff --git a/app/src/main/java/org/literacyapp/analytics/receiver/StoryBookLearningEventReceiver.java b/app/src/main/java/org/literacyapp/analytics/receiver/StoryBookLearningEventReceiver.java index 6bf83ae..75d3895 100644 --- a/app/src/main/java/org/literacyapp/analytics/receiver/StoryBookLearningEventReceiver.java +++ b/app/src/main/java/org/literacyapp/analytics/receiver/StoryBookLearningEventReceiver.java @@ -12,15 +12,15 @@ import org.apache.commons.io.FileUtils; import org.literacyapp.analytics.AnalyticsApplication; -import org.literacyapp.analytics.dao.VideoLearningEventDao; -import org.literacyapp.analytics.model.VideoLearningEvent; +import org.literacyapp.analytics.dao.StoryBookLearningEventDao; +import org.literacyapp.analytics.model.StoryBookLearningEvent; import org.literacyapp.analytics.util.DeviceInfoHelper; import java.io.File; import java.io.IOException; import java.util.Calendar; -public class VideoLearningEventReceiver extends BroadcastReceiver { +public class StoryBookLearningEventReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { @@ -29,50 +29,50 @@ public void onReceive(Context context, Intent intent) { String packageName = intent.getStringExtra("packageName"); Log.i(getClass().getName(), "packageName: " + packageName); - Long videoId = intent.getLongExtra("videoId", -1); - Log.i(getClass().getName(), "videoId: " + videoId); + Long storyBookId = intent.getLongExtra("storyBookId", -1); + Log.i(getClass().getName(), "storyBookId: " + storyBookId); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); String studentId = sharedPreferences.getString(StudentUpdatedReceiver.PREF_STUDENT_ID, null); Log.i(getClass().getName(), "studentId: " + studentId); // Store in database - VideoLearningEvent videoLearningEvent = new VideoLearningEvent(); - videoLearningEvent.setDeviceId(DeviceInfoHelper.getDeviceId(context)); - videoLearningEvent.setTime(Calendar.getInstance()); - videoLearningEvent.setPackageName(packageName); - videoLearningEvent.setStudentId(studentId); - videoLearningEvent.setVideoId(videoId); + StoryBookLearningEvent storyBookLearningEvent = new StoryBookLearningEvent(); + storyBookLearningEvent.setDeviceId(DeviceInfoHelper.getDeviceId(context)); + storyBookLearningEvent.setTime(Calendar.getInstance()); + storyBookLearningEvent.setPackageName(packageName); + storyBookLearningEvent.setStudentId(studentId); + storyBookLearningEvent.setStoryBookId(storyBookId); AnalyticsApplication analyticsApplication = (AnalyticsApplication) context.getApplicationContext(); - VideoLearningEventDao videoLearningEventDao = analyticsApplication.getDaoSession().getVideoLearningEventDao(); - long id = videoLearningEventDao.insert(videoLearningEvent); - Log.i(getClass().getName(), "VideoLearningEvent saved in database with id " + id); + StoryBookLearningEventDao storyBookLearningEventDao = analyticsApplication.getDaoSession().getStoryBookLearningEventDao(); + long id = storyBookLearningEventDao.insert(storyBookLearningEvent); + Log.i(getClass().getName(), "StoryBookLearningEvent saved in database with id " + id); // Store in log file - // Expected format: id:1|deviceId:4113947bec18b7ad|time:1481916197273|packageName:org.literacyapp|studentId:4113947bec18b7ad_1|videoId:25 + // Expected format: id:1|deviceId:4113947bec18b7ad|time:1481916197273|packageName:org.literacyapp|studentId:4113947bec18b7ad_1|storyBookId:25 String logLine = "id:" + id - + "|deviceId:" + videoLearningEvent.getDeviceId() - + "|time:" + videoLearningEvent.getTime().getTimeInMillis() - + "|packageName:" + videoLearningEvent.getPackageName() - + "|studentId:" + videoLearningEvent.getStudentId() - + "|videoId:" + videoLearningEvent.getVideoId() + + "|deviceId:" + storyBookLearningEvent.getDeviceId() + + "|time:" + storyBookLearningEvent.getTime().getTimeInMillis() + + "|packageName:" + storyBookLearningEvent.getPackageName() + + "|studentId:" + storyBookLearningEvent.getStudentId() + + "|storyBookId:" + storyBookLearningEvent.getStoryBookId() + "\n"; Log.i(getClass().getName(), "logLine: " + logLine); - String logsPath = Environment.getExternalStorageDirectory() + "/.literacyapp-analytics/events/device_" + videoLearningEvent.getDeviceId(); + String logsPath = Environment.getExternalStorageDirectory() + "/.literacyapp-analytics/events/device_" + storyBookLearningEvent.getDeviceId(); File logsDir = new File(logsPath); Log.i(getClass().getName(), "logsDir: " + logsDir); if (!logsDir.exists()) { logsDir.mkdirs(); } - if (!TextUtils.isEmpty(videoLearningEvent.getStudentId())) { + if (!TextUtils.isEmpty(storyBookLearningEvent.getStudentId())) { // TODO: create one subfolder per student id (if not null)? } String dateFormatted = (String) DateFormat.format("yyyy-MM-dd", Calendar.getInstance()); - String fileName = "video_learning_events_" + dateFormatted + ".log"; + String fileName = "storybook_learning_events_" + dateFormatted + ".log"; File logFile = new File(logsDir, fileName); Log.i(getClass().getName(), "logFile: " + logFile); try { diff --git a/eventtracker/build.gradle b/eventtracker/build.gradle index da41f5f..692c1db 100644 --- a/eventtracker/build.gradle +++ b/eventtracker/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 23 - versionCode 1000002 - versionName "1.0.2" + versionCode 1000003 + versionName "1.0.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -33,6 +33,6 @@ dependencies { }) testCompile 'junit:junit:4.12' - compile 'org.literacyapp:literacyapp-model:1.1.45' + compile 'org.literacyapp:literacyapp-model:1.1.48' compile 'com.android.support:appcompat-v7:23.4.0' } diff --git a/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java b/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java index bfcb245..c7eca0f 100644 --- a/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java +++ b/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java @@ -42,7 +42,7 @@ public static void reportNumberLearningEvent(Context context, Integer number) { } public static void reportVideoLearningEvent(Context context, Long videoId) { - Log.i(EventTracker.class.getName(), "reportNumberLearningEvent"); + Log.i(EventTracker.class.getName(), "reportVideoLearningEvent"); Intent intent = new Intent(); intent.setPackage("org.literacyapp.analytics"); @@ -51,4 +51,15 @@ public static void reportVideoLearningEvent(Context context, Long videoId) { intent.putExtra("videoId", videoId); context.sendBroadcast(intent); } + + public static void reportStoryBookLearningEvent(Context context, Long storyBookId) { + Log.i(EventTracker.class.getName(), "reportStoryBookLearningEvent"); + + Intent intent = new Intent(); + intent.setPackage("org.literacyapp.analytics"); + intent.setAction("literacyapp.intent.action.STORYBOOK_LEARNING_EVENT"); + intent.putExtra("packageName", context.getPackageName()); + intent.putExtra("storyBookId", storyBookId); + context.sendBroadcast(intent); + } }