index int64 | repo_id string | file_path string | content string |
|---|---|---|---|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/TaskLocation.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model;
import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;
/**
* TaskLocation is a location that can be represented by a lat/lng coordinate and/or a backend location ID.
* The location ID can specify a PUDOL or special stop like an airport terminal.
*/
public class TaskLocation implements Serializable {
private final LatLng latLng;
@Nullable
private final String locationId;
public TaskLocation(final LatLng latLng) {
this(latLng, null);
}
public TaskLocation(final LatLng latLng, @Nullable final String locationId) {
this.latLng = latLng;
this.locationId = locationId;
}
public LatLng getLatLng() {
return latLng;
}
public Optional<String> getLocationId() {
return Optional.ofNullable(locationId);
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof TaskLocation)) {
return false;
}
final TaskLocation otherModel = (TaskLocation) other;
return Objects.equals(locationId, otherModel.locationId)
&& latLng.equals(otherModel.latLng);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/VehiclePosition.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model;
public class VehiclePosition {
private final String vehicleId;
private final LatLng position;
private final float heading;
public VehiclePosition(final String vehicleId, final LatLng position, final float heading) {
this.vehicleId = vehicleId;
this.position = position;
this.heading = heading;
}
public LatLng getPosition() {
return position;
}
public float getHeading() {
return heading;
}
public String getVehicleId() {
return vehicleId;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof VehiclePosition)) {
return false;
}
final VehiclePosition otherModel = (VehiclePosition) other;
return vehicleId.equals(otherModel.getVehicleId())
&& position.equals(otherModel.getPosition())
&& heading == otherModel.getHeading();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/map/CameraUpdate.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model.map;
import ai.rideos.android.common.model.LatLng;
public class CameraUpdate {
public enum UpdateType {
NO_UPDATE, // NOOP. Use if you cannot filter out camera updates of an observable value
FIT_LAT_LNG_BOUNDS,
CENTER_AND_ZOOM
}
private final LatLng newPosition;
private final float newZoom;
private final LatLngBounds newBounds;
private final UpdateType updateType;
private CameraUpdate(final UpdateType updateType,
final LatLng newPosition,
final float newZoom,
final LatLngBounds newBounds) {
this.updateType = updateType;
this.newBounds = newBounds;
this.newPosition = newPosition;
this.newZoom = newZoom;
}
/**
* noUpdate provides a NOOP camera update
*/
public static CameraUpdate noUpdate() {
return new CameraUpdate(UpdateType.NO_UPDATE, null, 0, null);
}
public static CameraUpdate fitToBounds(final LatLngBounds latLngBounds) {
return new CameraUpdate(UpdateType.FIT_LAT_LNG_BOUNDS, null, 0, latLngBounds);
}
public static CameraUpdate centerAndZoom(final LatLng newCenter, final float newZoom) {
return new CameraUpdate(UpdateType.CENTER_AND_ZOOM, newCenter, newZoom, null);
}
public LatLng getNewCenter() {
return newPosition;
}
public float getNewZoom() {
return newZoom;
}
public LatLngBounds getNewBounds() {
return newBounds;
}
public UpdateType getUpdateType() {
return updateType;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof CameraUpdate)) {
return false;
}
final CameraUpdate otherModel = (CameraUpdate) other;
if (updateType != otherModel.getUpdateType()) {
return false;
}
switch (updateType) {
case FIT_LAT_LNG_BOUNDS:
return newBounds.equals(otherModel.getNewBounds());
case CENTER_AND_ZOOM:
return newPosition.equals(otherModel.getNewCenter()) && newZoom == otherModel.getNewZoom();
case NO_UPDATE:
default:
return true;
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/map/CenterPin.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model.map;
public class CenterPin {
private final boolean shouldShow;
private final Integer drawablePin;
private CenterPin(final boolean shouldShow, final Integer drawablePin) {
this.shouldShow = shouldShow;
this.drawablePin = drawablePin;
}
public static CenterPin hidden() {
return new CenterPin(false, null);
}
public static CenterPin ofDrawable(final Integer drawablePin) {
return new CenterPin(true, drawablePin);
}
public boolean shouldShow() {
return shouldShow;
}
public Integer getDrawablePin() {
return drawablePin;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof CenterPin)) {
return false;
}
final CenterPin otherModel = (CenterPin) other;
if (shouldShow != otherModel.shouldShow()) {
return false;
}
if (shouldShow) {
return drawablePin.equals(otherModel.getDrawablePin());
}
return true;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/map/DrawableMarker.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model.map;
import ai.rideos.android.common.model.LatLng;
public class DrawableMarker {
public enum Anchor {
CENTER,
BOTTOM
}
private final LatLng position;
private final float rotation;
private final int drawableIcon;
private final Anchor anchor;
public DrawableMarker(final LatLng position, final float rotation, final int drawableIcon, final Anchor anchor) {
this.position = position;
this.rotation = rotation;
this.drawableIcon = drawableIcon;
this.anchor = anchor;
}
public LatLng getPosition() {
return position;
}
public float getRotation() {
return rotation;
}
public int getDrawableIcon() {
return drawableIcon;
}
public Anchor getAnchor() {
return anchor;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof DrawableMarker)) {
return false;
}
final DrawableMarker otherModel = (DrawableMarker) other;
return position.equals(otherModel.getPosition())
&& rotation == otherModel.getRotation()
&& drawableIcon == otherModel.getDrawableIcon()
&& anchor == otherModel.getAnchor();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/map/DrawablePath.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model.map;
import ai.rideos.android.common.model.LatLng;
import java.util.List;
public class DrawablePath {
public enum Style {
SOLID,
DOTTED
}
private final List<LatLng> coordinates;
private final float width;
private final int color;
private final Style style;
public DrawablePath(final List<LatLng> coordinates, final float width, final int color) {
this(coordinates, width, color, Style.SOLID);
}
public DrawablePath(final List<LatLng> coordinates, final float width, final int color, final Style style) {
this.coordinates = coordinates;
this.width = width;
this.color = color;
this.style = style;
}
public List<LatLng> getCoordinates() {
return coordinates;
}
public float getWidth() {
return width;
}
public int getColor() {
return color;
}
public Style getStyle() {
return style;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof DrawablePath)) {
return false;
}
final DrawablePath otherModel = (DrawablePath) other;
return coordinates.equals(otherModel.getCoordinates())
&& width == otherModel.getWidth()
&& color == otherModel.getColor()
&& style == otherModel.getStyle();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/map/LatLngBounds.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model.map;
import ai.rideos.android.common.model.LatLng;
public class LatLngBounds {
private final LatLng southwest;
private final LatLng northeast;
public LatLngBounds(final LatLng southwest, final LatLng northeast) {
this.southwest = southwest;
this.northeast = northeast;
}
public LatLng getSouthwestCorner() {
return southwest;
}
public LatLng getNortheastCorner() {
return northeast;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof LatLngBounds)) {
return false;
}
final LatLngBounds otherModel = (LatLngBounds) other;
return southwest.equals(otherModel.getSouthwestCorner()) && northeast.equals(otherModel.getNortheastCorner());
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/model/map/MapSettings.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.model.map;
public class MapSettings {
private final boolean shouldShowUserLocation;
private final CenterPin centerPin;
public MapSettings(final boolean shouldShowUserLocation,
final CenterPin centerPin) {
this.shouldShowUserLocation = shouldShowUserLocation;
this.centerPin = centerPin;
}
public boolean shouldShowUserLocation() {
return shouldShowUserLocation;
}
public CenterPin getCenterPin() {
return centerPin;
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof MapSettings)) {
return false;
}
final MapSettings otherModel = (MapSettings) other;
return shouldShowUserLocation == otherModel.shouldShowUserLocation()
&& centerPin.equals(otherModel.getCenterPin());
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/ErrorHandlers.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
import io.reactivex.functions.Consumer;
public class ErrorHandlers {
public static Consumer<Throwable> swallow() {
return (error) -> {};
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/Notification.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
/**
* Notification can be used when there is an Observable that doesn't require an object. For example, if want a notification
* whenever some event occurs, you can use an Observable<Notification>
*/
public class Notification {
public static Notification create() {
return new Notification();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/Result.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
public class Result<T> {
private enum ResultType {
SUCCESS,
FAILURE
}
private final T resultObject;
private final ResultType resultType;
private final Throwable throwable;
private Result(final T resultObject, final ResultType resultType, final Throwable throwable) {
this.resultObject = resultObject;
this.resultType = resultType;
this.throwable = throwable;
}
public static <T> Result<T> success(final T resultObject) {
return new Result<>(resultObject, ResultType.SUCCESS, null);
}
public static <T> Result<T> failure(final Throwable throwable) {
return new Result<>(null, ResultType.FAILURE, throwable);
}
public boolean isSuccess() {
return resultType == ResultType.SUCCESS;
}
public boolean isFailure() {
return resultType == ResultType.FAILURE;
}
public T get() {
return resultObject;
}
public Throwable getError() {
return throwable;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/RetryBehavior.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;
public interface RetryBehavior extends Function<Observable<Throwable>, ObservableSource<?>> {
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/RetryBehaviors.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
import androidx.core.util.Pair;
import io.reactivex.Observable;
public class RetryBehaviors {
public static final int DEFAULT_RETRY_COUNT = 3;
private RetryBehaviors() {
}
// By default, retry
public static RetryBehavior getDefault() {
return retryAtMost(DEFAULT_RETRY_COUNT);
}
public static RetryBehavior retryAtMost(final int numberOfRetries) {
// The function required for the retryWhen operator takes in an observable error stream and returns another
// observable. If the returned observable emits a value, the retryWhen operator re-subscribes and tries again.
// If the returned observable emits an error, the retryWhen operator stops.
// So, this function zips the errors with the values [1...retries+1]. When the emitted value <= retries, a
// value is returned. On the last emitted value (value == retries + 1), an error is returned.
return observableErrors -> observableErrors
.zipWith(Observable.range(1, numberOfRetries + 1), Pair::create)
.flatMap(errorAndRetryNum -> {
if (errorAndRetryNum.second > numberOfRetries) {
return Observable.<Integer>error(errorAndRetryNum.first);
}
return Observable.just(errorAndRetryNum.second);
});
}
public static RetryBehavior neverRetry() {
return retryAtMost(0);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/SchedulerProvider.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
import io.reactivex.Scheduler;
/**
* SchedulerProvider allows injection of non-default schedulers for use in single-threaded environments like testing
*/
public interface SchedulerProvider {
Scheduler io();
Scheduler computation();
Scheduler mainThread();
Scheduler single();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/SchedulerProviders.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.schedulers.TestScheduler;
public class SchedulerProviders {
/**
* Default threads - to be used in production environments.
*/
public static class DefaultSchedulerProvider implements SchedulerProvider {
@Override
public Scheduler io() {
return Schedulers.io();
}
@Override
public Scheduler computation() {
return Schedulers.computation();
}
@Override
public Scheduler mainThread() {
return AndroidSchedulers.mainThread();
}
@Override
public Scheduler single() {
return Schedulers.single();
}
}
/**
* Trampoline runs all observables in a single thread, so everything is synchronous.
*/
public static class TrampolineSchedulerProvider implements SchedulerProvider {
@Override
public Scheduler io() {
return Schedulers.trampoline();
}
@Override
public Scheduler computation() {
return Schedulers.trampoline();
}
@Override
public Scheduler mainThread() {
return Schedulers.trampoline();
}
@Override
public Scheduler single() {
return Schedulers.trampoline();
}
}
public static class TestSchedulerProvider implements SchedulerProvider {
private final TestScheduler testScheduler;
public TestSchedulerProvider(final TestScheduler testScheduler) {
this.testScheduler = testScheduler;
}
@Override
public Scheduler io() {
return testScheduler;
}
@Override
public Scheduler computation() {
return testScheduler;
}
@Override
public Scheduler mainThread() {
return testScheduler;
}
@Override
public Scheduler single() {
return testScheduler;
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/reactive/TestUtils.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.reactive;
import io.reactivex.Observable;
import java.util.concurrent.atomic.AtomicInteger;
import org.mockito.ArgumentMatcher;
public class TestUtils {
public static <T> Observable<T> throwUntilLastRetryObservable(final int numRetries,
final T successfulResponse,
final Exception exception) {
final AtomicInteger count = new AtomicInteger(0);
return Observable.fromCallable(() -> {
if (count.incrementAndGet() > numRetries) {
return successfulResponse;
}
throw exception;
});
}
public static <T> ArgumentMatcher<Result<T>> matchResultWithOutcome(final boolean isSuccess) {
return new ArgumentMatcher<Result<T>>() {
@Override
public boolean matches(final Object argument) {
return argument instanceof Result && ((Result) argument).isSuccess() == isSuccess;
}
};
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/ApiEnvironment.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
/**
* Each ApiEnvironment value contains a stored name and an API endpoint. The stored name can be used in key-value
* stores to save a user's preference. This should be unchanged, whereas the API endpoint for each value can be updated
* as the URLs change.
*/
public enum ApiEnvironment {
DEVELOPMENT("dev", "gapi.development.rideos.ai"),
STAGING("staging", "gapi.staging.rideos.ai"),
PRODUCTION("prod", "gapi.rideos.ai");
private final String storedName;
private final String endpoint;
public static ApiEnvironment fromStoredNameOrThrow(final String name) {
for (final ApiEnvironment env : ApiEnvironment.values()) {
if (env.getStoredName().equals(name)) {
return env;
}
}
throw new RuntimeException("Invalid environment: " + name);
}
ApiEnvironment(final String storedName, final String endpoint) {
this.storedName = storedName;
this.endpoint = endpoint;
}
public String getEndpoint() {
return endpoint;
}
public String getStoredName() {
return storedName;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/SharedPreferencesFileNames.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
public class SharedPreferencesFileNames {
public static final String USER_AUTH_FILE = "ai.rideos.android.user";
public static final String USER_STORAGE_FILE = "ai.rideos.android.user.storage";
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/SharedPreferencesUserStorageReader.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
import static ai.rideos.android.common.user_storage.SharedPreferencesFileNames.USER_STORAGE_FILE;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import android.content.Context;
import android.content.SharedPreferences;
import com.f2prateek.rx.preferences2.RxSharedPreferences;
import io.reactivex.Observable;
public class SharedPreferencesUserStorageReader implements UserStorageReader {
private final RxSharedPreferences rxSharedPreferences;
private final SchedulerProvider schedulerProvider;
private SharedPreferencesUserStorageReader(final Context context, final SchedulerProvider schedulerProvider) {
this.schedulerProvider = schedulerProvider;
final SharedPreferences androidStorage = context.getSharedPreferences(USER_STORAGE_FILE, Context.MODE_PRIVATE);
rxSharedPreferences = RxSharedPreferences.create(androidStorage);
}
public static SharedPreferencesUserStorageReader forContext(final Context context) {
return new SharedPreferencesUserStorageReader(context, new DefaultSchedulerProvider());
}
@Override
public String getStringPreference(final StorageKey<String> key) {
return rxSharedPreferences.getString(key.getKey(), key.getDefaultValue()).get();
}
@Override
public Observable<String> observeStringPreference(final StorageKey<String> key) {
return rxSharedPreferences.getString(key.getKey(), key.getDefaultValue()).asObservable()
.subscribeOn(schedulerProvider.io());
}
@Override
public boolean getBooleanPreference(final StorageKey<Boolean> key) {
return rxSharedPreferences.getBoolean(key.getKey(), key.getDefaultValue()).get();
}
@Override
public Observable<Boolean> observeBooleanPreference(final StorageKey<Boolean> key) {
return rxSharedPreferences.getBoolean(key.getKey(), key.getDefaultValue()).asObservable()
.subscribeOn(schedulerProvider.io());
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/SharedPreferencesUserStorageWriter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
import static ai.rideos.android.common.user_storage.SharedPreferencesFileNames.USER_STORAGE_FILE;
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesUserStorageWriter implements UserStorageWriter {
private final SharedPreferences sharedPreferences;
private SharedPreferencesUserStorageWriter(final Context context) {
sharedPreferences = context.getSharedPreferences(USER_STORAGE_FILE, Context.MODE_PRIVATE);
}
public static SharedPreferencesUserStorageWriter forContext(final Context context) {
return new SharedPreferencesUserStorageWriter(context);
}
@Override
public void storeStringPreference(final StorageKey key, final String value) {
sharedPreferences.edit().putString(key.getKey(), value).apply();
}
@Override
public void storeBooleanPreference(final StorageKey<Boolean> key, final boolean value) {
sharedPreferences.edit().putBoolean(key.getKey(), value).apply();
}
@Override
public void clearStorage() {
sharedPreferences.edit().clear().apply();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/StorageKey.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
/**
* Storage key defines a key to be used for UserStorage with a default value if the key has not been stored yet.
*/
public class StorageKey<T> {
private final String key;
private final T defaultValue;
public StorageKey(final String key, final T defaultValue) {
this.key = key;
this.defaultValue = defaultValue;
}
public String getKey() {
return key;
}
public T getDefaultValue() {
return defaultValue;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/StorageKeys.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
/**
* StorageKeys has common keys used across both apps.
*/
public class StorageKeys {
public static final StorageKey<String> FLEET_ID = new StorageKey<>("fleet_id", "");
public static final StorageKey<String> RIDEOS_API_ENV
= new StorageKey<>("rideos_api_env", ApiEnvironment.PRODUCTION.getStoredName());
public static final StorageKey<String> PREFERRED_NAME = new StorageKey<>("preferred_name", "");
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/UserStorageReader.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
import io.reactivex.Observable;
/**
* UserStorageReader reads user preferences from some arbitrary key-value store
*/
public interface UserStorageReader {
/**
* Retrieve a preferred string value by its key.
*/
String getStringPreference(final StorageKey<String> key);
/**
* Observe a preferred string value by its key.
*/
Observable<String> observeStringPreference(final StorageKey<String> key);
/**
* Retrieve a preferred boolean value by its key.
*/
boolean getBooleanPreference(final StorageKey<Boolean> key);
/**
* Observe a preferred boolean value by its key.
*/
Observable<Boolean> observeBooleanPreference(final StorageKey<Boolean> key);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/user_storage/UserStorageWriter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.user_storage;
/**
* UserStorageWriter writes user preferences to an arbitrary key-value store
*/
public interface UserStorageWriter {
/**
* Store a key-string pair as a user preference. These can be things like the user's preferred fleet ID or API env.
*/
void storeStringPreference(final StorageKey<String> key, final String value);
/**
* Store a key-string pair as a user preference. These can be things like feature flags.
*/
void storeBooleanPreference(final StorageKey<Boolean> key, final boolean value);
/**
* Clear all user related information including credentials and preferences from the storage.
*/
void clearStorage();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/utils/DrawablePaths.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.utils;
import ai.rideos.android.common.R;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.map.DrawablePath;
import ai.rideos.android.common.view.resources.ResourceProvider;
import java.util.List;
public class DrawablePaths {
public static final float DEFAULT_PATH_WIDTH = 10.0f;
public static DrawablePath getActivePath(final List<LatLng> route, final ResourceProvider resourceProvider) {
return new DrawablePath(route, DEFAULT_PATH_WIDTH, resourceProvider.getColor(R.attr.rideos_route_color));
}
public static DrawablePath getInactivePath(final List<LatLng> route, final ResourceProvider resourceProvider) {
return new DrawablePath(route, DEFAULT_PATH_WIDTH, resourceProvider.getColor(R.attr.rideos_inactive_route_color));
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/utils/Locations.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.utils;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.map.LatLngBounds;
import ai.rideos.api.geo.v1.GeoProto.Position;
import android.location.Location;
import com.google.maps.android.SphericalUtil;
/**
* Locations contains various useful conversions between rideOS models and Google/Android models.
*/
public class Locations {
private static final int SOUTH_WEST_HEADING_DEGREES = 225;
private static final int NORTH_EAST_HEADING_DEGREES = 45;
public static com.google.android.gms.maps.model.LatLng toGoogleLatLng(final LatLng commonLatLng) {
return new com.google.android.gms.maps.model.LatLng(commonLatLng.getLatitude(), commonLatLng.getLongitude());
}
public static LatLng fromGoogleLatLng(final com.google.android.gms.maps.model.LatLng googleLatLng) {
return new LatLng(googleLatLng.latitude, googleLatLng.longitude);
}
public static Position toRideOsPosition(final LatLng latLng) {
return Position.newBuilder()
.setLatitude(latLng.getLatitude())
.setLongitude(latLng.getLongitude())
.build();
}
public static LatLng fromRideOsPosition(final Position position) {
return new LatLng(position.getLatitude(), position.getLongitude());
}
public static LatLngBounds getBoundsFromCenterAndRadius(final LatLng center, final int radiusMeters) {
return new LatLngBounds(
fromGoogleLatLng(SphericalUtil.computeOffset(toGoogleLatLng(center), radiusMeters, SOUTH_WEST_HEADING_DEGREES)),
fromGoogleLatLng(SphericalUtil.computeOffset(toGoogleLatLng(center), radiusMeters, NORTH_EAST_HEADING_DEGREES))
);
}
public static LatLng getLatLngFromAndroidLocation(final Location location) {
return new LatLng(location.getLatitude(), location.getLongitude());
}
/**
* An Android Location does not always have a heading. This can occur, for example, when the device is motionless.
* In this event, the default heading is used.
*/
public static float getHeadingFromAndroidLocationOrDefault(final Location location, final float defaultHeading) {
return location.hasBearing() ? location.getBearing() : defaultHeading;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/utils/Markers.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.utils;
import ai.rideos.android.common.R;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.RouteInfoModel;
import ai.rideos.android.common.model.map.DrawableMarker;
import ai.rideos.android.common.model.map.DrawableMarker.Anchor;
import ai.rideos.android.common.view.resources.ResourceProvider;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Markers {
public static final String PICKUP_MARKER_KEY = "pickup";
public static final String DROP_OFF_MARKER_KEY = "drop-off";
public static final String VEHICLE_KEY = "vehicle";
public static final String WAYPOINT_KEY_PREFIX = "waypoint-";
/**
* Helper function to get drawable markers for the pickup and drop-off locations of a route.
*/
public static Map<String, DrawableMarker> getMarkersForRoute(final RouteInfoModel routeInfoModel,
final ResourceProvider resourceProvider) {
final List<LatLng> path = routeInfoModel.getRoute();
final Map<String, DrawableMarker> markers = new HashMap<>();
if (path.size() > 0) {
markers.put(PICKUP_MARKER_KEY, getPickupMarker(path.get(0), resourceProvider));
markers.put(DROP_OFF_MARKER_KEY, getDropOffMarker(path.get(path.size() - 1), resourceProvider));
}
return markers;
}
public static DrawableMarker getPickupMarker(final LatLng pickup, final ResourceProvider resourceProvider) {
return getPinMarkerForPosition(
pickup,
resourceProvider.getDrawableId(R.attr.rideos_pickup_pin)
);
}
public static DrawableMarker getDropOffMarker(final LatLng dropOff, final ResourceProvider resourceProvider) {
return getPinMarkerForPosition(
dropOff,
resourceProvider.getDrawableId(R.attr.rideos_drop_off_pin)
);
}
public static Map<String, DrawableMarker> getWaypointMarkers(final List<LatLng> waypoints,
final ResourceProvider resourceProvider) {
return IntStream.range(0, waypoints.size())
.boxed()
.collect(Collectors.toMap(
index -> WAYPOINT_KEY_PREFIX + Integer.toString(index),
index -> new DrawableMarker(
waypoints.get(index),
0,
resourceProvider.getDrawableId(R.attr.rideos_waypoint_pin),
Anchor.CENTER
)
));
}
public static DrawableMarker getVehicleMarker(final LatLng vehicleLocation,
final float vehicleHeading,
final ResourceProvider resourceProvider) {
return new DrawableMarker(
vehicleLocation,
vehicleHeading,
resourceProvider.getDrawableId(R.attr.rideos_car_icon),
Anchor.CENTER
);
}
private static DrawableMarker getPinMarkerForPosition(final LatLng position, final int drawableIcon) {
return new DrawableMarker(position, 0, drawableIcon, Anchor.BOTTOM);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/utils/Paths.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.utils;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.RouteInfoModel;
import ai.rideos.android.common.model.map.LatLngBounds;
import ai.rideos.api.route.v1.RouteProto.RouteResponse;
import java.util.List;
import java.util.stream.Collectors;
public class Paths {
public static LatLngBounds getBoundsForPath(final List<LatLng> path, LatLng... additionalPoints) {
final com.google.android.gms.maps.model.LatLngBounds.Builder boundsBuilder =
com.google.android.gms.maps.model.LatLngBounds.builder();
for (final LatLng latLng : path) {
boundsBuilder.include(Locations.toGoogleLatLng(latLng));
}
for (final LatLng latLng : additionalPoints) {
boundsBuilder.include(Locations.toGoogleLatLng(latLng));
}
final com.google.android.gms.maps.model.LatLngBounds googleBounds = boundsBuilder.build();
return new LatLngBounds(
Locations.fromGoogleLatLng(googleBounds.southwest),
Locations.fromGoogleLatLng(googleBounds.northeast)
);
}
public static RouteInfoModel getRouteInfoFromRideOsRoute(final RouteResponse routeResponse) {
return new RouteInfoModel(
routeResponse.getPath().getGeometryList().stream()
.map(position -> new LatLng(position.getLatitude(), position.getLongitude()))
.collect(Collectors.toList()),
routeResponse.getPath().getTravelTime().getMilliseconds(),
routeResponse.getPath().getDistanceMeters()
);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/utils/Polylines.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.utils;
import ai.rideos.android.common.model.LatLng;
import com.google.maps.android.PolyUtil;
import java.util.List;
import java.util.stream.Collectors;
public class Polylines {
public interface PolylineDecoder {
List<LatLng> decode(final String polyline);
}
public interface PolylineEncoder {
String encode(final List<LatLng> path);
}
public static class GMSPolylineDecoder implements Polylines.PolylineDecoder {
@Override
public List<LatLng> decode(final String polyline) {
return PolyUtil.decode(polyline).stream()
.map(Locations::fromGoogleLatLng)
.collect(Collectors.toList());
}
}
public static class GMSPolylineEncoder implements Polylines.PolylineEncoder {
@Override
public String encode(final List<LatLng> path) {
return PolyUtil.encode(
path.stream()
.map(Locations::toGoogleLatLng)
.collect(Collectors.toList())
);
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/utils/SetOperations.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.utils;
import java.util.HashSet;
import java.util.Set;
public final class SetOperations {
public static class DiffResult<T> {
private final Set<T> onlyLeft;
private final Set<T> intersect;
private final Set<T> onlyRight;
DiffResult(final Set<T> onlyLeft, final Set<T> intersect, final Set<T> onlyRight) {
this.onlyLeft = onlyLeft;
this.intersect = intersect;
this.onlyRight = onlyRight;
}
public Set<T> getOnlyOnLeft() {
return onlyLeft;
}
public Set<T> getIntersecting() {
return intersect;
}
public Set<T> getOnlyOnRight() {
return onlyRight;
}
}
/**
* For two sets, Left and Right, getDifferences computes the objects only in Left, the objects shared by both
* Left and Right, and the objects only in Right.
* @param left - First Set
* @param right - Second Set
* @param <T> - Type of objects in set
* @return Objects only on Left, objects shared by both, and objects only on Right
*/
public static <T> DiffResult<T> getDifferences(final Set<T> left, final Set<T> right) {
final Set<T> onlyOnLeft = new HashSet<>(left);
onlyOnLeft.removeAll(right);
final Set<T> onlyOnRight = new HashSet<>(right);
onlyOnRight.removeAll(left);
final Set<T> intersect = new HashSet<>(left);
intersect.retainAll(right);
return new DiffResult<>(onlyOnLeft, intersect, onlyOnRight);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/BackPropagator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view;
public interface BackPropagator {
void propagateBackSignal();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/DensityConverter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view;
import android.content.Context;
import android.util.DisplayMetrics;
public class DensityConverter {
private final DisplayMetrics displayMetrics;
public static DensityConverter fromContext(final Context context) {
return new DensityConverter(context);
}
private DensityConverter(final Context context) {
displayMetrics = context.getResources().getDisplayMetrics();
}
public int convertDpToPixels(final int dp) {
return dp * (displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/ParentPresenter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view;
import ai.rideos.android.common.viewmodel.BackListener;
import androidx.annotation.CallSuper;
import android.view.View;
/**
* ParentPresenter defines a Presenter that controls other Presenter in a hierarchy. The parent
* may hold one child at a time.
*
* TODO remove and replace with a coordinator
* @param <P> Parent view
*/
public abstract class ParentPresenter<P extends View> implements Presenter<P> {
private Presenter<? extends View> child;
/**
* A back signal can originate from one of 2 places: the phone's back button, or some UI button in the view. When
* the signal originates from the phone, it has to be propagated from the top-level activity. To do this, the back
* signal is sent from parent to child until the last parent. Then, it is sent to the corresponding view model back
* listener.
*/
public void propagateBackSignalToChild(final BackListener onBackNotHandled) {
if (child instanceof BackPropagator) {
((BackPropagator) child).propagateBackSignal();
} else {
onBackNotHandled.back();
}
}
// TODO consider breaking this up into 2 replaceChild and attach methods for readability.
protected <C extends View> void replaceChildAndAttach(final Presenter<C> childController, final C childView) {
detachChild();
child = childController;
childController.attach(childView);
}
protected void detachChild() {
if (child != null) {
child.detach();
child = null;
}
}
protected Presenter<? extends View> getChild() {
return child;
}
@Override
@CallSuper
public void detach() {
detachChild();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/Presenter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view;
import android.view.View;
/**
* A Presenter binds a view to updates. These updates can (and usually do) come from a ViewModel. Note that a presenter
* does not own the view passed in and is not responsible for its lifecycle. For lifecycle-aware components, we should
* use the FragmentViewController.
*/
public interface Presenter<V extends View> {
void attach(final V view);
void detach();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/ViewMarginProvider.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view;
import androidx.core.util.Consumer;
/**
* ViewMarginProvider can be used for views that overlay on top of another view. This interface will calculate the view
* margins still shown in the bottom view.
*/
public interface ViewMarginProvider {
void calculateViewMargins(final Consumer<ViewMargins> marginsConsumer);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/ViewMargins.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view;
/**
* ViewMargins describes the left, top, right, and bottom margins for any view.
*/
public class ViewMargins {
private final int leftMargin;
private final int topMargin;
private final int rightMargin;
private final int bottomMargin;
private ViewMargins(final int leftMargin, final int topMargin, final int rightMargin, final int bottomMargin) {
this.leftMargin = leftMargin;
this.topMargin = topMargin;
this.rightMargin = rightMargin;
this.bottomMargin = bottomMargin;
}
public int getLeft() {
return leftMargin;
}
public int getTop() {
return topMargin;
}
public int getRight() {
return rightMargin;
}
public int getBottom() {
return bottomMargin;
}
public static Builder newBuilder() {
return new Builder();
}
public static class Builder {
private int leftMargin = 0;
private int topMargin = 0;
private int rightMargin = 0;
private int bottomMargin = 0;
public Builder setLeft(final int leftMargin) {
this.leftMargin = leftMargin;
return this;
}
public Builder setTop(final int topMargin) {
this.topMargin = topMargin;
return this;
}
public Builder setRight(final int rightMargin) {
this.rightMargin = rightMargin;
return this;
}
public Builder setBottom(final int bottomMargin) {
this.bottomMargin = bottomMargin;
return this;
}
public ViewMargins build() {
return new ViewMargins(leftMargin, topMargin, rightMargin, bottomMargin);
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/adapters/SingleSelectArrayAdapter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.adapters;
import ai.rideos.android.common.model.SingleSelectOptions;
import ai.rideos.android.common.model.SingleSelectOptions.Option;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/**
* SingleSelectArrayAdapter is an adapter for an Android Spinner that displays the SingleSelectOptions model.
* @param <T> - Type of value stored
*/
public class SingleSelectArrayAdapter<T> extends ArrayAdapter<Option<T>> {
private final Context context;
private final List<Option<T>> options;
public SingleSelectArrayAdapter(final Context context,
final SingleSelectOptions<T> singleSelectOptions) {
super(context, 0, singleSelectOptions.getOptions());
this.context = context;
options = singleSelectOptions.getOptions();
}
public Option<T> getOptionAtPosition(final int position) {
return options.get(position);
}
@NonNull
@Override
public View getView(final int position, final @Nullable View maybeView, final @NonNull ViewGroup parent) {
return getViewForLayout(position, maybeView, parent, android.R.layout.simple_spinner_item);
}
@Override
public View getDropDownView(final int position, final @Nullable View maybeView, final @NonNull ViewGroup parent) {
return getViewForLayout(position, maybeView, parent, android.R.layout.simple_spinner_dropdown_item);
}
private View getViewForLayout(final int position,
final @Nullable View maybeView,
final @NonNull ViewGroup parent,
final int layoutToInflate) {
final TextView listItem;
if (maybeView == null) {
listItem = (TextView) LayoutInflater.from(context).inflate(layoutToInflate, parent, false);
} else {
listItem = (TextView) maybeView;
}
listItem.setText(getOptionAtPosition(position).getDisplayText());
return listItem;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/errors/ErrorDialog.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.errors;
import ai.rideos.android.common.R;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
public class ErrorDialog {
private final Context context;
private final AlertDialog alertDialog;
public ErrorDialog(@NonNull final Context context) {
alertDialog = new AlertDialog.Builder(context, R.style.DefaultAlertDialogTheme)
.setPositiveButton(R.string.error_dialog_confirmation, (d, i) -> {})
.create();
this.context = context;
}
public void show(final String errorMessage) {
if (alertDialog.isShowing()) {
return;
}
final View dialogView = LayoutInflater.from(context).inflate(R.layout.default_error_alert, null);
final TextView message = dialogView.findViewById(R.id.error_message);
message.setText(errorMessage);
alertDialog.setView(dialogView);
alertDialog.show();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/layout/BottomDetailAndButtonView.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.layout;
import ai.rideos.android.common.R;
import ai.rideos.android.common.app.menu_navigator.OpenMenuListener;
import ai.rideos.android.common.view.ViewMarginProvider;
import ai.rideos.android.common.view.ViewMargins;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import androidx.annotation.DrawableRes;
import androidx.annotation.LayoutRes;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.util.Consumer;
public class BottomDetailAndButtonView extends ConstraintLayout implements ViewMarginProvider {
public static BottomDetailAndButtonView inflateWithUpButton(final LayoutInflater layoutInflater,
final ViewGroup container,
final Runnable onUpButtonClick,
@LayoutRes final int detailLayout) {
return inflateWithButton(layoutInflater, container, onUpButtonClick, detailLayout, R.drawable.ic_arrow_back_24dp);
}
public static BottomDetailAndButtonView inflateWithMenuButton(final LayoutInflater layoutInflater,
final ViewGroup container,
final Activity activity,
@LayoutRes final int detailLayout) {
Runnable onMenuClick = () -> {};
if (activity instanceof OpenMenuListener) {
onMenuClick = ((OpenMenuListener) activity)::openMenu;
}
return inflateWithButton(layoutInflater, container, onMenuClick, detailLayout, R.drawable.ic_menu);
}
public static BottomDetailAndButtonView inflateWithNoButton(final LayoutInflater layoutInflater,
final ViewGroup container,
@LayoutRes final int detailLayout) {
final BottomDetailAndButtonView bottomDetailView = inflateViewWithDetail(layoutInflater, container, detailLayout);
bottomDetailView.findViewById(R.id.top_button).setVisibility(GONE);
return bottomDetailView;
}
private static BottomDetailAndButtonView inflateWithButton(final LayoutInflater layoutInflater,
final ViewGroup container,
final Runnable onButtonClick,
@LayoutRes final int detailLayout,
@DrawableRes final int buttonDrawable) {
final BottomDetailAndButtonView bottomDetailView = inflateViewWithDetail(layoutInflater, container, detailLayout);
final ImageButton topButton = bottomDetailView.findViewById(R.id.top_button);
topButton.setImageResource(buttonDrawable);
topButton.setOnClickListener(click -> onButtonClick.run());
return bottomDetailView;
}
private static BottomDetailAndButtonView inflateViewWithDetail(final LayoutInflater layoutInflater,
final ViewGroup container,
@LayoutRes final int detailLayout) {
final BottomDetailAndButtonView bottomDetailView = (BottomDetailAndButtonView) layoutInflater.inflate(
R.layout.bottom_detail_and_button,
container,
false
);
final ViewGroup bottomContentContainer = bottomDetailView.findViewById(R.id.bottom_content);
final View bottomContent = layoutInflater.inflate(detailLayout, bottomContentContainer, false);
bottomContentContainer.addView(bottomContent);
return bottomDetailView;
}
public BottomDetailAndButtonView(final Context context) {
super(context);
}
public BottomDetailAndButtonView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public BottomDetailAndButtonView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void calculateViewMargins(final Consumer<ViewMargins> marginsConsumer) {
final ViewGroup bottomDetailContainer = findViewById(R.id.bottom_content);
bottomDetailContainer.measure(0, 0);
final View topButton = findViewById(R.id.top_button);
topButton.measure(0, 0);
int[] topButtonLocation = new int[2];
topButton.getLocationOnScreen(topButtonLocation);
int bottomOfTopButton = topButtonLocation[1] + topButton.getMeasuredHeight();
marginsConsumer.accept(ViewMargins.newBuilder()
.setTop(bottomOfTopButton)
.setBottom(bottomDetailContainer.getMeasuredHeight())
.build()
);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/layout/LoadableDividerView.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.layout;
import ai.rideos.android.common.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
/**
* LoadableDividerView defines a horizontal rule divider that can be swapped for a horizontal progress bar in-place.
*/
public class LoadableDividerView extends FrameLayout {
private View horizontalRule;
private ProgressBar progressBar;
public LoadableDividerView(final Context context) {
super(context);
init(context);
}
public LoadableDividerView(final Context context, final AttributeSet attrs) {
super(context, attrs);
init(context);
}
public LoadableDividerView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(final Context context) {
inflate(context, R.layout.loadable_divider, this);
horizontalRule = findViewById(R.id.horizontal_rule);
progressBar = findViewById(R.id.progress_bar);
stopLoading();
}
public void startLoading() {
horizontalRule.setVisibility(INVISIBLE);
progressBar.setVisibility(VISIBLE);
}
public void stopLoading() {
progressBar.setVisibility(INVISIBLE);
horizontalRule.setVisibility(VISIBLE);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/layout/TopDetailView.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.layout;
import ai.rideos.android.common.R;
import ai.rideos.android.common.view.ViewMarginProvider;
import ai.rideos.android.common.view.ViewMargins;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.LayoutRes;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.util.Consumer;
public class TopDetailView extends ConstraintLayout implements ViewMarginProvider {
public TopDetailView(final Context context) {
super(context);
}
public TopDetailView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public TopDetailView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public static TopDetailView inflateViewWithDetail(final LayoutInflater layoutInflater,
final ViewGroup container,
@LayoutRes final int detailLayout) {
final TopDetailView topDetailView = (TopDetailView) layoutInflater.inflate(
R.layout.top_detail,
container,
false
);
final ViewGroup topContentContainer = topDetailView.findViewById(R.id.top_content);
final View topContent = layoutInflater.inflate(detailLayout, topContentContainer, false);
topContentContainer.addView(topContent);
return topDetailView;
}
@Override
public void calculateViewMargins(final Consumer<ViewMargins> marginsConsumer) {
final ViewGroup topDetail = findViewById(R.id.top_content);
topDetail.measure(0, 0);
marginsConsumer.accept(
ViewMargins.newBuilder().setTop(topDetail.getMeasuredHeight()).build()
);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/resources/AndroidResourceProvider.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.resources;
import android.content.Context;
import android.content.res.Resources;
import androidx.core.content.res.ResourcesCompat;
import android.util.TypedValue;
import java.util.Locale;
public class AndroidResourceProvider implements ResourceProvider {
private final Context context;
private final Resources resources;
private AndroidResourceProvider(final Context context) {
this.context = context;
resources = context.getResources();
}
public static AndroidResourceProvider forContext(final Context context) {
return new AndroidResourceProvider(context);
}
@Override
public int getColor(final int colorAttributeId) {
final TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(colorAttributeId, typedValue, true);
if (typedValue.type == TypedValue.TYPE_REFERENCE) {
// It's a reference, get the associated color
return ResourcesCompat.getColor(resources, typedValue.resourceId, null);
} else {
// it's a color
return typedValue.data;
}
}
@Override
public Locale getLocale() {
return resources.getConfiguration().getLocales().get(0); // guaranteed to be at least 1 locale
}
@Override
public String getString(final int stringResourceId, final Object... args) {
return resources.getString(stringResourceId, args);
}
@Override
public String getQuantityString(final int pluralResourceId, final int quantity, final Object... args) {
return resources.getQuantityString(pluralResourceId, quantity, args);
}
@Override
public int getDrawableId(final int attributeId) {
final TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(attributeId, typedValue, true);
return typedValue.resourceId;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/resources/ResourceProvider.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.resources;
import java.util.Locale;
public interface ResourceProvider {
/**
* Get the locale of a user from the app resources. This is useful for displaying strings.
*/
Locale getLocale();
/**
* Retrieve a color in the SRGB space given a color attribute id.
* See https://developer.android.com/reference/android/graphics/ColorSpace.Named#SRGB for more details.
*/
int getColor(final int colorAttributeId);
/**
* Get a string formatted with arguments from app resources.
*/
String getString(final int stringResourceId, Object... args);
/**
* Get a string that changes based on the quantity provided. For example to show the number of cars in an area,
* for quantity 0 you might want to display "No cars", for quantity 1 "1 car" and for quantity 2 "2 cars".
*/
String getQuantityString(final int pluralResourceId, int quantity, Object... args);
/**
* Get the id of a drawable asset from an attribute id.
*/
int getDrawableId(final int attributeId);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/strings/RouteFormatter.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.strings;
import ai.rideos.android.common.R;
import ai.rideos.android.common.model.RouteInfoModel;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.location.Distance;
import ai.rideos.android.common.view.resources.ResourceProvider;
import ai.rideos.android.common.view.strings.Units.UnitType;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
public class RouteFormatter {
private final ResourceProvider resourceProvider;
public RouteFormatter(final ResourceProvider resourceProvider) {
this.resourceProvider = resourceProvider;
}
public String getDisplayStringForRouteResult(final Result<RouteInfoModel> routeInfoResult) {
if (routeInfoResult.isFailure()) {
return resourceProvider.getString(R.string.unknown_route_display);
}
final String distanceDisplay = getTravelDistanceDisplayString(routeInfoResult.get());
final String timeDisplay = getTravelTimeDisplayString(routeInfoResult.get());
return resourceProvider.getString(R.string.distance_time_display, distanceDisplay, timeDisplay);
}
public String getTravelDistanceDisplayString(final RouteInfoModel routeInfoModel) {
final double distanceMeters = routeInfoModel.getTravelDistanceMeters();
final Locale userLocale = resourceProvider.getLocale();
return Units.getPreferredUnitsFromLocale(userLocale) == UnitType.IMPERIAL
? getImperialDistanceString(distanceMeters) : getMetricDistanceString(distanceMeters);
}
public String getTravelTimeDisplayString(final RouteInfoModel routeInfoModel) {
final int minutes = (int) TimeUnit.MILLISECONDS.toMinutes(routeInfoModel.getTravelTimeMillis());
return resourceProvider.getString(R.string.time_display_minutes, minutes);
}
private String getImperialDistanceString(final double meters) {
final double miles = Distance.metersToMiles(meters);
return resourceProvider.getString(R.string.distance_display_miles, miles);
}
private String getMetricDistanceString(final double meters) {
return resourceProvider.getString(R.string.distance_display_kilometers, meters / 1000);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/strings/Units.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.strings;
import java.util.Locale;
public class Units {
public enum UnitType {
METRIC,
IMPERIAL
}
public static UnitType getPreferredUnitsFromLocale(final Locale locale) {
final String countryCode = locale.getISO3Country().toUpperCase();
switch (countryCode) {
case "USA": // United States
case "LBR": // Liberia
case "MMR": // Myanmar
return UnitType.IMPERIAL;
default:
return UnitType.METRIC;
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/view/transitions/TransitionListeners.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.view.transitions;
import android.transition.Transition;
import android.transition.Transition.TransitionListener;
/**
* Create a new TransitionListener that is only triggered at the end of a transition.
*/
public class TransitionListeners {
public static TransitionListener onEnd(final Runnable onEndListener) {
return new TransitionListener() {
@Override
public void onTransitionStart(final Transition transition) {
}
@Override
public void onTransitionEnd(final Transition transition) {
onEndListener.run();
}
@Override
public void onTransitionCancel(final Transition transition) {
}
@Override
public void onTransitionPause(final Transition transition) {
}
@Override
public void onTransitionResume(final Transition transition) {
}
};
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/BackListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel;
public interface BackListener {
void back();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/UpListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel;
public interface UpListener {
void navigateUp();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/ViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel;
/**
* Custom ViewModel interface that isn't tied to Android lifecycle.
*/
public interface ViewModel {
// Call to clean up any resources or subscriptions the ViewModel might have used
void destroy();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/map/FollowCurrentLocationMapStateProvider.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.map;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.model.map.CameraUpdate;
import ai.rideos.android.common.model.map.CenterPin;
import ai.rideos.android.common.model.map.DrawableMarker;
import ai.rideos.android.common.model.map.DrawableMarker.Anchor;
import ai.rideos.android.common.model.map.DrawablePath;
import ai.rideos.android.common.model.map.MapSettings;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.utils.Markers;
import io.reactivex.Observable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class FollowCurrentLocationMapStateProvider implements MapStateProvider {
private static final int POLL_INTERVAL_MILLIS = 2000;
private static final float ZOOM_LEVEL = 15;
private final SchedulerProvider schedulerProvider;
private final int drawableMarkerId;
private final Observable<LocationAndHeading> observableLocation;
public FollowCurrentLocationMapStateProvider(final DeviceLocator deviceLocator,
final int drawableMarkerId) {
this(deviceLocator, drawableMarkerId, new DefaultSchedulerProvider());
}
public FollowCurrentLocationMapStateProvider(final DeviceLocator deviceLocator,
final int drawableMarkerId,
final SchedulerProvider schedulerProvider) {
this.drawableMarkerId = drawableMarkerId;
this.schedulerProvider = schedulerProvider;
observableLocation = deviceLocator.observeCurrentLocation(POLL_INTERVAL_MILLIS)
.observeOn(schedulerProvider.computation());
}
@Override
public Observable<MapSettings> getMapSettings() {
return Observable.just(new MapSettings(false, CenterPin.hidden()));
}
@Override
public Observable<CameraUpdate> getCameraUpdates() {
return observableLocation
.map(locationAndHeading -> CameraUpdate.centerAndZoom(locationAndHeading.getLatLng(), ZOOM_LEVEL));
}
@Override
public Observable<Map<String, DrawableMarker>> getMarkers() {
return observableLocation
.map(locationAndHeading -> Collections.singletonMap(
Markers.VEHICLE_KEY,
new DrawableMarker(
locationAndHeading.getLatLng(),
locationAndHeading.getHeading(),
drawableMarkerId,
Anchor.CENTER
)
));
}
@Override
public Observable<List<DrawablePath>> getPaths() {
return Observable.just(Collections.emptyList());
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/map/MapStateProvider.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.map;
import ai.rideos.android.common.model.map.CameraUpdate;
import ai.rideos.android.common.model.map.DrawableMarker;
import ai.rideos.android.common.model.map.DrawablePath;
import ai.rideos.android.common.model.map.MapSettings;
import io.reactivex.Observable;
import java.util.List;
import java.util.Map;
public interface MapStateProvider {
Observable<MapSettings> getMapSettings();
Observable<CameraUpdate> getCameraUpdates();
Observable<Map<String, DrawableMarker>> getMarkers();
Observable<List<DrawablePath>> getPaths();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/progress/ProgressSubject.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.progress;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
import io.reactivex.subjects.BehaviorSubject;
import timber.log.Timber;
public class ProgressSubject {
public enum ProgressState {
IDLE,
LOADING,
SUCCEEDED,
FAILED
}
private final BehaviorSubject<ProgressState> stateSubject;
public ProgressSubject() {
this(ProgressState.IDLE);
}
public ProgressSubject(final ProgressState progressState) {
this.stateSubject = BehaviorSubject.createDefault(progressState);
}
public Observable<ProgressState> observeProgress() {
return stateSubject.distinctUntilChanged();
}
public ProgressState getProgress() {
return stateSubject.getValue();
}
public void idle() {
stateSubject.onNext(ProgressState.IDLE);
}
public void started() {
stateSubject.onNext(ProgressState.LOADING);
}
public void succeeded() {
stateSubject.onNext(ProgressState.SUCCEEDED);
}
public void failed() {
stateSubject.onNext(ProgressState.FAILED);
}
public Disposable followAsyncOperation(final Completable asyncOperation) {
switch (getProgress()) {
case IDLE:
case FAILED:
started();
return asyncOperation.subscribe(
this::succeeded,
throwable -> {
Timber.e(throwable);
failed();
}
);
}
return Disposables.empty();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/AsyncStateTransition.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
import io.reactivex.Single;
/**
* AsyncStateTransition is a type of event that changes the state after some asynchronous call. This is useful in situations where
* the state doesn't change immediately. E.g. you request a driver goes online, but this request takes some time to
* complete
* @param <State>
*/
public interface AsyncStateTransition<State> {
Single<State> applyAsyncChange(final State currentState) throws InvalidStateTransition;
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/BackStack.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
import io.reactivex.disposables.Disposable;
public interface BackStack<T> {
Disposable follow(final StateMachine<T> stateMachine);
void back(final Runnable onBackStackEmpty);
void clear();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/InvalidStateTransition.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
public class InvalidStateTransition extends Exception {
public InvalidStateTransition(final String s) {
super(s);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/StateMachine.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
import ai.rideos.android.common.reactive.SchedulerProvider;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.PublishSubject;
import timber.log.Timber;
/**
* StateMachine is a useful class for view models that behave like a state machine. The class takes in various events
* that modify the state. These events are applied serially. In the case that the event is asynchronous, the state
* machine waits for the previous event to finish before starting the next. The current state can be retrieved at any
* moment through getCurrentState
* @param <T> - state type
*/
public class StateMachine<T> {
private CompositeDisposable compositeDisposable = new CompositeDisposable();
private final PublishSubject<AsyncStateTransition<T>> transitionSubject = PublishSubject.create();
private final BehaviorSubject<T> stateSubject;
private final SchedulerProvider schedulerProvider;
/**
* Initialize the StateMachine with an initial state.
* @param initialState - initial state of the state machine
* @param schedulerProvider - scheduler provider for observing events
*/
public StateMachine(final T initialState, final SchedulerProvider schedulerProvider) {
stateSubject = BehaviorSubject.createDefault(initialState);
this.schedulerProvider = schedulerProvider;
}
public StateMachine(final SchedulerProvider schedulerProvider) {
stateSubject = BehaviorSubject.create();
this.schedulerProvider = schedulerProvider;
}
public void initialize(final T initialState) {
stateSubject.onNext(initialState);
}
/**
* Begin listening to events and apply them to the current state.
* @return disposable subscription to events
*/
public Disposable start() {
compositeDisposable.add(
transitionSubject
// The state machine should always be run on a single thread so that each transition is done serially.
.subscribeOn(schedulerProvider.single())
// Get the state asynchronously and if the transition fails, re-emit the current state
// Errors do not stop the state machine, they are merely logged
.flatMapSingle(event -> {
final T currentState = stateSubject.getValue();
try {
return event.applyAsyncChange(currentState)
.doOnError(error -> Timber.e(error, "Error while applying change"))
.onErrorReturnItem(currentState);
} catch (final InvalidStateTransition error) {
Timber.e(error, "Invalid state transition");
return Single.just(currentState);
}
})
.subscribe(stateSubject::onNext)
);
return compositeDisposable;
}
/**
* Add a new stateTransition to the state machine stateTransition subject.
* @param stateTransition - synchronous stateTransition to apply
*/
public void transition(final StateTransition<T> stateTransition) {
// Transform synchronous stateTransition into async stateTransition
transitionSubject.onNext(currentState -> Single.just(stateTransition.applyChange(currentState)));
}
/**
* Add a new async event to the state machine event subject.
* @param asyncStateTransition - asynchronous event to apply
*/
public void transitionAsync(final AsyncStateTransition<T> asyncStateTransition) {
transitionSubject.onNext(asyncStateTransition);
}
/**
* Get the current state of the state machine at any moment.
* @return Observable state
*/
public Observable<T> observeCurrentState() {
return stateSubject.observeOn(schedulerProvider.mainThread());
}
public T getCurrentState() {
return stateSubject.getValue();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/StateTransition.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
/**
* Represents an arbitrary event that transitions a state to a new state in a state machine.
* @param <State> state type to update
*/
public interface StateTransition<State> {
State applyChange(final State currentState) throws InvalidStateTransition;
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/StateTransitions.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
import java.util.function.Predicate;
public class StateTransitions {
public static <T> AsyncStateTransition<T> asyncTransitionIf(final Predicate<T> stateMatcher, final AsyncStateTransition<T> event) {
return currentState -> {
if (stateMatcher.test(currentState)) {
return event.applyAsyncChange(currentState);
}
throw new InvalidStateTransition(String.format(
"Invalid state transition. Current state %s does not match predicate %s",
currentState.toString(),
stateMatcher.toString()
));
};
}
public static <T> StateTransition<T> transitionIf(final Predicate<T> stateMatcher, final StateTransition<T> stateTransition) {
return currentState -> {
if (stateMatcher.test(currentState)) {
return stateTransition.applyChange(currentState);
}
throw new InvalidStateTransition(String.format(
"Invalid state transition. Current state %s does not match predicate %s",
currentState.toString(),
stateMatcher.toString()
));
};
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel | java-sources/ai/rideos/sdk/sdk-android-common/1.0.2/ai/rideos/android/common/viewmodel/state_machine/WorkflowBackStack.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.common.viewmodel.state_machine;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.PublishSubject;
import java.util.OptionalInt;
import java.util.Stack;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.stream.IntStream;
/**
* WorkflowBackStack is a back stack that keeps track of states in a sequential workflow. As new states are emitted
* from a state machine, they are added to the back stack. Calling `back` pushes the previous state to the state machine.
* Calling `clear` removes all states.
*
* You can also specify that the WorkflowBackStack "rolls back" states in the stack when it notices a previously emitted
* state. For example, say you have a workflow with the sequence A -> B -> C and the following events occurred:
* - Started state machine on state A (back stack : [A])
* - Navigated from state A to state B (back stack : [A, B])
* - Navigated from state B to state C (back stack : [A, B, C])
* Now, if you navigate "up" from state C to state A, the WorkflowBackStack rolls back the back stack to [A].
*
* Additionally, the WorkflowBackStack can track states in which the back button is disabled. For example, if there is
* an intermediate loading screen, you probably don't want the user to hit back when some background task is being
* executed.
* @param <T> - type of states to track
*/
public class WorkflowBackStack<T> implements BackStack<T> {
private final BiPredicate<T, T> stateComparer;
private final Predicate<T> disabledBackStates;
private final PublishSubject<Event<T>> eventSubject = PublishSubject.create();
private final Stack<T> previousStates = new Stack<>();
/**
* Create a new WorkflowBackStack
* @param stateComparer - function to call to check if a state already exists in the back stack
* @param disabledBackStates - function to call to check if a state can be removed from the back stack
*/
public WorkflowBackStack(final BiPredicate<T, T> stateComparer,
final Predicate<T> disabledBackStates) {
this.stateComparer = stateComparer;
this.disabledBackStates = disabledBackStates;
}
@Override
public Disposable follow(final StateMachine<T> stateMachine) {
final CompositeDisposable compositeDisposable = new CompositeDisposable();
compositeDisposable.add(
eventSubject.subscribe(event -> {
switch (event.eventType) {
case NEW_STATE:
checkForExistingStateAndPop(event.newState);
previousStates.push(event.newState);
return;
case BACK:
if (!previousStates.isEmpty() && disabledBackStates.test(previousStates.peek())) {
return;
}
if (previousStates.size() < 2) {
event.onBackStackEmpty.run();
} else {
previousStates.pop();
stateMachine.transition(state -> previousStates.peek());
}
return;
case CLEAR:
previousStates.clear();
}
})
);
compositeDisposable.add(
stateMachine.observeCurrentState()
.subscribe(newState -> eventSubject.onNext(Event.newState(newState)))
);
return compositeDisposable;
}
@Override
public void back(final Runnable onBackStackEmpty) {
eventSubject.onNext(Event.back(onBackStackEmpty));
}
@Override
public void clear() {
eventSubject.onNext(Event.clear());
}
private void checkForExistingStateAndPop(final T newState) {
final OptionalInt previousIndex = IntStream.range(0, previousStates.size())
.filter(i -> stateComparer.test(previousStates.get(previousStates.size() - i - 1), newState))
.findFirst();
if (previousIndex.isPresent()) {
final int numToPop = previousIndex.getAsInt() + 1;
for (int i = 0; i < numToPop; i++) {
previousStates.pop();
}
}
}
private static class Event<T> {
private enum EventType {
NEW_STATE,
BACK,
CLEAR
}
private final EventType eventType;
private final T newState;
private final Runnable onBackStackEmpty;
private static <T> Event<T> newState(final T newState) {
return new Event<>(EventType.NEW_STATE, newState, null);
}
private static <T> Event<T> back(final Runnable onBackStackEmpty) {
return new Event<>(EventType.BACK, null, onBackStackEmpty);
}
private static <T> Event<T> clear() {
return new Event<>(EventType.CLEAR, null, null);
}
private Event(final EventType eventType,
final T newState,
final Runnable onBackStackEmpty) {
this.eventType = eventType;
this.newState = newState;
this.onBackStackEmpty = onBackStackEmpty;
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/device/PotentiallySimulatedDeviceLocator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.device;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.device.FusedLocationDeviceLocator;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.TrampolineSchedulerProvider;
import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageReader;
import ai.rideos.android.common.user_storage.UserStorageReader;
import ai.rideos.android.settings.DriverStorageKeys;
import android.content.Context;
import androidx.annotation.VisibleForTesting;
import io.reactivex.Observable;
import io.reactivex.Single;
public class PotentiallySimulatedDeviceLocator implements DeviceLocator {
private final DeviceLocator simulatedDeviceLocator;
private final DeviceLocator nonSimulatedDeviceLocator;
private final UserStorageReader userStorageReader;
private final SchedulerProvider schedulerProvider;
public PotentiallySimulatedDeviceLocator(final Context context) {
this(
SimulatedDeviceLocator.get(context),
new FusedLocationDeviceLocator(context),
SharedPreferencesUserStorageReader.forContext(context),
new TrampolineSchedulerProvider()
);
}
@VisibleForTesting
PotentiallySimulatedDeviceLocator(final DeviceLocator simulatedDeviceLocator,
final DeviceLocator nonSimulatedDeviceLocator,
final UserStorageReader userStorageReader,
final SchedulerProvider schedulerProvider) {
this.simulatedDeviceLocator = simulatedDeviceLocator;
this.nonSimulatedDeviceLocator = nonSimulatedDeviceLocator;
this.userStorageReader = userStorageReader;
this.schedulerProvider = schedulerProvider;
}
@Override
public Observable<LocationAndHeading> observeCurrentLocation(final int pollIntervalMillis) {
return userStorageReader.observeBooleanPreference(DriverStorageKeys.SIMULATE_NAVIGATION)
.observeOn(schedulerProvider.computation())
.flatMap(simulationEnabled ->
getResolvedLocator(simulationEnabled).observeCurrentLocation(pollIntervalMillis)
);
}
@Override
public Single<LocationAndHeading> getLastKnownLocation() {
return userStorageReader.observeBooleanPreference(DriverStorageKeys.SIMULATE_NAVIGATION)
.observeOn(schedulerProvider.computation())
.firstOrError()
.flatMap(simulationEnabled -> getResolvedLocator(simulationEnabled).getLastKnownLocation());
}
private DeviceLocator getResolvedLocator(final boolean isSimulationEnabled) {
return isSimulationEnabled ? simulatedDeviceLocator : nonSimulatedDeviceLocator;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/device/SimulatedDeviceLocator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.device;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.device.FusedLocationDeviceLocator;
import ai.rideos.android.common.model.LocationAndHeading;
import android.content.Context;
import androidx.annotation.VisibleForTesting;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.subjects.BehaviorSubject;
public class SimulatedDeviceLocator implements DeviceLocator {
private static volatile SimulatedDeviceLocator INSTANCE = null;
private final BehaviorSubject<LocationAndHeading> simulatedLocationSubject = BehaviorSubject.create();
private final DeviceLocator initialDeviceLocator;
public static SimulatedDeviceLocator get(final Context context) {
if (INSTANCE == null) {
synchronized (SimulatedDeviceLocator.class) {
if (INSTANCE == null) {
INSTANCE = new SimulatedDeviceLocator(context);
}
}
}
return INSTANCE;
}
private SimulatedDeviceLocator(final Context context) {
this(new FusedLocationDeviceLocator(context));
}
@VisibleForTesting
SimulatedDeviceLocator(final DeviceLocator initialDeviceLocator) {
this.initialDeviceLocator = initialDeviceLocator;
}
public void updateSimulatedLocation(final LocationAndHeading locationAndHeading) {
simulatedLocationSubject.onNext(locationAndHeading);
}
@Override
public Observable<LocationAndHeading> observeCurrentLocation(final int pollIntervalMillis) {
final Observable<LocationAndHeading> locationUntilSimulated = initialDeviceLocator
.observeCurrentLocation(pollIntervalMillis)
.takeUntil(simulatedLocationSubject);
return Observable.concat(locationUntilSimulated, simulatedLocationSubject);
}
@Override
public Single<LocationAndHeading> getLastKnownLocation() {
final LocationAndHeading lastSimulatedLocation = simulatedLocationSubject.getValue();
if (lastSimulatedLocation == null) {
return initialDeviceLocator.getLastKnownLocation();
}
return Single.just(lastSimulatedLocation);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/DefaultMainViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app;
import static ai.rideos.android.common.viewmodel.state_machine.StateTransitions.transitionIf;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.viewmodel.state_machine.StateMachine;
import ai.rideos.android.interactors.DriverVehicleInteractor;
import ai.rideos.android.model.MainViewState;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import java.util.function.Predicate;
public class DefaultMainViewModel implements MainViewModel {
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final StateMachine<MainViewState> stateMachine;
private final DriverVehicleInteractor vehicleInteractor;
private final User user;
private final SchedulerProvider schedulerProvider;
public DefaultMainViewModel(final DriverVehicleInteractor vehicleInteractor,
final User user) {
this(vehicleInteractor, user, new DefaultSchedulerProvider());
}
public DefaultMainViewModel(final DriverVehicleInteractor vehicleInteractor,
final User user,
final SchedulerProvider schedulerProvider) {
this.vehicleInteractor = vehicleInteractor;
this.user = user;
this.schedulerProvider = schedulerProvider;
stateMachine = new StateMachine<>(schedulerProvider);
compositeDisposable.add(stateMachine.start());
}
@Override
public void initialize() {
stateMachine.initialize(MainViewState.UNKNOWN);
}
@Override
public Observable<MainViewState> getMainViewState() {
final Disposable vehicleStatusSubscription = vehicleInteractor.getVehicleStatus(user.getId())
.observeOn(schedulerProvider.computation())
.retry()
.subscribe(status -> {
switch (status) {
case READY:
stateMachine.transition(state -> MainViewState.ONLINE);
break;
case NOT_READY:
stateMachine.transition(state -> MainViewState.OFFLINE);
break;
case UNREGISTERED:
stateMachine.transition(state -> MainViewState.UNREGISTERED);
break;
}
});
return stateMachine.observeCurrentState()
.filter(state -> state != MainViewState.UNKNOWN)
.doOnDispose(vehicleStatusSubscription::dispose);
}
@Override
public void destroy() {
compositeDisposable.dispose();
}
@Override
public void didGoOnline() {
stateMachine.transition(transitionIf(
Predicate.isEqual(MainViewState.OFFLINE),
state -> MainViewState.ONLINE
));
}
@Override
public void didGoOffline() {
stateMachine.transition(transitionIf(
Predicate.isEqual(MainViewState.ONLINE),
state -> MainViewState.OFFLINE
));
}
@Override
public void doneRegistering() {
stateMachine.transition(transitionIf(
state -> state == MainViewState.UNREGISTERED,
state -> MainViewState.OFFLINE
));
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/MainCoordinator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app;
import ai.rideos.android.common.architecture.Coordinator;
import ai.rideos.android.common.architecture.EmptyArg;
import ai.rideos.android.common.architecture.NavigationController;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import ai.rideos.android.driver_app.offline.OfflineFragment;
import ai.rideos.android.driver_app.online.OnlineCoordinator;
import ai.rideos.android.driver_app.vehicle_unregistered.VehicleUnregisteredCoordinator;
import android.content.Context;
import io.reactivex.disposables.CompositeDisposable;
public class MainCoordinator implements Coordinator<EmptyArg> {
private CompositeDisposable compositeDisposable;
private final MainViewModel mainViewModel;
private final NavigationController navController;
private final Coordinator<EmptyArg> onlineCoordinator;
private final Coordinator<EmptyArg> unregisteredCoordinator;
private Coordinator activeChild = null;
public MainCoordinator(final Context context,
final NavigationController navController) {
this.navController = navController;
mainViewModel = new DefaultMainViewModel(
DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(context),
User.get(context)
);
onlineCoordinator = new OnlineCoordinator(context, navController, mainViewModel);
unregisteredCoordinator = new VehicleUnregisteredCoordinator(navController, mainViewModel);
}
@Override
public void start(final EmptyArg emptyArg) {
mainViewModel.initialize();
compositeDisposable = new CompositeDisposable();
compositeDisposable.addAll(
mainViewModel.getMainViewState()
.subscribe(state -> {
stopChild();
switch (state) {
case OFFLINE:
navController.navigateTo(
new OfflineFragment(),
EmptyArg.create(),
mainViewModel
);
break;
case ONLINE:
onlineCoordinator.start(EmptyArg.create());
activeChild = onlineCoordinator;
break;
case UNREGISTERED:
unregisteredCoordinator.start(EmptyArg.create());
activeChild = unregisteredCoordinator;
break;
}
})
);
}
private void stopChild() {
if (activeChild != null) {
activeChild.stop();
}
activeChild = null;
}
@Override
public void stop() {
stopChild();
compositeDisposable.dispose();
}
@Override
public void destroy() {
onlineCoordinator.destroy();
unregisteredCoordinator.destroy();
mainViewModel.destroy();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/MainFragment.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app;
import ai.rideos.android.common.app.map.MapInsetFragmentListener;
import ai.rideos.android.common.architecture.EmptyArg;
import ai.rideos.android.common.architecture.FragmentNavigationController;
import ai.rideos.android.common.architecture.ListenerRegistry;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class MainFragment extends Fragment {
private MainCoordinator mainCoordinator;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainCoordinator = new MainCoordinator(
getContext(),
new FragmentNavigationController(getChildFragmentManager(), R.id.overlay_fragment_container, ListenerRegistry.get())
);
}
@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.map_detail_fragment_container, container, false);
getChildFragmentManager().beginTransaction()
.replace(R.id.map_fragment_container, DriverDependencyRegistry.mapDependencyFactory().getMapFragment())
.commit();
return view;
}
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getChildFragmentManager().registerFragmentLifecycleCallbacks(new MapInsetFragmentListener(), true);
mainCoordinator.start(EmptyArg.create());
}
public void onDestroyView() {
super.onDestroyView();
mainCoordinator.stop();
}
@Override
public void onDestroy() {
super.onDestroy();
mainCoordinator.destroy();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/MainFragmentActivity.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app;
import ai.rideos.android.common.app.AppUpdateManagerLifecycleListener;
import ai.rideos.android.common.app.CommonMetadataKeys;
import ai.rideos.android.common.app.MetadataReader;
import ai.rideos.android.common.app.push_notifications.PushNotificationManager;
import ai.rideos.android.common.app.menu_navigator.LoggedOutListener;
import ai.rideos.android.common.app.menu_navigator.MenuOptionFragmentRegistry;
import ai.rideos.android.common.app.menu_navigator.OpenMenuListener;
import ai.rideos.android.common.app.menu_navigator.menu.MenuNavigator;
import ai.rideos.android.common.app.menu_navigator.menu.MenuPresenter;
import ai.rideos.android.common.connectivity.ConnectivityMonitor;
import ai.rideos.android.common.device.FusedLocationDeviceLocator;
import ai.rideos.android.common.fleets.DefaultFleetResolver;
import ai.rideos.android.common.fleets.ResolvedFleet;
import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageReader;
import ai.rideos.android.common.user_storage.StorageKeys;
import ai.rideos.android.common.viewmodel.BackListener;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import ai.rideos.android.driver_app.launch.LaunchActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentActivity;
import com.mapbox.mapboxsdk.Mapbox;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import timber.log.Timber;
public class MainFragmentActivity
extends FragmentActivity
implements BackListener, OpenMenuListener, LoggedOutListener {
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private MenuNavigator menuNavigator;
private MenuPresenter menuController;
private ConnectivityMonitor connectivityMonitor;
private AppUpdateManagerLifecycleListener appUpdateManager;
private MetadataReader metadataReader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
metadataReader = new MetadataReader(this);
// Keep the screen always on when the driver app is open. This way the device doesn't sleep while in the middle
// of a route.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Set up mapbox token
final String apiToken = metadataReader.getStringMetadata(CommonMetadataKeys.MAPBOX_TOKEN_KEY).getOrThrow();
Mapbox.getInstance(this, apiToken);
setContentView(R.layout.drawer_layout);
final DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
final MenuOptionFragmentRegistry registry = DriverDependencyRegistry.driverDependencyFactory()
.getMenuOptions(this);
menuController = new MenuPresenter(this, registry.getMenuOptions(), this);
menuController.attach(drawerLayout);
menuNavigator = new MenuNavigator(registry, menuController, getSupportFragmentManager(), R.id.content_frame);
connectivityMonitor = new ConnectivityMonitor(findViewById(R.id.connectivity_banner));
appUpdateManager = new AppUpdateManagerLifecycleListener();
appUpdateManager.onActivityCreated(this);
resolveFleetId();
}
@Override
protected void onResume() {
super.onResume();
appUpdateManager.onActivityResumed(this);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
appUpdateManager.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onStart() {
super.onStart();
connectivityMonitor.start();
final boolean enablePushNotifications = metadataReader
.getBooleanMetadata(CommonMetadataKeys.ENABLE_PUSH_NOTIFICATIONS)
.getOrDefault(true);
if (enablePushNotifications) {
compositeDisposable.add(PushNotificationManager.forDriver(this).requestTokenAndSync().subscribe(
() -> Timber.i("Initialized device token"),
e -> Timber.e(e, "Failed to request token")
));
}
}
@Override
public void onStop() {
super.onStop();
connectivityMonitor.stop();
}
@Override
public void onDestroy() {
super.onDestroy();
compositeDisposable.dispose();
menuController.detach();
}
/**
* Propagate phone's back button signal down to child view controllers. If the child view controllers cannot handle
* the signal (i.e. they're at the first state in a workflow), it is propagated back up through BackListeners
*/
@Override
public void onBackPressed() {
if (menuController.isMenuOpen()) {
menuController.closeMenu();
return;
}
menuNavigator.propagateBackSignal(this::back);
}
private void resolveFleetId() {
final DefaultFleetResolver fleetResolver = new DefaultFleetResolver(
DriverDependencyRegistry.driverDependencyFactory().getFleetInteractor(this),
new FusedLocationDeviceLocator(this),
new MetadataReader(this).getStringMetadata(CommonMetadataKeys.DEFAULT_FLEET_ID).getOrThrow()
);
final Disposable subscription = fleetResolver.resolveFleet(
SharedPreferencesUserStorageReader.forContext(this)
.observeStringPreference(StorageKeys.FLEET_ID)
)
.doOnDispose(fleetResolver::shutDown)
.subscribe(fleet -> ResolvedFleet.get().setFleetInfo(fleet));
compositeDisposable.add(subscription);
}
@Override
public void back() {
super.onBackPressed();
}
@Override
public void openMenu() {
menuController.openMenu();
}
@Override
public void loggedOut() {
Intent intent = new Intent(this, LaunchActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/MainViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app;
import ai.rideos.android.common.viewmodel.ViewModel;
import ai.rideos.android.driver_app.offline.GoOnlineListener;
import ai.rideos.android.driver_app.online.idle.GoOfflineListener;
import ai.rideos.android.driver_app.vehicle_unregistered.DoneRegisteringVehicleListener;
import ai.rideos.android.model.MainViewState;
import io.reactivex.Observable;
public interface MainViewModel extends ViewModel, GoOfflineListener, GoOnlineListener, DoneRegisteringVehicleListener {
void initialize();
Observable<MainViewState> getMainViewState();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/dependency/DefaultDriverDependencyFactory.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.dependency;
import ai.rideos.android.common.app.CommonMetadataKeys;
import ai.rideos.android.common.app.MetadataReader;
import ai.rideos.android.common.app.dependency.DefaultCommonDependencyFactory;
import ai.rideos.android.common.app.menu_navigator.DefaultMenuOptions;
import ai.rideos.android.common.app.menu_navigator.MenuOptionFragmentRegistry;
import ai.rideos.android.common.app.menu_navigator.account_settings.AccountSettingsFragment;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.grpc.ChannelProvider;
import ai.rideos.android.common.interactors.mapbox.MapboxApiInteractor;
import ai.rideos.android.common.model.MenuOption;
import ai.rideos.android.driver_app.MainFragment;
import ai.rideos.android.driver_app.R;
import ai.rideos.android.driver_app.menu.developer_options.DriverDeveloperOptionsFragment;
import ai.rideos.android.interactors.DefaultDriverPlanInteractor;
import ai.rideos.android.interactors.DefaultDriverVehicleInteractor;
import ai.rideos.android.interactors.DriverPlanInteractor;
import ai.rideos.android.interactors.DriverVehicleInteractor;
import android.content.Context;
public class DefaultDriverDependencyFactory extends DefaultCommonDependencyFactory implements DriverDependencyFactory {
@Override
public DriverPlanInteractor getDriverPlanInteractor(final Context context) {
return new DefaultDriverPlanInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(context));
}
@Override
public DriverVehicleInteractor getDriverVehicleInteractor(final Context context) {
return new DefaultDriverVehicleInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(context));
}
@Override
public MapboxApiInteractor getMapboxApiInteractor(final Context context) {
return new MapboxApiInteractor(context);
}
@Override
public MenuOptionFragmentRegistry getMenuOptions(final Context context) {
final MenuOptionFragmentRegistry registry = new MenuOptionFragmentRegistry(
new MenuOption(
DefaultMenuOptions.HOME.getId(),
context.getString(R.string.home_menu_option_title),
R.drawable.ic_home_24dp
),
MainFragment::new
)
.registerOption(
new MenuOption(
DefaultMenuOptions.ACCOUNT_SETTINGS.getId(),
context.getString(R.string.account_settings_menu_option_title),
R.drawable.ic_person_24dp
),
AccountSettingsFragment::new
);
final boolean shouldShowDeveloperOptions = new MetadataReader(context)
.getBooleanMetadata(CommonMetadataKeys.ENABLE_DEVELOPER_OPTIONS_KEY)
.getOrDefault(false);
if (shouldShowDeveloperOptions) {
registry.registerOption(
new MenuOption(
DefaultMenuOptions.DEVELOPER_OPTIONS.getId(),
context.getString(R.string.developer_options_menu_option_title),
R.drawable.ic_settings
),
DriverDeveloperOptionsFragment::new
);
}
return registry;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/dependency/DriverDependencyFactory.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.dependency;
import ai.rideos.android.common.app.dependency.CommonDependencyFactory;
import ai.rideos.android.common.app.menu_navigator.MenuOptionFragmentRegistry;
import ai.rideos.android.common.interactors.mapbox.MapboxApiInteractor;
import ai.rideos.android.interactors.DriverPlanInteractor;
import ai.rideos.android.interactors.DriverVehicleInteractor;
import android.content.Context;
public interface DriverDependencyFactory extends CommonDependencyFactory {
DriverPlanInteractor getDriverPlanInteractor(final Context context);
DriverVehicleInteractor getDriverVehicleInteractor(final Context context);
MapboxApiInteractor getMapboxApiInteractor(final Context context);
MenuOptionFragmentRegistry getMenuOptions(final Context context);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/dependency/DriverDependencyRegistry.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.dependency;
import ai.rideos.android.common.app.dependency.CommonDependencyRegistry;
import ai.rideos.android.common.app.dependency.MapDependencyFactory;
public class DriverDependencyRegistry {
private static DriverDependencyFactory DRIVER_DEPENDENCY_FACTORY;
private static MapDependencyFactory MAP_DEPENDENCY_FACTORY;
public static void init(final MapDependencyFactory mapDependencyFactory) {
init(new DefaultDriverDependencyFactory(), mapDependencyFactory);
}
public static void init(final DriverDependencyFactory driverDependencyFactory,
final MapDependencyFactory mapDependencyFactory) {
DRIVER_DEPENDENCY_FACTORY = driverDependencyFactory;
MAP_DEPENDENCY_FACTORY = mapDependencyFactory;
CommonDependencyRegistry.init(driverDependencyFactory, mapDependencyFactory);
}
public static DriverDependencyFactory driverDependencyFactory() {
if (DRIVER_DEPENDENCY_FACTORY == null) {
throw new RuntimeException(
"Driver dependency factory not set. Call DriverDependencyRegistry.init() before accessing " +
"driverDependencyFactory()"
);
}
return DRIVER_DEPENDENCY_FACTORY;
}
public static MapDependencyFactory mapDependencyFactory() {
if (MAP_DEPENDENCY_FACTORY == null) {
throw new RuntimeException(
"Map dependency factory not set. Call DriverDependencyRegistry.init() before accessing " +
"mapDependencyFactory()"
);
}
return MAP_DEPENDENCY_FACTORY;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/launch/LaunchActivity.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.launch;
import ai.rideos.android.common.R;
import ai.rideos.android.common.app.launch.LaunchPresenter;
import ai.rideos.android.common.app.launch.login.LoginPresenter;
import ai.rideos.android.common.app.launch.permissions.PermissionsPresenter;
import ai.rideos.android.driver_app.MainFragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Arrays;
public class LaunchActivity extends AppCompatActivity {
private LaunchPresenter launchViewController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
launchViewController = new LaunchPresenter(
this,
Arrays.asList(
LoginPresenter::new,
PermissionsPresenter::new
),
this::doneLaunching
);
launchViewController.attach(findViewById(android.R.id.content));
}
private void doneLaunching() {
Intent intent = new Intent(this, MainFragmentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
@Override
public void onDestroy() {
super.onDestroy();
launchViewController.detach();
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
launchViewController.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/menu | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/menu/developer_options/DefaultDriverDeveloperOptionsViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.menu.developer_options;
import ai.rideos.android.common.user_storage.UserStorageReader;
import ai.rideos.android.common.user_storage.UserStorageWriter;
import ai.rideos.android.settings.DriverStorageKeys;
import io.reactivex.Observable;
public class DefaultDriverDeveloperOptionsViewModel implements DriverDeveloperOptionsViewModel {
private final UserStorageReader reader;
private final UserStorageWriter writer;
public DefaultDriverDeveloperOptionsViewModel(final UserStorageReader reader,
final UserStorageWriter writer) {
this.reader = reader;
this.writer = writer;
}
@Override
public Observable<Boolean> isNavigationSimulationEnabled() {
return reader.observeBooleanPreference(DriverStorageKeys.SIMULATE_NAVIGATION)
.firstOrError()
.toObservable();
}
@Override
public void setNavigationSimulationEnabled(final boolean enabled) {
writer.storeBooleanPreference(DriverStorageKeys.SIMULATE_NAVIGATION, enabled);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/menu | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/menu/developer_options/DriverDeveloperOptionsFragment.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.menu.developer_options;
import ai.rideos.android.common.app.menu_navigator.developer_options.DeveloperOptionsFragment;
import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageReader;
import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageWriter;
import ai.rideos.android.driver_app.R;
import android.os.Bundle;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class DriverDeveloperOptionsFragment extends DeveloperOptionsFragment {
private CompositeDisposable compositeDisposable;
private DriverDeveloperOptionsViewModel viewModel;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.viewModel = new DefaultDriverDeveloperOptionsViewModel(
SharedPreferencesUserStorageReader.forContext(getContext()),
SharedPreferencesUserStorageWriter.forContext(getContext())
);
}
@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
final View view = super.onCreateView(inflater, container, savedInstanceState);
final ViewGroup extraSettingsContainer = view.findViewById(R.id.extra_settings_container);
final View driverSettings = inflater.inflate(R.layout.driver_developer_options, extraSettingsContainer, false);
extraSettingsContainer.addView(driverSettings);
return view;
}
@Override
public void onStart() {
super.onStart();
final View view = getView();
final Switch simulateNavigationSwitch = view.findViewById(R.id.simulate_navigation_switch);
simulateNavigationSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
viewModel.setNavigationSimulationEnabled(isChecked);
});
compositeDisposable = new CompositeDisposable();
compositeDisposable.add(
viewModel.isNavigationSimulationEnabled().observeOn(AndroidSchedulers.mainThread())
.subscribe(selectionEnabled -> {
simulateNavigationSwitch.setEnabled(true);
simulateNavigationSwitch.setChecked(selectionEnabled);
})
);
}
public void onStop() {
super.onStop();
compositeDisposable.dispose();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/menu | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/menu/developer_options/DriverDeveloperOptionsViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.menu.developer_options;
import io.reactivex.Observable;
public interface DriverDeveloperOptionsViewModel {
Observable<Boolean> isNavigationSimulationEnabled();
void setNavigationSimulationEnabled(final boolean simulated);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation/DefaultExternalRouteNavigationViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.navigation;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.interactors.RouteInteractor;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.model.RouteInfoModel;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import androidx.core.util.Pair;
import com.goebl.simplify.PointExtractor;
import com.goebl.simplify.Simplify;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.BehaviorSubject;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import timber.log.Timber;
public class DefaultExternalRouteNavigationViewModel implements ExternalRouteNavigationViewModel {
private static final int RETRY_COUNT = 3;
private static final int DEFAULT_MAX_COORDINATES = 500;
private static final float DEFAULT_SIMPLIFICATION_TOLERANCE = 0.002f;
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final BehaviorSubject<LatLng> destinationSubject = BehaviorSubject.create();
private final BehaviorSubject<Optional<LocationAndHeading>> originSubject = BehaviorSubject.create();
private final RouteInteractor routeInteractor;
private final DeviceLocator deviceLocator;
private final SchedulerProvider schedulerProvider;
private final int maxCoordinatesPerRoute;
private final float simplificationTolerance;
private final Simplify<LatLng> coordinateSimplifier;
public DefaultExternalRouteNavigationViewModel(final RouteInteractor routeInteractor,
final DeviceLocator deviceLocator) {
this(
routeInteractor,
deviceLocator,
DEFAULT_MAX_COORDINATES,
DEFAULT_SIMPLIFICATION_TOLERANCE,
new Simplify<>(new LatLng[0], new LatLngPointExtractor()),
new DefaultSchedulerProvider()
);
}
public DefaultExternalRouteNavigationViewModel(final RouteInteractor routeInteractor,
final DeviceLocator deviceLocator,
final int maxCoordinatesPerRoute,
final float simplificationTolerance,
final Simplify<LatLng> coordinateSimplifier,
final SchedulerProvider schedulerProvider) {
this.schedulerProvider = schedulerProvider;
this.routeInteractor = routeInteractor;
this.deviceLocator = deviceLocator;
this.maxCoordinatesPerRoute = maxCoordinatesPerRoute;
this.simplificationTolerance = simplificationTolerance;
this.coordinateSimplifier = coordinateSimplifier;
}
@Override
public Observable<Result<List<LatLng>>> getRoute() {
// Update when destination changes or forceUpdate is called. Don't update when current location changes
return Observable.combineLatest(
originSubject.startWith(Optional.empty()).observeOn(schedulerProvider.io()),
destinationSubject.observeOn(schedulerProvider.io()),
Pair::create
)
.observeOn(schedulerProvider.computation())
// If the origin is given, then use it for the route. If not, find the last known location and use it
// as the origin.
.flatMap(originDestination -> {
if (originDestination.first.isPresent()) {
return Observable.just(Pair.create(originDestination.first.get(), originDestination.second));
} else {
return deviceLocator.getLastKnownLocation()
.map(locationAndHeading -> Pair.create(locationAndHeading, originDestination.second))
.toObservable();
}
})
.flatMap(originDestination -> routeInteractor
.getRoute(originDestination.first, new LocationAndHeading(originDestination.second, 0))
.retry(RETRY_COUNT)
.doOnError(e -> Timber.e(e, "Failed to find route to destination"))
.map(RouteInfoModel::getRoute)
)
// simplify the route so it doesn't go over mapbox limits
.map(this::simplifyRoute)
.map(Result::success)
.onErrorReturn(Result::failure);
}
private List<LatLng> simplifyRoute(final List<LatLng> originalRoute) {
if (originalRoute.size() <= maxCoordinatesPerRoute) {
return originalRoute;
}
final LatLng[] simplifiedRoute = coordinateSimplifier.simplify(
originalRoute.toArray(new LatLng[0]),
simplificationTolerance,
false
);
return Arrays.asList(simplifiedRoute);
}
@Override
public void setDestination(final LatLng destination) {
destinationSubject.onNext(destination);
}
@Override
public void didGoOffRoute(final LocationAndHeading fromLocation) {
originSubject.onNext(Optional.of(fromLocation));
}
@Override
public void destroy() {
compositeDisposable.dispose();
}
// Create point extractor to interface with simplification library's internal point representation
private static class LatLngPointExtractor implements PointExtractor<LatLng> {
// Used to improve simplification algorithm by not dealing with small decimals
private static final int COORDINATE_MULTIPLE_CONSTANT = 1000000;
@Override
public double getX(LatLng latLng) {
return latLng.getLatitude() * COORDINATE_MULTIPLE_CONSTANT;
}
@Override
public double getY(LatLng latLng) {
return latLng.getLongitude() * COORDINATE_MULTIPLE_CONSTANT;
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation/ExternalRouteNavigationViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.navigation;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.viewmodel.ViewModel;
import io.reactivex.Observable;
import java.util.List;
/**
* ExternalRouteNavigationViewModel provides a way of routing to a destination external from a navigation view.
* It provides an observable route that can change if a new destination is set or the navigation went off route.
*/
public interface ExternalRouteNavigationViewModel extends ViewModel {
/**
* Set the destination of the navigation. This value can be reused if `didGoOffRoute` is called. This method can
* be called again to update the destination.
* @param destination - coordinates to route to.
*/
void setDestination(final LatLng destination);
/**
* Notify the view model that the navigation went off the route, prompting a re-route.
*/
void didGoOffRoute(final LocationAndHeading fromLocation);
/**
* Get the route to display in navigation.
* @return list of coordinates representing the route.
*/
Observable<Result<List<LatLng>>> getRoute();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation/NavigationDoneListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.navigation;
public interface NavigationDoneListener {
// Useful for setting an initial done listener instead of null checking
NavigationDoneListener NOOP = new NavigationDoneListener() {
@Override
public void finishedNavigation() {
}
@Override
public void finishedNavigationWithError(final Throwable throwable) {
}
};
void finishedNavigation();
void finishedNavigationWithError(final Throwable throwable);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation/mapbox/MapboxDeviceLocator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.navigation.mapbox;
import ai.rideos.android.common.device.AndroidPermissionsChecker;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.device.PermissionsChecker;
import ai.rideos.android.common.device.PermissionsNotGrantedException;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.utils.Locations;
import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import androidx.annotation.NonNull;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineCallback;
import com.mapbox.android.core.location.LocationEngineRequest;
import com.mapbox.android.core.location.LocationEngineResult;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Single;
import io.reactivex.disposables.Disposables;
import timber.log.Timber;
/**
* MapboxDeviceLocator is a device locator that uses Mapbox's LocationEngine class. This class itself uses almost the
* same interface as FusedLocationProviderClient, so this implementation is very close to FusedLocationDeviceLocator.
*/
public class MapboxDeviceLocator implements DeviceLocator {
private final LocationEngine mapboxLocationEngine;
private final PermissionsChecker permissionsChecker;
private final SchedulerProvider schedulerProvider;
public MapboxDeviceLocator(final Context context, final LocationEngine mapboxLocationEngine) {
this(mapboxLocationEngine, new AndroidPermissionsChecker(context), new DefaultSchedulerProvider());
}
public MapboxDeviceLocator(final LocationEngine mapboxLocationEngine,
final PermissionsChecker permissionsChecker,
final SchedulerProvider schedulerProvider) {
this.mapboxLocationEngine = mapboxLocationEngine;
this.permissionsChecker = permissionsChecker;
this.schedulerProvider = schedulerProvider;
}
@Override
public Observable<LocationAndHeading> observeCurrentLocation(final int pollIntervalMillis) {
final LocationEngineRequest locationRequest = new LocationEngineRequest.Builder(pollIntervalMillis)
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
.build();
return Observable.create(new LocationEngineObservableOnSubscribe(locationRequest))
.subscribeOn(schedulerProvider.mainThread());
}
@SuppressLint("MissingPermission") // This is checked in PermissionsChecker
@Override
public Single<LocationAndHeading> getLastKnownLocation() {
if (!permissionsChecker.areLocationPermissionsGranted()) {
return Single.error(new PermissionsNotGrantedException("Location permissions not granted"));
}
return Single.<Location>create(
emitter -> mapboxLocationEngine.getLastLocation(new LocationEngineCallback<LocationEngineResult>() {
@Override
public void onSuccess(final LocationEngineResult result) {
emitter.onSuccess(result.getLastLocation());
}
@Override
public void onFailure(@NonNull final Exception exception) {
emitter.onError(exception);
}
})
)
.map(location -> new LocationAndHeading(
Locations.getLatLngFromAndroidLocation(location),
location.getBearing()
))
.subscribeOn(schedulerProvider.mainThread());
}
/**
* Create an ObservableOnSubscribe, which starts emitting items when subscribed to. In this case, when the observable
* is subscribed to, location updates begin and when disposed, the locations stop.
*/
private class LocationEngineObservableOnSubscribe implements ObservableOnSubscribe<LocationAndHeading> {
private final LocationEngineRequest locationRequest;
LocationEngineObservableOnSubscribe(final LocationEngineRequest locationRequest) {
this.locationRequest = locationRequest;
}
@SuppressLint("MissingPermission") // This is checked in PermissionsChecker
@Override
public void subscribe(final ObservableEmitter<LocationAndHeading> emitter) {
if (!permissionsChecker.areLocationPermissionsGranted()) {
emitter.onError(new PermissionsNotGrantedException("Location permissions not granted"));
}
final DefaultLocationCallback callback = new DefaultLocationCallback(emitter);
mapboxLocationEngine.requestLocationUpdates(locationRequest, callback, null);
emitter.setDisposable(Disposables.fromAction(() -> dispose(callback)));
}
private void dispose(final DefaultLocationCallback listener) {
mapboxLocationEngine.removeLocationUpdates(listener);
}
}
/**
* Callback that emits a LatLng coordinate whenever onLocationResult is called.
*/
private static class DefaultLocationCallback implements LocationEngineCallback<LocationEngineResult> {
private final ObservableEmitter<LocationAndHeading> emitter;
DefaultLocationCallback(final ObservableEmitter<LocationAndHeading> emitter) {
this.emitter = emitter;
}
@Override
public void onSuccess(final LocationEngineResult result) {
final Location lastLocation = result.getLastLocation();
if (lastLocation != null) {
this.emitter.onNext(new LocationAndHeading(
Locations.getLatLngFromAndroidLocation(lastLocation),
lastLocation.getBearing()
));
}
}
@Override
public void onFailure(@NonNull final Exception exception) {
// Don't throw exceptions for transient errors, just log.
Timber.e(exception, "Failed to get location");
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation/mapbox/MapboxNavigationFragment.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.navigation.mapbox;
import ai.rideos.android.common.architecture.ControllerTypes;
import ai.rideos.android.common.architecture.FragmentViewController;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.device.FusedLocationDeviceLocator;
import ai.rideos.android.common.interactors.mapbox.MapboxApiInteractor;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageReader;
import ai.rideos.android.common.utils.Locations;
import ai.rideos.android.device.SimulatedDeviceLocator;
import ai.rideos.android.driver_app.R;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import ai.rideos.android.driver_app.navigation.DefaultExternalRouteNavigationViewModel;
import ai.rideos.android.driver_app.navigation.ExternalRouteNavigationViewModel;
import ai.rideos.android.driver_app.navigation.NavigationDoneListener;
import ai.rideos.android.driver_app.navigation.mapbox.MapboxNavigationFragment.NavigationArgs;
import ai.rideos.android.settings.DriverStorageKeys;
import android.content.DialogInterface;
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineProvider;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.services.android.navigation.ui.v5.NavigationView;
import com.mapbox.services.android.navigation.ui.v5.NavigationViewOptions;
import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.RouteListener;
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import java.io.Serializable;
public class MapboxNavigationFragment extends FragmentViewController<NavigationArgs, NavigationDoneListener>
implements RouteListener, NavigationListener, ProgressChangeListener {
public static class NavigationArgs implements Serializable {
private final LatLng destination;
private final boolean useExternalRouting;
public NavigationArgs(final LatLng destination, final boolean useExternalRouting) {
this.destination = destination;
this.useExternalRouting = useExternalRouting;
}
}
@Override
public ControllerTypes<NavigationArgs, NavigationDoneListener> getTypes() {
return new ControllerTypes<>(NavigationArgs.class, NavigationDoneListener.class);
}
private CompositeDisposable compositeDisposable;
@Nullable
private LocationEngine mapboxLocationEngine;
private MapboxNavigationViewModel mapboxViewModel;
private ExternalRouteNavigationViewModel externalNavViewModel;
private AlertDialog alertDialog;
private NavigationView navigationView;
private boolean shouldSimulateRoute;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
compositeDisposable = new CompositeDisposable();
shouldSimulateRoute = SharedPreferencesUserStorageReader.forContext(getContext())
.getBooleanPreference(DriverStorageKeys.SIMULATE_NAVIGATION);
final DeviceLocator deviceLocator;
if (shouldSimulateRoute) {
mapboxLocationEngine = null;
deviceLocator = SimulatedDeviceLocator.get(getContext());
} else {
mapboxLocationEngine = LocationEngineProvider.getBestLocationEngine(getContext());
deviceLocator = new MapboxDeviceLocator(getContext(), mapboxLocationEngine);
}
mapboxViewModel = new MapboxNavigationViewModel(
deviceLocator,
new MapboxApiInteractor(getContext())
);
if (getArgs().useExternalRouting) {
externalNavViewModel = new DefaultExternalRouteNavigationViewModel(
DriverDependencyRegistry.driverDependencyFactory().getRouteInteractor(getContext()),
new FusedLocationDeviceLocator(getContext())
);
}
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
alertDialog = new AlertDialog.Builder(getContext())
.setTitle(R.string.nav_failure_alert_title)
.setMessage(R.string.nav_failure_alert_message)
.setPositiveButton(
R.string.nav_failure_alert_retry_button,
(dialog, i) -> initiateRouteRequest()
)
.create();
return inflater.inflate(R.layout.mapbox_nav_view, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
navigationView = view.findViewById(R.id.nav_view);
navigationView.onCreate(savedInstanceState);
// the view model is subscribed to when the view is created because the navigation always runs as long as it's
// been created, ignoring if the app is closed or in the background
compositeDisposable.add(
mapboxViewModel.getInitialCameraPosition().observeOn(AndroidSchedulers.mainThread())
.subscribe(cameraPosition -> navigationView.initialize(running -> onNavigationReady(), cameraPosition))
);
}
private void onNavigationReady() {
compositeDisposable.add(
mapboxViewModel.getDirections().observeOn(AndroidSchedulers.mainThread())
.subscribe(directionsResult -> {
if (directionsResult.isFailure()) {
showAlertOnFailure(directionsResult.getError());
} else {
final NavigationViewOptions options = NavigationViewOptions.builder()
.shouldSimulateRoute(shouldSimulateRoute)
.directionsRoute(directionsResult.get())
.progressChangeListener(this)
.routeListener(this)
.navigationListener(this)
.locationEngine(mapboxLocationEngine)
.build();
navigationView.startNavigation(options);
}
})
);
if (externalNavViewModel != null) {
compositeDisposable.add(
externalNavViewModel.getRoute().observeOn(AndroidSchedulers.mainThread())
.subscribe(routeResult -> {
if (routeResult.isSuccess()) {
mapboxViewModel.matchDirectionsToRoute(routeResult.get());
} else {
showAlertOnFailure(routeResult.getError());
}
})
);
}
initiateRouteRequest();
}
private void initiateRouteRequest() {
if (externalNavViewModel != null) {
externalNavViewModel.setDestination(getArgs().destination);
} else {
mapboxViewModel.routeTo(getArgs().destination);
}
}
// Display an alert that allows the user to either exit navigation or retry navigation
private void showAlertOnFailure(final Throwable e) {
if (alertDialog.isShowing()) {
return;
}
alertDialog.setButton(
DialogInterface.BUTTON_NEGATIVE,
getString(R.string.nav_failure_alert_exit_button),
(dialog, i) -> getListener().finishedNavigationWithError(e)
);
alertDialog.show();
}
@Override
public void onStart() {
super.onStart();
navigationView.onStart();
}
@Override
public void onResume() {
super.onResume();
navigationView.onResume();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
navigationView.onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
}
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
navigationView.onRestoreInstanceState(savedInstanceState);
}
}
@Override
public void onPause() {
super.onPause();
navigationView.onPause();
}
@Override
public void onStop() {
super.onStop();
navigationView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
navigationView.onLowMemory();
}
@Override
public void onDestroyView() {
super.onDestroyView();
compositeDisposable.dispose();
navigationView.onDestroy();
}
//////////////
// Mapbox Listeners
//////////////
@Override
public boolean allowRerouteFrom(final Point offRoutePoint, final float heading) {
if (externalNavViewModel != null) {
externalNavViewModel.didGoOffRoute(new LocationAndHeading(
new LatLng(offRoutePoint.latitude(), offRoutePoint.longitude()),
heading
));
return false;
}
// Otherwise, let mapbox figure out re-route
return true;
}
@Override
public void onOffRoute(final Point offRoutePoint) {
// Do nothing, we don't care about this
}
@Override
public void onRerouteAlong(final DirectionsRoute directionsRoute) {
// Do nothing, we don't care about this
}
@Override
public void onFailedReroute(final String errorMessage) {
// Do nothing, we don't care about this
}
@Override
public void onArrival() {
navigationView.stopNavigation();
getListener().finishedNavigation();
}
@Override
public void onCancelNavigation() {
navigationView.stopNavigation();
getListener().finishedNavigation();
}
@Override
public void onNavigationFinished() {
navigationView.stopNavigation();
getListener().finishedNavigation();
}
@Override
public void onNavigationRunning() {
}
@Override
public void onProgressChange(final Location location, final RouteProgress routeProgress) {
if (shouldSimulateRoute) {
SimulatedDeviceLocator.get(getContext()).updateSimulatedLocation(new LocationAndHeading(
Locations.getLatLngFromAndroidLocation(location),
Locations.getHeadingFromAndroidLocationOrDefault(location, 0f)
));
}
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/navigation/mapbox/MapboxNavigationViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.navigation.mapbox;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.viewmodel.ViewModel;
import ai.rideos.android.common.interactors.mapbox.MapboxApiInteractor;
import androidx.core.util.Pair;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.PublishSubject;
import java.util.List;
import java.util.stream.Collectors;
/**
* MapboxNavigationViewModel is used only for MapboxNavigationFragment and only has one implementation. There is no need
* to generalize this view model since it should only be used directly with mapbox objects.
*/
public class MapboxNavigationViewModel implements ViewModel {
private static final int INITIAL_TILT_DEGREES = 45; // Degrees from straight down;
private static final int INITIAL_ZOOM_LEVEL = 15;
private static final int DEFAULT_RETRY_COUNT = 2;
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final BehaviorSubject<Result<DirectionsRoute>> directionsToDisplay = BehaviorSubject.create();
private final PublishSubject<LatLng> destinationsToRoute = PublishSubject.create();
private final PublishSubject<List<LatLng>> routesToMatch = PublishSubject.create();
private final DeviceLocator deviceLocator;
private final SchedulerProvider schedulerProvider;
public MapboxNavigationViewModel(final DeviceLocator deviceLocator,
final MapboxApiInteractor mapboxInteractor) {
this(deviceLocator, mapboxInteractor, new DefaultSchedulerProvider(), DEFAULT_RETRY_COUNT);
}
public MapboxNavigationViewModel(final DeviceLocator deviceLocator,
final MapboxApiInteractor mapboxInteractor,
final SchedulerProvider schedulerProvider,
final int retryCount) {
this.schedulerProvider = schedulerProvider;
this.deviceLocator = deviceLocator;
// listen for last known location
compositeDisposable.addAll(
subscribeToMapMatching(mapboxInteractor, retryCount),
subscribeToDirections(mapboxInteractor, retryCount)
);
}
/**
* Call into Mapbox's map matching API to match a list of coordinates to a route
* TODO: check that the route is < 100 points long, and simplify the route if so
* @param route - list of coordinates representing the requested route
*/
public void matchDirectionsToRoute(final List<LatLng> route) {
routesToMatch.onNext(route);
}
/**
* Directly route to a destination using Mapbox's directions API
* @param destination - destination of navigation
*/
public void routeTo(final LatLng destination) {
destinationsToRoute.onNext(destination);
}
/**
* Get the initial camera position to zoom in on. This alleviates issues of the camera being too far zoomed out
*
* @return
*/
public Single<CameraPosition> getInitialCameraPosition() {
return deviceLocator.getLastKnownLocation()
.observeOn(schedulerProvider.computation())
.map(locationAndHeading -> new CameraPosition.Builder()
.target(new com.mapbox.mapboxsdk.geometry.LatLng(
locationAndHeading.getLatLng().getLatitude(),
locationAndHeading.getLatLng().getLongitude()
))
.bearing(locationAndHeading.getHeading())
.tilt(INITIAL_TILT_DEGREES)
.zoom(INITIAL_ZOOM_LEVEL)
.build()
);
}
/**
* Get the result of either map matching or routing to display in the navigation view.
* @return - successful result of directions if API calls were successful.
*/
public Observable<Result<DirectionsRoute>> getDirections() {
return directionsToDisplay;
}
private Disposable subscribeToMapMatching(final MapboxApiInteractor mapboxInteractor,
final int retryCount) {
return routesToMatch.observeOn(schedulerProvider.computation())
.map(route -> route.stream()
.map(latLng -> Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()))
.collect(Collectors.toList())
)
.flatMap(coordinates -> mapboxInteractor.matchCoordinatesToDirections(coordinates)
.retry(retryCount)
.map(Result::success)
.onErrorReturn(Result::failure)
)
.subscribe(directionsToDisplay::onNext);
}
private Disposable subscribeToDirections(final MapboxApiInteractor mapboxInteractor,
final int retryCount) {
return destinationsToRoute
.observeOn(schedulerProvider.computation())
.flatMap(destination -> deviceLocator.getLastKnownLocation()
.toObservable()
.map(origin -> Pair.create(origin.getLatLng(), destination))
)
.flatMap(pudo ->
mapboxInteractor.getDirectionsToDestination(
Point.fromLngLat(pudo.first.getLongitude(), pudo.first.getLatitude()),
Point.fromLngLat(pudo.second.getLongitude(), pudo.second.getLatitude())
)
.retry(retryCount)
.map(Result::success)
.onErrorReturn(Result::failure)
)
.subscribe(directionsToDisplay::onNext);
}
@Override
public void destroy() {
compositeDisposable.dispose();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/offline/DefaultOfflineViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.offline;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.viewmodel.progress.ProgressSubject;
import ai.rideos.android.common.viewmodel.progress.ProgressSubject.ProgressState;
import ai.rideos.android.interactors.DriverVehicleInteractor;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
public class DefaultOfflineViewModel implements OfflineViewModel {
private final User user;
private final DriverVehicleInteractor vehicleInteractor;
private final ProgressSubject progressSubject = new ProgressSubject();
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
public DefaultOfflineViewModel(final User user,
final DriverVehicleInteractor vehicleInteractor) {
this.user = user;
this.vehicleInteractor = vehicleInteractor;
}
@Override
public Observable<ProgressState> getGoingOnlineProgress() {
return progressSubject.observeProgress();
}
@Override
public void goOnline() {
compositeDisposable.add(
progressSubject.followAsyncOperation(vehicleInteractor.markVehicleReady(user.getId()))
);
}
@Override
public void destroy() {
compositeDisposable.dispose();
vehicleInteractor.shutDown();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/offline/GoOnlineListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.offline;
public interface GoOnlineListener {
void didGoOnline();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/offline/OfflineFragment.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.offline;
import ai.rideos.android.common.app.map.MapRelay;
import ai.rideos.android.common.app.menu_navigator.OpenMenuListener;
import ai.rideos.android.common.app.progress.ProgressConnector;
import ai.rideos.android.common.architecture.ControllerTypes;
import ai.rideos.android.common.architecture.EmptyArg;
import ai.rideos.android.common.architecture.FragmentViewController;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.view.layout.TopDetailView;
import ai.rideos.android.common.viewmodel.map.FollowCurrentLocationMapStateProvider;
import ai.rideos.android.common.viewmodel.map.MapStateProvider;
import ai.rideos.android.device.PotentiallySimulatedDeviceLocator;
import ai.rideos.android.driver_app.R;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import androidx.annotation.NonNull;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class OfflineFragment extends FragmentViewController<EmptyArg, GoOnlineListener> {
private CompositeDisposable compositeDisposable;
private MapStateProvider mapStateProvider;
private OfflineViewModel offlineViewModel;
@Override
public ControllerTypes<EmptyArg, GoOnlineListener> getTypes() {
return new ControllerTypes<>(EmptyArg.class, GoOnlineListener.class);
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapStateProvider = new FollowCurrentLocationMapStateProvider(
new PotentiallySimulatedDeviceLocator(getContext()),
R.mipmap.car
);
offlineViewModel = new DefaultOfflineViewModel(
User.get(getContext()),
DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(getContext())
);
}
@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
final View view = TopDetailView.inflateViewWithDetail(inflater, container, R.layout.offline);
final View topButton = view.findViewById(R.id.top_button);
final Activity activity = getActivity();
if (activity instanceof OpenMenuListener) {
topButton.setOnClickListener(click -> ((OpenMenuListener) activity).openMenu());
}
return view;
}
@Override
public void onStart() {
super.onStart();
final View view = getView();
final Switch onlineOfflineToggle = view.findViewById(R.id.online_toggle_switch);
onlineOfflineToggle.setOnCheckedChangeListener((v, checked) -> {
if (checked) {
offlineViewModel.goOnline();
}
});
final GoOnlineListener listener = getListener();
compositeDisposable = new CompositeDisposable();
compositeDisposable.add(MapRelay.get().connectToProvider(mapStateProvider));
final ProgressConnector progressConnector = ProgressConnector.newBuilder()
.toggleSwitchWhenLoading(onlineOfflineToggle)
.alertOnFailure(getContext(), R.string.go_online_failure_message)
.doOnSuccess(listener::didGoOnline)
.build();
compositeDisposable.add(
progressConnector.connect(
offlineViewModel.getGoingOnlineProgress().observeOn(AndroidSchedulers.mainThread())
)
);
}
@Override
public void onStop() {
super.onStop();
compositeDisposable.dispose();
offlineViewModel.destroy();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/offline/OfflineViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.offline;
import ai.rideos.android.common.viewmodel.ViewModel;
import ai.rideos.android.common.viewmodel.progress.ProgressSubject.ProgressState;
import io.reactivex.Observable;
public interface OfflineViewModel extends ViewModel {
enum OfflineViewState {
OFFLINE,
GOING_ONLINE,
ONLINE,
FAILED_TO_GO_ONLINE
}
Observable<ProgressState> getGoingOnlineProgress();
void goOnline();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/DefaultExternalVehicleRouteSynchronizer.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.interactors.RouteInteractor;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.model.RouteInfoModel;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.interactors.DriverVehicleInteractor;
import ai.rideos.android.model.VehicleDisplayRouteLeg;
import ai.rideos.android.model.VehiclePlan;
import ai.rideos.android.model.VehiclePlan.Action.ActionType;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import androidx.core.util.Pair;
import io.reactivex.Completable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import timber.log.Timber;
public class DefaultExternalVehicleRouteSynchronizer implements ExternalVehicleRouteSynchronizer {
private final DriverVehicleInteractor vehicleInteractor;
private final RouteInteractor routeInteractor;
private final User user;
private final SchedulerProvider schedulerProvider;
public DefaultExternalVehicleRouteSynchronizer(final DriverVehicleInteractor vehicleInteractor,
final RouteInteractor routeInteractor,
final User user) {
this(vehicleInteractor, routeInteractor, user, new DefaultSchedulerProvider());
}
public DefaultExternalVehicleRouteSynchronizer(final DriverVehicleInteractor vehicleInteractor,
final RouteInteractor routeInteractor,
final User user,
final SchedulerProvider schedulerProvider) {
this.vehicleInteractor = vehicleInteractor;
this.routeInteractor = routeInteractor;
this.user = user;
this.schedulerProvider = schedulerProvider;
}
@Override
public Completable synchronizeForPlan(final VehiclePlan plan, final LocationAndHeading currentLocation) {
final List<Waypoint> filteredSteps = filterRoutableSteps(plan);
if (filteredSteps.isEmpty()) {
// Just update the location
return vehicleInteractor.updateVehicleLocation(user.getId(), currentLocation)
.doOnError(e -> Timber.e(e, "Could not synchronize vehicle route with backend"))
.onErrorComplete();
}
return routeInteractor.getRouteForWaypoints(getRoutableWaypoints(filteredSteps, currentLocation))
.observeOn(schedulerProvider.computation())
.map(routes -> collectRoutesByStep(routes, filteredSteps))
.map(routesByStep -> toDisplayRoutes(plan, routesByStep))
.flatMapCompletable(routeLegs -> Completable.mergeArray(
vehicleInteractor.updateVehicleLocation(user.getId(), currentLocation),
vehicleInteractor.updateVehicleRoute(user.getId(), routeLegs)
))
.doOnError(e -> Timber.e(e, "Could not synchronize vehicle route with backend"))
.onErrorComplete();
}
private static Map<Pair<String, String>, RouteInfoModel> collectRoutesByStep(
final List<RouteInfoModel> routes,
final List<Waypoint> routableWaypoints
) {
return IntStream.range(0, routableWaypoints.size())
.boxed()
.collect(Collectors.toMap(i -> toWaypointKey(routableWaypoints.get(i)), routes::get));
}
private static List<VehicleDisplayRouteLeg> toDisplayRoutes(
final VehiclePlan plan,
final Map<Pair<String, String>, RouteInfoModel> routesByStep
) {
final List<VehicleDisplayRouteLeg> routes = new ArrayList<>(routesByStep.size());
for (int i = 0; i < plan.getWaypoints().size(); i++) {
final Waypoint currentWaypoint = plan.getWaypoints().get(i);
if (!isRoutable(currentWaypoint)) {
continue;
}
final Pair<String, String> waypointKey = toWaypointKey(currentWaypoint);
if (i == 0) {
routes.add(new VehicleDisplayRouteLeg(null, waypointKey, routesByStep.get(waypointKey)));
} else {
final Waypoint previousWaypoint = plan.getWaypoints().get(i - 1);
routes.add(new VehicleDisplayRouteLeg(
Pair.create(
previousWaypoint.getTaskId(),
// previous step should be the last step in the previous waypoint
previousWaypoint.getStepIds().get(previousWaypoint.getStepIds().size() - 1)
),
waypointKey,
routesByStep.get(waypointKey)
));
}
}
return routes;
}
private static List<Waypoint> filterRoutableSteps(final VehiclePlan plan) {
return plan.getWaypoints().stream()
.filter(DefaultExternalVehicleRouteSynchronizer::isRoutable)
.collect(Collectors.toList());
}
private static boolean isRoutable(final Waypoint waypoint) {
return waypoint.getAction().getActionType() == ActionType.DRIVE_TO_DROP_OFF
|| waypoint.getAction().getActionType() == ActionType.DRIVE_TO_PICKUP;
}
private static List<LatLng> getRoutableWaypoints(final List<Waypoint> waypoints,
final LocationAndHeading currentLocation) {
final List<LatLng> routableWaypoints = new ArrayList<>(waypoints.size() + 1);
routableWaypoints.add(currentLocation.getLatLng());
routableWaypoints.addAll(
waypoints.stream()
.map(waypoint -> waypoint.getAction().getDestination())
.collect(Collectors.toList())
);
return routableWaypoints;
}
/**
* This key identifies a Waypoint based on the current assumption that each waypoint has a unique task and first
* step.
*/
private static Pair<String, String> toWaypointKey(final Waypoint waypoint) {
return Pair.create(waypoint.getTaskId(), waypoint.getStepIds().get(0));
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/DefaultOnlineViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.reactive.Notification;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.driver_app.online.idle.GoOfflineListener;
import ai.rideos.android.interactors.DriverPlanInteractor;
import ai.rideos.android.model.OnlineViewState;
import ai.rideos.android.model.VehiclePlan;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import androidx.core.util.Pair;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.PublishSubject;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import timber.log.Timber;
public class DefaultOnlineViewModel implements OnlineViewModel {
private static final int DEFAULT_POLL_INTERVAL_MILLIS = 2000;
private static final int DEFAULT_RETRY_COUNT = 2;
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
// send any value to this subject to initiate syncing the vehicle state
private final PublishSubject<Boolean> forceSyncSubject = PublishSubject.create();
private final BehaviorSubject<VehiclePlan> currentPlan;
private final BehaviorSubject<Boolean> shouldShowTripDetailsSubject = BehaviorSubject.createDefault(false);
private final BehaviorSubject<LocationAndHeading> currentLocation = BehaviorSubject.create();
private final GoOfflineListener listener;
private final DriverPlanInteractor planInteractor;
private final User user;
private final SchedulerProvider schedulerProvider;
private final int retryCount;
public DefaultOnlineViewModel(final GoOfflineListener listener,
final DriverPlanInteractor planInteractor,
final ExternalVehicleRouteSynchronizer vehicleRouteSynchronizer,
final DeviceLocator deviceLocator,
final User user) {
this(
listener,
planInteractor,
vehicleRouteSynchronizer,
deviceLocator,
user,
new DefaultSchedulerProvider(),
DEFAULT_POLL_INTERVAL_MILLIS,
DEFAULT_RETRY_COUNT
);
}
public DefaultOnlineViewModel(final GoOfflineListener listener,
final DriverPlanInteractor planInteractor,
final ExternalVehicleRouteSynchronizer vehicleRouteSynchronizer,
final DeviceLocator deviceLocator,
final User user,
final SchedulerProvider schedulerProvider,
final int pollIntervalMillis,
final int retryCount) {
this.listener = listener;
this.planInteractor = planInteractor;
this.user = user;
this.schedulerProvider = schedulerProvider;
this.retryCount = retryCount;
currentPlan = BehaviorSubject.createDefault(new VehiclePlan(Collections.emptyList()));
compositeDisposable.addAll(
deviceLocator.observeCurrentLocation(pollIntervalMillis)
.subscribe(currentLocation::onNext),
subscribeToPlanUpdates(pollIntervalMillis),
currentPlan.toFlowable(BackpressureStrategy.LATEST)
.flatMapSingle(plan -> currentLocation.firstOrError().map(location -> Pair.create(plan, location)))
.flatMapCompletable(planAndLocation ->
vehicleRouteSynchronizer.synchronizeForPlan(planAndLocation.first, planAndLocation.second)
)
.subscribe()
);
}
@Override
public void pickedUpPassenger() {
forceSyncSubject.onNext(true);
}
@Override
public void finishedDriving() {
forceSyncSubject.onNext(true);
}
@Override
public Observable<OnlineViewState> getOnlineViewState() {
return Observable.combineLatest(
currentPlan,
shouldShowTripDetailsSubject,
Pair::create
)
.observeOn(schedulerProvider.computation())
.map(planAndShouldShowDetails -> {
final VehiclePlan plan = planAndShouldShowDetails.first;
final boolean shouldShowTripDetails = planAndShouldShowDetails.second;
if (shouldShowTripDetails) {
return OnlineViewState.tripDetails(plan);
}
if (plan.getWaypoints().isEmpty()) {
return OnlineViewState.idle();
}
final Waypoint currentWaypoint = plan.getWaypoints().get(0);
switch (currentWaypoint.getAction().getActionType()) {
case DRIVE_TO_PICKUP:
return OnlineViewState.drivingToPickup(currentWaypoint);
case DRIVE_TO_DROP_OFF:
return OnlineViewState.drivingToDropOff(currentWaypoint);
case LOAD_RESOURCE:
return OnlineViewState.waitingForPassenger(currentWaypoint);
}
throw new IllegalStateException("Unknown step action " + currentWaypoint.getAction().getActionType().name());
})
// If the display is equivalent (same display type AND current waypoint), don't update
.distinctUntilChanged();
}
@Override
public void didGoOffline() {
listener.didGoOffline();
}
private Disposable subscribeToPlanUpdates(final int updateIntervalMillis) {
// Poll current location to sync at a certain interval. If an update should be forced, a notification is
// emitted to forceSyncSubject.
return Flowable.combineLatest(
Observable.interval(0, updateIntervalMillis, TimeUnit.MILLISECONDS, schedulerProvider.io())
.toFlowable(BackpressureStrategy.DROP),
forceSyncSubject.startWith(true).observeOn(schedulerProvider.computation())
.toFlowable(BackpressureStrategy.DROP), // we don't care about missed syncs
(timer, forceSync) -> Notification.create()
)
.observeOn(schedulerProvider.computation())
// Drop location updates when getPlanForVehicle is backed up
.onBackpressureDrop()
// Sync the vehicle state using the latest state
.flatMap(notification -> getPlanAndRetry())
// Ignore failures (it will be retried after the polling interval regardless)
.filter(Result::isSuccess)
.map(Result::get)
.subscribe(currentPlan::onNext);
}
private Flowable<Result<VehiclePlan>> getPlanAndRetry() {
return planInteractor.getPlanForVehicle(user.getId())
.observeOn(schedulerProvider.computation())
// Retry a few times
.retry(retryCount)
.doOnError(e -> Timber.e(e, "Failed to get plan"))
// Return success/failure based on error emitted
.map(Result::success)
.onErrorReturn(Result::failure)
// We should only receive one plan at a time, so drop the rest if this ever happens
.toFlowable(BackpressureStrategy.DROP);
}
@Override
public void destroy() {
compositeDisposable.dispose();
}
@Override
public void openTripDetails() {
shouldShowTripDetailsSubject.onNext(true);
}
@Override
public void closeTripDetails() {
shouldShowTripDetailsSubject.onNext(false);
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/ExternalVehicleRouteSynchronizer.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.model.VehiclePlan;
import io.reactivex.Completable;
public interface ExternalVehicleRouteSynchronizer {
ExternalVehicleRouteSynchronizer NOOP = (plan, location) -> Completable.complete();
Completable synchronizeForPlan(final VehiclePlan plan, final LocationAndHeading currentLocation);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/OnlineCoordinator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online;
import ai.rideos.android.common.architecture.Coordinator;
import ai.rideos.android.common.architecture.EmptyArg;
import ai.rideos.android.common.architecture.NavigationController;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.device.PotentiallySimulatedDeviceLocator;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import ai.rideos.android.driver_app.online.driving.DrivingCoordinator;
import ai.rideos.android.driver_app.online.driving.DrivingInput;
import ai.rideos.android.driver_app.online.idle.GoOfflineListener;
import ai.rideos.android.driver_app.online.idle.IdleFragment;
import ai.rideos.android.driver_app.online.trip_details.TripDetailsFragment;
import ai.rideos.android.driver_app.online.trip_details.TripDetailsFragment.TripDetailsArgs;
import ai.rideos.android.driver_app.online.waiting_for_pickup.WaitingForPickupFragment;
import ai.rideos.android.driver_app.online.waiting_for_pickup.WaitingForPickupFragment.WaitingForPickupArgs;
import android.content.Context;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
/**
* OnlineViewController is a parent view controller for controlling the view when the driver's vehicle goes online.
*/
public class OnlineCoordinator implements Coordinator<EmptyArg> {
private CompositeDisposable compositeDisposable;
private final NavigationController navController;
private final OnlineViewModel onlineViewModel;
private final Coordinator<DrivingInput> drivingCoordinator;
private Coordinator activeChild = null;
public OnlineCoordinator(final Context context,
final NavigationController navController,
final GoOfflineListener goOfflineListener) {
this.navController = navController;
final User user = User.get(context);
onlineViewModel = new DefaultOnlineViewModel(
goOfflineListener,
DriverDependencyRegistry.driverDependencyFactory().getDriverPlanInteractor(context),
new DefaultExternalVehicleRouteSynchronizer(
DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(context),
DriverDependencyRegistry.driverDependencyFactory().getRouteInteractor(context),
user
),
new PotentiallySimulatedDeviceLocator(context),
user
);
drivingCoordinator = new DrivingCoordinator(navController, onlineViewModel);
}
@Override
public void start(final EmptyArg emptyArg) {
final Disposable subscription = onlineViewModel.getOnlineViewState()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(state -> {
stopChild();
switch (state.getDisplayType()) {
case IDLE:
navController.navigateTo(new IdleFragment(), EmptyArg.create(), onlineViewModel);
return;
case DRIVING_TO_PICKUP:
drivingCoordinator.start(DrivingInput.forPickup(state.getCurrentWaypoint()));
activeChild = drivingCoordinator;
return;
case DRIVING_TO_DROP_OFF:
drivingCoordinator.start(DrivingInput.forDropOff(state.getCurrentWaypoint()));
activeChild = drivingCoordinator;
return;
case WAITING_FOR_PASSENGER:
navController.navigateTo(
new WaitingForPickupFragment(),
new WaitingForPickupArgs(state.getCurrentWaypoint()),
onlineViewModel
);
return;
case TRIP_DETAILS:
navController.navigateTo(
new TripDetailsFragment(),
new TripDetailsArgs(state.getVehiclePlan()),
onlineViewModel
);
}
});
compositeDisposable = new CompositeDisposable();
compositeDisposable.add(subscription);
}
private void stopChild() {
if (activeChild != null) {
activeChild.stop();
}
activeChild = null;
}
@Override
public void stop() {
stopChild();
compositeDisposable.dispose();
}
@Override
public void destroy() {
drivingCoordinator.destroy();
onlineViewModel.destroy();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/OnlineViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online;
import ai.rideos.android.common.viewmodel.ViewModel;
import ai.rideos.android.driver_app.online.driving.DrivingListener;
import ai.rideos.android.driver_app.online.idle.GoOfflineListener;
import ai.rideos.android.driver_app.online.trip_details.TripDetailsListener;
import ai.rideos.android.driver_app.online.waiting_for_pickup.WaitingForPickupListener;
import ai.rideos.android.model.OnlineViewState;
import io.reactivex.Observable;
public interface OnlineViewModel extends ViewModel, GoOfflineListener, DrivingListener, WaitingForPickupListener,
TripDetailsListener {
Observable<OnlineViewState> getOnlineViewState();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/OpenTripDetailsListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online;
public interface OpenTripDetailsListener {
void openTripDetails();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/DefaultDrivingViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving;
import static ai.rideos.android.common.viewmodel.state_machine.StateTransitions.transitionIf;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.viewmodel.state_machine.StateMachine;
import ai.rideos.android.model.DrivingViewState;
import ai.rideos.android.model.DrivingViewState.DrivingStep;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
public class DefaultDrivingViewModel implements DrivingViewModel {
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final StateMachine<DrivingViewState> stateMachine;
private final DrivingListener listener;
private final DrivingStep initialStep;
public DefaultDrivingViewModel(final DrivingListener listener) {
this(
listener,
DrivingStep.DRIVE_PENDING,
new DefaultSchedulerProvider()
);
}
public DefaultDrivingViewModel(final DrivingListener listener,
final DrivingStep initialStep,
final SchedulerProvider schedulerProvider) {
this.listener = listener;
this.initialStep = initialStep;
stateMachine = new StateMachine<>(schedulerProvider);
compositeDisposable.add(stateMachine.start());
}
@Override
public void initialize(final Waypoint waypointToComplete) {
stateMachine.initialize(new DrivingViewState(initialStep, waypointToComplete));
}
@Override
public void startNavigation() {
stateMachine.transition(transitionIf(
state -> state.getDrivingStep() == DrivingStep.DRIVE_PENDING,
state -> new DrivingViewState(DrivingStep.NAVIGATING, state.getWaypointToComplete())
));
}
@Override
public void finishedNavigation() {
stateMachine.transition(transitionIf(
state -> state.getDrivingStep() == DrivingStep.NAVIGATING,
state -> new DrivingViewState(DrivingStep.CONFIRMING_ARRIVAL, state.getWaypointToComplete())
));
}
@Override
public void finishedNavigationWithError(final Throwable throwable) {
stateMachine.transition(transitionIf(
state -> state.getDrivingStep() == DrivingStep.NAVIGATING,
// Go right to confirm arrival, so that the driver can continue with the trip despite navigation issues.
state -> new DrivingViewState(DrivingStep.CONFIRMING_ARRIVAL, state.getWaypointToComplete())
));
}
@Override
public void didConfirmArrival() {
stateMachine.transition(transitionIf(
state -> state.getDrivingStep() == DrivingStep.CONFIRMING_ARRIVAL,
state -> {
listener.finishedDriving();
return state;
}
));
}
@Override
public Observable<DrivingViewState> getDrivingViewState() {
return stateMachine.observeCurrentState().distinctUntilChanged();
}
@Override
public void destroy() {
compositeDisposable.dispose();
}
@Override
public void openTripDetails() {
listener.openTripDetails();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/DrivingCoordinator.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving;
import ai.rideos.android.common.architecture.Coordinator;
import ai.rideos.android.common.architecture.NavigationController;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.driver_app.navigation.mapbox.MapboxNavigationFragment;
import ai.rideos.android.driver_app.navigation.mapbox.MapboxNavigationFragment.NavigationArgs;
import ai.rideos.android.driver_app.online.driving.confirming_arrival.ConfirmingArrivalFragment;
import ai.rideos.android.driver_app.online.driving.confirming_arrival.ConfirmingArrivalFragment.ConfirmingArrivalArgs;
import ai.rideos.android.driver_app.online.driving.drive_pending.DrivePendingFragment;
import ai.rideos.android.driver_app.online.driving.drive_pending.DrivePendingFragment.DrivePendingArgs;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
public class DrivingCoordinator implements Coordinator<DrivingInput> {
private CompositeDisposable compositeDisposable;
private final NavigationController navController;
private final DrivingViewModel drivingViewModel;
public DrivingCoordinator(final NavigationController navController,
final DrivingListener drivingListener) {
this.navController = navController;
this.drivingViewModel = new DefaultDrivingViewModel(drivingListener);
}
@Override
public void start(final DrivingInput input) {
drivingViewModel.initialize(input.getWaypointToComplete());
compositeDisposable = new CompositeDisposable();
final Disposable stateSubscription = drivingViewModel.getDrivingViewState()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(state -> {
final LatLng destination = state.getWaypointToComplete().getAction().getDestination();
switch (state.getDrivingStep()) {
case DRIVE_PENDING:
navController.navigateTo(
new DrivePendingFragment(),
new DrivePendingArgs(
input.getDrivePendingTitleResourceId(),
input.getDrawableDestinationPinAttr(),
destination
),
drivingViewModel
);
break;
case NAVIGATING:
navController.navigateTo(
new MapboxNavigationFragment(),
new NavigationArgs(destination, true),
drivingViewModel
);
break;
case CONFIRMING_ARRIVAL:
navController.navigateTo(
new ConfirmingArrivalFragment(),
new ConfirmingArrivalArgs(
input.getArrivalTitleResourceId(),
input.getDrawableDestinationPinAttr(),
state.getWaypointToComplete()
),
drivingViewModel
);
break;
}
});
compositeDisposable.add(stateSubscription);
}
@Override
public void stop() {
compositeDisposable.dispose();
}
@Override
public void destroy() {
drivingViewModel.destroy();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/DrivingInput.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving;
import ai.rideos.android.driver_app.R;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import androidx.annotation.AttrRes;
import androidx.annotation.StringRes;
public class DrivingInput {
private final int drivePendingTitleResourceId;
private final int arrivalTitleResourceId;
private final int drawableDestinationPinAttr;
private final Waypoint waypointToComplete;
public static DrivingInput forPickup(final Waypoint waypointToComplete) {
return new DrivingInput(
R.string.drive_pending_pickup_title_text,
R.string.confirming_arrival_pickup_title_text,
R.attr.rideos_pickup_pin,
waypointToComplete
);
}
public static DrivingInput forDropOff(final Waypoint waypointToComplete) {
return new DrivingInput(
R.string.drive_pending_drop_off_title_text,
R.string.confirming_arrival_drop_off_title_text,
R.attr.rideos_drop_off_pin,
waypointToComplete
);
}
private DrivingInput(@StringRes final int drivePendingTitleResourceId,
@StringRes final int arrivalTitleResourceId,
@AttrRes final int drawableDestinationPinAttr,
final Waypoint waypointToComplete) {
this.drivePendingTitleResourceId = drivePendingTitleResourceId;
this.arrivalTitleResourceId = arrivalTitleResourceId;
this.drawableDestinationPinAttr = drawableDestinationPinAttr;
this.waypointToComplete = waypointToComplete;
}
public int getDrivePendingTitleResourceId() {
return drivePendingTitleResourceId;
}
public int getArrivalTitleResourceId() {
return arrivalTitleResourceId;
}
public Waypoint getWaypointToComplete() {
return waypointToComplete;
}
public int getDrawableDestinationPinAttr() {
return drawableDestinationPinAttr;
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/DrivingListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving;
import ai.rideos.android.driver_app.online.OpenTripDetailsListener;
public interface DrivingListener extends OpenTripDetailsListener {
void finishedDriving();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/DrivingViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving;
import ai.rideos.android.common.viewmodel.ViewModel;
import ai.rideos.android.driver_app.navigation.NavigationDoneListener;
import ai.rideos.android.driver_app.online.driving.confirming_arrival.ConfirmArrivalListener;
import ai.rideos.android.driver_app.online.driving.drive_pending.DrivePendingListener;
import ai.rideos.android.model.DrivingViewState;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import io.reactivex.Observable;
public interface DrivingViewModel extends ViewModel, DrivePendingListener, NavigationDoneListener, ConfirmArrivalListener {
void initialize(final Waypoint waypointToComplete);
Observable<DrivingViewState> getDrivingViewState();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/FinishedDrivingListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving;
import ai.rideos.android.model.VehiclePlan.Waypoint;
public interface FinishedDrivingListener {
void finishedDriving(final Waypoint completedWaypoint);
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/confirming_arrival/ConfirmArrivalListener.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving.confirming_arrival;
import ai.rideos.android.driver_app.online.OpenTripDetailsListener;
public interface ConfirmArrivalListener extends OpenTripDetailsListener {
void didConfirmArrival();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/confirming_arrival/ConfirmingArrivalFragment.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving.confirming_arrival;
import ai.rideos.android.common.app.map.MapRelay;
import ai.rideos.android.common.app.progress.ProgressConnector;
import ai.rideos.android.common.architecture.ControllerTypes;
import ai.rideos.android.common.architecture.FragmentViewController;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.view.layout.BottomDetailAndButtonView;
import ai.rideos.android.common.view.layout.LoadableDividerView;
import ai.rideos.android.common.view.resources.AndroidResourceProvider;
import ai.rideos.android.common.view.resources.ResourceProvider;
import ai.rideos.android.device.PotentiallySimulatedDeviceLocator;
import ai.rideos.android.driver_app.R;
import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry;
import ai.rideos.android.driver_app.online.driving.confirming_arrival.ConfirmingArrivalFragment.ConfirmingArrivalArgs;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import java.io.Serializable;
public class ConfirmingArrivalFragment extends FragmentViewController<ConfirmingArrivalArgs, ConfirmArrivalListener> {
public static class ConfirmingArrivalArgs implements Serializable {
private final int titleTextResourceId;
private final int drawableDestinationPinAttr;
private final Waypoint waypoint;
public ConfirmingArrivalArgs(@StringRes final int titleTextResourceId,
@AttrRes final int drawableDestinationPinAttr,
final Waypoint waypoint) {
this.titleTextResourceId = titleTextResourceId;
this.drawableDestinationPinAttr = drawableDestinationPinAttr;
this.waypoint = waypoint;
}
}
private CompositeDisposable compositeDisposable;
private ConfirmingArrivalViewModel arrivalViewModel;
@Override
public ControllerTypes<ConfirmingArrivalArgs, ConfirmArrivalListener> getTypes() {
return new ControllerTypes<>(ConfirmingArrivalArgs.class, ConfirmArrivalListener.class);
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ResourceProvider resourceProvider = AndroidResourceProvider.forContext(getContext());
arrivalViewModel = new DefaultConfirmingArrivalViewModel(
DriverDependencyRegistry.mapDependencyFactory().getGeocodeInteractor(getContext()),
DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(getContext()),
User.get(getContext()),
getArgs().waypoint,
resourceProvider.getDrawableId(getArgs().drawableDestinationPinAttr),
new PotentiallySimulatedDeviceLocator(getContext()),
resourceProvider
);
}
@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
final View view = BottomDetailAndButtonView.inflateWithMenuButton(inflater, container, getActivity(), R.layout.confirming_arrival);
final TextView titleView = view.findViewById(R.id.confirming_arrival_title);
titleView.setText(getArgs().titleTextResourceId);
return view;
}
@Override
public void onStart() {
super.onStart();
final View view = getView();
final Button confirmArrivalButton = view.findViewById(R.id.confirm_arrival_button);
confirmArrivalButton.setOnClickListener(click -> arrivalViewModel.confirmArrival());
final View expandDetailsButton = view.findViewById(R.id.expand_trip_details_button);
expandDetailsButton.setOnClickListener(click -> getListener().openTripDetails());
final LoadableDividerView loadableDividerView = view.findViewById(R.id.loadable_divider);
final TextView detailText = view.findViewById(R.id.confirming_arrival_detail);
final Disposable mapSubscription = MapRelay.get().connectToProvider(arrivalViewModel);
final Disposable detailSubscription = arrivalViewModel.getArrivalDetailText()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(detailText::setText);
compositeDisposable = new CompositeDisposable();
compositeDisposable.addAll(mapSubscription, detailSubscription);
final ProgressConnector progressConnector = ProgressConnector.newBuilder()
.disableButtonWhenLoadingOrSuccessful(confirmArrivalButton)
.showLoadableDividerWhenLoading(loadableDividerView)
.alertOnFailure(getContext(), R.string.confirm_arrival_failure_message)
.doOnSuccess(() -> getListener().didConfirmArrival())
.build();
compositeDisposable.add(
progressConnector.connect(
arrivalViewModel.getConfirmingArrivalProgress().observeOn(AndroidSchedulers.mainThread())
)
);
}
@Override
public void onStop() {
super.onStop();
compositeDisposable.dispose();
}
@Override
public void onDestroy() {
super.onDestroy();
arrivalViewModel.destroy();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/confirming_arrival/ConfirmingArrivalViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving.confirming_arrival;
import ai.rideos.android.common.viewmodel.ViewModel;
import ai.rideos.android.common.viewmodel.map.MapStateProvider;
import ai.rideos.android.common.viewmodel.progress.ProgressSubject.ProgressState;
import io.reactivex.Observable;
public interface ConfirmingArrivalViewModel extends ViewModel, MapStateProvider {
Observable<String> getArrivalDetailText();
void confirmArrival();
Observable<ProgressState> getConfirmingArrivalProgress();
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/confirming_arrival/DefaultConfirmingArrivalViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving.confirming_arrival;
import ai.rideos.android.common.authentication.User;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.interactors.GeocodeInteractor;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.model.map.CameraUpdate;
import ai.rideos.android.common.model.map.CenterPin;
import ai.rideos.android.common.model.map.DrawableMarker;
import ai.rideos.android.common.model.map.DrawableMarker.Anchor;
import ai.rideos.android.common.model.map.DrawablePath;
import ai.rideos.android.common.model.map.LatLngBounds;
import ai.rideos.android.common.model.map.MapSettings;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.utils.Markers;
import ai.rideos.android.common.utils.Paths;
import ai.rideos.android.common.view.resources.ResourceProvider;
import ai.rideos.android.common.viewmodel.progress.ProgressSubject;
import ai.rideos.android.common.viewmodel.progress.ProgressSubject.ProgressState;
import ai.rideos.android.interactors.DriverVehicleInteractor;
import ai.rideos.android.model.VehiclePlan.Waypoint;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.BehaviorSubject;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import timber.log.Timber;
public class DefaultConfirmingArrivalViewModel implements ConfirmingArrivalViewModel {
private static final int RETRY_COUNT = 2;
private static final int POLL_INTERVAL_MILLIS = 1000;
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final GeocodeInteractor geocodeInteractor;
private final DriverVehicleInteractor vehicleInteractor;
private final User user;
private final SchedulerProvider schedulerProvider;
private final Waypoint waypoint;
private final LatLng destination;
private final int drawableDestinationPin;
private final ResourceProvider resourceProvider;
private final BehaviorSubject<LocationAndHeading> currentLocation = BehaviorSubject.create();
private final ProgressSubject progressSubject = new ProgressSubject();
public DefaultConfirmingArrivalViewModel(final GeocodeInteractor geocodeInteractor,
final DriverVehicleInteractor vehicleInteractor,
final User user,
final Waypoint waypoint,
final int drawableDestinationPin,
final DeviceLocator deviceLocator,
final ResourceProvider resourceProvider) {
this(
geocodeInteractor,
vehicleInteractor,
user,
waypoint,
drawableDestinationPin,
deviceLocator,
resourceProvider,
new DefaultSchedulerProvider()
);
}
public DefaultConfirmingArrivalViewModel(final GeocodeInteractor geocodeInteractor,
final DriverVehicleInteractor vehicleInteractor,
final User user,
final Waypoint waypoint,
final int drawableDestinationPin,
final DeviceLocator deviceLocator,
final ResourceProvider resourceProvider,
final SchedulerProvider schedulerProvider) {
this.geocodeInteractor = geocodeInteractor;
this.vehicleInteractor = vehicleInteractor;
this.user = user;
this.schedulerProvider = schedulerProvider;
this.waypoint = waypoint;
destination = waypoint.getAction().getDestination();
this.drawableDestinationPin = drawableDestinationPin;
this.resourceProvider = resourceProvider;
compositeDisposable.add(
deviceLocator.observeCurrentLocation(POLL_INTERVAL_MILLIS).subscribe(currentLocation::onNext)
);
}
@Override
public Observable<String> getArrivalDetailText() {
return geocodeInteractor.getBestReverseGeocodeResult(destination)
.observeOn(schedulerProvider.computation())
.retry(RETRY_COUNT)
.doOnError(error -> Timber.e(error, "Failed to geocode location"))
.onErrorReturn(Result::failure)
.map(result -> {
if (result.isFailure()) {
return "";
}
return result.get().getDisplayName();
});
}
@Override
public void confirmArrival() {
compositeDisposable.add(
progressSubject.followAsyncOperation(
vehicleInteractor.finishSteps(
user.getId(),
waypoint.getTaskId(),
waypoint.getStepIds()
)
)
);
}
@Override
public Observable<ProgressState> getConfirmingArrivalProgress() {
return progressSubject.observeProgress();
}
@Override
public Observable<MapSettings> getMapSettings() {
return Observable.just(new MapSettings(false, CenterPin.hidden()));
}
@Override
public Observable<CameraUpdate> getCameraUpdates() {
return currentLocation.observeOn(schedulerProvider.computation())
.map(location -> {
final LatLngBounds bounds = Paths.getBoundsForPath(Arrays.asList(
location.getLatLng(),
destination
));
return CameraUpdate.fitToBounds(bounds);
});
}
@Override
public Observable<Map<String, DrawableMarker>> getMarkers() {
return currentLocation.observeOn(schedulerProvider.computation())
.map(location -> {
final Map<String, DrawableMarker> markers = new HashMap<>();
markers.put(
"destination",
new DrawableMarker(destination, 0, drawableDestinationPin, Anchor.BOTTOM)
);
markers.put(
Markers.VEHICLE_KEY,
Markers.getVehicleMarker(location.getLatLng(), location.getHeading(), resourceProvider)
);
return markers;
});
}
@Override
public Observable<List<DrawablePath>> getPaths() {
return Observable.just(Collections.emptyList());
}
@Override
public void destroy() {
compositeDisposable.dispose();
}
}
|
0 | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving | java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/driving/drive_pending/DefaultDrivePendingViewModel.java | /**
* Copyright 2018-2019 rideOS, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.rideos.android.driver_app.online.driving.drive_pending;
import ai.rideos.android.common.device.DeviceLocator;
import ai.rideos.android.common.interactors.RouteInteractor;
import ai.rideos.android.common.model.LatLng;
import ai.rideos.android.common.model.LocationAndHeading;
import ai.rideos.android.common.model.RouteInfoModel;
import ai.rideos.android.common.model.map.CameraUpdate;
import ai.rideos.android.common.model.map.CenterPin;
import ai.rideos.android.common.model.map.DrawableMarker;
import ai.rideos.android.common.model.map.DrawableMarker.Anchor;
import ai.rideos.android.common.model.map.DrawablePath;
import ai.rideos.android.common.model.map.LatLngBounds;
import ai.rideos.android.common.model.map.MapSettings;
import ai.rideos.android.common.reactive.Result;
import ai.rideos.android.common.reactive.SchedulerProvider;
import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider;
import ai.rideos.android.common.utils.Markers;
import ai.rideos.android.common.utils.Paths;
import ai.rideos.android.common.view.resources.ResourceProvider;
import ai.rideos.android.common.view.strings.RouteFormatter;
import ai.rideos.android.driver_app.R;
import androidx.core.util.Pair;
import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.SingleSubject;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import timber.log.Timber;
public class DefaultDrivePendingViewModel implements DrivePendingViewModel {
private static final int RETRY_COUNT = 2;
private static final float PATH_WIDTH = 10.0f;
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final SingleSubject<Result<RouteInfoModel>> routeInfoResult = SingleSubject.create();
private final BehaviorSubject<LocationAndHeading> currentLocation = BehaviorSubject.create();
private final RouteInteractor routeInteractor;
private final SchedulerProvider schedulerProvider;
private final ResourceProvider resourceProvider;
private final LatLng destination;
private final int drawableDestinationPin;
private final RouteFormatter routeFormatter;
public DefaultDrivePendingViewModel(final DeviceLocator deviceLocator,
final RouteInteractor routeInteractor,
final ResourceProvider resourceProvider,
final LatLng destination,
final int drawableDestinationPin) {
this(
deviceLocator,
routeInteractor,
resourceProvider,
destination,
drawableDestinationPin,
new DefaultSchedulerProvider(),
new RouteFormatter(resourceProvider)
);
}
public DefaultDrivePendingViewModel(final DeviceLocator deviceLocator,
final RouteInteractor routeInteractor,
final ResourceProvider resourceProvider,
final LatLng destination,
final int drawableDestinationPin,
final SchedulerProvider schedulerProvider,
final RouteFormatter routeFormatter) {
this.routeInteractor = routeInteractor;
this.schedulerProvider = schedulerProvider;
this.destination = destination;
this.resourceProvider = resourceProvider;
this.drawableDestinationPin = drawableDestinationPin;
this.routeFormatter = routeFormatter;
compositeDisposable.addAll(
deviceLocator.getLastKnownLocation().subscribe(currentLocation::onNext),
fetchRouteInfo().subscribe(routeInfoResult::onSuccess)
);
}
@Override
public Observable<String> getRouteDetailText() {
return routeInfoResult.observeOn(schedulerProvider.computation())
.toObservable()
.map(routeFormatter::getDisplayStringForRouteResult);
}
@Override
public void destroy() {
compositeDisposable.dispose();
routeInteractor.shutDown();
}
@Override
public Observable<MapSettings> getMapSettings() {
return Observable.just(new MapSettings(false, CenterPin.hidden()));
}
@Override
public Observable<CameraUpdate> getCameraUpdates() {
return routeInfoResult.observeOn(schedulerProvider.computation())
.toObservable()
.filter(Result::isSuccess)
.map(routeResponse -> {
final LatLngBounds bounds = Paths.getBoundsForPath(routeResponse.get().getRoute(), destination);
return CameraUpdate.fitToBounds(bounds);
});
}
@Override
public Observable<Map<String, DrawableMarker>> getMarkers() {
return Observable.combineLatest(
routeInfoResult.toObservable().filter(Result::isSuccess),
currentLocation,
Pair::create
)
.observeOn(schedulerProvider.computation())
.map(routeAndLocation -> {
final List<LatLng> path = routeAndLocation.first.get().getRoute();
final LocationAndHeading vehicleLocation = routeAndLocation.second;
final Map<String, DrawableMarker> markers = new HashMap<>();
if (path.size() > 0) {
markers.put(
"destination",
new DrawableMarker(destination, 0, drawableDestinationPin, Anchor.BOTTOM)
);
markers.put(
Markers.VEHICLE_KEY,
Markers.getVehicleMarker(
vehicleLocation.getLatLng(),
vehicleLocation.getHeading(),
resourceProvider
)
);
}
return markers;
});
}
@Override
public Observable<List<DrawablePath>> getPaths() {
return routeInfoResult.observeOn(schedulerProvider.computation())
.toObservable()
.filter(Result::isSuccess)
.map(routeResponse -> Collections.singletonList(
new DrawablePath(
routeResponse.get().getRoute(),
PATH_WIDTH,
resourceProvider.getColor(R.attr.rideos_route_color)
)
));
}
private Observable<Result<RouteInfoModel>> fetchRouteInfo() {
return currentLocation
.observeOn(schedulerProvider.computation())
.flatMap(origin -> routeInteractor.getRoute(origin.getLatLng(), destination))
.retry(RETRY_COUNT)
.map(Result::success)
.doOnError(error -> Timber.e(error, "Failed to get route to destination"))
.onErrorReturn(Result::failure);
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.