/** * constructor * * @throws Exception */ public UIUserActivitiesDisplay() throws Exception { List<SelectItemOption<String>> displayModes = new ArrayList<SelectItemOption<String>>(4); displayModes.add( new SelectItemOption<String>("All_Updates", DisplayMode.ALL_ACTIVITIES.toString())); displayModes.add( new SelectItemOption<String>("Space_Updates", DisplayMode.MY_SPACE.toString())); displayModes.add( new SelectItemOption<String>("Network_Updates", DisplayMode.CONNECTIONS.toString())); displayModes.add( new SelectItemOption<String>("My_Status", DisplayMode.MY_ACTIVITIES.toString())); UIDropDownControl uiDropDownControl = addChild(UIDropDownControl.class, "DisplayModesDropDown", null); uiDropDownControl.setOptions(displayModes); setSelectedMode(uiDropDownControl); addChild(uiDropDownControl); // TODO: init() run two time when initiation this form. // String remoteId = Utils.getOwnerRemoteId(); // this.setOwnerName(remoteId); String selectedDisplayMode = Utils.getCookies( String.format(Utils.ACTIVITY_STREAM_TAB_SELECTED_COOKIED, Utils.getViewerRemoteId())); selectedDisplayMode = (selectedDisplayMode != null) ? selectedDisplayMode : DisplayMode.ALL_ACTIVITIES.name(); // setSelectedDisplayMode(selectedDisplayMode); // set lastUpdatedNumber after init() method invoked inside setSelectedDisplayMode() method // int numberOfUpdates = this.getNumberOfUpdatedActivities(); // setLastUpdatedNum(selectedDisplayMode.toString(), "" + numberOfUpdates); }
private int getActivitiesUpdatedNum(boolean hasRefresh) { if (this.postActivity) { resetCookies(); this.postActivity = false; return 0; } // UIActivitiesLoader activitiesLoader = getChild(UIActivitiesLoader.class); ActivitiesRealtimeListAccess activitiesListAccess = (ActivitiesRealtimeListAccess) activitiesLoader.getActivityListAccess(); String mode = DisplayMode.ALL_ACTIVITIES.toString(); ActivityFilterType.ACTIVITY_FEED .oldFromSinceTime(Utils.getLastVisited(Utils.OLD_FROM, mode)) .fromSinceTime(Utils.getLastVisited(Utils.FROM, mode)) .toSinceTime(Utils.getLastVisited(Utils.TO, mode)) .lastNumberOfUpdated(getLastUpdatedNum(mode)); // mode = DisplayMode.CONNECTIONS.toString(); ActivityFilterType.CONNECTIONS_ACTIVITIES .oldFromSinceTime(Utils.getLastVisited(Utils.OLD_FROM, mode)) .fromSinceTime(Utils.getLastVisited(Utils.FROM, mode)) .toSinceTime(Utils.getLastVisited(Utils.TO, mode)) .lastNumberOfUpdated(getLastUpdatedNum(mode)); // mode = DisplayMode.MY_ACTIVITIES.toString(); ActivityFilterType.USER_ACTIVITIES .oldFromSinceTime(Utils.getLastVisited(Utils.OLD_FROM, mode)) .fromSinceTime(Utils.getLastVisited(Utils.FROM, mode)) .toSinceTime(Utils.getLastVisited(Utils.TO, mode)) .lastNumberOfUpdated(getLastUpdatedNum(mode)); // mode = DisplayMode.MY_SPACE.toString(); ActivityFilterType.USER_SPACE_ACTIVITIES .oldFromSinceTime(Utils.getLastVisited(Utils.OLD_FROM, mode)) .fromSinceTime(Utils.getLastVisited(Utils.FROM, mode)) .toSinceTime(Utils.getLastVisited(Utils.TO, mode)) .lastNumberOfUpdated(getLastUpdatedNum(mode)); ActivityUpdateFilter updatedFilter = new ActivityUpdateFilter(hasRefresh); int gotNumber = activitiesListAccess.getNumberOfUpdated(updatedFilter); // if (gotNumber == 0 && hasRefresh) { // only in case lastUpdatedNumber > 0 then reset cookies long lastNumber = getLastUpdatedNum(selectedDisplayMode.toString()); if (lastNumber > 0) { resetCookies(); } } return gotNumber; }
public void resetCookies() { Utils.setLastVisited(this.selectedDisplayMode.toString()); // if (this.selectedDisplayMode == DisplayMode.ALL_ACTIVITIES) { Utils.setLastVisited(DisplayMode.CONNECTIONS.toString()); // Utils.setLastVisited(DisplayMode.MY_ACTIVITIES.toString()); // Utils.setLastVisited(DisplayMode.MY_SPACE.toString()); } }
public void execute(Event<UIDropDownControl> event) throws Exception { UIDropDownControl uiDropDown = event.getSource(); UIUserActivitiesDisplay uiUserActivities = uiDropDown.getParent(); WebuiRequestContext requestContext = event.getRequestContext(); String selectedDisplayMode = requestContext.getRequestParameter(OBJECTID); if (selectedDisplayMode.equals(DisplayMode.ALL_ACTIVITIES.toString())) { uiUserActivities.setSelectedDisplayMode(DisplayMode.ALL_ACTIVITIES); } else if (selectedDisplayMode.equals(DisplayMode.MY_ACTIVITIES.toString())) { uiUserActivities.setSelectedDisplayMode(DisplayMode.MY_ACTIVITIES); } else if (selectedDisplayMode.equals(DisplayMode.MY_SPACE.toString())) { uiUserActivities.setSelectedDisplayMode(DisplayMode.MY_SPACE); } else { uiUserActivities.setSelectedDisplayMode(DisplayMode.CONNECTIONS); } if (selectedDisplayMode != null) { uiUserActivities.setSelectedDisplayMode(selectedDisplayMode); uiUserActivities.init(); uiUserActivities.setChangedMode(false); // int numberOfUpdates = uiUserActivities.getNumberOfUpdatedActivities(); // event .getRequestContext() .getJavascriptManager() .require("SHARED/social-ui-activity-updates", "activityUpdates") .addScripts( "activityUpdates.resetCookie('" + String.format( Utils.ACTIVITY_STREAM_TAB_SELECTED_COOKIED, Utils.getViewerRemoteId()) + "','" + selectedDisplayMode + "');"); // // event.getRequestContext().getJavascriptManager() // .require("SHARED/social-ui-activity-updates", // "activityUpdates").addScripts("activityUpdates.resetCookie('" + // String.format(Utils.LAST_UPDATED_ACTIVITIES_NUM, selectedDisplayMode, // Utils.getViewerRemoteId()) + "','" + numberOfUpdates + "');"); } requestContext.addUIComponentToUpdateByAjax(uiUserActivities); Utils.resizeHomePage(); }