Last active
April 3, 2018 09:57
-
-
Save drobyshys/4bf1eb65a4f266c16936fdbd8309ef91 to your computer and use it in GitHub Desktop.
mixpanel twick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseSalonyApp extends Application { | |
private static Tweak<Boolean> canSkipSignUp = MixpanelAPI.booleanTweak("Can skip", false); | |
public void onCreate() { | |
super.onCreate | |
new MixpanelTracker(this); | |
} | |
public static boolean canSkipSignUp() { | |
return Boolean.TRUE.equals(canSkipSignUp.get()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MixpanelTracker { | |
@Nullable | |
private final MixpanelAPI mixpanel; | |
private volatile boolean tweaksLoaded = false; | |
MixpanelTracker(final Application app) { | |
if (ENABLED) { | |
mixpanel = MixpanelAPI.getInstance(app, "---"); | |
mixpanel.getPeople().addOnMixpanelUpdatesReceivedListener(() -> { | |
mixpanel.getPeople().joinExperimentIfAvailable(); | |
}); | |
mixpanel.getPeople().addOnMixpanelTweaksUpdatedListener(updatedTweaksName -> { | |
tweaksLoaded = true; | |
Timber.tag("MIXPANEL").d("tweaksLoaded %s %s", App.canSkipSignUp(), updatedTweaksName); | |
}); | |
} else { | |
mixpanel = null; | |
tweaksLoaded = true; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WelcomeFragment extends BaseRxFragment { | |
@BindView(R.id.btn_skip) View btnSkip; | |
@Nullable @Override | |
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_welcome, container, false); | |
boolean visible = SalonyApp.canSkipSignUp(); | |
UiUtil.setVisible(btnSkip, visible); | |
Timber.tag("MIXPANEL").d("canShowSkip %s", visible); | |
if (!visible) { | |
subscription.add(Observable.interval(1200, TimeUnit.MILLISECONDS) | |
.take(10) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(aLong -> { | |
boolean canSkipSignUp = SalonyApp.canSkipSignUp(); | |
if (canSkipSignUp && btnSkip.getVisibility() == View.GONE) { | |
UiUtil.setVisible(btnSkip, true); | |
subscription.clear(); | |
} | |
Timber.tag("MIXPANEL").d("canShowSkip %s", canSkipSignUp); | |
}) | |
); | |
} | |
return view; | |
} | |
@Override public void onDestroyView() { | |
super.onDestroyView(); | |
subscription.clear(); | |
} | |
@OnClick(R.id.btn_skip) void onSkipAction() { | |
callback.onSkip(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment