diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index c7b718e..bf08e59 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -4,9 +4,6 @@
-
- uses
-
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
index e4a7837..a51d298 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
@@ -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.RunAsyncCallback;
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.user.client.Timer;
import com.google.gwt.user.client.Window;
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.ui.Composite;
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.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
/**
*
* @author Massimiliano Assante, ISTI-CNR
@@ -115,6 +119,7 @@ public class NewsFeedPanel extends Composite {
private UserInfo myUserInfo;
private FilterType currentFilter;
private Timer feedsTimer;
+ private ShowMoreFeeds showMoreWidget;
//needed to know the next range start
private Integer fromStartingPoint;
@@ -231,7 +236,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
loadingImage = new Image(loading);
newsPanel.add(loadingImage);
-
+
newsService.getUserSettings(new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
@@ -276,10 +281,19 @@ public class NewsFeedPanel extends Composite {
}
};
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)
*/
@@ -300,6 +314,8 @@ public class NewsFeedPanel extends Composite {
case MINE:
showOnlyMyFeeds();
break;
+ default:
+ break;
}
}
/**
@@ -505,7 +521,8 @@ public class NewsFeedPanel extends Composite {
if (feeds.size() >= feedsNoPerCategory*3-1 && (!isInfrastructure)) {
GWT.log("Show MORE " + feedsNoPerCategory);
showMoreUpdatesPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
- showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
+ showMoreWidget = new ShowMoreFeeds(eventBus);
+ showMoreUpdatesPanel.add(showMoreWidget);
newsPanel.add(showMoreUpdatesPanel);
}
isFirstTweet = false;
@@ -530,6 +547,7 @@ public class NewsFeedPanel extends Composite {
*/
protected void doShowMoreUpdates() {
showMoreUpdatesPanel.remove(0);
+ loadingImage.getElement().getStyle().setMargin(10, Unit.PX);
showMoreUpdatesPanel.add(loadingImage);
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
GWT.log("there could be more feeds");
showMoreUpdatesPanel.clear();
- showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
+ showMoreWidget = new ShowMoreFeeds(eventBus);
+ showMoreUpdatesPanel.add(showMoreWidget);
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) {
for (EnhancedFeed feed : allUpdates) {
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/ShowMoreFeeds.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/ShowMoreFeeds.java
index 58c9a5a..524c6dd 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/ShowMoreFeeds.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/ShowMoreFeeds.java
@@ -4,6 +4,7 @@ import org.gcube.portlets.user.newsfeed.client.event.ShowMoreUpdatesEvent;
import com.google.gwt.core.client.GWT;
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.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
@@ -38,6 +39,8 @@ public class ShowMoreFeeds extends Composite {
caption.getElement().getStyle().setBackgroundColor("transparent");
caption.getElement().getStyle().setFontSize(14, Unit.PX);
caption.setHTML("Show more feeds");
+ //done after
+ panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
}
@UiHandler("caption")