Skip to content

Commit

Permalink
Merge pull request #36 from jogrimst/master
Browse files Browse the repository at this point in the history
#35 Add Student id to UsageEvent
  • Loading branch information
literacyapp authored Dec 19, 2016
2 parents 510fd31 + 22484b0 commit 9320c52
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "org.literacyapp.analytics"
minSdkVersion 21
targetSdkVersion 23
versionCode 1000005
versionName "1.0.5"
versionCode 1000006
versionName "1.0.6"
}

buildTypes {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
<action android:name="literacyapp.intent.action.USAGE_EVENT" />
</intent-filter>
</receiver>

<receiver
android:name=".receiver.StudentUpdatedReceiver"
android:enabled="true"
android:exported="true">

<intent-filter>
<action android:name="literacyapp.intent.action.STUDENT_UPDATED" />
</intent-filter>
</receiver>
</application>

</manifest>
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 1000005): knows all DAOs.
* Master of DAO (schema version 1000006): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 1000005;
public static final int SCHEMA_VERSION = 1000006;

/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.literacyapp.analytics.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

public class StudentUpdatedReceiver extends BroadcastReceiver {

public static final String PREF_STUDENT_ID = "pref_student_id";

@Override
public void onReceive(Context context, Intent intent) {
Log.i(getClass().getName(), "onReceive");

String packageName = intent.getStringExtra("packageName");
Log.i(getClass().getName(), "packageName: " + packageName);

String studentId = intent.getStringExtra("studentId");
Log.i(getClass().getName(), "studentId: " + studentId);

if (!TextUtils.isEmpty(studentId)) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

String existingStudentId = sharedPreferences.getString(PREF_STUDENT_ID, null);
Log.i(getClass().getName(), "existingStudentId: " + existingStudentId);

sharedPreferences.edit().putString(PREF_STUDENT_ID, studentId).commit();
Log.i(getClass().getName(), "Updated Student id to: " + studentId);

// Store StudentUpdatedEvent
// TODO
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
Expand Down Expand Up @@ -73,11 +75,15 @@ public void onReceive(Context context, Intent intent) {
// TODO: add task type, task result, duration, etc.


SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String studentId = sharedPreferences.getString(StudentUpdatedReceiver.PREF_STUDENT_ID, null);
Log.i(getClass().getName(), "studentId: " + studentId);

// Store in database
UsageEvent usageEvent = new UsageEvent();
usageEvent.setTime(Calendar.getInstance());
usageEvent.setDeviceId(DeviceInfoHelper.getDeviceId(context));
// TODO: studentId
usageEvent.setStudentId(studentId);
usageEvent.setPackageName(packageName);
usageEvent.setLiteracySkill(literacySkill);
usageEvent.setNumeracySkill(numeracySkill);
Expand Down

0 comments on commit 9320c52

Please sign in to comment.