Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-4642] Fixed timed event not accepting Date. Cleaned up strings to #449

Merged
merged 2 commits into from
Sep 15, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@

package ti.modules.titanium.analytics;

import org.appcelerator.kroll.KrollDate;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.analytics.TiAnalyticsEventFactory;
import org.appcelerator.titanium.util.TiConvert;

@Kroll.module
public class AnalyticsModule extends KrollModule {
public class AnalyticsModule extends KrollModule
{

public AnalyticsModule(TiContext tiContext) {
protected static final String PROPERTY_APP_NAV = "app.nav";
protected static final String PROPERTY_APP_TIMED = "app.timed";
protected static final String PROPERTY_APP_FEATURE = "app.feature";
protected static final String PROPERTY_APP_SETTINGS = "app.settings";
protected static final String PROPERTY_APP_USER = "app.user";

public AnalyticsModule(TiContext tiContext)
{
super(tiContext);
}

Expand All @@ -27,7 +37,8 @@ public void addEvent(String type, String event, @Kroll.argument(optional=true) K
localAddEvent(type, event, data);
}

protected void localAddEvent(String type, String event, KrollDict data) {
protected void localAddEvent(String type, String event, KrollDict data)
{
getTiContext().getTiApp().postAnalyticsEvent(TiAnalyticsEventFactory.createEvent(type, event, TiConvert.toJSON(data).toString()));
}

Expand All @@ -37,40 +48,57 @@ public void navEvent(String from, String to,
@Kroll.argument(optional=true) KrollDict data)
{
KrollDict payload = new KrollDict();
payload.put("from", from);
payload.put("to", to);
payload.put("event", event);
payload.put("data", data);
payload.put(TiC.PROPERTY_FROM, from);
payload.put(TiC.PROPERTY_TO, to);
payload.put(TiC.PROPERTY_EVENT, event);
payload.put(TiC.PROPERTY_DATA, data);

localAddEvent("app.nav", payload.getString("event"), payload);
localAddEvent(PROPERTY_APP_NAV, payload.getString(TiC.PROPERTY_EVENT), payload);
}

@Kroll.method
public void timedEvent(String event, long start, long stop, int duration,
public void timedEvent(String event, Object start, Object stop, int duration,
@Kroll.argument(optional=true) KrollDict data)
{
KrollDict payload = new KrollDict();
payload.put("event", event);
payload.put("start", start);
payload.put("stop", stop);
payload.put("duration", duration);
payload.put("data", data);
payload.put(TiC.PROPERTY_EVENT, event);
if (start instanceof Number) {
payload.put(TiC.PROPERTY_START, ((Number) start).longValue());
} else if (start instanceof KrollDate) {
payload.put(TiC.PROPERTY_START, ((KrollDate) start).getTime());
} else {
throw new IllegalArgumentException("start must be a long or Date.");
}

if (stop instanceof Number) {
payload.put(TiC.PROPERTY_STOP, ((Number) stop).longValue());
} else if (stop instanceof KrollDate) {
payload.put(TiC.PROPERTY_STOP, ((KrollDate) start).getTime());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you referenced "start" here, when you meant to reference "stop"

} else {
throw new IllegalArgumentException("stop must be a long or Date.");
}

payload.put(TiC.PROPERTY_DURATION, duration);
payload.put(TiC.PROPERTY_DATA, data);

localAddEvent("app.timed", payload.getString("event"), payload);
localAddEvent(PROPERTY_APP_TIMED, payload.getString(TiC.PROPERTY_EVENT), payload);
}

@Kroll.method
public void featureEvent(String event, @Kroll.argument(optional=true) KrollDict data) {
localAddEvent("app.feature", event, data);
public void featureEvent(String event, @Kroll.argument(optional=true) KrollDict data)
{
localAddEvent(PROPERTY_APP_FEATURE, event, data);
}

@Kroll.method
public void settingsEvent(String event, @Kroll.argument(optional=true) KrollDict data) {
localAddEvent("app.settings", event, data);
public void settingsEvent(String event, @Kroll.argument(optional=true) KrollDict data)
{
localAddEvent(PROPERTY_APP_SETTINGS, event, data);
}

@Kroll.method
public void userEvent(String event, @Kroll.argument(optional=true) KrollDict data) {
localAddEvent("app.user", event, data);
public void userEvent(String event, @Kroll.argument(optional=true) KrollDict data)
{
localAddEvent(PROPERTY_APP_USER, event, data);
}
}
5 changes: 5 additions & 0 deletions android/titanium/src/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public class TiC
public static final String PROPERTY_ELLIPSIZE = "ellipsize";
public static final String PROPERTY_ENABLE_ZOOM_CONTROLS = "enableZoomControls";
public static final String PROPERTY_ENABLED = "enabled";
public static final String PROPERTY_EVENT = "event";
public static final String PROPERTY_EXIT_ON_CLOSE = "exitOnClose";
public static final String PROPERTY_FILE = "file";
public static final String PROPERTY_FILTER_ATTRIBUTE = "filterAttribute";
Expand All @@ -165,6 +166,7 @@ public class TiC
public static final String PROPERTY_FOOTER_TITLE = "footerTitle";
public static final String PROPERTY_FOOTER_VIEW = "footerView";
public static final String PROPERTY_FREQUENCY = "frequency";
public static final String PROPERTY_FROM = "from";
public static final String PROPERTY_FULLSCREEN = "fullscreen";
public static final String PROPERTY_GROUP_ID = "groupId";
public static final String PROPERTY_HAS_CHECK = "hasCheck";
Expand Down Expand Up @@ -268,8 +270,10 @@ public class TiC
public static final String PROPERTY_SOURCE = EVENT_PROPERTY_SOURCE;
public static final String PROPERTY_SOURCE_LENGTH = "sourceLength";
public static final String PROPERTY_SOURCE_POSITION = "sourcePosition";
public static final String PROPERTY_START = "start";
public static final String PROPERTY_STATE = "state";
public static final String PROPERTY_STATUS = "status";
public static final String PROPERTY_STOP = "stop";
public static final String PROPERTY_STREET = "street";
public static final String PROPERTY_STREET1 = "street1";
public static final String PROPERTY_STYLE = "style";
Expand All @@ -287,6 +291,7 @@ public class TiC
public static final String PROPERTY_TITLEID = "titleid";
public static final String PROPERTY_TITLE_ON = "titleOn";
public static final String PROPERTY_TITLE_OFF = "titleOff";
public static final String PROPERTY_TO = "to";
public static final String PROPERTY_TOP = "top";
public static final String PROPERTY_TOUCH_ENABLED = "touchEnabled";
public static final String PROPERTY_TRANSFORM = "transform";
Expand Down