automatic load of previous feeds on scrolling done
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@94027 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2683e7284f
commit
3cacb91ead
|
@ -4,9 +4,6 @@
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
||||||
<dependent-module archiveName="user-selection-dialog-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/user-selection-dialog/user-selection-dialog">
|
|
||||||
<dependency-type>uses</dependency-type>
|
|
||||||
</dependent-module>
|
|
||||||
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
|
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
|
||||||
<property name="context-root" value="news-feed"/>
|
<property name="context-root" value="news-feed"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
|
@ -52,10 +52,13 @@ import org.gcube.portlets.widgets.userselection.shared.ItemSelectableBean;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.core.client.RunAsyncCallback;
|
import com.google.gwt.core.client.RunAsyncCallback;
|
||||||
import com.google.gwt.dom.client.Document;
|
import com.google.gwt.dom.client.Document;
|
||||||
|
import com.google.gwt.dom.client.Style.Unit;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.user.client.Timer;
|
import com.google.gwt.user.client.Timer;
|
||||||
import com.google.gwt.user.client.Window;
|
import com.google.gwt.user.client.Window;
|
||||||
import com.google.gwt.user.client.Window.Location;
|
import com.google.gwt.user.client.Window.Location;
|
||||||
|
import com.google.gwt.user.client.Window.ScrollEvent;
|
||||||
|
import com.google.gwt.user.client.Window.ScrollHandler;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.gwt.user.client.ui.Composite;
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
import com.google.gwt.user.client.ui.HTML;
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
|
@ -65,6 +68,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
import com.google.gwt.user.client.ui.Image;
|
import com.google.gwt.user.client.ui.Image;
|
||||||
import com.google.gwt.user.client.ui.SimplePanel;
|
import com.google.gwt.user.client.ui.SimplePanel;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Massimiliano Assante, ISTI-CNR
|
* @author Massimiliano Assante, ISTI-CNR
|
||||||
|
@ -115,6 +119,7 @@ public class NewsFeedPanel extends Composite {
|
||||||
private UserInfo myUserInfo;
|
private UserInfo myUserInfo;
|
||||||
private FilterType currentFilter;
|
private FilterType currentFilter;
|
||||||
private Timer feedsTimer;
|
private Timer feedsTimer;
|
||||||
|
private ShowMoreFeeds showMoreWidget;
|
||||||
//needed to know the next range start
|
//needed to know the next range start
|
||||||
private Integer fromStartingPoint;
|
private Integer fromStartingPoint;
|
||||||
|
|
||||||
|
@ -231,7 +236,7 @@ public class NewsFeedPanel extends Composite {
|
||||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||||
loadingImage = new Image(loading);
|
loadingImage = new Image(loading);
|
||||||
newsPanel.add(loadingImage);
|
newsPanel.add(loadingImage);
|
||||||
|
|
||||||
newsService.getUserSettings(new AsyncCallback<UserSettings>() {
|
newsService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -276,10 +281,19 @@ public class NewsFeedPanel extends Composite {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
feedsTimer.scheduleRepeating(delayMillis);
|
feedsTimer.scheduleRepeating(delayMillis);
|
||||||
|
|
||||||
|
//this is for the automatic scroll of feeds
|
||||||
|
Window.addWindowScrollHandler(new ScrollHandler() {
|
||||||
|
@Override
|
||||||
|
public void onWindowScroll(ScrollEvent event) {
|
||||||
|
boolean isInView = isScrolledIntoView(showMoreWidget);
|
||||||
|
if (isInView) {
|
||||||
|
eventBus.fireEvent(new ShowMoreUpdatesEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stop the feeds timer (when session expires)
|
* stop the feeds timer (when session expires)
|
||||||
*/
|
*/
|
||||||
|
@ -300,6 +314,8 @@ public class NewsFeedPanel extends Composite {
|
||||||
case MINE:
|
case MINE:
|
||||||
showOnlyMyFeeds();
|
showOnlyMyFeeds();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -505,7 +521,8 @@ public class NewsFeedPanel extends Composite {
|
||||||
if (feeds.size() >= feedsNoPerCategory*3-1 && (!isInfrastructure)) {
|
if (feeds.size() >= feedsNoPerCategory*3-1 && (!isInfrastructure)) {
|
||||||
GWT.log("Show MORE " + feedsNoPerCategory);
|
GWT.log("Show MORE " + feedsNoPerCategory);
|
||||||
showMoreUpdatesPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
showMoreUpdatesPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
||||||
showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
|
showMoreWidget = new ShowMoreFeeds(eventBus);
|
||||||
|
showMoreUpdatesPanel.add(showMoreWidget);
|
||||||
newsPanel.add(showMoreUpdatesPanel);
|
newsPanel.add(showMoreUpdatesPanel);
|
||||||
}
|
}
|
||||||
isFirstTweet = false;
|
isFirstTweet = false;
|
||||||
|
@ -530,6 +547,7 @@ public class NewsFeedPanel extends Composite {
|
||||||
*/
|
*/
|
||||||
protected void doShowMoreUpdates() {
|
protected void doShowMoreUpdates() {
|
||||||
showMoreUpdatesPanel.remove(0);
|
showMoreUpdatesPanel.remove(0);
|
||||||
|
loadingImage.getElement().getStyle().setMargin(10, Unit.PX);
|
||||||
showMoreUpdatesPanel.add(loadingImage);
|
showMoreUpdatesPanel.add(loadingImage);
|
||||||
int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
|
int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
|
||||||
|
|
||||||
|
@ -552,7 +570,8 @@ public class NewsFeedPanel extends Composite {
|
||||||
if (c >= quantity) { //there could be more feeds
|
if (c >= quantity) { //there could be more feeds
|
||||||
GWT.log("there could be more feeds");
|
GWT.log("there could be more feeds");
|
||||||
showMoreUpdatesPanel.clear();
|
showMoreUpdatesPanel.clear();
|
||||||
showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
|
showMoreWidget = new ShowMoreFeeds(eventBus);
|
||||||
|
showMoreUpdatesPanel.add(showMoreWidget);
|
||||||
newsPanel.add(showMoreUpdatesPanel);
|
newsPanel.add(showMoreUpdatesPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -566,6 +585,20 @@ public class NewsFeedPanel extends Composite {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param widget the widget to check
|
||||||
|
* @returnn true if the widget is in the visible part of the page
|
||||||
|
*/
|
||||||
|
private boolean isScrolledIntoView(Widget widget) {
|
||||||
|
if (widget != null) {
|
||||||
|
int docViewTop = Window.getScrollTop();
|
||||||
|
int docViewBottom = docViewTop + Window.getClientHeight();
|
||||||
|
int elemTop = widget.getAbsoluteTop();
|
||||||
|
int elemBottom = elemTop + widget.getOffsetHeight();
|
||||||
|
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isFeedPresent(EnhancedFeed toCheck) {
|
private boolean isFeedPresent(EnhancedFeed toCheck) {
|
||||||
for (EnhancedFeed feed : allUpdates) {
|
for (EnhancedFeed feed : allUpdates) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.gcube.portlets.user.newsfeed.client.event.ShowMoreUpdatesEvent;
|
||||||
|
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.dom.client.Style.Unit;
|
import com.google.gwt.dom.client.Style.Unit;
|
||||||
|
import com.google.gwt.dom.client.Style.Visibility;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.uibinder.client.UiBinder;
|
import com.google.gwt.uibinder.client.UiBinder;
|
||||||
|
@ -38,6 +39,8 @@ public class ShowMoreFeeds extends Composite {
|
||||||
caption.getElement().getStyle().setBackgroundColor("transparent");
|
caption.getElement().getStyle().setBackgroundColor("transparent");
|
||||||
caption.getElement().getStyle().setFontSize(14, Unit.PX);
|
caption.getElement().getStyle().setFontSize(14, Unit.PX);
|
||||||
caption.setHTML("Show more feeds");
|
caption.setHTML("Show more feeds");
|
||||||
|
//done after
|
||||||
|
panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiHandler("caption")
|
@UiHandler("caption")
|
||||||
|
|
Loading…
Reference in New Issue