Skip to content

Commit

Permalink
Merge pull request #1414 from dimagi/rc/core-make-widowWidth-availabl…
Browse files Browse the repository at this point in the history
…e-in-session

Rc/core make widow width available in session
  • Loading branch information
Robert-Costello authored Aug 7, 2024
2 parents 126ec06 + 96f938b commit 03d2fa8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
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

0 comments on commit 03d2fa8

Please sign in to comment.