Improved desktop/ mobile switching for actions

This commit is contained in:
Papick Garcia Taboada committed 2015-07-01 18:34:06 +02:00
1 parent 5455019cca
commit ff2ea7f787
3 files changed
+21 -37

No files matched your search

@@ -60,9 +60,6 @@ public class Footer extends Composite {
});
@UiField AnchorElement mobileUi;
private final String mobileBaseUrl;
private String otherLanguage;
private final LocaleInfo currentLocale = LocaleInfo.getCurrentLocale();
@@ -75,7 +72,6 @@ public class Footer extends Composite {
releaseNotesNavigation = navigator.getWhatsNewNavigation(WhatsNewNavigationTabs.SailingAnalytics);
initWidget(uiBinder.createAndBindUi(this));
mobileBaseUrl = mobileUi.getHref();
updateUI();
DOM.sinkEvents(mobileUi, Event.ONCLICK);
@@ -19,8 +19,6 @@ import com.sap.sailing.gwt.home.shared.app.HasMobileVersion;
public class MobileActivityMapper implements ActivityMapper {
private final MobileApplicationClientFactory clientFactory;
private Place lastVisitedPlace = new StartPlace();
public MobileActivityMapper(MobileApplicationClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
@@ -29,33 +27,25 @@ public class MobileActivityMapper implements ActivityMapper {
@Override
public Activity getActivity(Place place) {
if (!(place instanceof HasMobileVersion)) {
SwitchingEntryPoint.switchToDesktop(place);
SwitchingEntryPoint.switchToDesktop();
return null;
}
if (place instanceof StartPlace) {
// going to events place
// lastVisitedPlace = place;
// return new StartActivityProxy((StartPlace) place, clientFactory);
lastVisitedPlace = place;
return new EventsActivityProxy(new EventsPlace(), clientFactory);
} else if (place instanceof EventsPlace) {
lastVisitedPlace = place;
EventsPlace eventPlace = (EventsPlace) place;
return new EventsActivityProxy(eventPlace, clientFactory);
} else if (place instanceof RegattaLeaderboardPlace) {
lastVisitedPlace = place;
RegattaLeaderboardPlace eventPlace = (RegattaLeaderboardPlace) place;
return new MiniLeaderboardActivityProxy(eventPlace, clientFactory);
} else if (place instanceof LatestNewsPlace) {
lastVisitedPlace = place;
LatestNewsPlace eventPlace = (LatestNewsPlace) place;
return new LatestNewsActivityProxy(eventPlace, clientFactory);
} else if (place instanceof AbstractEventPlace) {
lastVisitedPlace = place;
return new EventActivityProxy((AbstractEventPlace) place, clientFactory);
} else {
return null;
}
}
}
@@ -5,10 +5,10 @@ import java.util.logging.Logger;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.MetaElement;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window;
@@ -17,11 +17,9 @@ import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.sap.sailing.gwt.home.desktop.DesktopEntryPoint;
import com.sap.sailing.gwt.home.mobile.MobileEntryPoint;
import com.sap.sailing.gwt.home.shared.app.ApplicationHistoryMapper;
public class SwitchingEntryPoint implements EntryPoint {
private static Logger LOG = Logger.getLogger(SwitchingEntryPoint.class.getName());
private static final PlaceHistoryMapper appHistoryMapper = GWT.create(ApplicationHistoryMapper.class);
private static final String SAPSAILING_MOBILE = "sapsailing_mobile";
private static final RegExp isMobileRegExp = RegExp.compile(
"Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini", "i");
@@ -59,7 +57,7 @@ public class SwitchingEntryPoint implements EntryPoint {
LOG.info("Navigator user agent matched mobile regex: " + isMobile);
return isMobile;
}
/**
* Convinience method
*
@@ -76,7 +74,12 @@ public class SwitchingEntryPoint implements EntryPoint {
// only force "not mobile" on mobile devices
Cookies.setCookie(SAPSAILING_MOBILE, "false");
}
Window.Location.reload();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
Window.Location.reload();
}
});
}
public static void switchToMobile() {
@@ -86,7 +89,12 @@ public class SwitchingEntryPoint implements EntryPoint {
// only force mobile version on desktop
Cookies.setCookie(SAPSAILING_MOBILE, "true");
}
Window.Location.reload();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
Window.Location.reload();
}
});
}
private void startMobile() {
@@ -96,6 +104,7 @@ public class SwitchingEntryPoint implements EntryPoint {
public void onSuccess() {
new MobileEntryPoint().onModuleLoad();
}
@Override
public void onFailure(Throwable reason) {
LOG.severe("Failed to async start mobile version: " + reason.getMessage());
@@ -111,6 +120,7 @@ public class SwitchingEntryPoint implements EntryPoint {
public void onSuccess() {
new DesktopEntryPoint().onModuleLoad();
}
@Override
public void onFailure(Throwable reason) {
LOG.severe("Failed to async start desktop version: " + reason.getMessage());
@@ -118,10 +128,11 @@ public class SwitchingEntryPoint implements EntryPoint {
}
});
}
private void configureDesktopHeader() {
metaElement("viewport", "width=device-width,initial-scale=0.5,maximum-scale=1");
}
private void configureMobileHeader() {
metaElement("viewport", "width=device-width,initial-scale=1,maximum-scale=1");
}
@@ -132,17 +143,4 @@ public class SwitchingEntryPoint implements EntryPoint {
metaElement.setContent(content);
Document.get().getHead().appendChild(metaElement);
}
public static void switchToDesktop(Place desktopPlace) {
String destinationInDesktop = Window.Location.createUrlBuilder()
.setHash(appHistoryMapper.getToken(desktopPlace)).buildString();
if (isMobile()) {
Cookies.setCookie(SAPSAILING_MOBILE, "false");
} else {
Cookies.removeCookie(SAPSAILING_MOBILE);
}
Window.Location.assign(destinationInDesktop);
;
}
}