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

Duplicate of rc/core-make-widowWidth-available-in-session #1420

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,15 @@ protected InstanceRoot setupSessionData(ExternalDataInstance instance) {
TreeElement root =
SessionInstanceBuilder.getSessionInstance(sessionWrapper.getFrame(), getDeviceId(),
getVersionString(), getCurrentDrift(), u.getUsername(), u.getUniqueId(),
u.getProperties());
u.getProperties(), getWindowWidth());
root.setParent(instance.getBase());
return new ConcreteInstanceRoot(root);
}

protected String getWindowWidth() {
return sessionWrapper.getWindowWidth();
}

protected long getCurrentDrift() {
return 0;
}
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/org/commcare/modern/session/SessionWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ public class SessionWrapper extends CommCareSession implements SessionWrapperInt
final protected CommCarePlatform mPlatform;
protected CommCareInstanceInitializer initializer;
protected RemoteInstanceFetcher remoteInstanceFetcher;
/**
* A string representing the width of the user's screen in pixels.
* To be used in a display condition determining what content to show to the user.
*/
private String windowWidth;

public SessionWrapper(CommCareSession session, CommCarePlatform platform, UserSandbox sandbox,
RemoteInstanceFetcher remoteInstanceFetcher) {
this(platform, sandbox, remoteInstanceFetcher);
RemoteInstanceFetcher remoteInstanceFetcher, String windowWidth) {
this(platform, sandbox, remoteInstanceFetcher, windowWidth);
this.frame = session.getFrame();
this.setFrameStack(session.getFrameStack());
}


public SessionWrapper(CommCareSession session, CommCarePlatform platform, UserSandbox sandbox) {
this(session, platform, sandbox, null);
public SessionWrapper(CommCareSession session, CommCarePlatform platform, UserSandbox sandbox, String windowWidth) {
this(session, platform, sandbox, null, windowWidth);
}

public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox) {
Expand All @@ -43,11 +48,12 @@ public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox) {
this.mPlatform = platform;
}

public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox, RemoteInstanceFetcher remoteInstanceFetcher) {
public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox, RemoteInstanceFetcher remoteInstanceFetcher, String windowWidth) {
super(platform);
this.mSandbox = sandbox;
this.mPlatform = platform;
this.remoteInstanceFetcher = remoteInstanceFetcher;
this.windowWidth = windowWidth;
}

/**
Expand Down Expand Up @@ -119,4 +125,8 @@ public void stepBack() {
public RemoteInstanceFetcher getRemoteInstanceFetcher() {
return remoteInstanceFetcher;
}

public String getWindowWidth() {
return this.windowWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class SessionInstanceBuilder {
public static TreeElement getSessionInstance(SessionFrame frame, String deviceId,
String appversion, long drift,
String username, String userId,
Hashtable<String, String> userFields) {
Hashtable<String, String> userFields, String windowWidth) {
TreeElement sessionRoot = new TreeElement("session", 0);

addSessionNavData(sessionRoot, frame);
addMetadata(sessionRoot, deviceId, appversion, username, userId, drift);
addMetadata(sessionRoot, deviceId, appversion, username, userId, drift, windowWidth);
addUserProperties(sessionRoot, userFields);

return sessionRoot;
Expand Down Expand Up @@ -88,14 +88,15 @@ private static String getCalloutSearchResultCount(StackFrameStep step) {

private static void addMetadata(TreeElement sessionRoot, String deviceId,
String appversion, String username,
String userId, long drift) {
String userId, long drift, String windowWidth) {
TreeElement sessionMeta = new TreeElement("context", 0);

addData(sessionMeta, "deviceid", deviceId);
addData(sessionMeta, "appversion", appversion);
addData(sessionMeta, "username", username);
addData(sessionMeta, "userid", userId);
addData(sessionMeta, "drift", String.valueOf(drift));
addData(sessionMeta, "window_width", windowWidth);

sessionRoot.addChild(sessionMeta);
}
Expand Down
Loading