/** * 添加路线 * * @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); } }); }
/** * 复制路线 * * @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); } }); }