index
int64
repo_id
string
file_path
string
content
string
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/DrivePendingFragment.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.app.map.MapRelay; import ai.rideos.android.common.architecture.ControllerTypes; import ai.rideos.android.common.architecture.FragmentViewController; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.view.layout.BottomDetailAndButtonView; import ai.rideos.android.common.view.resources.AndroidResourceProvider; 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.drive_pending.DrivePendingFragment.DrivePendingArgs; import ai.rideos.android.view.ActionDetailView; 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 DrivePendingFragment extends FragmentViewController<DrivePendingArgs, DrivePendingListener> { public static class DrivePendingArgs implements Serializable { private final int titleTextResourceId; private final int drawableDestinationPinAttr; private final LatLng destination; public DrivePendingArgs(@StringRes final int titleTextResourceId, @AttrRes final int drawableDestinationPinAttr, final LatLng destination) { this.titleTextResourceId = titleTextResourceId; this.drawableDestinationPinAttr = drawableDestinationPinAttr; this.destination = destination; } } private CompositeDisposable compositeDisposable; private DrivePendingViewModel drivingViewModel; @Override public ControllerTypes<DrivePendingArgs, DrivePendingListener> getTypes() { return new ControllerTypes<>(DrivePendingArgs.class, DrivePendingListener.class); } @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); drivingViewModel = new DefaultDrivePendingViewModel( new PotentiallySimulatedDeviceLocator(getContext()), DriverDependencyRegistry.driverDependencyFactory().getRouteInteractor(getContext()), AndroidResourceProvider.forContext(getContext()), getArgs().destination, AndroidResourceProvider.forContext(getContext()).getDrawableId(getArgs().drawableDestinationPinAttr) ); } @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = BottomDetailAndButtonView.inflateWithMenuButton(inflater, container, getActivity(), R.layout.drive_pending); final TextView titleText = view.findViewById(R.id.drive_pending_title); titleText.setText(getArgs().titleTextResourceId); return view; } @Override public void onStart() { super.onStart(); final View view = getView(); final Button startNavButton = view.findViewById(R.id.start_nav_button); startNavButton.setOnClickListener(click -> getListener().startNavigation()); final View expandDetailsButton = view.findViewById(R.id.expand_trip_details_button); expandDetailsButton.setOnClickListener(click -> getListener().openTripDetails()); final TextView detailText = view.findViewById(R.id.drive_pending_detail); final Disposable mapSubscription = MapRelay.get().connectToProvider(drivingViewModel); final Disposable detailSubscription = drivingViewModel.getRouteDetailText() .observeOn(AndroidSchedulers.mainThread()) .subscribe(detailText::setText); compositeDisposable = new CompositeDisposable(); compositeDisposable.addAll(mapSubscription, detailSubscription); } @Override public void onStop() { super.onStop(); compositeDisposable.dispose(); } @Override public void onDestroy() { super.onDestroy(); drivingViewModel.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/drive_pending/DrivePendingListener.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.driver_app.online.OpenTripDetailsListener; public interface DrivePendingListener extends OpenTripDetailsListener { void startNavigation(); }
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/DrivePendingViewModel.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.viewmodel.ViewModel; import ai.rideos.android.common.viewmodel.map.MapStateProvider; import io.reactivex.Observable; public interface DrivePendingViewModel extends ViewModel, MapStateProvider { Observable<String> getRouteDetailText(); }
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/StartNavigationListener.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; public interface StartNavigationListener { void startNavigation(); }
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/idle/DefaultIdleViewModel.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.idle; 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 DefaultIdleViewModel implements IdleViewModel { private final User user; private final DriverVehicleInteractor vehicleInteractor; private final ProgressSubject progressSubject = new ProgressSubject(); private final CompositeDisposable compositeDisposable = new CompositeDisposable(); public DefaultIdleViewModel(final User user, final DriverVehicleInteractor vehicleInteractor) { this.user = user; this.vehicleInteractor = vehicleInteractor; } @Override public Observable<ProgressState> getGoingOfflineProgress() { return progressSubject.observeProgress(); } @Override public void goOffline() { compositeDisposable.add( progressSubject.followAsyncOperation(vehicleInteractor.markVehicleNotReady(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/online
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/idle/GoOfflineListener.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.idle; public interface GoOfflineListener { void didGoOffline(); }
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/idle/IdleFragment.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.idle; 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 IdleFragment extends FragmentViewController<EmptyArg, GoOfflineListener> { private CompositeDisposable compositeDisposable; private MapStateProvider mapStateProvider; private IdleViewModel idleViewModel; @Override public ControllerTypes<EmptyArg, GoOfflineListener> getTypes() { return new ControllerTypes<>(EmptyArg.class, GoOfflineListener.class); } @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mapStateProvider = new FollowCurrentLocationMapStateProvider( new PotentiallySimulatedDeviceLocator(getContext()), R.mipmap.car ); idleViewModel = new DefaultIdleViewModel( 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.online_idle); 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) { idleViewModel.goOffline(); } }); final GoOfflineListener listener = getListener(); compositeDisposable = new CompositeDisposable(); compositeDisposable.add(MapRelay.get().connectToProvider(mapStateProvider)); final ProgressConnector progressConnector = ProgressConnector.newBuilder() .toggleSwitchWhenLoading(onlineOfflineToggle) .alertOnFailure(getContext(), R.string.go_offline_failure_message) .doOnSuccess(listener::didGoOffline) .build(); compositeDisposable.add( progressConnector.connect( idleViewModel.getGoingOfflineProgress().observeOn(AndroidSchedulers.mainThread()) ) ); } @Override public void onStop() { super.onStop(); compositeDisposable.dispose(); idleViewModel.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/idle/IdleViewModel.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.idle; import ai.rideos.android.common.viewmodel.ViewModel; import ai.rideos.android.common.viewmodel.progress.ProgressSubject.ProgressState; import io.reactivex.Observable; public interface IdleViewModel extends ViewModel { Observable<ProgressState> getGoingOfflineProgress(); void goOffline(); }
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/trip_details/DefaultTripDetailsViewModel.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.trip_details; import ai.rideos.android.common.authentication.User; import ai.rideos.android.driver_app.online.trip_details.TripDetail.ActionToPerform; import ai.rideos.android.interactors.DriverVehicleInteractor; import ai.rideos.android.model.VehiclePlan; import ai.rideos.android.model.VehiclePlan.Action.ActionType; import ai.rideos.android.model.VehiclePlan.Waypoint; import io.reactivex.Observable; import io.reactivex.disposables.CompositeDisposable; import java.util.LinkedHashMap; import java.util.List; import java.util.stream.Collectors; import timber.log.Timber; public class DefaultTripDetailsViewModel implements TripDetailsViewModel { private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private final DriverVehicleInteractor vehicleInteractor; private final User user; private final VehiclePlan vehiclePlan; public DefaultTripDetailsViewModel(final DriverVehicleInteractor vehicleInteractor, final User user, final VehiclePlan vehiclePlan) { this.vehicleInteractor = vehicleInteractor; this.user = user; this.vehiclePlan = vehiclePlan; } @Override public Observable<List<TripDetail>> getTripDetails() { final LinkedHashMap<String, Waypoint> tripsAndNextWaypoint = new LinkedHashMap<>(); for (final Waypoint waypoint : vehiclePlan.getWaypoints()) { if (!tripsAndNextWaypoint.containsKey(waypoint.getTaskId())) { tripsAndNextWaypoint.put(waypoint.getTaskId(), waypoint); } } final List<TripDetail> tripDetails = tripsAndNextWaypoint.entrySet().stream() .map(tripAndNextWaypoint -> { final Waypoint nextWaypoint = tripAndNextWaypoint.getValue(); final ActionToPerform actionToPerform = nextWaypoint.getAction().getActionType() == ActionType.DRIVE_TO_DROP_OFF ? ActionToPerform.END_TRIP : ActionToPerform.REJECT_TRIP; return new TripDetail( nextWaypoint, actionToPerform, nextWaypoint.getAction().getTripResourceInfo().getNameOfTripRequester(), // TODO use rider count null // TODO get passenger phone from backend ); }) .collect(Collectors.toList()); return Observable.just(tripDetails); } @Override public void performActionOnTrip(final TripDetail tripDetail) { // TODO handle progress state switch (tripDetail.getActionToPerform()) { case REJECT_TRIP: compositeDisposable.add( vehicleInteractor.rejectTrip(user.getId(), tripDetail.getNextWaypoint().getTaskId()) .subscribe(() -> {}, e -> Timber.e(e, "Failed to reject trip")) ); break; case END_TRIP: compositeDisposable.add( vehicleInteractor.finishSteps( user.getId(), tripDetail.getNextWaypoint().getTaskId(), tripDetail.getNextWaypoint().getStepIds() ) .subscribe(() -> {}, e -> Timber.e(e, "Failed to end trip")) ); break; } } @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/online
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/trip_details/TripDetail.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.trip_details; import ai.rideos.android.model.VehiclePlan.Waypoint; import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; public class TripDetail { public enum ActionToPerform { REJECT_TRIP, END_TRIP } private final Waypoint nextWaypoint; private final ActionToPerform actionToPerform; private final String passengerName; @Nullable private final String passengerPhone; public TripDetail(final Waypoint nextWaypoint, final ActionToPerform actionToPerform, final String passengerName, @Nullable final String passengerPhone) { this.nextWaypoint = nextWaypoint; this.actionToPerform = actionToPerform; this.passengerName = passengerName; this.passengerPhone = passengerPhone; } public Waypoint getNextWaypoint() { return nextWaypoint; } public ActionToPerform getActionToPerform() { return actionToPerform; } public String getPassengerName() { return passengerName; } public Optional<String> getPassengerPhone() { return Optional.ofNullable(passengerPhone); } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final TripDetail that = (TripDetail) o; return nextWaypoint.equals(that.nextWaypoint) && actionToPerform == that.actionToPerform && Objects.equals(passengerName, that.passengerName) && Objects.equals(passengerPhone, that.passengerPhone); } }
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/trip_details/TripDetailsFragment.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.trip_details; 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.driver_app.R; import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry; import ai.rideos.android.driver_app.online.trip_details.TripDetailsFragment.TripDetailsArgs; import ai.rideos.android.model.VehiclePlan; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toolbar; import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import java.io.Serializable; public class TripDetailsFragment extends FragmentViewController<TripDetailsArgs, TripDetailsListener> { private CompositeDisposable compositeDisposable; private TripDetailsViewModel viewModel; public static class TripDetailsArgs implements Serializable { private final VehiclePlan vehiclePlan; public TripDetailsArgs(final VehiclePlan vehiclePlan) { this.vehiclePlan = vehiclePlan; } } @Override public ControllerTypes<TripDetailsArgs, TripDetailsListener> getTypes() { return new ControllerTypes<>(TripDetailsArgs.class, TripDetailsListener.class); } @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); viewModel = new DefaultTripDetailsViewModel( DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(getContext()), User.get(getContext()), getArgs().vehiclePlan ); } @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { return inflater.inflate(R.layout.trip_details, container, false); } @Override public void onStart() { super.onStart(); final View view = getView(); compositeDisposable = new CompositeDisposable(); final Toolbar toolbar = view.findViewById(ai.rideos.android.common.R.id.title_bar); toolbar.setNavigationOnClickListener(click -> getListener().closeTripDetails()); final RecyclerView recyclerView = view.findViewById(R.id.trip_details_recycler); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); // specify an adapter (see also next example) final TripDetailsRecyclerAdapter recyclerAdapter = new TripDetailsRecyclerAdapter( getActivity(), viewModel::performActionOnTrip ); recyclerView.setAdapter(recyclerAdapter); compositeDisposable.add( viewModel.getTripDetails().observeOn(AndroidSchedulers.mainThread()) .subscribe(recyclerAdapter::setTripDetails) ); } @Override public void onStop() { super.onStop(); compositeDisposable.dispose(); viewModel.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/trip_details/TripDetailsListener.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.trip_details; public interface TripDetailsListener { void closeTripDetails(); }
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/trip_details/TripDetailsRecyclerAdapter.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.trip_details; import ai.rideos.android.driver_app.R; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog.Builder; import androidx.recyclerview.widget.RecyclerView; import java.util.Collections; import java.util.List; public class TripDetailsRecyclerAdapter extends RecyclerView.Adapter<TripDetailsRecyclerAdapter.ViewHolder> { private List<TripDetail> tripDetails; private final Activity parentActivity; private final OnClickRowListener onClickRowListener; public static class ViewHolder extends RecyclerView.ViewHolder { // For now, each row is just a string public View view; ViewHolder(View view) { super(view); this.view = view; } } public interface OnClickRowListener { void clickedRow(final TripDetail tripDetail); } public TripDetailsRecyclerAdapter(final Activity parentActivity, final OnClickRowListener onClickRowListener) { this.parentActivity = parentActivity; this.onClickRowListener = onClickRowListener; this.tripDetails = Collections.emptyList(); } @NonNull @Override public TripDetailsRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { final View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.trip_detail_row, parent, false); return new ViewHolder(v); } @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final TextView passengerTextView = holder.view.findViewById(R.id.trip_detail_passenger_name); final TextView actionButtonText = holder.view.findViewById(R.id.trip_detail_action_button); final View contactButton = holder.view.findViewById(R.id.contact_button); final TripDetail tripDetail = tripDetails.get(position); passengerTextView.setText(tripDetail.getPassengerName()); switch (tripDetail.getActionToPerform()) { case REJECT_TRIP: actionButtonText.setText(R.string.trip_detail_reject_ride_action_button); actionButtonText.setOnClickListener(click -> checkAndPerformAction( tripDetail, R.string.trip_detail_reject_alert_title, R.string.trip_detail_reject_alert_description, R.string.trip_detail_reject_alert_positive_button )); break; case END_TRIP: actionButtonText.setText(R.string.trip_detail_end_trip_action_button); actionButtonText.setOnClickListener(click -> checkAndPerformAction( tripDetail, R.string.trip_detail_end_alert_title, R.string.trip_detail_end_alert_description, R.string.trip_detail_end_alert_positive_button )); break; } if (tripDetail.getPassengerPhone().isPresent()) { final String phoneLink = String.format("tel:%s", tripDetail.getPassengerPhone().get()); contactButton.setVisibility(View.VISIBLE); contactButton.setOnClickListener(click -> { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(phoneLink)); parentActivity.startActivity(intent); }); } else { contactButton.setVisibility(View.GONE); } } private void checkAndPerformAction(final TripDetail tripDetail, @StringRes final int alertTitle, @StringRes final int alertDescription, @StringRes final int alertPositiveText) { new Builder(parentActivity, R.style.DefaultAlertDialogTheme) .setTitle(alertTitle) .setMessage(alertDescription) .setPositiveButton(alertPositiveText, (dialog, i) -> onClickRowListener.clickedRow(tripDetail)) .setNegativeButton(R.string.trip_detail_alert_negative_button, null) .show(); } @Override public int getItemCount() { return tripDetails.size(); } public void setTripDetails(final List<TripDetail> tripDetails) { this.tripDetails = tripDetails; notifyDataSetChanged(); } }
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/trip_details/TripDetailsViewModel.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.trip_details; import ai.rideos.android.common.viewmodel.ViewModel; import io.reactivex.Observable; import java.util.List; public interface TripDetailsViewModel extends ViewModel { Observable<List<TripDetail>> getTripDetails(); void performActionOnTrip(final TripDetail tripDetail); }
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/waiting_for_pickup/DefaultWaitingForPickupViewModel.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.waiting_for_pickup; 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.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.DrawablePath; import ai.rideos.android.common.model.map.LatLngBounds; 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 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.driver_app.R; import ai.rideos.android.interactors.DriverVehicleInteractor; import ai.rideos.android.model.TripResourceInfo; 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; class DefaultWaitingForPickupViewModel implements WaitingForPickupViewModel { private static final int POLL_INTERVAL_MILLIS = 1000; private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private final Waypoint waypoint; private final DriverVehicleInteractor vehicleInteractor; private final User user; private final ResourceProvider resourceProvider; private final SchedulerProvider schedulerProvider; private final BehaviorSubject<LocationAndHeading> currentLocation = BehaviorSubject.create(); private final ProgressSubject progressSubject = new ProgressSubject(); public DefaultWaitingForPickupViewModel(final DriverVehicleInteractor vehicleInteractor, final User user, final Waypoint waypoint, final ResourceProvider resourceProvider, final DeviceLocator deviceLocator) { this(vehicleInteractor, user, waypoint, resourceProvider, deviceLocator, new DefaultSchedulerProvider()); } public DefaultWaitingForPickupViewModel(final DriverVehicleInteractor vehicleInteractor, final User user, final Waypoint waypoint, final ResourceProvider resourceProvider, final DeviceLocator deviceLocator, final SchedulerProvider schedulerProvider) { this.waypoint = waypoint; this.vehicleInteractor = vehicleInteractor; this.user = user; this.resourceProvider = resourceProvider; this.schedulerProvider = schedulerProvider; compositeDisposable.add( deviceLocator.observeCurrentLocation(POLL_INTERVAL_MILLIS).subscribe(currentLocation::onNext) ); } @Override public String getPassengersToPickupText() { final String passengersToPickupText; final TripResourceInfo tripResourceInfo = waypoint.getAction().getTripResourceInfo(); if (tripResourceInfo.getNumPassengers() > 1) { final int numberOfRidersExcludingRequester = tripResourceInfo.getNumPassengers() - 1; passengersToPickupText = String.format( "%s + %s", tripResourceInfo.getNameOfTripRequester(), numberOfRidersExcludingRequester ); } else { passengersToPickupText = tripResourceInfo.getNameOfTripRequester(); } return resourceProvider.getString(R.string.waiting_for_pickup_title_format, passengersToPickupText); } @Override public void confirmPickup() { compositeDisposable.add( progressSubject.followAsyncOperation( vehicleInteractor.finishSteps( user.getId(), waypoint.getTaskId(), waypoint.getStepIds() ) ) ); } @Override public Observable<ProgressState> getConfirmingPickupProgress() { 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(), waypoint.getAction().getDestination() )); 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( Markers.PICKUP_MARKER_KEY, Markers.getPickupMarker(waypoint.getAction().getDestination(), resourceProvider) ); 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
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/online/waiting_for_pickup/WaitingForPickupFragment.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.waiting_for_pickup; 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.device.PotentiallySimulatedDeviceLocator; import ai.rideos.android.driver_app.R; import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry; import ai.rideos.android.driver_app.online.waiting_for_pickup.WaitingForPickupFragment.WaitingForPickupArgs; 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.NonNull; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import java.io.Serializable; public class WaitingForPickupFragment extends FragmentViewController<WaitingForPickupArgs, WaitingForPickupListener> { public static class WaitingForPickupArgs implements Serializable { private final Waypoint waypointToComplete; public WaitingForPickupArgs(final Waypoint waypointToComplete) { this.waypointToComplete = waypointToComplete; } } private CompositeDisposable compositeDisposable; private WaitingForPickupViewModel viewModel; @Override public ControllerTypes<WaitingForPickupArgs, WaitingForPickupListener> getTypes() { return new ControllerTypes<>(WaitingForPickupArgs.class, WaitingForPickupListener.class); } @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); viewModel = new DefaultWaitingForPickupViewModel( DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(getContext()), User.get(getContext()), getArgs().waypointToComplete, AndroidResourceProvider.forContext(getContext()), new PotentiallySimulatedDeviceLocator(getContext()) ); } @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { return BottomDetailAndButtonView.inflateWithMenuButton(inflater, container, getActivity(), R.layout.waiting_for_pickup); } @Override public void onStart() { super.onStart(); compositeDisposable = new CompositeDisposable(); final View view = getView(); final Button confirmPickupButton = view.findViewById(R.id.confirm_pickup_button); confirmPickupButton.setOnClickListener(click -> viewModel.confirmPickup()); 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 titleView = view.findViewById(R.id.waiting_for_pickup_title); titleView.setText(viewModel.getPassengersToPickupText()); compositeDisposable.add(MapRelay.get().connectToProvider(viewModel)); final ProgressConnector progressConnector = ProgressConnector.newBuilder() .disableButtonWhenLoadingOrSuccessful(confirmPickupButton) .showLoadableDividerWhenLoading(loadableDividerView) .alertOnFailure(getContext(), R.string.waiting_for_pickup_failure_message) .doOnSuccess(() -> getListener().pickedUpPassenger()) .build(); compositeDisposable.add( progressConnector.connect( viewModel.getConfirmingPickupProgress().observeOn(AndroidSchedulers.mainThread()) ) ); } @Override public void onStop() { super.onStop(); compositeDisposable.dispose(); } @Override public void onDestroy() { super.onDestroy(); viewModel.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/waiting_for_pickup/WaitingForPickupListener.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.waiting_for_pickup; import ai.rideos.android.driver_app.online.OpenTripDetailsListener; public interface WaitingForPickupListener extends OpenTripDetailsListener { void pickedUpPassenger(); }
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/waiting_for_pickup/WaitingForPickupViewModel.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.waiting_for_pickup; 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 WaitingForPickupViewModel extends MapStateProvider, ViewModel { String getPassengersToPickupText(); void confirmPickup(); Observable<ProgressState> getConfirmingPickupProgress(); }
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/push_notifications/DriverTokenUpdaterService.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.push_notifications; import ai.rideos.android.common.authentication.User; import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry; import com.google.firebase.messaging.FirebaseMessagingService; import timber.log.Timber; public class DriverTokenUpdaterService extends FirebaseMessagingService { @Override public void onNewToken(String token) { final User user = User.get(getApplicationContext()); final String userId = user.getId(); if (userId.isEmpty()) { // User is logged out. Wait for the app to start up and log in return; } DriverDependencyRegistry.driverDependencyFactory().getDeviceRegistryInteractor(this) .registerDriverDevice(userId, token) .blockingAwait(); Timber.i("Successfully updated device for user %s and device %s", userId, token); } }
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/vehicle_unregistered/DefaultVehicleUnregisteredViewModel.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.vehicle_unregistered; 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.VehicleUnregisteredViewState; import io.reactivex.Observable; import io.reactivex.disposables.CompositeDisposable; public class DefaultVehicleUnregisteredViewModel implements VehicleUnregisteredViewModel { private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private final DoneRegisteringVehicleListener doneRegisteringListener; private final StateMachine<VehicleUnregisteredViewState> stateMachine; public DefaultVehicleUnregisteredViewModel(final DoneRegisteringVehicleListener doneRegisteringListener) { this(doneRegisteringListener, new DefaultSchedulerProvider()); } public DefaultVehicleUnregisteredViewModel(final DoneRegisteringVehicleListener doneRegisteringListener, final SchedulerProvider schedulerProvider) { this.doneRegisteringListener = doneRegisteringListener; stateMachine = new StateMachine<>(schedulerProvider); compositeDisposable.add(stateMachine.start()); } @Override public void initialize() { stateMachine.initialize(VehicleUnregisteredViewState.PRE_REGISTRATION); } @Override public Observable<VehicleUnregisteredViewState> getViewState() { return stateMachine.observeCurrentState().distinctUntilChanged(); } @Override public void startRegistration() { stateMachine.transition(state -> VehicleUnregisteredViewState.REGISTER_VEHICLE); } @Override public void cancelRegistration() { stateMachine.transition(state -> VehicleUnregisteredViewState.PRE_REGISTRATION); } @Override public void doneRegistering() { doneRegisteringListener.doneRegistering(); } @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/vehicle_unregistered/DoneRegisteringVehicleListener.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.vehicle_unregistered; public interface DoneRegisteringVehicleListener { void doneRegistering(); }
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/vehicle_unregistered/VehicleUnregisteredCoordinator.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.vehicle_unregistered; 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.driver_app.vehicle_unregistered.pre_registration.PreRegistrationFragment; import ai.rideos.android.driver_app.vehicle_unregistered.register_vehicle.RegisterVehicleFragment; import io.reactivex.disposables.CompositeDisposable; public class VehicleUnregisteredCoordinator implements Coordinator<EmptyArg> { private CompositeDisposable compositeDisposable; private final NavigationController navController; private final VehicleUnregisteredViewModel viewModel; public VehicleUnregisteredCoordinator(final NavigationController navController, final DoneRegisteringVehicleListener doneRegisteringListener) { this.navController = navController; viewModel = new DefaultVehicleUnregisteredViewModel(doneRegisteringListener); } @Override public void start(final EmptyArg emptyArg) { viewModel.initialize(); compositeDisposable = new CompositeDisposable(); compositeDisposable.add( viewModel.getViewState() .subscribe(state -> { switch (state) { case PRE_REGISTRATION: navController.navigateTo(new PreRegistrationFragment(), EmptyArg.create(), viewModel); break; case REGISTER_VEHICLE: navController.navigateTo(new RegisterVehicleFragment(), EmptyArg.create(), viewModel); break; } }) ); } @Override public void stop() { compositeDisposable.dispose(); } @Override public void destroy() { viewModel.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/vehicle_unregistered/VehicleUnregisteredViewModel.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.vehicle_unregistered; import ai.rideos.android.common.viewmodel.ViewModel; import ai.rideos.android.driver_app.vehicle_unregistered.pre_registration.PreRegistrationListener; import ai.rideos.android.driver_app.vehicle_unregistered.register_vehicle.RegisterVehicleListener; import ai.rideos.android.model.VehicleUnregisteredViewState; import io.reactivex.Observable; public interface VehicleUnregisteredViewModel extends ViewModel, PreRegistrationListener, RegisterVehicleListener { void initialize(); Observable<VehicleUnregisteredViewState> getViewState(); }
0
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered/pre_registration/PreRegistrationFragment.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.vehicle_unregistered.pre_registration; 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.view.layout.BottomDetailAndButtonView; import ai.rideos.android.driver_app.R; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import androidx.annotation.NonNull; public class PreRegistrationFragment extends FragmentViewController<EmptyArg, PreRegistrationListener> { @Override public ControllerTypes<EmptyArg, PreRegistrationListener> getTypes() { return new ControllerTypes<>(EmptyArg.class, PreRegistrationListener.class); } @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = BottomDetailAndButtonView.inflateWithMenuButton(inflater, container, getActivity(), R.layout.pre_registration); final Button startRegistrationButton = view.findViewById(R.id.start_registration_button); startRegistrationButton.setOnClickListener(click -> getListener().startRegistration()); return view; } }
0
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered/pre_registration/PreRegistrationListener.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.vehicle_unregistered.pre_registration; public interface PreRegistrationListener { void startRegistration(); }
0
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered/register_vehicle/DefaultRegisterVehicleViewModel.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.vehicle_unregistered.register_vehicle; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.model.FleetInfo; 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.VehicleRegistration; import android.telephony.PhoneNumberUtils; import io.reactivex.Completable; import io.reactivex.Observable; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.subjects.BehaviorSubject; import java.util.function.Function; import timber.log.Timber; public class DefaultRegisterVehicleViewModel implements RegisterVehicleViewModel { private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private final BehaviorSubject<String> nameSubject = BehaviorSubject.createDefault(""); private final BehaviorSubject<String> phoneSubject = BehaviorSubject.createDefault(""); private final BehaviorSubject<String> licenseSubject = BehaviorSubject.createDefault(""); private final BehaviorSubject<Integer> capacitySubject = BehaviorSubject.createDefault(0); private final DriverVehicleInteractor vehicleInteractor; private final User user; private final Observable<FleetInfo> observableFleet; private final RegisterVehicleListener registerVehicleListener; // Phone number validator is injected because the static isGlobalPhoneNumber method must be mocked in testing private final Function<String, Boolean> phoneNumberValidator; private final SchedulerProvider schedulerProvider; public DefaultRegisterVehicleViewModel(final DriverVehicleInteractor vehicleInteractor, final User user, final Observable<FleetInfo> observableFleet, final RegisterVehicleListener registerVehicleListener) { this( vehicleInteractor, user, observableFleet, registerVehicleListener, PhoneNumberUtils::isGlobalPhoneNumber, new DefaultSchedulerProvider() ); } public DefaultRegisterVehicleViewModel(final DriverVehicleInteractor vehicleInteractor, final User user, final Observable<FleetInfo> observableFleet, final RegisterVehicleListener registerVehicleListener, final Function<String, Boolean> phoneNumberValidator, final SchedulerProvider schedulerProvider) { this.vehicleInteractor = vehicleInteractor; this.user = user; this.observableFleet = observableFleet; this.registerVehicleListener = registerVehicleListener; this.phoneNumberValidator = phoneNumberValidator; this.schedulerProvider = schedulerProvider; } @Override public Observable<Boolean> isSavingEnabled() { return Observable.combineLatest( nameSubject.observeOn(schedulerProvider.io()), phoneSubject.observeOn(schedulerProvider.io()), licenseSubject.observeOn(schedulerProvider.io()), capacitySubject.observeOn(schedulerProvider.io()), VehicleRegistration::new ) .observeOn(schedulerProvider.computation()) .map(this::isVehicleRegistrationValid); } @Override public void save() { compositeDisposable.add( observableFleet.firstOrError() .flatMapCompletable(fleetInfo -> { final VehicleRegistration registration = new VehicleRegistration( nameSubject.getValue(), phoneSubject.getValue(), licenseSubject.getValue(), capacitySubject.getValue() ); // If fields become invalid between when saving is enabled and save is clicked, log // an error and move on. The saving button will disappear. if (!isVehicleRegistrationValid(registration)) { return Completable.error(new IllegalArgumentException("Invalid registration")); } return vehicleInteractor.createVehicle(user.getId(), fleetInfo.getId(), registration); }) .subscribe( registerVehicleListener::doneRegistering, // For now, just log errors, but we should probably show this to the user. e -> Timber.e(e, "Failed to create vehicle %s", user.getId()) ) ); } @Override public void setPreferredName(final String preferredName) { nameSubject.onNext(preferredName); } @Override public void setPhoneNumber(final String phoneNumber) { phoneSubject.onNext(phoneNumber); } @Override public void setLicensePlate(final String licensePlate) { licenseSubject.onNext(licensePlate); } @Override public void setRiderCapacity(final int riderCapacity) { capacitySubject.onNext(riderCapacity); } @Override public void destroy() { compositeDisposable.dispose(); } private boolean isVehicleRegistrationValid(final VehicleRegistration registration) { return registration.getPreferredName().length() > 0 && phoneNumberValidator.apply(registration.getPhoneNumber()) && registration.getLicensePlate().length() > 0 && registration.getRiderCapacity() > 0; } }
0
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered/register_vehicle/RegisterVehicleFragment.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.vehicle_unregistered.register_vehicle; 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.device.InputMethodManagerKeyboardManager; import ai.rideos.android.common.device.KeyboardManager; import ai.rideos.android.common.fleets.ResolvedFleet; import ai.rideos.android.driver_app.R; import ai.rideos.android.driver_app.dependency.DriverDependencyRegistry; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.transition.Slide; import android.transition.TransitionSet; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.Toolbar; import androidx.annotation.NonNull; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import java.util.function.Consumer; public class RegisterVehicleFragment extends FragmentViewController<EmptyArg, RegisterVehicleListener> { private CompositeDisposable compositeDisposable; private RegisterVehicleViewModel viewModel; @Override public ControllerTypes<EmptyArg, RegisterVehicleListener> getTypes() { return new ControllerTypes<>(EmptyArg.class, RegisterVehicleListener.class); } @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); viewModel = new DefaultRegisterVehicleViewModel( DriverDependencyRegistry.driverDependencyFactory().getDriverVehicleInteractor(getContext()), User.get(getContext()), ResolvedFleet.get().observeFleetInfo(), getListener() ); } @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final TransitionSet transitionSet = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget("vehicle_registration") ); setSharedElementEnterTransition(transitionSet); setExitTransition(transitionSet); return inflater.inflate(R.layout.register_vehicle, container, false); } @Override public void onStart() { super.onStart(); compositeDisposable = new CompositeDisposable(); final View view = getView(); final KeyboardManager keyboardManager = new InputMethodManagerKeyboardManager(getContext(), view); final EditText nameInput = view.findViewById(R.id.registration_preferred_name_input); listenToEditText(nameInput, viewModel::setPreferredName); final EditText phoneInput = view.findViewById(R.id.registration_phone_number_input); listenToEditText(phoneInput, viewModel::setPhoneNumber); final EditText licenseInput = view.findViewById(R.id.registration_license_plate_input); listenToEditText(licenseInput, viewModel::setLicensePlate); final EditText capacityInput = view.findViewById(R.id.registration_rider_capacity_input); listenToEditText(capacityInput, input -> viewModel.setRiderCapacity(Integer.parseInt(input))); final Toolbar toolbar = view.findViewById(R.id.title_bar); toolbar.setNavigationOnClickListener(click -> { keyboardManager.hideKeyboard(); getListener().cancelRegistration(); }); final Button saveButton = view.findViewById(R.id.save_button); saveButton.setOnClickListener(click -> { viewModel.save(); keyboardManager.hideKeyboard(); }); compositeDisposable.addAll( viewModel.isSavingEnabled().observeOn(AndroidSchedulers.mainThread()).subscribe(enabled -> { if (enabled) { saveButton.setVisibility(View.VISIBLE); } else { saveButton.setVisibility(View.GONE); } }) ); } private static void listenToEditText(final EditText editText, final Consumer<String> onChange) { editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { onChange.accept(s.toString()); } @Override public void afterTextChanged(final Editable s) { } }); } @Override public void onStop() { super.onStop(); compositeDisposable.dispose(); } }
0
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered/register_vehicle/RegisterVehicleListener.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.vehicle_unregistered.register_vehicle; public interface RegisterVehicleListener { void cancelRegistration(); void doneRegistering(); }
0
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered
java-sources/ai/rideos/sdk/sdk-android-driver/1.0.2/ai/rideos/android/driver_app/vehicle_unregistered/register_vehicle/RegisterVehicleViewModel.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.vehicle_unregistered.register_vehicle; import ai.rideos.android.common.viewmodel.ViewModel; import io.reactivex.Observable; public interface RegisterVehicleViewModel extends ViewModel { Observable<Boolean> isSavingEnabled(); void save(); void setPreferredName(final String preferredName); void setPhoneNumber(final String phoneNumber); void setLicensePlate(final String licensePlate); void setRiderCapacity(final int riderCapacity); }
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/interactors/DefaultDriverPlanInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; import ai.rideos.android.common.reactive.SchedulerProvider; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.common.utils.Locations; import ai.rideos.android.model.TripResourceInfo; import ai.rideos.android.model.VehiclePlan; import ai.rideos.android.model.VehiclePlan.Action.ActionType; import ai.rideos.android.model.VehiclePlan.Waypoint; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Step; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Step.VehicleActionCase; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.GetVehicleStateRequest; import ai.rideos.api.ride_hail_driver.v1.RideHailDriverServiceGrpc; import ai.rideos.api.ride_hail_driver.v1.RideHailDriverServiceGrpc.RideHailDriverServiceFutureStub; import io.grpc.ManagedChannel; import io.reactivex.Observable; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.function.Supplier; import timber.log.Timber; public class DefaultDriverPlanInteractor extends GrpcServerInteractor<RideHailDriverServiceFutureStub> implements DriverPlanInteractor { public DefaultDriverPlanInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { this(channelSupplier, user, new DefaultSchedulerProvider()); } public DefaultDriverPlanInteractor(final Supplier<ManagedChannel> channelSupplier, final User user, final SchedulerProvider schedulerProvider) { super(RideHailDriverServiceGrpc::newFutureStub, channelSupplier, user, schedulerProvider); } @Override public Observable<VehiclePlan> getPlanForVehicle(final String vehicleId) { return fetchAuthorizedStubAndExecute(stub -> stub.getVehicleState( GetVehicleStateRequest.newBuilder() .setId(vehicleId) .build() )) .map(response -> { final List<Step> steps = response.getState().getPlan().getStepList(); final List<Waypoint> waypoints = new ArrayList<>(); int stepIndex = 0; while (stepIndex < steps.size()) { final Step step = steps.get(stepIndex); switch (step.getVehicleActionCase()) { case DRIVE_TO_LOCATION: if (stepIndex + 1 >= steps.size()) { Timber.e( "Received DRIVE_TO_LOCATION step without pickup or drop-off step after. Plan: %s", response.getState().getPlan().toString() ); break; } final Step nextStep = steps.get(stepIndex + 1); if (!nextStep.getTripId().equals(step.getTripId())) { Timber.e( "Step after DRIVE_TO_LOCATION does not have same trip id. Plan: %s", response.getState().getPlan().toString() ); break; } if (nextStep.getVehicleActionCase() == VehicleActionCase.PICKUP_RIDER) { waypoints.add(getWaypointForStep( step, ActionType.DRIVE_TO_PICKUP, nextStep.getPickupRider().getRiderCount(), nextStep.getPickupRider().getRiderInfo().getContactInfo().getName() )); } else { waypoints.add(getWaypointForStep( step, ActionType.DRIVE_TO_DROP_OFF, nextStep.getDropoffRider().getRiderCount(), nextStep.getDropoffRider().getRiderInfo().getContactInfo().getName(), nextStep.getId() )); // Skip over the drop-off step, since it has been accounted for as part of processing // the drive to location step. This differs from how we handle the pickup step because, // currently, we represent the action of picking up a rider // (VehiclePlan.Action.ActionType.LOAD_RESOURCE), but do not have a corresponding // representation for the action of dropping off a passenger (e.g., something like // VehiclePlan.Action.ActionType.UNLOAD_RESOURCE). This representation could // change in the future. stepIndex++; } break; case PICKUP_RIDER: waypoints.add(getWaypointForStep( step, ActionType.LOAD_RESOURCE, step.getPickupRider().getRiderCount(), step.getPickupRider().getRiderInfo().getContactInfo().getName() )); break; case DROPOFF_RIDER: // In the event we receive a drop-off rider without a drive-to-location before it, treat it // as a drive to drop-off waypoints.add(getWaypointForStep( step, ActionType.DRIVE_TO_DROP_OFF, step.getDropoffRider().getRiderCount(), step.getDropoffRider().getRiderInfo().getContactInfo().getName() )); break; } stepIndex++; } return new VehiclePlan(waypoints); }); } private static Waypoint getWaypointForStep(final Step step, final ActionType actionType, final int riderCount, final String riderName, final String... additionalStepsIdsInWaypoint) { final LinkedHashSet<String> uniqueStepIds = new LinkedHashSet<>(); uniqueStepIds.add(step.getId()); uniqueStepIds.addAll(Arrays.asList(additionalStepsIdsInWaypoint)); return new Waypoint( step.getTripId(), new ArrayList<>(uniqueStepIds), new VehiclePlan.Action( Locations.fromRideOsPosition(step.getPosition()), actionType, new TripResourceInfo(riderCount, riderName) ) ); } }
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/interactors/DefaultDriverVehicleInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; 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.common.utils.Locations; import ai.rideos.android.model.VehicleDisplayRouteLeg; import ai.rideos.android.model.VehicleRegistration; import ai.rideos.android.model.VehicleStatus; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.ContactInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.DriverInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleDefinition; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Step.RouteLeg; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.CompleteStepRequest; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.CreateVehicleRequest; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.GetVehicleStateRequest; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.RejectTripRequest; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.UpdateVehicleStateRequest; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.UpdateVehicleStateRequest.SetRouteLegs; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.UpdateVehicleStateRequest.SetRouteLegs.LegDefinition; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.UpdateVehicleStateRequest.SetToNotReady; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.UpdateVehicleStateRequest.SetToReady; import ai.rideos.api.ride_hail_driver.v1.RideHailDriver.UpdateVehicleStateRequest.UpdatePosition; import ai.rideos.api.ride_hail_driver.v1.RideHailDriverServiceGrpc; import ai.rideos.api.ride_hail_driver.v1.RideHailDriverServiceGrpc.RideHailDriverServiceFutureStub; import androidx.core.util.Pair; import com.google.maps.android.PolyUtil; import com.google.protobuf.FloatValue; import io.grpc.ManagedChannel; import io.grpc.Status.Code; import io.grpc.StatusRuntimeException; import io.reactivex.Completable; import io.reactivex.Observable; import io.reactivex.Single; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; public class DefaultDriverVehicleInteractor extends GrpcServerInteractor<RideHailDriverServiceFutureStub> implements DriverVehicleInteractor { public interface PolylineEncoder { String encodePolyline(final List<LatLng> route); } private final PolylineEncoder polylineEncoder; public DefaultDriverVehicleInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { this(channelSupplier, user, new DefaultPolylineEncoder(), new DefaultSchedulerProvider()); } public DefaultDriverVehicleInteractor(final Supplier<ManagedChannel> channelSupplier, final User user, final PolylineEncoder polylineEncoder, final SchedulerProvider schedulerProvider) { super(RideHailDriverServiceGrpc::newFutureStub, channelSupplier, user, schedulerProvider); this.polylineEncoder = polylineEncoder; } @Override public Single<VehicleStatus> getVehicleStatus(final String vehicleId) { return fetchAuthorizedStubAndExecute(stub -> stub.getVehicleState( GetVehicleStateRequest.newBuilder().setId(vehicleId).build() )) .map(stateResponse -> stateResponse.getState().getReadiness() ? VehicleStatus.READY : VehicleStatus.NOT_READY ) .firstOrError() .onErrorResumeNext(e -> { final Throwable cause = e.getCause(); if (cause instanceof StatusRuntimeException) { if (((StatusRuntimeException) cause).getStatus().getCode() == Code.NOT_FOUND) { return Single.just(VehicleStatus.UNREGISTERED); } } return Single.error(e); }); } @Override public Completable createVehicle(final String vehicleId, final String fleetId, final VehicleRegistration vehicleRegistration) { return fetchAuthorizedStubAndExecute(stub -> stub.createVehicle( CreateVehicleRequest.newBuilder() .setId(vehicleId) .setInfo( VehicleInfo.newBuilder() .setDriverInfo(DriverInfo.newBuilder().setContactInfo( ContactInfo.newBuilder() .setName(vehicleRegistration.getPreferredName()) .setPhoneNumber(vehicleRegistration.getPhoneNumber()) )) .setLicensePlate(vehicleRegistration.getLicensePlate()) ) .setFleetId(fleetId) .setDefinition( VehicleDefinition.newBuilder().setRiderCapacity(vehicleRegistration.getRiderCapacity()) ) .build() )) .ignoreElements(); } @Override public Completable markVehicleReady(final String vehicleId) { return fetchAuthorizedStubAndExecute(stub -> stub.updateVehicleState( UpdateVehicleStateRequest.newBuilder() .setId(vehicleId) .setSetToReady(SetToReady.getDefaultInstance()) .build() )) .ignoreElements(); } @Override public Completable markVehicleNotReady(final String vehicleId) { return fetchAuthorizedStubAndExecute(stub -> stub.updateVehicleState( UpdateVehicleStateRequest.newBuilder() .setId(vehicleId) .setSetToNotReady(SetToNotReady.getDefaultInstance()) .build() )) .ignoreElements(); } @Override public Completable finishSteps(final String vehicleId, final String taskId, final List<String> stepIds) { return Observable.fromIterable(stepIds) .concatMapCompletable(stepId -> fetchAuthorizedStubAndExecute(stub -> stub.completeStep( CompleteStepRequest.newBuilder() .setVehicleId(vehicleId) .setTripId(taskId) .setStepId(stepId) .build() )) .ignoreElements() ); } @Override public Completable rejectTrip(final String vehicleId, final String tripId) { return fetchAuthorizedStubAndExecute(stub -> stub.rejectTrip(RejectTripRequest.newBuilder() .setVehicleId(vehicleId) .setTripId(tripId) .build()) ) .ignoreElements(); } @Override public Completable updateVehicleLocation(final String vehicleId, final LocationAndHeading locationAndHeading) { return fetchAuthorizedStubAndExecute(stub -> stub.updateVehicleState( UpdateVehicleStateRequest.newBuilder() .setId(vehicleId) .setUpdatePosition( UpdatePosition.newBuilder() .setUpdatedHeading(FloatValue.newBuilder().setValue(locationAndHeading.getHeading())) .setUpdatedPosition(Locations.toRideOsPosition(locationAndHeading.getLatLng())) ) .build() )) .ignoreElements(); } @Override public Completable updateVehicleRoute(final String vehicleId, final List<VehicleDisplayRouteLeg> updatedLegs) { final List<LegDefinition> legDefinitions = updatedLegs.stream() .map(displayLeg -> { final Pair<String, String> prevTripAndStep = displayLeg.getPreviousTripAndStep() .orElse(Pair.create("", "")); return LegDefinition.newBuilder() .setFromTripId(prevTripAndStep.first) .setFromStepId(prevTripAndStep.second) .setToTripId(displayLeg.getRoutableTripAndStep().first) .setToStepId(displayLeg.getRoutableTripAndStep().second) .setRouteLeg(getRouteLegFromRouteInfo(displayLeg.getRoute())) .build(); }) .collect(Collectors.toList()); return fetchAuthorizedStubAndExecute(stub -> stub.updateVehicleState( UpdateVehicleStateRequest.newBuilder() .setId(vehicleId) .setSetRouteLegs(SetRouteLegs.newBuilder().addAllLegDefinition(legDefinitions)) .build() )) .ignoreElements(); } private RouteLeg getRouteLegFromRouteInfo(final RouteInfoModel routeInfo) { return RouteLeg.newBuilder() .setPolyline(polylineEncoder.encodePolyline(routeInfo.getRoute())) .setDistanceInMeters(routeInfo.getTravelDistanceMeters()) .setTravelTimeInSeconds(((double) routeInfo.getTravelTimeMillis()) / 1000) .build(); } private static class DefaultPolylineEncoder implements PolylineEncoder { @Override public String encodePolyline(final List<LatLng> route) { return PolyUtil.encode( route.stream() .map(Locations::toGoogleLatLng) .collect(Collectors.toList()) ); } } }
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/interactors/DriverPlanInteractor.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.interactors; import ai.rideos.android.model.VehiclePlan; import io.reactivex.Observable; public interface DriverPlanInteractor { Observable<VehiclePlan> getPlanForVehicle(final String vehicleId); }
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/interactors/DriverVehicleInteractor.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.interactors; import ai.rideos.android.common.model.LocationAndHeading; import ai.rideos.android.model.VehicleDisplayRouteLeg; import ai.rideos.android.model.VehicleRegistration; import ai.rideos.android.model.VehicleStatus; import io.reactivex.Completable; import io.reactivex.Single; import java.util.List; public interface DriverVehicleInteractor { Single<VehicleStatus> getVehicleStatus(final String vehicleId); Completable createVehicle(final String vehicleId, final String fleetId, final VehicleRegistration vehicleRegistration); Completable markVehicleReady(final String vehicleId); Completable markVehicleNotReady(final String vehicleId); Completable finishSteps(final String vehicleId, final String taskId, final List<String> stepIds); Completable rejectTrip(final String vehicleId, final String tripId); Completable updateVehicleLocation(final String vehicleId, final LocationAndHeading locationAndHeading); Completable updateVehicleRoute(final String vehicleId, final List<VehicleDisplayRouteLeg> updatedLegs); void shutDown(); }
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/model/DrivingViewState.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.model; import ai.rideos.android.model.VehiclePlan.Waypoint; import androidx.annotation.NonNull; public class DrivingViewState { public enum DrivingStep { DRIVE_PENDING, NAVIGATING, CONFIRMING_ARRIVAL } private final DrivingStep drivingStep; private final Waypoint waypointToComplete; public DrivingViewState(final DrivingStep drivingStep, final Waypoint waypointToComplete) { this.drivingStep = drivingStep; this.waypointToComplete = waypointToComplete; } public DrivingStep getDrivingStep() { return drivingStep; } public Waypoint getWaypointToComplete() { return waypointToComplete; } @NonNull @Override public String toString() { return drivingStep.toString(); } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof DrivingViewState)) { return false; } final DrivingViewState otherModel = (DrivingViewState) other; return drivingStep == otherModel.drivingStep && waypointToComplete.equals(otherModel.waypointToComplete); } }
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/model/MainViewState.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.model; public enum MainViewState { OFFLINE, ONLINE, UNREGISTERED, UNKNOWN }
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/model/OnlineViewState.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.model; import ai.rideos.android.model.VehiclePlan.Waypoint; import java.util.Objects; public class OnlineViewState { public enum DisplayType { IDLE, DRIVING_TO_PICKUP, WAITING_FOR_PASSENGER, DRIVING_TO_DROP_OFF, TRIP_DETAILS } private final DisplayType displayType; private final Waypoint currentWaypoint; private final VehiclePlan vehiclePlan; public static OnlineViewState idle() { return new OnlineViewState(DisplayType.IDLE, null, null); } public static OnlineViewState drivingToPickup(final Waypoint currentWaypoint) { return new OnlineViewState(DisplayType.DRIVING_TO_PICKUP, currentWaypoint, null); } public static OnlineViewState waitingForPassenger(final Waypoint currentWaypoint) { return new OnlineViewState(DisplayType.WAITING_FOR_PASSENGER, currentWaypoint, null); } public static OnlineViewState drivingToDropOff(final Waypoint currentWaypoint) { return new OnlineViewState(DisplayType.DRIVING_TO_DROP_OFF, currentWaypoint, null); } public static OnlineViewState tripDetails(final VehiclePlan vehiclePlan) { return new OnlineViewState(DisplayType.TRIP_DETAILS, null, vehiclePlan); } private OnlineViewState(final DisplayType displayType, final Waypoint currentWaypoint, final VehiclePlan vehiclePlan) { this.displayType = displayType; this.currentWaypoint = currentWaypoint; this.vehiclePlan = vehiclePlan; } public DisplayType getDisplayType() { return displayType; } public Waypoint getCurrentWaypoint() { return currentWaypoint; } public VehiclePlan getVehiclePlan() { return vehiclePlan; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof OnlineViewState)) { return false; } final OnlineViewState otherModel = (OnlineViewState) other; return displayType == otherModel.displayType && Objects.equals(currentWaypoint, otherModel.currentWaypoint) && Objects.equals(vehiclePlan, otherModel.vehiclePlan); } }
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/model/TripResourceInfo.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.model; import java.io.Serializable; public class TripResourceInfo implements Serializable { private final int numPassengers; private final String nameOfTripRequester; // TODO passenger number public TripResourceInfo(final int numPassengers, final String nameOfTripRequester) { this.numPassengers = numPassengers; this.nameOfTripRequester = nameOfTripRequester; } public int getNumPassengers() { return numPassengers; } public String getNameOfTripRequester() { return nameOfTripRequester; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof TripResourceInfo)) { return false; } final TripResourceInfo that = (TripResourceInfo) other; return numPassengers == that.numPassengers && nameOfTripRequester.equals(that.nameOfTripRequester); } }
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/model/VehicleDisplayRouteLeg.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.model; import ai.rideos.android.common.model.RouteInfoModel; import androidx.core.util.Pair; import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; public class VehicleDisplayRouteLeg { @Nullable private final Pair<String, String> previousTripAndStep; private final Pair<String, String> routableTripAndStep; private final RouteInfoModel routeInfoModel; public VehicleDisplayRouteLeg(@Nullable final Pair<String, String> previousTripAndStep, final Pair<String, String> routableTripAndStep, final RouteInfoModel routeInfoModel) { this.previousTripAndStep = previousTripAndStep; this.routableTripAndStep = routableTripAndStep; this.routeInfoModel = routeInfoModel; } public Optional<Pair<String, String>> getPreviousTripAndStep() { return Optional.ofNullable(previousTripAndStep); } public Pair<String, String> getRoutableTripAndStep() { return routableTripAndStep; } public RouteInfoModel getRoute() { return routeInfoModel; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof VehicleDisplayRouteLeg)) { return false; } final VehicleDisplayRouteLeg otherModel = (VehicleDisplayRouteLeg) other; return Objects.equals(previousTripAndStep, otherModel.previousTripAndStep) && routableTripAndStep.equals(otherModel.routableTripAndStep) && routeInfoModel.equals(otherModel.routeInfoModel); } }
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/model/VehiclePlan.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.model; import ai.rideos.android.common.model.LatLng; import com.google.gson.Gson; import java.util.List; import java.util.Set; import org.jetbrains.annotations.NotNull; public class VehiclePlan { public static class Waypoint { private final String taskId; private final List<String> stepIds; private final Action action; public Waypoint(final String taskId, final List<String> stepIds, final Action action) { this.taskId = taskId; this.stepIds = stepIds; this.action = action; } public String getTaskId() { return taskId; } public List<String> getStepIds() { return stepIds; } public Action getAction() { return action; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof Waypoint)) { return false; } final Waypoint otherModel = (Waypoint) other; return taskId.equals(otherModel.taskId) && stepIds.equals(otherModel.stepIds) && action.equals(otherModel.action); } } public static class Action { public enum ActionType { DRIVE_TO_PICKUP, LOAD_RESOURCE, DRIVE_TO_DROP_OFF } private final LatLng destination; private final ActionType actionType; private final TripResourceInfo tripResourceInfo; public Action(final LatLng destination, final ActionType actionType, final TripResourceInfo tripResourceInfo) { this.destination = destination; this.actionType = actionType; this.tripResourceInfo = tripResourceInfo; } public LatLng getDestination() { return destination; } public ActionType getActionType() { return actionType; } public TripResourceInfo getTripResourceInfo() { return tripResourceInfo; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof Action)) { return false; } final Action otherModel = (Action) other; return destination.equals(otherModel.destination) && actionType == otherModel.actionType && tripResourceInfo.equals(otherModel.tripResourceInfo); } } private final List<Waypoint> waypoints; public VehiclePlan(final List<Waypoint> waypoints) { this.waypoints = waypoints; } public List<Waypoint> getWaypoints() { return waypoints; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof VehiclePlan)) { return false; } return waypoints.equals(((VehiclePlan) other).waypoints); } @NotNull @Override public String toString() { return new Gson().toJson(this); } }
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/model/VehicleRegistration.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.model; public class VehicleRegistration { private final String preferredName; private final String phoneNumber; private final String licensePlate; private final int riderCapacity; public VehicleRegistration(final String preferredName, final String phoneNumber, final String licensePlate, final int riderCapacity) { this.preferredName = preferredName; this.phoneNumber = phoneNumber; this.licensePlate = licensePlate; this.riderCapacity = riderCapacity; } public String getPreferredName() { return preferredName; } public String getPhoneNumber() { return phoneNumber; } public String getLicensePlate() { return licensePlate; } public int getRiderCapacity() { return riderCapacity; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof VehicleRegistration)) { return false; } final VehicleRegistration otherModel = (VehicleRegistration) other; return preferredName.equals(otherModel.preferredName) && phoneNumber.equals(otherModel.phoneNumber) && licensePlate.equals(otherModel.licensePlate) && riderCapacity == otherModel.riderCapacity; } }
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/model/VehicleStatus.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.model; public enum VehicleStatus { READY, NOT_READY, UNREGISTERED }
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/model/VehicleUnregisteredViewState.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.model; public enum VehicleUnregisteredViewState { PRE_REGISTRATION, REGISTER_VEHICLE }
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/settings/DriverStorageKeys.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.settings; import ai.rideos.android.common.user_storage.StorageKey; public class DriverStorageKeys { public static final StorageKey<Boolean> SIMULATE_NAVIGATION = new StorageKey<>("simulate_navigation", false); }
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/view/ActionDetailView.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.view; import ai.rideos.android.driver_app.R; import android.content.Context; import android.util.AttributeSet; import android.widget.Button; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.cardview.widget.CardView; /** * ActionDetailView is a useful view for displaying a title text, detail text, and action button. */ public class ActionDetailView extends CardView { private TextView titleView; private TextView detailView; private Button actionButton; public ActionDetailView(@NonNull final Context context) { this(context, null); } public ActionDetailView(@NonNull final Context context, @Nullable final AttributeSet attrs) { super(context, attrs, 0); } public ActionDetailView(@NonNull final Context context, @Nullable final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void onFinishInflate() { super.onFinishInflate(); titleView = findViewById(R.id.action_title_text); detailView = findViewById(R.id.action_detail_text); actionButton = findViewById(R.id.action_button); } public TextView getTitleView() { return titleView; } public TextView getDetailView() { return detailView; } public Button getActionButton() { return actionButton; } }
0
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google/GoogleMetadataKeys.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.google; public class GoogleMetadataKeys { public static final String GMS_API_KEY = "com.google.android.geo.API_KEY"; }
0
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google/dependency/GoogleMapDependencyFactory.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.google.dependency; import ai.rideos.android.common.app.dependency.MapDependencyFactory; import ai.rideos.android.common.interactors.GeocodeInteractor; import ai.rideos.android.common.interactors.LocationAutocompleteInteractor; import ai.rideos.android.google.interactors.AndroidGeocodeInteractor; import ai.rideos.android.google.interactors.GooglePlacesAutocompleteInteractor; import ai.rideos.android.google.map.GoogleMapFragment; import android.content.Context; import androidx.fragment.app.Fragment; import com.google.android.libraries.places.api.Places; public class GoogleMapDependencyFactory implements MapDependencyFactory { public GoogleMapDependencyFactory(final Context applicationContext, final String gmsKey) { Places.initialize(applicationContext, gmsKey); } @Override public Fragment getMapFragment() { return new GoogleMapFragment(); } @Override public LocationAutocompleteInteractor getAutocompleteInteractor(final Context context) { return new GooglePlacesAutocompleteInteractor(context); } @Override public GeocodeInteractor getGeocodeInteractor(final Context context) { return new AndroidGeocodeInteractor(context); } }
0
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google/interactors/AndroidGeocodeInteractor.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.google.interactors; import ai.rideos.android.common.interactors.GeocodeInteractor; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.model.NamedTaskLocation; import ai.rideos.android.common.reactive.Result; import ai.rideos.android.common.reactive.SchedulerProvider; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import android.content.Context; import android.location.Address; import android.location.Geocoder; import io.reactivex.Observable; import java.util.List; import java.util.stream.Collectors; /** * AndroidGeocodeInteractor uses the default Android Geocoder object to perform reverse geocodings. It is important to * note that this library cannot be used for location autocompletion because the forward geocoding is only intended * for singular results. */ public class AndroidGeocodeInteractor implements GeocodeInteractor { private static final int MAX_RESULTS_TO_SCAN = 10; private final Geocoder geocoder; private final SchedulerProvider schedulerProvider; public AndroidGeocodeInteractor(final Context context) { this(new Geocoder(context), new DefaultSchedulerProvider()); } public AndroidGeocodeInteractor(final Geocoder geocoder, final SchedulerProvider schedulerProvider) { this.geocoder = geocoder; this.schedulerProvider = schedulerProvider; } @Override public Observable<List<NamedTaskLocation>> getReverseGeocodeResults(final LatLng latLng, final int maxResults) { return Observable.fromCallable(() -> geocoder.getFromLocation( latLng.getLatitude(), latLng.getLongitude(), maxResults )) .subscribeOn(schedulerProvider.io()) .observeOn(schedulerProvider.computation()) .map(addressList -> addressList.stream() .map(address -> new NamedTaskLocation( getDisplayNameFromAddress(address), new LatLng(address.getLatitude(), address.getLongitude()) )) .collect(Collectors.toList()) ); } @Override public Observable<Result<NamedTaskLocation>> getBestReverseGeocodeResult(final LatLng latLng) { return Observable.fromCallable(() -> geocoder.getFromLocation( latLng.getLatitude(), latLng.getLongitude(), MAX_RESULTS_TO_SCAN )) .subscribeOn(schedulerProvider.io()) .observeOn(schedulerProvider.computation()) .map(fullAddressList -> { if (fullAddressList.size() == 0) { return Result.failure(new ReverseGeocodeException("Failed to find any geocode results")); } final List<Address> addressesWithAllDisplayInfo = fullAddressList.stream() .filter(AndroidGeocodeInteractor::hasAddressNumberAndStreet) .collect(Collectors.toList()); // Use an address with good display information, or else just return the first address in the list final Address addressToReturn = addressesWithAllDisplayInfo.size() > 0 ? addressesWithAllDisplayInfo.get(0) : fullAddressList.get(0); return Result.success( new NamedTaskLocation( getDisplayNameFromAddress(addressToReturn), new LatLng(addressToReturn.getLatitude(), addressToReturn.getLongitude()) ) ); }); } private static String getDisplayNameFromAddress(final Address address) { final String number = address.getSubThoroughfare(); final String street = address.getThoroughfare(); final String city = address.getLocality(); if (number != null && street != null) { return String.format("%s %s", number, street); } else if (street != null && city != null) { return String.format("%s, %s", street, city); } else if (city != null) { return String.format("%s", city); } else { return "Unknown Location"; } } private static boolean hasAddressNumberAndStreet(final Address address) { return address.getSubThoroughfare() != null && address.getThoroughfare() != null; } public static class ReverseGeocodeException extends Exception { ReverseGeocodeException(final String message) { super(message); } } }
0
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google/interactors/GooglePlacesAutocompleteInteractor.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.google.interactors; import ai.rideos.android.common.interactors.LocationAutocompleteInteractor; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.model.LocationAutocompleteResult; import ai.rideos.android.common.model.NamedTaskLocation; import ai.rideos.android.common.model.map.LatLngBounds; import ai.rideos.android.common.reactive.SchedulerProvider; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.common.utils.Locations; import android.content.Context; import com.google.android.libraries.places.api.Places; import com.google.android.libraries.places.api.model.AutocompletePrediction; import com.google.android.libraries.places.api.model.AutocompleteSessionToken; import com.google.android.libraries.places.api.model.Place; import com.google.android.libraries.places.api.model.Place.Field; import com.google.android.libraries.places.api.model.RectangularBounds; import com.google.android.libraries.places.api.net.FetchPlaceRequest; import com.google.android.libraries.places.api.net.FindAutocompletePredictionsRequest; import com.google.android.libraries.places.api.net.PlacesClient; import io.reactivex.Observable; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; /** * GooglePlacesAutocompleteInteractor uses the Places SDK to return autocomplete results when searching for a location. * Note: in order for this to be used, the Places SDK needs to be initialized somewhere in the code, like in a top * level activity, with `Places.initialize(context, apiKey)`. */ public class GooglePlacesAutocompleteInteractor implements LocationAutocompleteInteractor { private final PlacesClient placesClient; private final AutocompleteSessionToken sessionToken = AutocompleteSessionToken.newInstance(); private final SchedulerProvider schedulerProvider; public GooglePlacesAutocompleteInteractor(final Context context) { this(Places.createClient(context), new DefaultSchedulerProvider()); } public GooglePlacesAutocompleteInteractor(final PlacesClient placesClient, final SchedulerProvider schedulerProvider) { this.placesClient = placesClient; this.schedulerProvider = schedulerProvider; } @Override public Observable<List<LocationAutocompleteResult>> getAutocompleteResults(final String searchText, final LatLngBounds bounds) { final RectangularBounds rectangularBounds = RectangularBounds.newInstance( Locations.toGoogleLatLng(bounds.getSouthwestCorner()), Locations.toGoogleLatLng(bounds.getNortheastCorner()) ); final FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder() .setLocationBias(rectangularBounds) .setQuery(searchText) .setSessionToken(sessionToken) .build(); return Observable.<List<AutocompletePrediction>>create(emitter -> placesClient.findAutocompletePredictions(request) .addOnSuccessListener(result -> { emitter.onNext(result.getAutocompletePredictions()); emitter.onComplete(); }) .addOnFailureListener(emitter::onError) ) .subscribeOn(schedulerProvider.io()) .observeOn(schedulerProvider.computation()) .map(GooglePlacesAutocompleteInteractor::convertAutocompletePredictionsToResults); } @Override public Observable<NamedTaskLocation> getLocationFromAutocompleteResult(final LocationAutocompleteResult result) { final FetchPlaceRequest request = FetchPlaceRequest.newInstance( result.getId(), // Need to return coordinates, address, and the name of the place Arrays.asList(Field.LAT_LNG, Field.ADDRESS, Field.NAME) ); return Observable.<Place>create(emitter -> placesClient.fetchPlace(request) .addOnSuccessListener(placeResult -> { emitter.onNext(placeResult.getPlace()); emitter.onComplete(); }) .addOnFailureListener(emitter::onError) ) .subscribeOn(schedulerProvider.io()) .map(GooglePlacesAutocompleteInteractor::convertPlaceToNamedTaskLocation); } private static List<LocationAutocompleteResult> convertAutocompletePredictionsToResults( final List<AutocompletePrediction> predictions) { return predictions.stream() .map(prediction -> new LocationAutocompleteResult( prediction.getPrimaryText(null).toString(), prediction.getSecondaryText(null).toString(), prediction.getPlaceId() )) .collect(Collectors.toList()); } private static NamedTaskLocation convertPlaceToNamedTaskLocation(final Place place) { // Prefer to use the name of the place (like the business name) and default to the address if not available final LatLng latLng = Locations.fromGoogleLatLng(place.getLatLng()); if (place.getName() != null) { return new NamedTaskLocation(place.getName(), latLng); } else { return new NamedTaskLocation(place.getAddress(), latLng); } } }
0
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google
java-sources/ai/rideos/sdk/sdk-android-google/1.0.2/ai/rideos/android/google/map/GoogleMapFragment.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.google.map; import ai.rideos.android.common.app.map.MapRelay; import ai.rideos.android.common.app.map.MapStateReceiver.MapCenterListener; import ai.rideos.android.common.app.map.MapViewModel; 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.DrawablePath.Style; import ai.rideos.android.common.model.map.MapSettings; import ai.rideos.android.common.utils.Locations; import ai.rideos.android.common.utils.SetOperations; import ai.rideos.android.common.utils.SetOperations.DiffResult; import ai.rideos.android.common.view.DensityConverter; import ai.rideos.android.common.view.ViewMargins; import ai.rideos.android.google.R; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.OnCameraMoveStartedListener; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.UiSettings; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.Dot; import com.google.android.gms.maps.model.Gap; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.PatternItem; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class GoogleMapFragment extends Fragment { private static final int BOUNDS_PADDING = 50; private static final int ANIMATION_SPEED_MILLIS = 250; private static final int RE_CENTER_PADDING_DP = 20; private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private MapViewModel mapViewModel; private GoogleMap googleMap; private View reCenterButton; private ImageView centerPin; private final Map<String, Marker> currentMarkers = new HashMap<>(); private List<Polyline> currentPaths = new ArrayList<>(); @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.google_map_fragment, container, false); centerPin = view.findViewById(R.id.center_pin); mapViewModel = MapRelay.get(); reCenterButton = view.findViewById(R.id.re_center_button); reCenterButton.setVisibility(View.GONE); reCenterButton.setOnClickListener(click -> mapViewModel.reCenterMap()); final SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager() .findFragmentById(R.id.support_map_fragment); mapFragment.getMapAsync(map -> { googleMap = map; final UiSettings uiSettings = googleMap.getUiSettings(); uiSettings.setMyLocationButtonEnabled(false); uiSettings.setRotateGesturesEnabled(false); uiSettings.setTiltGesturesEnabled(false); uiSettings.setCompassEnabled(false); uiSettings.setMapToolbarEnabled(false); uiSettings.setZoomControlsEnabled(false); // https://issuetracker.google.com/issues/35829548 googleMap.setIndoorEnabled(false); subscribeToMapViewModel(); }); return view; } @Override public void onDestroy() { super.onDestroy(); compositeDisposable.dispose(); } private void subscribeToMapViewModel() { compositeDisposable.addAll( mapViewModel.getCameraUpdatesToPerform().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::performCameraUpdate), mapViewModel.shouldAllowReCentering().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::setRecenterButtonVisibility), mapViewModel.getMapSettings().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::setMapSettings), mapViewModel.getMarkers().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::showMarkers), mapViewModel.getPaths().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::showPaths), mapViewModel.getMapMargins().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::setMapMargins), mapViewModel.getMapCenterListener().observeOn(AndroidSchedulers.mainThread()) .subscribe(this::setMapCenterListener) ); } private void performCameraUpdate(final CameraUpdate cameraUpdate) { switch (cameraUpdate.getUpdateType()) { case FIT_LAT_LNG_BOUNDS: googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds( new LatLngBounds( Locations.toGoogleLatLng(cameraUpdate.getNewBounds().getSouthwestCorner()), Locations.toGoogleLatLng(cameraUpdate.getNewBounds().getNortheastCorner()) ), BOUNDS_PADDING ), ANIMATION_SPEED_MILLIS, null); break; case CENTER_AND_ZOOM: googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom( Locations.toGoogleLatLng(cameraUpdate.getNewCenter()), cameraUpdate.getNewZoom() ), ANIMATION_SPEED_MILLIS, null); break; case NO_UPDATE: // Do nothing } } private void setRecenterButtonVisibility(final boolean isVisible) { if (isVisible) { reCenterButton.setVisibility(View.VISIBLE); } else { reCenterButton.setVisibility(View.GONE); } } private void setMapSettings(final MapSettings mapSettings) { setCenterPin(mapSettings.getCenterPin()); setCurrentLocationEnabled(mapSettings.shouldShowUserLocation()); } private void setCenterPin(final CenterPin centerPin) { if (centerPin.shouldShow()) { displayCenterPin(centerPin.getDrawablePin()); } else { hideCenterPin(); } } private void setCurrentLocationEnabled(final boolean enabled) { if (enabled && !googleMap.isMyLocationEnabled()) { setMyLocationEnabledIfPermitted(true); } else if (!enabled && googleMap.isMyLocationEnabled()) { setMyLocationEnabledIfPermitted(false); } } private void setMyLocationEnabledIfPermitted(final boolean enabled) { if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions( new String[]{ Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }, 1 ); } else { googleMap.setMyLocationEnabled(enabled); } } private void displayCenterPin(final int drawable) { centerPin.setVisibility(View.VISIBLE); centerPin.setBackgroundResource(drawable); } private void hideCenterPin() { centerPin.setVisibility(View.INVISIBLE); centerPin.setBackgroundResource(0); // remove } private void showMarkers(final Map<String, DrawableMarker> newMarkers) { final DiffResult<String> diffResult = SetOperations.getDifferences( newMarkers.keySet(), currentMarkers.keySet() ); for (final String newMarkerKey : diffResult.getOnlyOnLeft()) { final DrawableMarker markerToAdd = newMarkers.get(newMarkerKey); final Marker newMarker = googleMap.addMarker(new MarkerOptions() .anchor(0.5f, getVerticalAnchor(markerToAdd)) .position(Locations.toGoogleLatLng(markerToAdd.getPosition())) .rotation(markerToAdd.getRotation()) .icon(getMarkerIcon(markerToAdd.getDrawableIcon())) ); currentMarkers.put(newMarkerKey, newMarker); } for (final String currentMarkerKey : diffResult.getIntersecting()) { final DrawableMarker markerToUpdate = newMarkers.get(currentMarkerKey); final Marker drawnMarker = currentMarkers.get(currentMarkerKey); drawnMarker.setPosition(Locations.toGoogleLatLng(markerToUpdate.getPosition())); drawnMarker.setRotation(markerToUpdate.getRotation()); // Cannot update color } for (final String deletedMarkerKey : diffResult.getOnlyOnRight()) { currentMarkers.get(deletedMarkerKey).remove(); currentMarkers.remove(deletedMarkerKey); } } private float getVerticalAnchor(final DrawableMarker marker) { if (marker.getAnchor() == Anchor.BOTTOM) { return 1.0f; } else { return 0.5f; } } private static BitmapDescriptor getMarkerIcon(final int drawableIcon) { return BitmapDescriptorFactory.fromResource(drawableIcon); } private void showPaths(final List<DrawablePath> paths) { for (final Polyline drawnPath : currentPaths) { drawnPath.remove(); } currentPaths = new ArrayList<>(paths.size()); for (final DrawablePath newPath : paths) { final Polyline addedPath = googleMap.addPolyline(new PolylineOptions() .addAll( newPath.getCoordinates().stream() .map(Locations::toGoogleLatLng) .collect(Collectors.toList()) ) .width(newPath.getWidth()) .color(newPath.getColor()) .pattern(getPatternForStyle(newPath.getStyle())) ); currentPaths.add(addedPath); } } private static List<PatternItem> getPatternForStyle(final Style style) { if (style == Style.DOTTED) { return Arrays.asList(new Dot(), new Gap(11)); } else { // null == standard solid line pattern return null; } } private void setMapCenterListener(final MapCenterListener listener) { googleMap.setOnCameraIdleListener(() -> listener.mapCenterDidMove( Locations.fromGoogleLatLng(googleMap.getCameraPosition().target) )); googleMap.setOnCameraMoveStartedListener((reason) -> { listener.mapCenterStartedMoving(); if (reason == OnCameraMoveStartedListener.REASON_GESTURE) { mapViewModel.mapWasDragged(); } }); } private void setMapMargins(final ViewMargins mapMargins) { googleMap.setPadding(mapMargins.getLeft(), mapMargins.getTop(), mapMargins.getRight(), mapMargins.getBottom()); setLayoutParamsForView( centerPin, calculateCenteredMargins(mapMargins) ); final int reCenterPaddingPx = DensityConverter.fromContext(getContext()) .convertDpToPixels(RE_CENTER_PADDING_DP); setLayoutParamsForView( reCenterButton, ViewMargins.newBuilder() .setRight(mapMargins.getRight() + reCenterPaddingPx) .setBottom(mapMargins.getBottom() + reCenterPaddingPx) .build() ); } /** * When centering an object in the map with insets, simply adding the top/bottom/left/right margins will not work. * This is because, for example, setting the top margin as some amount and bottom margin as some amount does not * actually center the object vertically. Instead, we have to find the average of the top/bottom and left/right * insets and use that as the margin. */ private ViewMargins calculateCenteredMargins(final ViewMargins mapMargins) { final int topOffset = (mapMargins.getTop() - mapMargins.getBottom()) / 2; final int leftOffset = (mapMargins.getLeft() - mapMargins.getRight()) / 2; ViewMargins.Builder builder = ViewMargins.newBuilder(); builder = topOffset > 0 ? builder.setTop(topOffset) : builder.setBottom(-topOffset); builder = leftOffset > 0 ? builder.setLeft(leftOffset) : builder.setRight(-leftOffset); return builder.build(); } private static void setLayoutParamsForView(final View view, final ViewMargins mapMargins) { final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) view.getLayoutParams(); lp.setMargins(mapMargins.getLeft(), mapMargins.getTop(), mapMargins.getRight(), mapMargins.getBottom()); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/adapters/LocationSearchRecyclerAdapter.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.adapters; import ai.rideos.android.model.LocationSearchOptionModel; import ai.rideos.android.rider_app.R; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageView; import androidx.recyclerview.widget.RecyclerView; import java.util.Collections; import java.util.List; public class LocationSearchRecyclerAdapter extends RecyclerView.Adapter<LocationSearchRecyclerAdapter.ViewHolder> { private List<LocationSearchOptionModel> locations; private final OnClickRowListener onClickListener; public static class ViewHolder extends RecyclerView.ViewHolder { // For now, each row is just a string public View view; ViewHolder(View view) { super(view); this.view = view; } } public interface OnClickRowListener { void clicked(final LocationSearchOptionModel selectedRow); } public LocationSearchRecyclerAdapter(final OnClickRowListener onClickListener) { this.onClickListener = onClickListener; this.locations = Collections.emptyList(); } @NonNull @Override public LocationSearchRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { final View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.location_recycler_row, parent, false); return new ViewHolder(v); } @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final TextView primaryTextView = holder.view.findViewById(R.id.location_row_primary_name); final TextView secondaryTextView = holder.view.findViewById(R.id.location_row_secondary_name); final TextView singleTextView = holder.view.findViewById(R.id.location_row_single_name); final AppCompatImageView imageView = holder.view.findViewById(R.id.option_icon); final LocationSearchOptionModel location = locations.get(position); // View holders will be reused, so explicitly set each text view to visible/invisible as required. if (location.getSecondaryName() == null || location.getSecondaryName().isEmpty()) { primaryTextView.setVisibility(View.INVISIBLE); secondaryTextView.setVisibility(View.INVISIBLE); singleTextView.setVisibility(View.VISIBLE); singleTextView.setText(location.getPrimaryName()); } else { primaryTextView.setVisibility(View.VISIBLE); secondaryTextView.setVisibility(View.VISIBLE); singleTextView.setVisibility(View.INVISIBLE); primaryTextView.setText(location.getPrimaryName()); secondaryTextView.setText(location.getSecondaryName()); } if (location.getDrawableIcon().isPresent()) { imageView.setImageResource(location.getDrawableIcon().get()); } else { // 0 is the empty resource id imageView.setImageResource(0); } holder.view.setOnClickListener(v -> onClickListener.clicked(locations.get(position))); } @Override public int getItemCount() { return locations.size(); } public void setLocations(final List<LocationSearchOptionModel> locations) { this.locations = locations; notifyDataSetChanged(); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/AvailableVehicleInteractor.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.interactors; import ai.rideos.android.model.AvailableVehicle; import io.reactivex.Observable; import java.util.List; public interface AvailableVehicleInteractor { /** * Retrieves the all available vehicles in a fleet. These vehicles can be used for requests to the backend. */ Observable<List<AvailableVehicle>> getAvailableVehicles(final String fleetId); void shutDown(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/DefaultAvailableVehicleInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.model.AvailableVehicle; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.Vehicle; import ai.rideos.api.ride_hail_operations.v1.RideHailOperations.GetVehiclesRequest; import ai.rideos.api.ride_hail_operations.v1.RideHailOperationsServiceGrpc; import ai.rideos.api.ride_hail_operations.v1.RideHailOperationsServiceGrpc.RideHailOperationsServiceFutureStub; import io.grpc.ManagedChannel; import io.reactivex.Observable; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; public class DefaultAvailableVehicleInteractor extends GrpcServerInteractor<RideHailOperationsServiceFutureStub> implements AvailableVehicleInteractor { public DefaultAvailableVehicleInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { super(RideHailOperationsServiceGrpc::newFutureStub, channelSupplier, user, new DefaultSchedulerProvider()); } @Override public Observable<List<AvailableVehicle>> getAvailableVehicles(final String fleetId) { return fetchAuthorizedStubAndExecute(operationsStub -> operationsStub.getVehicles( GetVehiclesRequest.newBuilder() .setFleetId(fleetId) .build() )) .map(vehicles -> vehicles.getVehicleList().stream() .filter(vehicle -> vehicle.getState().getReadiness()) .map(vehicle -> new AvailableVehicle(vehicle.getId(), getDisplayNameForVehicle(vehicle))) .collect(Collectors.toList()) ); } private static String getDisplayNameForVehicle(final Vehicle vehicle) { if (vehicle.getInfo().getLicensePlate().isEmpty()) { return vehicle.getId(); } return vehicle.getInfo().getLicensePlate(); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/DefaultPreviewVehicleInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.model.VehiclePosition; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.common.utils.Locations; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.GetVehiclesInVicinityRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc.RideHailRiderServiceFutureStub; import io.grpc.ManagedChannel; import io.reactivex.Observable; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; public class DefaultPreviewVehicleInteractor extends GrpcServerInteractor<RideHailRiderServiceFutureStub> implements PreviewVehicleInteractor { public DefaultPreviewVehicleInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { super(RideHailRiderServiceGrpc::newFutureStub, channelSupplier, user, new DefaultSchedulerProvider()); } @Override public Observable<List<VehiclePosition>> getVehiclesInVicinity(final LatLng center, final String fleetId) { return fetchAuthorizedStubAndExecute(dispatchStub -> dispatchStub.getVehiclesInVicinity( GetVehiclesInVicinityRequest.newBuilder() .setQueryPosition(Locations.toRideOsPosition(center)) .setFleetId(fleetId) .build() )) .map(response -> response.getVehicleList().stream() .map(vehiclePosition -> new VehiclePosition( vehiclePosition.getId(), Locations.fromRideOsPosition(vehiclePosition.getPosition()), vehiclePosition.getHeading().getValue() )) .collect(Collectors.toList()) ); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/DefaultRiderTripInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; import ai.rideos.android.common.model.TaskLocation; import ai.rideos.android.common.reactive.SchedulerProvider; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.common.utils.Locations; import ai.rideos.android.model.ContactInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.PickupDropoff; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.RiderInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.Stop; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripDefinition; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleFilter; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.CancelTripRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.ChangeTripDefinitionRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.ChangeTripDefinitionRequest.ChangePickup; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.DispatchParameters; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.GetActiveTripIdRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.GetActiveTripIdResponse.TypeCase; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.RequestTripRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc.RideHailRiderServiceFutureStub; import io.grpc.ManagedChannel; import io.reactivex.Completable; import io.reactivex.Observable; import java.util.Optional; import java.util.UUID; import java.util.function.Supplier; public class DefaultRiderTripInteractor extends GrpcServerInteractor<RideHailRiderServiceFutureStub> implements RiderTripInteractor { private final Supplier<String> tripIdSupplier; public DefaultRiderTripInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { this( channelSupplier, user, () -> UUID.randomUUID().toString(), new DefaultSchedulerProvider() ); } public DefaultRiderTripInteractor(final Supplier<ManagedChannel> channelSupplier, final User user, final Supplier<String> tripIdSupplier, final SchedulerProvider schedulerProvider) { super(RideHailRiderServiceGrpc::newFutureStub, channelSupplier, user, schedulerProvider); this.tripIdSupplier = tripIdSupplier; } @Override public Observable<String> createTripForPassenger(final String passengerId, final ContactInfo contactInfo, final String fleetId, final int numPassengers, final TaskLocation pickupLocation, final TaskLocation dropOffLocation) { return createTripWithParameters( passengerId, contactInfo, fleetId, numPassengers, pickupLocation, dropOffLocation, DispatchParameters.getDefaultInstance() ); } @Override public Observable<String> createTripForPassengerAndVehicle(final String passengerId, final ContactInfo contactInfo, final String vehicleId, final String fleetId, final int numPassengers, final TaskLocation pickupLocation, final TaskLocation dropOffLocation) { return createTripWithParameters( passengerId, contactInfo, fleetId, numPassengers, pickupLocation, dropOffLocation, DispatchParameters.newBuilder() .addVehicleFilter(VehicleFilter.newBuilder().setVehicleId(vehicleId)) .build() ); } private Observable<String> createTripWithParameters(final String passengerId, final ContactInfo contactInfo, final String fleetId, final int numPassengers, final TaskLocation pickupLocation, final TaskLocation dropOffLocation, final DispatchParameters dispatchParameters) { final String tripId = tripIdSupplier.get(); return fetchAuthorizedStubAndExecute(taskStub -> taskStub.requestTrip( RequestTripRequest.newBuilder() .setId(tripId) .setFleetId(fleetId) .setRiderId(passengerId) .setDefinition( TripDefinition.newBuilder() .setPickupDropoff( PickupDropoff.newBuilder() .setPickup(buildStop(pickupLocation)) .setDropoff(buildStop(dropOffLocation)) .setRiderCount(numPassengers) ) ) .setInfo( TripInfo.newBuilder().setRiderInfo( RiderInfo.newBuilder().setContactInfo( RideHailCommons.ContactInfo.newBuilder() .setName(contactInfo.getName()) ) ) ) .setDispatchParameters(dispatchParameters) .build() )) .map(response -> tripId); } @Override public Completable cancelTrip(final String ignoredPassengerId, final String tripId) { return fetchAuthorizedStubAndExecute(taskStub -> taskStub.cancelTrip( CancelTripRequest.newBuilder() .setId(tripId) .build() )) .ignoreElements(); } @Override public Observable<String> editPickup(final String tripId, final TaskLocation newPickupLocation) { final String newTripId = tripIdSupplier.get(); return fetchAuthorizedStubAndExecute(taskStub -> taskStub.changeTripDefinition( ChangeTripDefinitionRequest.newBuilder() .setTripId(tripId) .setReplacementTripId(newTripId) .setChangePickup( ChangePickup.newBuilder().setNewPickup(buildStop(newPickupLocation)) ) .build() )) .map(response -> newTripId); } @Override public Observable<Optional<String>> getCurrentTripForPassenger(final String passengerId) { return fetchAuthorizedStubAndExecute(taskStub -> taskStub.getActiveTripId( GetActiveTripIdRequest.newBuilder() .setRiderId(passengerId) .build() )) .map(response -> { if (response.getTypeCase() == TypeCase.ACTIVE_TRIP) { return Optional.of(response.getActiveTrip().getId()); } return Optional.<String>empty(); }) .onErrorReturnItem(Optional.empty()); } private static Stop buildStop(final TaskLocation taskLocation) { if (taskLocation.getLocationId().isPresent()) { return Stop.newBuilder() .setPredefinedStopId(taskLocation.getLocationId().get()) .build(); } return Stop.newBuilder() .setPosition(Locations.toRideOsPosition(taskLocation.getLatLng())) .build(); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/DefaultRiderTripStateInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; 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.common.utils.Locations; import ai.rideos.android.common.utils.Polylines.GMSPolylineDecoder; import ai.rideos.android.common.utils.Polylines.PolylineDecoder; import ai.rideos.android.model.TripStateModel; import ai.rideos.android.model.TripStateModel.CancellationReason; import ai.rideos.android.model.TripStateModel.CancellationReason.Source; import ai.rideos.android.model.TripStateModel.Stage; import ai.rideos.android.model.VehicleInfo; import ai.rideos.android.model.VehicleInfo.ContactInfo; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.AssignedVehicle; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.Stop; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.Stop.TypeCase; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripDefinition; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripState; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripState.CancelSource; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripState.Canceled; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.TripState.TripStateCase; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Plan; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Step; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Step.RouteLeg; import ai.rideos.api.commons.ride_hail_commons.RideHailCommons.VehicleState.Step.VehicleActionCase; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.FindPredefinedStopRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.GetTripDefinitionRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.GetTripStateRequestRC; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.StopSearchParameters; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc.RideHailRiderServiceFutureStub; import androidx.core.util.Pair; import io.grpc.ManagedChannel; import io.reactivex.Single; import java.util.Collections; import java.util.List; import java.util.OptionalInt; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; import timber.log.Timber; public class DefaultRiderTripStateInteractor extends GrpcServerInteractor<RideHailRiderServiceFutureStub> implements RiderTripStateInteractor { private final PolylineDecoder polylineDecoder; public DefaultRiderTripStateInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { this(channelSupplier, user, new GMSPolylineDecoder(), new DefaultSchedulerProvider()); } public DefaultRiderTripStateInteractor(final Supplier<ManagedChannel> channelSupplier, final User user, final PolylineDecoder polylineDecoder, final SchedulerProvider schedulerProvider) { super(RideHailRiderServiceGrpc::newFutureStub, channelSupplier, user, schedulerProvider); this.polylineDecoder = polylineDecoder; } @Override public Single<TripStateModel> getTripState(final String tripId, final String fleetId) { return fetchAuthorizedStub() .flatMap(rideHailStub -> Single.zip( Single.fromFuture(rideHailStub.getTripStateRC( GetTripStateRequestRC.newBuilder() .setId(tripId) .build() )), // TODO we can probably just call this once in whatever interactor requires the pickup/drop-off location Single.fromFuture(rideHailStub.getTripDefinition( GetTripDefinitionRequest.newBuilder() .setId(tripId) .build() )) .flatMap(response -> resolveStopsToPickupDropOff(response.getDefinition(), fleetId)), (stateResponse, pickupAndDropOff) -> new CompleteTripInfo( stateResponse.getState(), pickupAndDropOff.first, pickupAndDropOff.second ) )) .map(tripInfo -> { final TripState tripState = tripInfo.tripState; final LatLng pickup = tripInfo.pickup; final LatLng dropOff = tripInfo.dropOff; switch (tripState.getTripStateCase()) { case WAITING_FOR_ASSIGNMENT: return new TripStateModel( Stage.WAITING_FOR_ASSIGNMENT, null, null, null, pickup, dropOff, Collections.emptyList(), null ); case DRIVING_TO_PICKUP: final AssignedVehicle pickupVehicle = tripState.getDrivingToPickup().getAssignedVehicle(); return new TripStateModel( Stage.DRIVING_TO_PICKUP, getRouteInfoFromTrip(pickupVehicle, tripState.getTripStateCase(), tripId), getVehicleInfoFromTrip(pickupVehicle.getInfo()), getVehiclePosition(pickupVehicle), pickup, dropOff, getWaypoints(pickupVehicle.getPlanThroughTripEnd(), tripState.getTripStateCase(), tripId), null ); case WAITING_FOR_PICKUP: final AssignedVehicle waitingVehicle = tripState.getWaitingForPickup().getAssignedVehicle(); return new TripStateModel( Stage.WAITING_FOR_PICKUP, null, getVehicleInfoFromTrip(waitingVehicle.getInfo()), getVehiclePosition(waitingVehicle), pickup, dropOff, Collections.emptyList(), null ); case DRIVING_TO_DROPOFF: final AssignedVehicle dropOffVehicle = tripState.getDrivingToDropoff().getAssignedVehicle(); return new TripStateModel( Stage.DRIVING_TO_DROP_OFF, getRouteInfoFromTrip(dropOffVehicle, tripState.getTripStateCase(), tripId), getVehicleInfoFromTrip(tripState.getDrivingToDropoff().getAssignedVehicle().getInfo()), getVehiclePosition(dropOffVehicle), pickup, dropOff, getWaypoints(dropOffVehicle.getPlanThroughTripEnd(), tripState.getTripStateCase(), tripId), null ); case COMPLETED: return new TripStateModel( Stage.COMPLETED, null, null, null, pickup, dropOff, Collections.emptyList(), null ); case CANCELED: return new TripStateModel( Stage.CANCELLED, null, null, null, pickup, dropOff, Collections.emptyList(), getCancellationReason(tripState.getCanceled()) ); default: return new TripStateModel( Stage.UNKNOWN, null, null, null, pickup, dropOff, Collections.emptyList(), null ); } }); } private RouteInfoModel getRouteInfoFromTrip(final AssignedVehicle assignedVehicle, final TripStateCase state, final String tripId) { final List<Step> steps = stepsUntilCurrent( assignedVehicle.getPlanThroughTripEnd().getStepList(), tripId, state ); final List<RouteLeg> legs = steps.stream() .filter(step -> step.getVehicleActionCase() == VehicleActionCase.DRIVE_TO_LOCATION) .map(step -> step.getDriveToLocation().getRoute()) .collect(Collectors.toList()); return new RouteInfoModel( legs.stream() .map(leg -> polylineDecoder.decode(leg.getPolyline())) .flatMap(List::stream) .collect(Collectors.toList()), legs.stream() .map(leg -> leg.getTravelTimeInSeconds() * 1000) .mapToLong(Double::longValue) .sum(), legs.stream() .map(RouteLeg::getDistanceInMeters) .mapToDouble(Double::doubleValue) .sum() ); } /** * The ride-hail api gives all the steps until the end of the trip. For display purposes, we would only like to * show the steps until the current step, and nothing beyond. */ private static List<Step> stepsUntilCurrent(final List<Step> steps, final String tripId, final TripStateCase stateCase) { if (stateCase == TripStateCase.DRIVING_TO_DROPOFF) { return steps; } final OptionalInt indexOpt = IntStream.range(0, steps.size()) .filter(i -> steps.get(i).getTripId().equals(tripId) && steps.get(i).getVehicleActionCase() == VehicleActionCase.PICKUP_RIDER ) .findFirst(); if (!indexOpt.isPresent()) { Timber.e("Invalid plan: Could not find DRIVING_TO_DROP_OFF step in trip %s", tripId); return Collections.emptyList(); } return steps.subList(0, indexOpt.getAsInt() + 1); } private static List<LatLng> getWaypoints(final Plan plan, final TripStateCase state, final String tripId) { final List<Step> steps = stepsUntilCurrent(plan.getStepList(), tripId, state); return steps.stream() .filter(step -> isDisplayableWaypoint(step, tripId)) .map(Step::getPosition) .map(Locations::fromRideOsPosition) .collect(Collectors.toList()); } /** * A displayable waypoint should have the following 2 traits: * 1. It should not be part of the rider's trip * 2. It should be a drive-to step * This filter basically leaves displayable points along the rider's route to show other trips that need to take * place along the way. */ private static boolean isDisplayableWaypoint(final Step step, final String tripId) { return !step.getTripId().equals(tripId) && step.getVehicleActionCase() == VehicleActionCase.DRIVE_TO_LOCATION; } private static LocationAndHeading getVehiclePosition(final AssignedVehicle assignedVehicle) { return new LocationAndHeading( assignedVehicle.hasPosition() ? Locations.fromRideOsPosition(assignedVehicle.getPosition()) : new LatLng(0, 0), assignedVehicle.hasHeading() ? assignedVehicle.getHeading().getValue() : 0f ); } private static VehicleInfo getVehicleInfoFromTrip(final RideHailCommons.VehicleInfo assignedVehicle) { final String contactUrl; if (assignedVehicle.getDriverInfo().hasContactInfo()) { if (!assignedVehicle.getDriverInfo().getContactInfo().getContactUrl().isEmpty()) { contactUrl = assignedVehicle.getDriverInfo().getContactInfo().getContactUrl(); } else if (!assignedVehicle.getDriverInfo().getContactInfo().getPhoneNumber().isEmpty()) { contactUrl = "tel://" + assignedVehicle.getDriverInfo().getContactInfo().getPhoneNumber(); } else { contactUrl = ""; } } else { contactUrl = ""; } return new VehicleInfo(assignedVehicle.getLicensePlate(), new ContactInfo(contactUrl)); } private static CancellationReason getCancellationReason(final Canceled canceledState) { return new CancellationReason( translateCancellationSource(canceledState.getSource()), canceledState.getDescription() ); } private static CancellationReason.Source translateCancellationSource(final CancelSource source) { switch (source) { case RIDER: return Source.RIDER; case DRIVER: return Source.DRIVER; default: return Source.INTERNAL; } } private Single<Pair<LatLng, LatLng>> resolveStopsToPickupDropOff(final TripDefinition tripDefinition, final String fleetId) { return Single.zip( getLocationFromStop(tripDefinition.getPickupDropoff().getPickup(), fleetId), getLocationFromStop(tripDefinition.getPickupDropoff().getDropoff(), fleetId), Pair::create ); } private Single<LatLng> getLocationFromStop(final Stop stop, final String fleetId) { if (stop.getTypeCase() == TypeCase.POSITION) { return Single.just(Locations.fromRideOsPosition(stop.getPosition())); } return fetchAuthorizedStubAndExecute(stub -> stub.findPredefinedStop( FindPredefinedStopRequest.newBuilder() .setFleetId(fleetId) .setSearchParameters(StopSearchParameters.newBuilder().setStopId(stop.getPredefinedStopId())) .build() )) .firstOrError() .map(stopResponse -> Locations.fromRideOsPosition(stopResponse.getPredefinedStop(0).getPosition())); } private static class CompleteTripInfo { private final TripState tripState; private final LatLng pickup; private final LatLng dropOff; private CompleteTripInfo(final TripState tripState, final LatLng pickup, final LatLng dropOff) { this.tripState = tripState; this.pickup = pickup; this.dropOff = dropOff; } } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/DefaultStopInteractor.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.interactors; import ai.rideos.android.common.authentication.User; import ai.rideos.android.common.interactors.GrpcServerInteractor; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.common.utils.Locations; import ai.rideos.android.model.Stop; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.FindPredefinedStopRequest; import ai.rideos.api.ride_hail_rider.v1.RideHailRider.StopSearchParameters; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc; import ai.rideos.api.ride_hail_rider.v1.RideHailRiderServiceGrpc.RideHailRiderServiceFutureStub; import io.grpc.ManagedChannel; import io.reactivex.Observable; import java.util.function.Supplier; public class DefaultStopInteractor extends GrpcServerInteractor<RideHailRiderServiceFutureStub> implements StopInteractor { public DefaultStopInteractor(final Supplier<ManagedChannel> channelSupplier, final User user) { super(RideHailRiderServiceGrpc::newFutureStub, channelSupplier, user, new DefaultSchedulerProvider()); } @Override public Observable<Stop> getBestStop(final String fleetId, final LatLng location) { return fetchAuthorizedStubAndExecute(stub -> stub.findPredefinedStop( FindPredefinedStopRequest.newBuilder() .setFleetId(fleetId) .setSearchParameters( StopSearchParameters.newBuilder().setQueryPosition(Locations.toRideOsPosition(location)) ) .build() )) .map(response -> new Stop( Locations.fromRideOsPosition(response.getPredefinedStop(0).getPosition()), response.getPredefinedStop(0).getId() )); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/HistoricalSearchInteractor.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.interactors; import ai.rideos.android.common.model.LocationAutocompleteResult; import io.reactivex.Completable; import io.reactivex.Observable; import java.util.List; public interface HistoricalSearchInteractor { Observable<List<LocationAutocompleteResult>> getHistoricalSearchOptions(); Completable storeSearchedOption(final LocationAutocompleteResult searchOption); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/PreviewVehicleInteractor.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.interactors; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.model.VehiclePosition; import io.reactivex.Observable; import java.util.List; public interface PreviewVehicleInteractor { /** * Retrieves a preview of the vehicles in an area. There is no guarantee these vehicle ids match the actual backend * objects. */ Observable<List<VehiclePosition>> getVehiclesInVicinity(final LatLng center, final String fleetId); void shutDown(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/RiderTripInteractor.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.interactors; import ai.rideos.android.common.model.TaskLocation; import ai.rideos.android.model.ContactInfo; import io.reactivex.Completable; import io.reactivex.Observable; import java.util.Optional; public interface RiderTripInteractor { Observable<String> createTripForPassenger(final String passengerId, final ContactInfo contactInfo, final String fleetId, final int numPassengers, final TaskLocation pickupLocation, final TaskLocation dropOffLocation); Observable<String> createTripForPassengerAndVehicle(final String passengerId, final ContactInfo contactInfo, final String vehicleId, final String fleetId, final int numPassengers, final TaskLocation pickupLocation, final TaskLocation dropOffLocation); /** * Get the current trip given a passenger, if it exists. * @param passengerId - passenger to find trip for * @return Optional task id. This value is empty if a trip doesn't exist (or is over) and the trip id otherwise */ Observable<Optional<String>> getCurrentTripForPassenger(final String passengerId); Completable cancelTrip(final String passengerId, final String tripId); /** * Modify the pickup location for a trip and emit the new task id or an error if it could not be updated * @param tripId - current trip id * @param newPickupLocation - updated pickup location * @return new task id if successful */ Observable<String> editPickup(final String tripId, final TaskLocation newPickupLocation); void shutDown(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/RiderTripStateInteractor.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.interactors; import ai.rideos.android.model.TripStateModel; import io.reactivex.Single; public interface RiderTripStateInteractor { Single<TripStateModel> getTripState(final String tripId, final String fleetId); void shutDown(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/StopInteractor.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.interactors; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.model.Stop; import io.reactivex.Observable; public interface StopInteractor { Observable<Stop> getBestStop(final String fleetId, final LatLng location); void shutDown(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/interactors/UserStorageHistoricalSearchInteractor.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.interactors; import ai.rideos.android.common.model.LocationAutocompleteResult; import ai.rideos.android.common.reactive.SchedulerProvider; import ai.rideos.android.common.reactive.SchedulerProviders.DefaultSchedulerProvider; import ai.rideos.android.common.user_storage.StorageKey; import ai.rideos.android.common.user_storage.UserStorageReader; import ai.rideos.android.common.user_storage.UserStorageWriter; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; import io.reactivex.Completable; import io.reactivex.Observable; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class UserStorageHistoricalSearchInteractor implements HistoricalSearchInteractor { public interface HistoricalOptionsSerializer { String serialize(final List<LocationAutocompleteResult> options); List<LocationAutocompleteResult> deserialize(final String serializedOptions) throws DeserializeException; } public static class DeserializeException extends Exception { DeserializeException(final Exception e) { super(e); } } private static final int DEFAULT_MAX_OPTIONS = 5; private static final StorageKey<String> STORAGE_KEY = new StorageKey<>("historical_searches", ""); private final UserStorageReader userStorageReader; private final UserStorageWriter userStorageWriter; private final HistoricalOptionsSerializer serializer; private final SchedulerProvider schedulerProvider; private final int maxOptions; public UserStorageHistoricalSearchInteractor(final UserStorageReader userStorageReader, final UserStorageWriter userStorageWriter) { this( userStorageReader, userStorageWriter, new GsonSerializer(), DEFAULT_MAX_OPTIONS, new DefaultSchedulerProvider() ); } public UserStorageHistoricalSearchInteractor(final UserStorageReader userStorageReader, final UserStorageWriter userStorageWriter, final HistoricalOptionsSerializer serializer, final int maxOptions, final SchedulerProvider schedulerProvider) { this.userStorageReader = userStorageReader; this.userStorageWriter = userStorageWriter; this.serializer = serializer; this.maxOptions = maxOptions; this.schedulerProvider = schedulerProvider; } @Override public Observable<List<LocationAutocompleteResult>> getHistoricalSearchOptions() { return Observable.fromCallable(this::getResultsFromUserStorage) // This is reading from storage, potentially blocking .subscribeOn(schedulerProvider.io()); } @Override public Completable storeSearchedOption(final LocationAutocompleteResult searchOption) { return Completable.fromRunnable(() -> storeSearchOptionAndTrim(searchOption)) .subscribeOn(schedulerProvider.io()); } private List<LocationAutocompleteResult> getResultsFromUserStorage() { final String storedSearchString = userStorageReader.getStringPreference(STORAGE_KEY); try { return serializer.deserialize(storedSearchString); } catch (final DeserializeException e) { userStorageWriter.storeStringPreference(STORAGE_KEY, ""); return Collections.emptyList(); } } private void storeSearchOptionAndTrim(final LocationAutocompleteResult newOption) { final List<LocationAutocompleteResult> storedOptions = new ArrayList<>(getResultsFromUserStorage()); // Remove existing option if it exists, so that we can reorder the latest search storedOptions.remove(newOption); // Add option to front storedOptions.add(0, newOption); if (storedOptions.size() > maxOptions) { // Trim end of list storedOptions.subList(maxOptions, storedOptions.size()).clear(); } final String serializedOptions = serializer.serialize(storedOptions); userStorageWriter.storeStringPreference(STORAGE_KEY, serializedOptions); } public static class GsonSerializer implements HistoricalOptionsSerializer { @Override public String serialize(final List<LocationAutocompleteResult> options) { final Type listType = new TypeToken<List<LocationAutocompleteResult>>() {}.getType(); return new Gson().toJson(options, listType); } @Override public List<LocationAutocompleteResult> deserialize(final String serializedOptions) throws DeserializeException { if (serializedOptions.isEmpty()) { return Collections.emptyList(); } final Type listType = new TypeToken<List<LocationAutocompleteResult>>() {}.getType(); try { return new Gson().fromJson(serializedOptions, listType); } catch (final JsonSyntaxException e) { throw new DeserializeException(e); } } } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/AvailableVehicle.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.model; public class AvailableVehicle { private final String vehicleId; private final String displayName; public AvailableVehicle(final String vehicleId, final String displayName) { this.vehicleId = vehicleId; this.displayName = displayName; } public String getVehicleId() { return vehicleId; } public String getDisplayName() { return displayName; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/ContactInfo.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.model; public class ContactInfo { private final String name; public ContactInfo(final String name) { this.name = name; } public String getName() { return name; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof ContactInfo)) { return false; } final ContactInfo otherModel = (ContactInfo) other; return name.equals(otherModel.getName()); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/DesiredAndAssignedLocation.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.model; import ai.rideos.android.common.model.NamedTaskLocation; /** * DesiredAndAssignedLocation wraps the user's desired pickup/drop-off spot and the one that is actually assigned. In * most cases only the desired location is used, but in the event that the app needs to assign a nearby PUDOL or stop, * the assigned location is used. */ public class DesiredAndAssignedLocation { private final NamedTaskLocation desiredLocation; private final NamedTaskLocation assignedLocation; /** * In the case where the desired and assigned location are one in the same, the desired location only need be * specified. */ public DesiredAndAssignedLocation(final NamedTaskLocation desiredLocation) { this(desiredLocation, desiredLocation); } public DesiredAndAssignedLocation(final NamedTaskLocation desiredLocation, final NamedTaskLocation assignedLocation) { this.desiredLocation = desiredLocation; this.assignedLocation = assignedLocation; } public NamedTaskLocation getDesiredLocation() { return desiredLocation; } public NamedTaskLocation getAssignedLocation() { return assignedLocation; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof DesiredAndAssignedLocation)) { return false; } final DesiredAndAssignedLocation otherModel = (DesiredAndAssignedLocation) other; return desiredLocation.equals(otherModel.desiredLocation) && assignedLocation.equals(otherModel.assignedLocation); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/FollowTripDisplayState.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.model; public class FollowTripDisplayState { private final boolean stageChanged; private final TripStateModel passengerState; private final NamedPickupDropOff namedPickupDropOff; public FollowTripDisplayState(final boolean stageChanged, final TripStateModel passengerState, final NamedPickupDropOff namedPickupDropOff) { this.stageChanged = stageChanged; this.passengerState = passengerState; this.namedPickupDropOff = namedPickupDropOff; } public boolean hasStageChanged() { return stageChanged; } public TripStateModel getPassengerState() { return passengerState; } public NamedPickupDropOff getNamedPickupDropOff() { return namedPickupDropOff; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/LocationSearchFocusType.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.model; public enum LocationSearchFocusType { NONE, PICKUP, DROP_OFF }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/LocationSearchInitialState.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.model; import ai.rideos.android.common.model.NamedTaskLocation; import androidx.annotation.Nullable; import java.io.Serializable; import java.util.Optional; public class LocationSearchInitialState implements Serializable { private final LocationSearchFocusType initialFocus; private final NamedTaskLocation initialPickup; private final NamedTaskLocation initialDropOff; public LocationSearchInitialState(final LocationSearchFocusType initialFocus, final @Nullable NamedTaskLocation initialPickup, final @Nullable NamedTaskLocation initialDropOff) { this.initialFocus = initialFocus; this.initialPickup = initialPickup; this.initialDropOff = initialDropOff; } public LocationSearchFocusType getInitialFocus() { return initialFocus; } public Optional<NamedTaskLocation> getInitialPickup() { return Optional.ofNullable(initialPickup); } public Optional<NamedTaskLocation> getInitialDropOff() { return Optional.ofNullable(initialDropOff); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/LocationSearchOptionModel.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.model; import ai.rideos.android.common.model.LocationAutocompleteResult; import ai.rideos.android.rider_app.R; import java.util.Objects; import java.util.Optional; public class LocationSearchOptionModel { public enum OptionType { AUTOCOMPLETE_LOCATION, CURRENT_LOCATION, SELECT_ON_MAP } private final String primaryName; private final String secondaryName; private final Integer drawableIcon; private final LocationAutocompleteResult autocompleteResult; private final OptionType optionType; public static LocationSearchOptionModel autocompleteLocation(final LocationAutocompleteResult autocompleteResult) { return new LocationSearchOptionModel( autocompleteResult.getPrimaryName(), autocompleteResult.getSecondaryName(), autocompleteResult, OptionType.AUTOCOMPLETE_LOCATION, null ); } public static LocationSearchOptionModel currentLocation(final String primaryName) { return new LocationSearchOptionModel( primaryName, "", null, OptionType.CURRENT_LOCATION, R.drawable.ic_my_location_24dp ); } public static LocationSearchOptionModel selectOnMap(final String primaryName) { return new LocationSearchOptionModel( primaryName, "", null, OptionType.SELECT_ON_MAP, R.drawable.ic_set_on_map_24dp ); } public static LocationSearchOptionModel historicalSearch(final LocationAutocompleteResult autocompleteResult) { return new LocationSearchOptionModel( autocompleteResult.getPrimaryName(), autocompleteResult.getSecondaryName(), autocompleteResult, OptionType.AUTOCOMPLETE_LOCATION, R.drawable.ic_history_24dp ); } private LocationSearchOptionModel(final String primaryName, final String secondaryName, final LocationAutocompleteResult autocompleteResult, final OptionType optionType, final Integer drawableIcon) { this.primaryName = primaryName; this.secondaryName = secondaryName; this.autocompleteResult = autocompleteResult; this.optionType = optionType; this.drawableIcon = drawableIcon; } public String getPrimaryName() { return primaryName; } public String getSecondaryName() { return secondaryName; } public LocationAutocompleteResult getAutocompleteResult() { return autocompleteResult; } public OptionType getOptionType() { return optionType; } public Optional<Integer> getDrawableIcon() { return Optional.ofNullable(drawableIcon); } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof LocationSearchOptionModel)) { return false; } final LocationSearchOptionModel otherModel = (LocationSearchOptionModel) other; return primaryName.equals(otherModel.primaryName) && secondaryName.equals(otherModel.secondaryName) && Objects.equals(autocompleteResult, otherModel.autocompleteResult) && optionType == otherModel.optionType; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/MainViewState.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.model; import java.util.Objects; public class MainViewState { public enum Step { START_SCREEN, PRE_TRIP, ON_TRIP, } private final Step step; private final String taskId; public MainViewState(final Step step, final String taskId) { this.step = step; this.taskId = taskId; } public Step getStep() { return step; } public String getTaskId() { return taskId; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof MainViewState)) { return false; } final MainViewState otherModel = (MainViewState) other; return Objects.equals(taskId, otherModel.taskId) && step == otherModel.step; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/NamedPickupDropOff.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.model; import ai.rideos.android.common.model.NamedTaskLocation; public class NamedPickupDropOff { private final NamedTaskLocation pickup; private final NamedTaskLocation dropOff; public NamedPickupDropOff(final NamedTaskLocation pickup, final NamedTaskLocation dropOff) { this.pickup = pickup; this.dropOff = dropOff; } public NamedTaskLocation getPickup() { return pickup; } public NamedTaskLocation getDropOff() { return dropOff; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof NamedPickupDropOff)) { return false; } final NamedPickupDropOff otherModel = (NamedPickupDropOff) other; return pickup.equals(otherModel.pickup) && dropOff.equals(otherModel.dropOff); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/OnTripDisplayState.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.model; import ai.rideos.android.common.model.NamedTaskLocation; import java.util.Objects; import java.util.Optional; public class OnTripDisplayState { public enum Display { CURRENT_TRIP, CONFIRMING_CANCEL, EDITING_PICKUP, CONFIRMING_EDIT_PICKUP } private final Display display; private final NamedTaskLocation pickupLocation; private final String tripId; public OnTripDisplayState(final Display display, final String tripId) { this(display, tripId, null); } public OnTripDisplayState(final Display display, final String tripId, final NamedTaskLocation pickupLocation) { this.display = display; this.tripId = tripId; this.pickupLocation = pickupLocation; } public String getTripId() { return tripId; } public Display getDisplay() { return display; } public Optional<NamedTaskLocation> getPickupLocation() { return Optional.ofNullable(pickupLocation); } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof OnTripDisplayState)) { return false; } final OnTripDisplayState otherModel = (OnTripDisplayState) other; return display == otherModel.display && tripId.equals(otherModel.tripId) && Objects.equals(pickupLocation, otherModel.pickupLocation); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/PreTripLocation.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.model; public class PreTripLocation { private final DesiredAndAssignedLocation desiredAndAssignedLocation; private final boolean wasConfirmedOnMap; public PreTripLocation(final DesiredAndAssignedLocation desiredAndAssignedLocation, final boolean wasConfirmedOnMap) { this.desiredAndAssignedLocation = desiredAndAssignedLocation; this.wasConfirmedOnMap = wasConfirmedOnMap; } public DesiredAndAssignedLocation getDesiredAndAssignedLocation() { return desiredAndAssignedLocation; } public boolean wasConfirmedOnMap() { return wasConfirmedOnMap; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof PreTripLocation)) { return false; } final PreTripLocation otherModel = (PreTripLocation) other; return desiredAndAssignedLocation.equals(otherModel.desiredAndAssignedLocation) && wasConfirmedOnMap == otherModel.wasConfirmedOnMap; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/PreTripLocationModel.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.model; import ai.rideos.android.common.model.NamedTaskLocation; public class PreTripLocationModel { private final NamedTaskLocation geocodedLocation; private final boolean isConfirmed; public PreTripLocationModel(final NamedTaskLocation geocodedLocation, final boolean isConfirmed) { this.geocodedLocation = geocodedLocation; this.isConfirmed = isConfirmed; } public NamedTaskLocation getGeocodedLocation() { return geocodedLocation; } public boolean isConfirmed() { return isConfirmed; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/PreTripState.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.model; import androidx.annotation.Nullable; import java.util.Objects; import java.util.Optional; public class PreTripState { public enum Step { SELECTING_PICKUP_DROP_OFF, CONFIRMING_DROP_OFF, CONFIRMING_PICKUP, CONFIRMING_TRIP, CONFIRMING_VEHICLE, CONFIRMED } private final PreTripLocation pickup; private final PreTripLocation dropOff; // Only valid for SELECTING_PICKUP_DROP_OFF state, but unfortunately Java enums can't have associated values. private final LocationSearchFocusType initialSearchFocus; private final int numPassengers; @Nullable private final VehicleSelectionOption vehicleSelection; private final Step step; public PreTripState(final PreTripLocation pickup, final PreTripLocation dropOff, final int numPassengers, final VehicleSelectionOption vehicleSelection, final Step step) { this(pickup, dropOff, LocationSearchFocusType.DROP_OFF, numPassengers, vehicleSelection, step); } public PreTripState(final PreTripLocation pickup, final PreTripLocation dropOff, final LocationSearchFocusType initialSearchFocus, final int numPassengers, @Nullable final VehicleSelectionOption vehicleSelection, final Step step) { this.pickup = pickup; this.dropOff = dropOff; this.initialSearchFocus = initialSearchFocus; this.numPassengers = numPassengers; this.vehicleSelection = vehicleSelection; this.step = step; } public PreTripLocation getPickup() { return pickup; } public PreTripLocation getDropOff() { return dropOff; } public int getNumPassengers() { return numPassengers; } public Step getStep() { return step; } public LocationSearchFocusType getInitialSearchFocus() { return initialSearchFocus; } public Optional<VehicleSelectionOption> getVehicleSelection() { return Optional.ofNullable(vehicleSelection); } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof PreTripState)) { return false; } final PreTripState otherModel = (PreTripState) other; return Objects.equals(pickup, otherModel.pickup) && Objects.equals(dropOff, otherModel.dropOff) && numPassengers == otherModel.numPassengers && Objects.equals(vehicleSelection, otherModel.vehicleSelection) && step == otherModel.step && initialSearchFocus == otherModel.initialSearchFocus; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/RouteTimeDistanceDisplay.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.model; public class RouteTimeDistanceDisplay { private final String time; private final String distance; public RouteTimeDistanceDisplay(final String time, final String distance) { this.time = time; this.distance = distance; } public String getTime() { return time; } public String getDistance() { return distance; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof RouteTimeDistanceDisplay)) { return false; } final RouteTimeDistanceDisplay otherModel = (RouteTimeDistanceDisplay) other; return distance.equals(otherModel.distance) && time.equals(otherModel.time); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/SelectPickupDropOffDisplayState.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.model; import ai.rideos.android.common.model.NamedTaskLocation; import java.util.Objects; /** * Display state for the select pickup/drop-off flow. */ public class SelectPickupDropOffDisplayState { public enum SetPickupDropOffStep { SEARCHING_FOR_PICKUP_DROP_OFF, SETTING_PICKUP_ON_MAP, SETTING_DROP_OFF_ON_MAP } private final SetPickupDropOffStep step; private final NamedTaskLocation pickup; private final NamedTaskLocation dropOff; private final LocationSearchFocusType focus; public SelectPickupDropOffDisplayState(final SetPickupDropOffStep step, final NamedTaskLocation pickup, final NamedTaskLocation dropOff, final LocationSearchFocusType focus) { this.step = step; this.pickup = pickup; this.dropOff = dropOff; this.focus = focus; } public SetPickupDropOffStep getStep() { return step; } public NamedTaskLocation getPickup() { return pickup; } public NamedTaskLocation getDropOff() { return dropOff; } public LocationSearchFocusType getFocus() { return focus; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof SelectPickupDropOffDisplayState)) { return false; } final SelectPickupDropOffDisplayState otherModel = (SelectPickupDropOffDisplayState) other; return step == otherModel.step && Objects.equals(pickup, otherModel.pickup) && Objects.equals(dropOff, otherModel.dropOff); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/Stop.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.model; import ai.rideos.android.common.model.LatLng; public class Stop { private final LatLng latLng; private final String id; public Stop(final LatLng latLng, final String id) { this.latLng = latLng; this.id = id; } public LatLng getLatLng() { return latLng; } public String getId() { return id; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof Stop)) { return false; } final Stop otherModel = (Stop) other; return id.equals(otherModel.id) && latLng.equals(otherModel.latLng); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/TripStateModel.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.model; import ai.rideos.android.common.model.LatLng; import ai.rideos.android.common.model.LocationAndHeading; import ai.rideos.android.common.model.RouteInfoModel; import androidx.annotation.Nullable; import java.util.List; import java.util.Objects; import java.util.Optional; public class TripStateModel { public enum Stage { WAITING_FOR_ASSIGNMENT, DRIVING_TO_PICKUP, WAITING_FOR_PICKUP, DRIVING_TO_DROP_OFF, COMPLETED, CANCELLED, UNKNOWN } public static class CancellationReason { public enum Source { DRIVER, RIDER, INTERNAL } private final Source source; private final String description; public CancellationReason(final Source source, final String description) { this.source = source; this.description = description; } public Source getSource() { return source; } public String getDescription() { return description; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof CancellationReason)) { return false; } final CancellationReason otherModel = (CancellationReason) other; return source == otherModel.source && Objects.equals(description, otherModel.description); } } private final Stage stage; @Nullable private final RouteInfoModel vehicleRoute; @Nullable private final VehicleInfo vehicleInfo; @Nullable private final LocationAndHeading vehiclePosition; private final LatLng passengerPickupLocation; private final LatLng passengerDropOffLocation; private final List<LatLng> waypoints; @Nullable private final CancellationReason cancellationReason; public TripStateModel(final Stage stage, @Nullable final RouteInfoModel vehicleRoute, @Nullable final VehicleInfo vehicleInfo, @Nullable final LocationAndHeading vehiclePosition, final LatLng passengerPickupLocation, final LatLng passengerDropOffLocation, final List<LatLng> waypoints, @Nullable final CancellationReason cancellationReason) { this.stage = stage; this.vehicleRoute = vehicleRoute; this.vehicleInfo = vehicleInfo; this.vehiclePosition = vehiclePosition; this.passengerPickupLocation = passengerPickupLocation; this.passengerDropOffLocation = passengerDropOffLocation; this.waypoints = waypoints; this.cancellationReason = cancellationReason; } public Stage getStage() { return stage; } // Vehicle route is optional, for example, in the case that the task is cancelled public Optional<RouteInfoModel> getVehicleRouteInfo() { return Optional.ofNullable(vehicleRoute); } public LatLng getPassengerPickupLocation() { return passengerPickupLocation; } public LatLng getPassengerDropOffLocation() { return passengerDropOffLocation; } public Optional<VehicleInfo> getVehicleInfo() { return Optional.ofNullable(vehicleInfo); } public Optional<LocationAndHeading> getVehiclePosition() { return Optional.ofNullable(vehiclePosition); } public List<LatLng> getWaypoints() { return waypoints; } public Optional<CancellationReason> getCancellationReason() { return Optional.ofNullable(cancellationReason); } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof TripStateModel)) { return false; } final TripStateModel otherModel = (TripStateModel) other; return stage == otherModel.stage && Objects.equals(vehicleRoute, otherModel.vehicleRoute) && Objects.equals(vehicleInfo, otherModel.vehicleInfo) && Objects.equals(vehiclePosition, otherModel.vehiclePosition) && passengerPickupLocation.equals(otherModel.passengerPickupLocation) && passengerDropOffLocation.equals(otherModel.passengerDropOffLocation) && waypoints.equals(otherModel.waypoints) && Objects.equals(cancellationReason, otherModel.cancellationReason); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/VehicleInfo.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.model; import java.io.Serializable; public class VehicleInfo implements Serializable { public static class ContactInfo implements Serializable { private final String url; public ContactInfo(final String url) { this.url = url; } public String getUrl() { return url; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof ContactInfo)) { return false; } final ContactInfo otherModel = (ContactInfo) other; return url.equals(otherModel.url); } } private final String licensePlate; private final ContactInfo contactInfo; public VehicleInfo(final String licensePlate, final ContactInfo contactInfo) { this.licensePlate = licensePlate; this.contactInfo = contactInfo; } public String getLicensePlate() { return licensePlate; } public ContactInfo getContactInfo() { return contactInfo; } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof VehicleInfo)) { return false; } final VehicleInfo otherModel = (VehicleInfo) other; return licensePlate.equals(otherModel.licensePlate) && contactInfo.equals(otherModel.contactInfo); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/model/VehicleSelectionOption.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.model; import androidx.annotation.Nullable; import java.util.Objects; import java.util.Optional; public class VehicleSelectionOption { public enum SelectionType { AUTOMATIC, MANUAL } private final SelectionType selectionType; @Nullable private final String vehicleId; private VehicleSelectionOption(final SelectionType selectionType, final @Nullable String vehicleId) { this.selectionType = selectionType; this.vehicleId = vehicleId; } public static VehicleSelectionOption automatic() { return new VehicleSelectionOption(SelectionType.AUTOMATIC, null); } public static VehicleSelectionOption manual(final String vehicleId) { return new VehicleSelectionOption(SelectionType.MANUAL, vehicleId); } public SelectionType getSelectionType() { return selectionType; } public Optional<String> getVehicleId() { return Optional.ofNullable(vehicleId); } @Override public boolean equals(final Object other) { if (other == this) { return true; } if (!(other instanceof VehicleSelectionOption)) { return false; } final VehicleSelectionOption otherModel = (VehicleSelectionOption) other; return selectionType == otherModel.selectionType && Objects.equals(vehicleId, otherModel.vehicleId); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_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.rider_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.BackListener; import ai.rideos.android.common.viewmodel.state_machine.StateMachine; import ai.rideos.android.interactors.RiderTripInteractor; import ai.rideos.android.model.MainViewState; import ai.rideos.android.model.MainViewState.Step; import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; import io.reactivex.Observable; import io.reactivex.disposables.CompositeDisposable; import java.util.Optional; import java.util.concurrent.TimeUnit; public class DefaultMainViewModel implements MainViewModel { private static final MainViewState INITIAL_STATE = new MainViewState(Step.START_SCREEN, null); private static final int DEFAULT_TASK_POLL_INTERVAL_MILLIS = 1000; private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private final StateMachine<MainViewState> stateMachine; private final Flowable<String> currentTask; private final MainViewState initialState; private final SchedulerProvider schedulerProvider; private final BackListener backListener; private final RiderTripInteractor tripInteractor; public DefaultMainViewModel(final BackListener backListener, final RiderTripInteractor tripInteractor, final User user) { this( backListener, tripInteractor, user, INITIAL_STATE, new DefaultSchedulerProvider(), DEFAULT_TASK_POLL_INTERVAL_MILLIS ); } // Allow injection of state machine to allow different schedulers for polling and the state machine public DefaultMainViewModel(final BackListener backListener, final RiderTripInteractor tripInteractor, final User user, final MainViewState initialState, final SchedulerProvider schedulerProvider, final int pollIntervalMilli) { this.schedulerProvider = schedulerProvider; this.initialState = initialState; this.stateMachine = new StateMachine<>(schedulerProvider); this.backListener = backListener; this.tripInteractor = tripInteractor; compositeDisposable.addAll( stateMachine.start() ); currentTask = pollForCurrentTask(tripInteractor, user.getId(), pollIntervalMilli); } @Override public void initialize() { stateMachine.initialize(initialState); } @Override public Observable<MainViewState> getMainViewState() { // When main view state is subscribed to, the current task will be polled return Observable.combineLatest( currentTask.toObservable().startWith(""), stateMachine.observeCurrentState(), (task, state) -> state ) .distinctUntilChanged(); } @Override public void startPreTripFlow() { stateMachine.transition(transitionIf( state -> state.getStep() == Step.START_SCREEN, state -> new MainViewState(Step.PRE_TRIP, null) )); } @Override public void cancelTripRequest() { stateMachine.transition(transitionIf( state -> state.getStep() == Step.PRE_TRIP, state -> new MainViewState(Step.START_SCREEN, null) )); } @Override public void onTripCreated(final String tripId) { stateMachine.transition(transitionIf( state -> state.getStep() == Step.PRE_TRIP, state -> new MainViewState(Step.ON_TRIP, tripId) )); } @Override public void tripFinished() { stateMachine.transition(transitionIf( state -> state.getStep() == Step.ON_TRIP, state -> new MainViewState(Step.START_SCREEN, null) )); } @Override public void back() { // Always apply event stateMachine.transition(state -> { // Only go back if the current step is pre-trip if (state.getStep() == Step.PRE_TRIP) { return new MainViewState(Step.START_SCREEN, null); } // Otherwise propagate back call to parent and return current state backListener.back(); return state; }); } @Override public void destroy() { compositeDisposable.dispose(); tripInteractor.shutDown(); } private Flowable<String> pollForCurrentTask(final RiderTripInteractor tripInteractor, final String passengerId, final int pollIntervalMilli) { // Use `flowable` to take advantage of back-pressure strategies // If the interval is emitting faster than the taskInteractor is consuming, it will drop incoming requests // so that the queue doesn't fill up return Flowable.interval(0, pollIntervalMilli, TimeUnit.MILLISECONDS, schedulerProvider.io()) .onBackpressureDrop() // get current task .flatMap( // getCurrentTaskForPassenger should only return one value, so drop the rest time -> tripInteractor.getCurrentTripForPassenger(passengerId) .observeOn(schedulerProvider.computation()) .toFlowable(BackpressureStrategy.DROP), 1 ) .observeOn(schedulerProvider.computation()) // filter out when task does not exist .filter(Optional::isPresent) .map(Optional::get) // ensure the same task doesn't get reported twice .distinctUntilChanged() .doOnNext(taskId -> stateMachine.transition(currentState -> new MainViewState(Step.ON_TRIP, taskId))); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_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.rider_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.common.view.BackPropagator; import ai.rideos.android.common.viewmodel.BackListener; import ai.rideos.android.rider_app.dependency.RiderDependencyRegistry; import ai.rideos.android.rider_app.on_trip.OnTripCoordinator; import ai.rideos.android.rider_app.pre_trip.PreTripCoordinator; import ai.rideos.android.rider_app.start_screen.StartScreenFragment; import android.content.Context; import io.reactivex.disposables.CompositeDisposable; public class MainCoordinator implements Coordinator<EmptyArg>, BackPropagator { private CompositeDisposable compositeDisposable; private final MainViewModel mainViewModel; private final NavigationController navController; private final Coordinator<EmptyArg> preTripCoordinator; private final Coordinator<String> onTripCoordinator; private Coordinator activeChild = null; public MainCoordinator(final Context context, final NavigationController navController, final BackListener backListener) { this.navController = navController; mainViewModel = new DefaultMainViewModel( backListener, RiderDependencyRegistry.riderDependencyFactory().getTripInteractor(context), User.get(context) ); preTripCoordinator = new PreTripCoordinator(context, navController, mainViewModel); onTripCoordinator = new OnTripCoordinator(context, navController, mainViewModel); } @Override public void start(final EmptyArg emptyArg) { mainViewModel.initialize(); compositeDisposable = new CompositeDisposable(); compositeDisposable.addAll( mainViewModel.getMainViewState() .subscribe(state -> { stopChild(); switch (state.getStep()) { case START_SCREEN: navController.navigateTo(new StartScreenFragment(), EmptyArg.create(), mainViewModel); break; case PRE_TRIP: preTripCoordinator.start(EmptyArg.create()); activeChild = preTripCoordinator; break; case ON_TRIP: onTripCoordinator.start(state.getTaskId()); activeChild = onTripCoordinator; break; } }) ); } private void stopChild() { if (activeChild != null) { activeChild.stop(); } activeChild = null; } @Override public void stop() { stopChild(); compositeDisposable.dispose(); } @Override public void destroy() { preTripCoordinator.destroy(); onTripCoordinator.destroy(); mainViewModel.destroy(); } @Override public void propagateBackSignal() { if (activeChild instanceof BackPropagator) { ((BackPropagator) activeChild).propagateBackSignal(); } else { mainViewModel.back(); } } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_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.rider_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.common.view.BackPropagator; import ai.rideos.android.common.viewmodel.BackListener; import ai.rideos.android.rider_app.dependency.RiderDependencyRegistry; 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 implements BackPropagator { 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()), (BackListener) getActivity() ); } @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, RiderDependencyRegistry.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(); } @Override public void propagateBackSignal() { mainCoordinator.propagateBackSignal(); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_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.rider_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.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.app.push_notifications.PushNotificationManager; 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.rider_app.dependency.RiderDependencyRegistry; import ai.rideos.android.rider_app.launch.LaunchActivity; import android.content.Intent; import android.os.Bundle; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.FragmentActivity; 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; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drawer_layout); final DrawerLayout drawerLayout = findViewById(R.id.drawer_layout); final MenuOptionFragmentRegistry registry = RiderDependencyRegistry.riderDependencyFactory() .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 onDestroy() { super.onDestroy(); compositeDisposable.dispose(); menuController.detach(); } @Override public void onStart() { super.onStart(); connectivityMonitor.start(); final boolean enablePushNotifications = new MetadataReader(this) .getBooleanMetadata(CommonMetadataKeys.ENABLE_PUSH_NOTIFICATIONS) .getOrDefault(true); if (enablePushNotifications) { compositeDisposable.add(PushNotificationManager.forRider(this).requestTokenAndSync().subscribe( () -> Timber.i("Initialized device token"), e -> Timber.e(e, "Failed to request token") )); } } @Override public void onStop() { super.onStop(); connectivityMonitor.stop(); } /** * 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( RiderDependencyRegistry.riderDependencyFactory().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-rider/1.0.2/ai/rideos/android
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_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.rider_app; import ai.rideos.android.common.viewmodel.BackListener; import ai.rideos.android.common.viewmodel.ViewModel; import ai.rideos.android.model.MainViewState; import ai.rideos.android.rider_app.on_trip.OnTripListener; import ai.rideos.android.rider_app.pre_trip.PreTripListener; import ai.rideos.android.rider_app.start_screen.StartScreenListener; import io.reactivex.Observable; public interface MainViewModel extends ViewModel, BackListener, StartScreenListener, PreTripListener, OnTripListener { void initialize(); Observable<MainViewState> getMainViewState(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/deeplink/KnownAppSchemes.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.rider_app.deeplink; import androidx.annotation.Nullable; import com.google.common.collect.ImmutableMap; import java.util.Map; import java.util.Optional; public class KnownAppSchemes { private static final Map<String, String> playStoreUrisByScheme = ImmutableMap.<String, String>builder() .put("slack", "https://play.google.com/store/apps/details?id=com.Slack") .build(); public static Optional<String> getPlayStoreLinkFromScheme(@Nullable final String scheme) { if (scheme == null) { return Optional.empty(); } return Optional.ofNullable(playStoreUrisByScheme.getOrDefault(scheme, null)); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/deeplink/UriLauncher.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.rider_app.deeplink; import ai.rideos.android.rider_app.R; import android.app.Activity; import android.app.AlertDialog.Builder; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; import java.util.Optional; import timber.log.Timber; public class UriLauncher { private final Activity activity; private final String uriString; public UriLauncher(final Context context, final String uriString) { this.activity = (Activity) context; this.uriString = uriString; } public void launch() { if (uriString.isEmpty()) { Timber.e("Tried to open empty URI"); return; // Don't do anything } final Uri uri = Uri.parse(uriString); final Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); try { activity.startActivity(browserIntent); } catch (final ActivityNotFoundException e) { tryToShowPlayStoreLink(uri); } } private void tryToShowPlayStoreLink(final Uri uri) { final Optional<String> playStoreLink = KnownAppSchemes.getPlayStoreLinkFromScheme(uri.getScheme()); if (playStoreLink.isPresent()) { final Uri playStoreUri = Uri.parse(playStoreLink.get()); final Intent browserIntent = new Intent(Intent.ACTION_VIEW, playStoreUri); try { activity.startActivity(browserIntent); } catch (final ActivityNotFoundException e) { showFailureMessage(); } } else { showFailureMessage(); } } private void showFailureMessage() { new Builder(activity) .setMessage(activity.getString(R.string.open_uri_error_unknown_app, uriString)) .setPositiveButton(activity.getString(R.string.open_uri_error_confirmation_button), (dialog, i) -> {}) .create() .show(); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/dependency/DefaultRiderDependencyFactory.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.rider_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.model.MenuOption; import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageReader; import ai.rideos.android.common.user_storage.SharedPreferencesUserStorageWriter; import ai.rideos.android.interactors.AvailableVehicleInteractor; import ai.rideos.android.interactors.DefaultAvailableVehicleInteractor; import ai.rideos.android.interactors.DefaultPreviewVehicleInteractor; import ai.rideos.android.interactors.DefaultStopInteractor; import ai.rideos.android.interactors.DefaultRiderTripInteractor; import ai.rideos.android.interactors.DefaultRiderTripStateInteractor; import ai.rideos.android.interactors.HistoricalSearchInteractor; import ai.rideos.android.interactors.PreviewVehicleInteractor; import ai.rideos.android.interactors.StopInteractor; import ai.rideos.android.interactors.RiderTripInteractor; import ai.rideos.android.interactors.RiderTripStateInteractor; import ai.rideos.android.interactors.UserStorageHistoricalSearchInteractor; import ai.rideos.android.rider_app.MainFragment; import ai.rideos.android.rider_app.R; import ai.rideos.android.rider_app.developer_settings.RiderDeveloperOptionsFragment; import android.content.Context; public class DefaultRiderDependencyFactory extends DefaultCommonDependencyFactory implements RiderDependencyFactory { @Override public AvailableVehicleInteractor getAvailableVehicleInteractor(final Context context) { return new DefaultAvailableVehicleInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(context)); } @Override public RiderTripStateInteractor getTripStateInteractor(final Context context) { return new DefaultRiderTripStateInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(context)); } @Override public PreviewVehicleInteractor getPreviewVehicleInteractor(final Context context) { return new DefaultPreviewVehicleInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(context)); } @Override public StopInteractor getStopInteractor(final Context context) { return new DefaultStopInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(context)); } @Override public HistoricalSearchInteractor getHistoricalSearchInteractor(final Context context) { return new UserStorageHistoricalSearchInteractor( SharedPreferencesUserStorageReader.forContext(context), SharedPreferencesUserStorageWriter.forContext(context) ); } @Override public RiderTripInteractor getTripInteractor(final Context context) { return new DefaultRiderTripInteractor(ChannelProvider.getChannelSupplierForContext(context), User.get(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 ), RiderDeveloperOptionsFragment::new ); } return registry; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/dependency/RiderDependencyFactory.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.rider_app.dependency; import ai.rideos.android.common.app.dependency.CommonDependencyFactory; import ai.rideos.android.common.app.menu_navigator.MenuOptionFragmentRegistry; import ai.rideos.android.interactors.AvailableVehicleInteractor; import ai.rideos.android.interactors.HistoricalSearchInteractor; import ai.rideos.android.interactors.PreviewVehicleInteractor; import ai.rideos.android.interactors.RiderTripInteractor; import ai.rideos.android.interactors.RiderTripStateInteractor; import ai.rideos.android.interactors.StopInteractor; import android.content.Context; public interface RiderDependencyFactory extends CommonDependencyFactory { AvailableVehicleInteractor getAvailableVehicleInteractor(final Context context); RiderTripStateInteractor getTripStateInteractor(final Context context); PreviewVehicleInteractor getPreviewVehicleInteractor(final Context context); StopInteractor getStopInteractor(final Context context); HistoricalSearchInteractor getHistoricalSearchInteractor(final Context context); RiderTripInteractor getTripInteractor(final Context context); MenuOptionFragmentRegistry getMenuOptions(final Context context); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/dependency/RiderDependencyRegistry.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.rider_app.dependency; import ai.rideos.android.common.app.dependency.CommonDependencyRegistry; import ai.rideos.android.common.app.dependency.MapDependencyFactory; public class RiderDependencyRegistry { private static RiderDependencyFactory RIDER_DEPENDENCY_FACTORY; private static MapDependencyFactory MAP_DEPENDENCY_FACTORY; public static void init(final MapDependencyFactory mapDependencyFactory) { init(new DefaultRiderDependencyFactory(), mapDependencyFactory); } public static void init(final RiderDependencyFactory riderDependencyFactory, final MapDependencyFactory mapDependencyFactory) { RIDER_DEPENDENCY_FACTORY = riderDependencyFactory; MAP_DEPENDENCY_FACTORY = mapDependencyFactory; CommonDependencyRegistry.init(riderDependencyFactory, mapDependencyFactory); } public static RiderDependencyFactory riderDependencyFactory() { if (RIDER_DEPENDENCY_FACTORY == null) { throw new RuntimeException( "Rider dependency factory not set. Call RiderDependencyRegistry.init() before accessing " + "riderDependencyFactory()" ); } return RIDER_DEPENDENCY_FACTORY; } public static MapDependencyFactory mapDependencyFactory() { if (MAP_DEPENDENCY_FACTORY == null) { throw new RuntimeException( "Map dependency factory not set. Call RiderDependencyRegistry.init() before accessing " + "mapDependencyFactory()" ); } return MAP_DEPENDENCY_FACTORY; } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/developer_settings/DefaultRiderDeveloperOptionsViewModel.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.rider_app.developer_settings; import ai.rideos.android.common.user_storage.UserStorageReader; import ai.rideos.android.common.user_storage.UserStorageWriter; import ai.rideos.android.settings.RiderStorageKeys; import io.reactivex.Observable; class DefaultRiderDeveloperOptionsViewModel implements RiderDeveloperOptionsViewModel { private final UserStorageReader reader; private final UserStorageWriter writer; public DefaultRiderDeveloperOptionsViewModel(final UserStorageReader reader, final UserStorageWriter writer) { this.reader = reader; this.writer = writer; } @Override public Observable<Boolean> isManualVehicleSelectionEnabled() { return reader.observeBooleanPreference(RiderStorageKeys.MANUAL_VEHICLE_SELECTION) .firstOrError() .toObservable(); } @Override public void setManualVehicleSelection(final boolean enabled) { writer.storeBooleanPreference(RiderStorageKeys.MANUAL_VEHICLE_SELECTION, enabled); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/developer_settings/RiderDeveloperOptionsFragment.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.rider_app.developer_settings; 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.rider_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 RiderDeveloperOptionsFragment extends DeveloperOptionsFragment { private CompositeDisposable compositeDisposable; private RiderDeveloperOptionsViewModel viewModel; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.viewModel = new DefaultRiderDeveloperOptionsViewModel( 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 riderSettings = inflater.inflate(R.layout.rider_developer_settings, extraSettingsContainer, false); extraSettingsContainer.addView(riderSettings); return view; } @Override public void onStart() { super.onStart(); final View view = getView(); final Switch vehicleSelectionSwitch = view.findViewById(R.id.vehicle_select_switch); vehicleSelectionSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { viewModel.setManualVehicleSelection(isChecked); }); compositeDisposable = new CompositeDisposable(); compositeDisposable.add( viewModel.isManualVehicleSelectionEnabled().observeOn(AndroidSchedulers.mainThread()) .subscribe(selectionEnabled -> { vehicleSelectionSwitch.setEnabled(true); vehicleSelectionSwitch.setChecked(selectionEnabled); }) ); } public void onStop() { super.onStop(); compositeDisposable.dispose(); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/developer_settings/RiderDeveloperOptionsViewModel.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.rider_app.developer_settings; import io.reactivex.Observable; public interface RiderDeveloperOptionsViewModel { Observable<Boolean> isManualVehicleSelectionEnabled(); void setManualVehicleSelection(final boolean enabled); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_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.rider_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.rider_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-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/on_trip/DefaultOnTripViewModel.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.rider_app.on_trip; import ai.rideos.android.common.authentication.User; 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.state_machine.StateMachine; import ai.rideos.android.common.viewmodel.state_machine.StateTransitions; import ai.rideos.android.interactors.RiderTripInteractor; import ai.rideos.android.model.DesiredAndAssignedLocation; import ai.rideos.android.model.OnTripDisplayState; import ai.rideos.android.model.OnTripDisplayState.Display; import io.reactivex.Observable; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import timber.log.Timber; public class DefaultOnTripViewModel implements OnTripViewModel { private final CompositeDisposable compositeDisposable = new CompositeDisposable(); private final StateMachine<OnTripDisplayState> stateMachine; private final RiderTripInteractor tripInteractor; private final OnTripListener onTripListener; private final SchedulerProvider schedulerProvider; public DefaultOnTripViewModel(final User user, final RiderTripInteractor tripInteractor, final OnTripListener listener) { this(user, tripInteractor, listener, new DefaultSchedulerProvider()); } public DefaultOnTripViewModel(final User user, final RiderTripInteractor tripInteractor, final OnTripListener listener, final SchedulerProvider schedulerProvider) { this.tripInteractor = tripInteractor; this.onTripListener = listener; this.schedulerProvider = schedulerProvider; stateMachine = new StateMachine<>(schedulerProvider); compositeDisposable.addAll( stateMachine.start(), subscribeToCancellations(user.getId()), subscribeToTripEdits() ); } @Override public void initialize(final String tripId) { stateMachine.initialize(new OnTripDisplayState(Display.CURRENT_TRIP, tripId)); } @Override public void confirmPickup(final DesiredAndAssignedLocation newPickup) { stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.EDITING_PICKUP, state -> new OnTripDisplayState(Display.CONFIRMING_EDIT_PICKUP, state.getTripId(), newPickup.getAssignedLocation()) )); } @Override public void confirmDropOff(final DesiredAndAssignedLocation location) { // Not supported Timber.e("Changing drop-off while on-trip is not yet supported"); } @Override public Observable<OnTripDisplayState> getDisplayState() { return stateMachine.observeCurrentState().distinctUntilChanged(); } @Override public void cancelTrip() { stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.CURRENT_TRIP, state -> new OnTripDisplayState(Display.CONFIRMING_CANCEL, state.getTripId()) )); } @Override public void changePickup() { stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.CURRENT_TRIP, state -> new OnTripDisplayState(Display.EDITING_PICKUP, state.getTripId()) )); } @Override public void tripFinished() { onTripListener.tripFinished(); } private Disposable subscribeToCancellations(final String passengerId) { return stateMachine.observeCurrentState() .observeOn(schedulerProvider.computation()) .distinctUntilChanged() .filter(state -> state.getDisplay() == Display.CONFIRMING_CANCEL) .flatMapSingle(state -> tripInteractor.cancelTrip(passengerId, state.getTripId()) // map completable to Single<Result> so that there are no errors in the pipeline .doOnError(throwable -> Timber.e(throwable, "Failed to cancel task")) .toSingleDefault(Result.success(true)) .onErrorReturn(Result::failure) ) // After a cancellation occurs, go back to polling the current trip // If the cancellation was successful, it will show the cancellation dialog // If not, it will continue showing the current state .subscribe(result -> stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.CONFIRMING_CANCEL, state -> new OnTripDisplayState(Display.CURRENT_TRIP, state.getTripId()) ))); } private Disposable subscribeToTripEdits() { return stateMachine.observeCurrentState() .observeOn(schedulerProvider.computation()) .distinctUntilChanged() .filter(state -> state.getDisplay() == Display.CONFIRMING_EDIT_PICKUP) .flatMapSingle(state -> tripInteractor .editPickup(state.getTripId(), state.getPickupLocation().get().getLocation()) .doOnError(throwable -> Timber.e(throwable, "Failed to edit task")) // We can ignore the new task id, because it is picked up by the MainViewModel. // We just care if there's an error here so we can allow the user to retry. .map(taskId -> Result.success(true)) .onErrorReturn(Result::failure) .firstOrError() ) .subscribe(result -> { // On a successful result, just wait for the current task to be updated from the main view model if (result.isFailure()) { stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.CONFIRMING_EDIT_PICKUP, state -> new OnTripDisplayState(Display.CURRENT_TRIP, state.getTripId()) )); } }); } @Override public void back() { stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.EDITING_PICKUP, state -> new OnTripDisplayState(Display.CURRENT_TRIP, state.getTripId()) )); } @Override public void destroy() { compositeDisposable.dispose(); tripInteractor.shutDown(); } @Override public void navigateUp() { stateMachine.transition(StateTransitions.transitionIf( state -> state.getDisplay() == Display.EDITING_PICKUP, state -> new OnTripDisplayState(Display.CURRENT_TRIP, state.getTripId()) )); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/on_trip/OnTripCoordinator.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.rider_app.on_trip; 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.common.view.BackPropagator; import ai.rideos.android.rider_app.R; import ai.rideos.android.rider_app.dependency.RiderDependencyRegistry; import ai.rideos.android.rider_app.on_trip.confirming_cancel.ConfirmingCancelFragment; import ai.rideos.android.rider_app.on_trip.confirming_edit_pickup.ConfirmingEditPickupFragment; import ai.rideos.android.rider_app.on_trip.current_trip.CurrentTripCoordinator; import ai.rideos.android.rider_app.pre_trip.confirm_location.ConfirmLocationFragment; import ai.rideos.android.rider_app.pre_trip.confirm_location.ConfirmLocationFragment.ConfirmLocationArgs; import ai.rideos.android.rider_app.pre_trip.confirm_location.ConfirmLocationFragment.ConfirmLocationType; import android.content.Context; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; public class OnTripCoordinator implements Coordinator<String>, BackPropagator { private CompositeDisposable compositeDisposable; private final NavigationController navController; private final OnTripViewModel onTripViewModel; private final Coordinator<String> currentTripCoordinator; private Coordinator activeChild; public OnTripCoordinator(final Context context, final NavigationController navController, final OnTripListener listener) { this.navController = navController; final User user = User.get(context); onTripViewModel = new DefaultOnTripViewModel( user, RiderDependencyRegistry.riderDependencyFactory().getTripInteractor(context), listener ); currentTripCoordinator = new CurrentTripCoordinator( context, navController, onTripViewModel ); } @Override public void start(final String tripId) { compositeDisposable = new CompositeDisposable(); onTripViewModel.initialize(tripId); compositeDisposable.add( onTripViewModel.getDisplayState().observeOn(AndroidSchedulers.mainThread()).subscribe(state -> { stopChild(); switch (state.getDisplay()) { case CURRENT_TRIP: currentTripCoordinator.start(tripId); activeChild = currentTripCoordinator; break; case CONFIRMING_CANCEL: navController.navigateTo( new ConfirmingCancelFragment(), EmptyArg.create(), onTripViewModel ); break; case EDITING_PICKUP: navController.navigateTo( new ConfirmLocationFragment(), new ConfirmLocationArgs( false, ConfirmLocationType.PICKUP, null, R.string.set_pickup_on_map_title, R.string.set_pickup_on_map_button ), onTripViewModel ); break; case CONFIRMING_EDIT_PICKUP: navController.navigateTo( new ConfirmingEditPickupFragment(), EmptyArg.create(), onTripViewModel ); break; } }) ); } private void stopChild() { if (activeChild != null) { activeChild.stop(); } activeChild = null; } @Override public void stop() { stopChild(); compositeDisposable.dispose(); } @Override public void destroy() { currentTripCoordinator.destroy(); onTripViewModel.destroy(); } @Override public void propagateBackSignal() { if (activeChild instanceof BackPropagator) { ((BackPropagator) activeChild).propagateBackSignal(); } else { onTripViewModel.back(); } } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/on_trip/OnTripListener.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.rider_app.on_trip; public interface OnTripListener { void tripFinished(); }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/on_trip/OnTripTransitions.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.rider_app.on_trip; import ai.rideos.android.rider_app.R; import android.transition.ChangeBounds; import android.transition.Transition; import android.transition.TransitionSet; import android.view.View; import android.view.ViewGroup; public class OnTripTransitions { public static Transition changeDetail(final ViewGroup detailContainer, final View detailView) { return new TransitionSet() .addTransition(new ChangeBounds() .addTarget(detailContainer) .addTarget("detail_view") .addTarget(R.id.on_trip_state_title) .addTarget(R.id.pickup_address_text) .addTarget(R.id.drop_off_address_text) .addTarget(R.id.cancel_button) ); } }
0
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app
java-sources/ai/rideos/sdk/sdk-android-rider/1.0.2/ai/rideos/android/rider_app/on_trip/OnTripViewModel.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.rider_app.on_trip; import ai.rideos.android.common.viewmodel.BackListener; import ai.rideos.android.common.viewmodel.ViewModel; import ai.rideos.android.model.OnTripDisplayState; import ai.rideos.android.rider_app.on_trip.confirming_cancel.ConfirmingCancelListener; import ai.rideos.android.rider_app.on_trip.confirming_edit_pickup.ConfirmingEditPickupListener; import ai.rideos.android.rider_app.on_trip.current_trip.CurrentTripListener; import ai.rideos.android.rider_app.pre_trip.confirm_location.ConfirmLocationListener; import io.reactivex.Observable; public interface OnTripViewModel extends CurrentTripListener, ConfirmLocationListener, BackListener, ViewModel, ConfirmingCancelListener, ConfirmingEditPickupListener { void initialize(final String tripId); Observable<OnTripDisplayState> getDisplayState(); }