Ejemplo n.º 1
0
  /**
   * 取消路线
   *
   * @param route 路线
   * @param listener 回调
   */
  public void cancelRoute(Route route, final OnRouteListener listener) {
    route.update(
        mContext,
        route.getObjectId(),
        new UpdateListener() {
          @Override
          public void onSuccess() {
            UserManager.getInstance(mContext)
                .setStartRoute(
                    false,
                    new UserManager.OnUpdateListener() {
                      @Override
                      public void onSuccess() {
                        listener.onSuccess(null);
                      }

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

          @Override
          public void onFailure(int i, String s) {
            listener.onError(s);
          }
        });
  }
Ejemplo n.º 2
0
  /**
   * 添加评论
   *
   * @param route 路线
   * @param listener 回调
   */
  public void addComment(final Route route, final OnRouteListener listener) {
    int commentNum = 0;
    if (route.getCommentNum() != null) {
      commentNum = route.getCommentNum();
    }
    commentNum++;
    route.setCommentNum(commentNum);
    route.update(
        mContext,
        route.getObjectId(),
        new UpdateListener() {
          @Override
          public void onSuccess() {
            UserManager.getInstance(mContext)
                .addComment(
                    route,
                    new UserManager.OnUpdateListener() {
                      @Override
                      public void onSuccess() {
                        listener.onSuccess(null);
                      }

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

          @Override
          public void onFailure(int i, String s) {
            listener.onError(s);
          }
        });
  }
Ejemplo n.º 3
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);
          }
        });
  }
Ejemplo n.º 4
0
  /**
   * 添加路线
   *
   * @param route 路线
   * @param listener 回调
   */
  public void addRoute(final Route route, final OnRouteListener listener) {
    BmobQuery<Route> query1 = new BmobQuery<>();
    query1.addWhereEqualTo("name", route.getName());
    BmobQuery<Route> query2 = new BmobQuery<>();
    query2.addWhereEqualTo("creator", UserManager.getInstance(mContext).getUser());
    List<BmobQuery<Route>> andQuerys = new ArrayList<>();
    andQuerys.add(query1);
    andQuerys.add(query2);

    BmobQuery<Route> mainQuery = new BmobQuery<>();
    mainQuery.and(andQuerys);
    mainQuery.findObjects(
        mContext,
        new FindListener<Route>() {
          @Override
          public void onSuccess(List<Route> list) {
            if (list.size() > 0) {
              listener.onError(null);
            } else {
              saveRoute(route, listener);
            }
          }

          @Override
          public void onError(int i, String s) {
            listener.onError(null);
          }
        });
  }
Ejemplo n.º 5
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);
          }
        });
  }
Ejemplo n.º 6
0
  /**
   * 增加天数
   *
   * @param route 路线
   * @param listener 回调
   */
  public void addDay(Route route, final OnRouteListener listener) {
    Route r = new Route();
    r.setDays(route.getDays());
    r.update(
        mContext,
        route.getObjectId(),
        new UpdateListener() {
          @Override
          public void onSuccess() {
            listener.onSuccess(null);
          }

          @Override
          public void onFailure(int i, String s) {
            listener.onError(null);
          }
        });
  }
Ejemplo n.º 7
0
  /**
   * 查看路线
   *
   * @param route 路线
   * @param listener 回调
   */
  public void watch(Route route, final OnRouteListener listener) {
    int watchNum = 0;
    if (route.getWatchNum() != null) {
      watchNum = route.getWatchNum().intValue();
    }
    watchNum++;
    route.setWatchNum(watchNum);
    route.update(
        mContext,
        new UpdateListener() {
          @Override
          public void onSuccess() {
            listener.onSuccess(null);
          }

          @Override
          public void onFailure(int i, String s) {
            listener.onError(s);
          }
        });
  }
Ejemplo n.º 8
0
  /**
   * 路线点赞
   *
   * @param route 路线
   * @param listener 回调
   */
  public void good(Route route, final OnRouteListener listener) {
    int favor = 0;
    if (route.getFavor() != null) {
      favor = route.getFavor().intValue();
    }
    favor++;
    route.setFavor(favor);
    route.update(
        mContext,
        route.getObjectId(),
        new UpdateListener() {
          @Override
          public void onSuccess() {
            listener.onSuccess(null);
          }

          @Override
          public void onFailure(int i, String s) {
            listener.onError(s);
          }
        });
  }
Ejemplo n.º 9
0
  /**
   * 批量删除路线
   *
   * @param routes 要删除的路线列表
   * @param listener 回调
   */
  public void deleteRoutes(final List<BmobObject> routes, final OnRouteListener listener) {
    mFlag = false;
    Route route;
    int finishedNum = 0;
    for (int i = 0; i < routes.size(); i++) {
      route = (Route) routes.get(i);
      if (route.getStatus() != null && route.getStatus() == Route.TRAVELLING) {
        mFlag = true;
      } else if (route.getStatus() != null && route.getStatus() == Route.FINISHED) {
        finishedNum++;
      }
    }
    final int routeNum = routes.size();
    final int num = finishedNum;
    new BmobObject()
        .deleteBatch(
            mContext,
            routes,
            new DeleteListener() {
              @Override
              public void onSuccess() {
                UserManager.getInstance(mContext)
                    .deleteRoute(
                        routeNum,
                        new UserManager.OnUpdateListener() {
                          @Override
                          public void onSuccess() {
                            if (mFlag) {
                              UserManager.getInstance(mContext)
                                  .setStartRoute(
                                      false,
                                      new UserManager.OnUpdateListener() {
                                        @Override
                                        public void onSuccess() {}

                                        @Override
                                        public void onError() {}
                                      });
                            }

                            if (num != 0) {
                              UserManager.getInstance(mContext)
                                  .deleteFinishRoute(
                                      num,
                                      new UserManager.OnUpdateListener() {
                                        @Override
                                        public void onSuccess() {}

                                        @Override
                                        public void onError() {}
                                      });
                            }

                            listener.onSuccess(null);
                            mRoutes.removeAll(routes);
                          }

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

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