Skip to content

Commit

Permalink
Merge pull request #268 from snowplow/release/0.8.0
Browse files Browse the repository at this point in the history
Release/0.8.0
  • Loading branch information
mhadam committed Jun 21, 2018
2 parents 09ae970 + 81e7ac1 commit 849b1b6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
Version 0.8.0 (2018-06-20)
--------------------------
Fix LifecycleHandler callbacks being unregistered on activity destruction (#266)
Add ability to change custom context sent by LifecycleHandler (#267)

Version 0.7.0 (2018-05-10)
--------------------------
Make tracker.setLifecycleHandler take a Context instead of an Activity (#224)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -92,7 +92,7 @@ limitations under the License.
[travis]: https://travis-ci.org/snowplow/snowplow-android-tracker
[travis-image]: https://travis-ci.org/snowplow/snowplow-android-tracker.svg?branch=master

[release-image]: http://img.shields.io/badge/release-0.7.0-blue.svg?style=flat
[release-image]: http://img.shields.io/badge/release-0.8.0-blue.svg?style=flat
[releases]: https://github.com/snowplow/snowplow-android-tracker/releases

[license-image]: http://img.shields.io/badge/license-Apache--2-blue.svg?style=flat
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.7.0
0.8.0
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -15,7 +15,7 @@ buildscript {

subprojects {
group = 'com.snowplowanalytics'
version = '0.7.0'
version = '0.8.0'
repositories {
maven {
url "http://maven.snplow.com/releases"
Expand Down
Expand Up @@ -92,7 +92,7 @@ public void testSetValues() {
assertEquals(false, tracker.getBase64Encoded());
assertNotNull(tracker.getEmitter());
assertNotNull(tracker.getSubject());
assertEquals("andr-0.7.0", tracker.getTrackerVersion());
assertEquals("andr-0.8.0", tracker.getTrackerVersion());
assertEquals(LogLevel.VERBOSE, tracker.getLogLevel());
assertEquals(2, tracker.getThreadCount());
assertEquals(false, tracker.getApplicationCrash());
Expand Down
Expand Up @@ -207,7 +207,7 @@ public void checkGetRequest(LinkedList<RecordedRequest> requests) throws Excepti
assertEquals("mob", query.get("p"));
assertEquals("myAppId", query.get("aid"));
assertEquals("myNamespace", query.get("tna"));
assertEquals("andr-0.7.0", query.get("tv"));
assertEquals("andr-0.8.0", query.get("tv"));
assertEquals("English", query.get("lang"));
assertTrue(query.has("dtm"));
assertTrue(query.has("stm"));
Expand Down Expand Up @@ -248,7 +248,7 @@ public void checkPostRequest(LinkedList<RecordedRequest> requests) throws Except
assertEquals("mob", json.getString("p"));
assertEquals("myAppId", json.getString("aid"));
assertEquals("myNamespace", json.getString("tna"));
assertEquals("andr-0.7.0", json.getString("tv"));
assertEquals("andr-0.8.0", json.getString("tv"));
assertEquals("English", json.getString("lang"));
assertTrue(json.has("dtm"));
assertTrue(json.has("stm"));
Expand Down
Expand Up @@ -585,20 +585,43 @@ public void setLifecycleHandler(Context context) {
*
* @param context The application context
*/
public void setLifecycleHandler(Context context, List<SelfDescribingJson> customContext) {
public void setLifecycleHandler(Context context, List<SelfDescribingJson> customContexts) {
if ((this.lifecycleEvents || this.sessionContext) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
LifecycleHandler handler = new LifecycleHandler(customContext);
LifecycleHandler handler = new LifecycleHandler(customContexts);
Application application = (Application)context;
application.registerActivityLifecycleCallbacks(handler);
application.registerComponentCallbacks(handler);
}
}

/**
* Sets the custom contexts sent whenever LifecycleHandler sends an event.
*
* @param customContexts A list of self-describing JSONs (custom contexts)
*/
public void setLifecycleCustomContexts(List<SelfDescribingJson> customContexts) {
LifecycleHandler.setLifecycleContexts(customContexts);
}

/**
* @return the custom contexts sent by LifecycleHandler
*/
public List<SelfDescribingJson> getLifecycleCustomContexts() {
return LifecycleHandler.getLifecycleContexts();
}

/**
* Prevent the LifecycleHandler from sending events, in order to ignore foreground
* and background transitions.
*/
public void pauseLifecycleHandler() {
LifecycleHandler.pauseHandler();
}

/**
* Allow the LifecycleHandler to send events again.
*/
public void resumeLifecycleHandler() {
LifecycleHandler.resumeHandler();
}
Expand Down
Expand Up @@ -43,14 +43,22 @@ public class LifecycleHandler implements Application.ActivityLifecycleCallbacks,
private static AtomicInteger foregroundIndex = new AtomicInteger(0);
private static AtomicInteger backgroundIndex = new AtomicInteger(0);
private static boolean isHandlerPaused = false;
private static List<SelfDescribingJson> lifecycleContext = null;
private static List<SelfDescribingJson> lifecycleContexts = null;

public LifecycleHandler(List<SelfDescribingJson> context) {
lifecycleContext = context;
public LifecycleHandler(List<SelfDescribingJson> contexts) {
lifecycleContexts = contexts;
}

public LifecycleHandler() {}

public static void setLifecycleContexts(List<SelfDescribingJson> contexts) {
lifecycleContexts = contexts;
}

public static List<SelfDescribingJson> getLifecycleContexts() {
return lifecycleContexts;
}

public static void pauseHandler() {
isHandlerPaused = true;
}
Expand Down Expand Up @@ -85,10 +93,10 @@ public void onActivityResumed(Activity activity) {
Map<String, Object> data = new HashMap<>();
Util.addToMap(Parameters.APP_FOREGROUND_INDEX, index, data);

if (lifecycleContext != null) {
if (lifecycleContexts != null) {
tracker.track(SelfDescribing.builder()
.eventData(new SelfDescribingJson(TrackerConstants.APPLICATION_FOREGOUND_SCHEMA, data))
.customContext(lifecycleContext)
.customContext(lifecycleContexts)
.build()
);
} else {
Expand All @@ -114,10 +122,7 @@ public void onActivityStopped(Activity activity) {}
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {}

@Override
public void onActivityDestroyed(Activity activity) {
activity.unregisterComponentCallbacks(this);
activity.getApplication().unregisterActivityLifecycleCallbacks(this);
}
public void onActivityDestroyed(Activity activity) {}

@Override
public void onConfigurationChanged(Configuration configuration) {}
Expand Down Expand Up @@ -145,10 +150,10 @@ public void onTrimMemory(int i) {
Map<String, Object> data = new HashMap<>();
Util.addToMap(Parameters.APP_BACKGROUND_INDEX, index, data);

if (lifecycleContext != null) {
if (lifecycleContexts != null) {
tracker.track(SelfDescribing.builder()
.eventData(new SelfDescribingJson(TrackerConstants.APPLICATION_BACKGROUND_SCHEMA, data))
.customContext(lifecycleContext)
.customContext(lifecycleContexts)
.build()
);
} else {
Expand Down

0 comments on commit 849b1b6

Please sign in to comment.