Exemplo n.º 1
0
  /**
   * 保存路线
   *
   * @param route 路线
   * @param listener 回调
   */
  private void saveRoute(final Route route, final OnRouteListener listener) {
    route.setCreator(UserManager.getInstance(mContext).getUser());
    route.save(
        mContext,
        new SaveListener() {
          @Override
          public void onSuccess() {
            UserManager.getInstance(mContext)
                .addRoute(
                    new UserManager.OnUpdateListener() {
                      @Override
                      public void onSuccess() {
                        listener.onSuccess(null);
                        mRoutes.add(0, route);
                      }

                      @Override
                      public void onError() {
                        listener.onError(null);
                      }
                    });
          }

          @Override
          public void onFailure(int i, String s) {
            listener.onError(s);
          }
        });
  }
Exemplo n.º 2
0
  /**
   * 复制路线
   *
   * @param route 路线
   * @param listener 回调
   */
  public void copyRoute(final Route route, final OnRouteListener listener) {
    final Route myRoute = new Route();
    myRoute.setCreator(UserManager.getInstance(mContext).getUser());
    myRoute.setName(route.getName());
    myRoute.setDescription(route.getDescription());
    myRoute.setStatus(Route.PLANNING);
    myRoute.setDays(route.getDays());
    myRoute.save(
        mContext,
        new SaveListener() {
          @Override
          public void onSuccess() {
            UserManager.getInstance(mContext)
                .addRoute(
                    new UserManager.OnUpdateListener() {
                      @Override
                      public void onSuccess() {}

                      @Override
                      public void onError() {}
                    });
            BmobQuery<Daily> query = new BmobQuery<>();
            query.addWhereEqualTo("route", new BmobPointer(route));
            query.order("day");
            query.findObjects(
                mContext,
                new FindListener<Daily>() {
                  @Override
                  public void onSuccess(List<Daily> list) {
                    copyDaily(myRoute, list, listener);
                  }

                  @Override
                  public void onError(int i, String s) {
                    listener.onError(s);
                  }
                });
          }

          @Override
          public void onFailure(int i, String s) {
            listener.onError(s);
          }
        });
  }