Skip to content

Commit

Permalink
Merge branch '4.3.1rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowers committed Sep 10, 2014
2 parents 46bf4bf + cdd9e96 commit e95ee1a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group = com.mixpanel.android
version = 4.3.0
version = 4.3.1-SNAPSHOT
68 changes: 43 additions & 25 deletions src/main/java/com/mixpanel/android/mpmetrics/InAppFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setDisplayState(final int stateId, final UpdateDisplayState.DisplayS
// Fragments require a default constructor that is called when Activities recreate them.
// This means that when the Activity recreates this Fragment (due to rotation, or
// the Activity going away and coming back), mDisplayStateId and mDisplayState are not
// initialized, but this is okay since we remove the Fragment in onStart.
// initialized. Lifecycle methods should be aware of this case, and decline to show.
mDisplayStateId = stateId;
mDisplayState = displayState;
}
Expand Down Expand Up @@ -146,24 +146,27 @@ public boolean onSingleTapUp(MotionEvent event) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mKill = false;
mCleanedUp = false;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);

mInAppView = inflater.inflate(R.layout.com_mixpanel_android_activity_notification_mini, container, false);
final TextView titleView = (TextView) mInAppView.findViewById(R.id.com_mixpanel_android_notification_title);
final ImageView notifImage = (ImageView) mInAppView.findViewById(R.id.com_mixpanel_android_notification_image);
if (null == mDisplayState) {
cleanUp();
} else {
mInAppView = inflater.inflate(R.layout.com_mixpanel_android_activity_notification_mini, container, false);
final TextView titleView = (TextView) mInAppView.findViewById(R.id.com_mixpanel_android_notification_title);
final ImageView notifImage = (ImageView) mInAppView.findViewById(R.id.com_mixpanel_android_notification_image);

InAppNotification inApp = mDisplayState.getInAppNotification();
InAppNotification inApp = mDisplayState.getInAppNotification();

titleView.setText(inApp.getTitle());
notifImage.setImageBitmap(inApp.getImage());
titleView.setText(inApp.getTitle());
notifImage.setImageBitmap(inApp.getImage());

mHandler.postDelayed(mRemover, MINI_REMOVE_TIME);
mHandler.postDelayed(mRemover, MINI_REMOVE_TIME);
}

return mInAppView;
}
Expand All @@ -172,7 +175,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onStart() {
super.onStart();

if (mKill) {
if (mCleanedUp) {
mParent.getFragmentManager().beginTransaction().remove(this).commit();
}
}
Expand All @@ -188,28 +191,43 @@ public void onResume() {
}

@Override
public void onStop() {
super.onStop();

mHandler.removeCallbacks(mRemover);
mHandler.removeCallbacks(mDisplayMini);

// This Fragment when registered on the Activity is part of its state, and so gets
// restored / recreated when the Activity goes away and comes back. We prefer to just not
// keep the notification around in the case of mini, so we have to remember to kill it.
// If the Activity object fully dies, then it is not remembered, so onSaveInstanceState is not necessary.
mKill = true;
UpdateDisplayState.releaseDisplayState(mDisplayStateId);
public void onSaveInstanceState(Bundle outState) {
cleanUp();
super.onSaveInstanceState(outState);
}

@Override
public void onPause() {
super.onPause();
cleanUp();
}

private void cleanUp() {
if (!mCleanedUp) {
mHandler.removeCallbacks(mRemover);
mHandler.removeCallbacks(mDisplayMini);
UpdateDisplayState.releaseDisplayState(mDisplayStateId);

final FragmentManager fragmentManager = mParent.getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.remove(this).commit();
}

mCleanedUp = true;
}

private void remove() {
if (mParent != null) {
if (mParent != null && !mCleanedUp) {
mHandler.removeCallbacks(mRemover);
mHandler.removeCallbacks(mDisplayMini);

final FragmentManager fragmentManager = mParent.getFragmentManager();

// setCustomAnimations works on a per transaction level, so the animations set
// when this fragment was created do not apply
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setCustomAnimations(0, R.anim.com_mixpanel_android_slide_down).remove(this).commit();
mCleanedUp = true;
}
}

Expand All @@ -228,7 +246,7 @@ public float getInterpolation(float t) {
private Runnable mRemover, mDisplayMini;
private View mInAppView;

private boolean mKill;
private boolean mCleanedUp;

private static final String LOGTAG = "InAppFragment";
private static final int MINI_REMOVE_TIME = 6000;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Stores global configuration options for the Mixpanel library.
*/
public class MPConfig {
public static final String VERSION = "4.3.0";
public static final String VERSION = "4.3.1-SNAPSHOT";

public static boolean DEBUG = false;

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/mixpanel/android/surveys/SurveyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ protected void onCreate(Bundle savedInstanceState) {

if (isShowingInApp()) {
onCreateInAppNotification(savedInstanceState);
}
if (isShowingSurvey()) {
} else if (isShowingSurvey()) {
onCreateSurvey(savedInstanceState);
} else {
finish();
}
}

Expand Down Expand Up @@ -251,8 +252,8 @@ public void onQuestionAnswered(Question question, String answer) {
@Override
protected void onStart() {
super.onStart();

if (mUpdateDisplayState.getDisplayState().getType() == UpdateDisplayState.DisplayState.SurveyState.TYPE) {
final UpdateDisplayState.DisplayState displayState = mUpdateDisplayState.getDisplayState();
if (null != displayState && displayState.getType() == UpdateDisplayState.DisplayState.SurveyState.TYPE) {
onStartSurvey();
}
}
Expand Down Expand Up @@ -395,11 +396,13 @@ private UpdateDisplayState.DisplayState.InAppNotificationState getInAppState() {
}

private boolean isShowingSurvey() {
return mUpdateDisplayState.getDisplayState().getType() == UpdateDisplayState.DisplayState.SurveyState.TYPE;
final UpdateDisplayState.DisplayState displayState = mUpdateDisplayState.getDisplayState();
return displayState != null && displayState.getType() == UpdateDisplayState.DisplayState.SurveyState.TYPE;
}

private boolean isShowingInApp() {
return mUpdateDisplayState.getDisplayState().getType() == UpdateDisplayState.DisplayState.InAppNotificationState.TYPE;
final UpdateDisplayState.DisplayState displayState = mUpdateDisplayState.getDisplayState();
return displayState != null && displayState.getType() == UpdateDisplayState.DisplayState.InAppNotificationState.TYPE;
}

private void trackSurveyAttempted() {
Expand Down

0 comments on commit e95ee1a

Please sign in to comment.