/** * Removes presenter from user meals * * @param meal */ private void removeMyMealPresenter(MealModel meal) { try { // remove also from presenters for (int i = 0; i < myMealPresenters.size(); i++) { MealLinkPresenter presenter = myMealPresenters.get(i); if (presenter != null && presenter.meal.getId() == meal.getId()) { presenter.stop(); myMealPresenters.remove(presenter); } } // if no meals -> show empty presenter if (myMealPresenters.size() == 0) { if (emptyPresenter != null) { emptyPresenter.stop(); } emptyPresenter = new EmptyPresenter( rpcService, eventBus, (EmptyDisplay) GWT.create(EmptyView.class), AppController.Lang.NoMeals()); emptyPresenter.run(display.getMyMealsContainer()); } } catch (Exception e) { Motiver.showException(e); } }
/** Unbinds all the presenters */ private void unbindPresenters() { try { if (emptyPresenter != null) { emptyPresenter.stop(); } if (presenters != null) { for (int i = 0; i < presenters.size(); i++) { try { final Presenter presenter = presenters.get(i); if (presenter != null) { presenter.stop(); } } catch (Exception e) { Motiver.showException(e); } } presenters = new ArrayList<Presenter>(); } } catch (Exception e) { Motiver.showException(e); } }
@Override public void onStop() { if (emptyPresenter != null) { emptyPresenter.stop(); } if (emptyPresenter2 != null) { emptyPresenter2.stop(); } // stop show more if (showMorePresenter != null) { showMorePresenter.stop(); } if (showMorePresenter2 != null) { showMorePresenter2.stop(); } // stop presenters unbindPresenters(0); }
/** * Unbinds all the presenters * * @param target : which presenters all unbinded, 0=all, 1=mymeals, 2=most popular, 3=search * results */ private void unbindPresenters(int target) { // my meals if (myMealPresenters != null && (target == 0 || target == 1)) { if (emptyPresenter != null) { emptyPresenter.stop(); } if (showMorePresenter != null) { showMorePresenter.stop(); } for (int i = 0; i < myMealPresenters.size(); i++) { final Presenter presenter = myMealPresenters.get(i); if (presenter != null) { presenter.stop(); } } myMealPresenters.clear(); } // most popular if (mostPopularPresenters != null && (target == 0 || target == 2)) { if (emptyPresenter2 != null) { emptyPresenter2.stop(); } if (showMorePresenter2 != null) { showMorePresenter2.stop(); } for (int i = 0; i < mostPopularPresenters.size(); i++) { final Presenter presenter = mostPopularPresenters.get(i); if (presenter != null) { presenter.stop(); } } mostPopularPresenters.clear(); } }
/** Loads meals */ void loadMyMeals(final int index) { if (emptyPresenter != null) { emptyPresenter.stop(); } // stop show more if (showMorePresenter != null) { showMorePresenter.stop(); } // stop presenters if first items if (index == 0) { unbindPresenters(1); } // add empty presenter emptyPresenter = new EmptyPresenter( rpcService, eventBus, (EmptyDisplay) GWT.create(EmptyView.class), EmptyPresenter.EMPTY_LOADING); emptyPresenter.run(display.getMyMealsContainer()); // get meals Motiver.setNextCallCacheable(true); final Request req = rpcService.getMeals( index, new MyAsyncCallback<List<MealModel>>() { @Override public void onSuccess(List<MealModel> result) { showMyMeals(index, result); } }); addRequest(req); }
/** * Adds new presenter to view * * @param presenter */ protected void addNewPresenter(Presenter presenter) { try { // remove emptypresenter if present if (emptyPresenter != null) { emptyPresenter.stop(); emptyPresenter = null; } presenters.add(presenter); presenter.run(display.getBodyContainer()); } catch (Exception e) { Motiver.showException(e); } }
/** * Adds new presenter to view (most popular meals) * * @param presenter */ protected void addNewMostPopularPresenter(MealLinkPresenter presenter) { try { // remove emptypresenter if present if (emptyPresenter2 != null) { emptyPresenter2.stop(); emptyPresenter2 = null; } mostPopularPresenters.add(presenter); presenter.run(display.getMostPopularContainer()); } catch (Exception e) { Motiver.showException(e); } }
/** * Shows user's meals * * @param list : MealModels */ private void showMyMeals(final int index, List<MealModel> list) { try { if (emptyPresenter != null) { emptyPresenter.stop(); } // stop show more if (showMorePresenter != null) { showMorePresenter.stop(); } // stop presenters if first items if (index == 0) { unbindPresenters(1); } // if no meals if (index == 0 && list.size() == 0) { emptyPresenter = new EmptyPresenter( rpcService, eventBus, (EmptyDisplay) GWT.create(EmptyView.class), AppController.Lang.NoMeals()); emptyPresenter.run(display.getMyMealsContainer()); } else { for (final MealModel m : list) { // if null value -> list was limited -> add showMorePresenter if (m == null) { showMorePresenter = new ShowMorePresenter( rpcService, eventBus, (ShowMoreDisplay) GWT.create(ShowMoreView.class), new ShowMoreHandler() { @Override public void showMore() { loadMyMeals(index + Constants.LIMIT_MEALS); } }); showMorePresenter.run(display.getMyMealsContainer()); } else { // new presenter final MealLinkPresenter wp = new MealLinkPresenter( rpcService, eventBus, (MealLinkDisplay) GWT.create(MealLinkView.class), m, quickSelectionEnabled); addNewMyMealPresenter(wp); } } } } catch (Exception e) { Motiver.showException(e); } }