Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback System #405

Merged
merged 9 commits into from
Oct 20, 2017
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackBottomSheet;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackItem;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackSelectedCallback;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackBottomSheetListener;
import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.ui.v5.route.RouteViewModel;
Expand Down Expand Up @@ -62,7 +62,7 @@
* </p>
*/
public class NavigationView extends CoordinatorLayout implements OnMapReadyCallback, MapboxMap.OnScrollListener,
NavigationContract.View, FeedbackSelectedCallback {
NavigationContract.View, FeedbackBottomSheetListener {

private MapView mapView;
private InstructionView instructionView;
Expand Down Expand Up @@ -318,10 +318,15 @@ public void showFeedbackBottomSheet() {
}

@Override
public void onFeedbackItemSelected(FeedbackItem feedbackItem) {
public void onFeedbackSelected(FeedbackItem feedbackItem) {
navigationViewModel.updateFeedback(feedbackItem);
}

@Override
public void onFeedbackDismissed() {
navigationViewModel.cancelFeedback();
}

public void startNavigation(Activity activity) {
routeViewModel.extractLaunchData(activity);
}
Expand Down Expand Up @@ -432,7 +437,7 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
navigationPresenter.onFeedbackClick();
navigationViewModel.onFeedbackClick();
navigationViewModel.recordFeedback();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.SharedPreferences;
import android.location.Location;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.mapbox.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class NavigationViewModel extends AndroidViewModel implements LifecycleOb
private NavigationInstructionPlayer instructionPlayer;
private DecimalFormat decimalFormat;
private SharedPreferences preferences;
private String feedbackId;

public NavigationViewModel(Application application) {
super(application);
Expand Down Expand Up @@ -133,16 +135,22 @@ public MapboxNavigation getNavigation() {
return navigation;
}

void onFeedbackClick() {
// TODO telem stuff - record screenshot
void recordFeedback() {
feedbackId = navigation.recordFeedback("", "");
}

void recordFeedback(FeedbackItem feedbackItem) {
navigation.recordFeedback("", "");
void updateFeedback(FeedbackItem feedbackItem) {
if (!TextUtils.isEmpty(feedbackId)) {
navigation.updateFeedback(feedbackId, feedbackItem.getFeedbackType(), feedbackItem.getDescription());
feedbackId = null;
}
}

void updateFeedback(FeedbackItem feedbackItem) {
navigation.updateFeedback("", "", "");
void cancelFeedback() {
if (!TextUtils.isEmpty(feedbackId)) {
navigation.cancelFeedback(feedbackId);
feedbackId = null;
}
}

void updateRoute(DirectionsRoute route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public class FeedbackAdapter extends RecyclerView.Adapter<FeedbackViewHolder> {

FeedbackAdapter() {
feedbackItems.add(new FeedbackItem("Road\nClosed",
R.drawable.ic_road_closed, "", ""));
R.drawable.ic_road_closed, FeedbackItem.FEEDBACK_TYPE_ROAD_CLOSED, ""));
feedbackItems.add(new FeedbackItem("Not\nAllowed",
R.drawable.ic_no_turn_allowed, "", ""));
R.drawable.ic_no_turn_allowed, FeedbackItem.FEEDBACK_TYPE_UNALLOWED_TURN, ""));
feedbackItems.add(new FeedbackItem("Report\nTraffic",
R.drawable.ic_traffic, "", ""));
R.drawable.ic_traffic, FeedbackItem.FEEDBACK_TYPE_REPORT_TRAFFIC, ""));
feedbackItems.add(new FeedbackItem("Confusing\nInstruction",
R.drawable.ic_confusing_directions, "", ""));
R.drawable.ic_confusing_directions, FeedbackItem.FEEDBACK_TYPE_CONFUSING_INSTRUCTION, ""));
feedbackItems.add(new FeedbackItem("GPS\nInaccurate",
R.drawable.ic_gps, "", ""));
R.drawable.ic_gps, FeedbackItem.FEEDBACK_TYPE_INACCURATE_GPS, ""));
feedbackItems.add(new FeedbackItem("Bad\nRoute",
R.drawable.ic_wrong_directions, "", ""));
R.drawable.ic_wrong_directions, FeedbackItem.FEEDBACK_TYPE_BAD_ROUTE, ""));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public class FeedbackBottomSheet extends BottomSheetDialogFragment implements Fe

public static final String TAG = FeedbackBottomSheet.class.getSimpleName();

private FeedbackSelectedCallback feedbackSelectedCallback;
private FeedbackBottomSheetListener feedbackBottomSheetListener;
private FeedbackAdapter feedbackAdapter;
private RecyclerView feedbackItems;
private ProgressBar feedbackProgressBar;

public static FeedbackBottomSheet newInstance(FeedbackSelectedCallback feedbackSelectedCallback) {
public static FeedbackBottomSheet newInstance(FeedbackBottomSheetListener feedbackBottomSheetListener) {
FeedbackBottomSheet feedbackBottomSheet = new FeedbackBottomSheet();
feedbackBottomSheet.setFeedbackSelectedCallback(feedbackSelectedCallback);
feedbackBottomSheet.setFeedbackBottomSheetListener(feedbackBottomSheetListener);
return feedbackBottomSheet;
}

Expand Down Expand Up @@ -86,12 +86,18 @@ public void onShow(DialogInterface dialog) {
@Override
public void onFeedbackItemClick(int feedbackPosition) {
FeedbackItem feedbackItem = feedbackAdapter.getFeedbackItem(feedbackPosition);
Toast.makeText(getContext(), feedbackItem.getFeedbackText(), Toast.LENGTH_SHORT).show();
feedbackSelectedCallback.onFeedbackItemSelected(feedbackItem);
Toast.makeText(getContext(), feedbackItem.getFeedbackType(), Toast.LENGTH_SHORT).show();
feedbackBottomSheetListener.onFeedbackSelected(feedbackItem);
}

public void setFeedbackSelectedCallback(FeedbackSelectedCallback feedbackSelectedCallback) {
this.feedbackSelectedCallback = feedbackSelectedCallback;
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
feedbackBottomSheetListener.onFeedbackDismissed();
}

public void setFeedbackBottomSheetListener(FeedbackBottomSheetListener feedbackBottomSheetListener) {
this.feedbackBottomSheetListener = feedbackBottomSheetListener;
}

private void bind(View bottomSheetView) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mapbox.services.android.navigation.ui.v5.feedback;

public interface FeedbackBottomSheetListener {

void onFeedbackSelected(FeedbackItem feedbackItem);

void onFeedbackDismissed();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
package com.mapbox.services.android.navigation.ui.v5.feedback;

import android.support.annotation.StringDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class FeedbackItem {

@FeedbackType
private String feedbackType;
private String feedbackText;
private String description;
private int feedbackImage;

private String feedbackId;
private String feedbackType;
private String description;
@Retention(RetentionPolicy.SOURCE)
@StringDef( {
FEEDBACK_TYPE_GENERAL,
FEEDBACK_TYPE_ACCIDENT,
FEEDBACK_TYPE_HAZARD,
FEEDBACK_TYPE_ROAD_CLOSED,
FEEDBACK_TYPE_UNALLOWED_TURN,
FEEDBACK_TYPE_ROUTING_ERROR,
FEEDBACK_TYPE_INSTRUCTION_TIMING,
FEEDBACK_TYPE_CONFUSING_INSTRUCTION,
FEEDBACK_TYPE_INACCURATE_GPS,
FEEDBACK_TYPE_BAD_ROUTE,
FEEDBACK_TYPE_REPORT_TRAFFIC
})
public @interface FeedbackType {
}

public static final String FEEDBACK_TYPE_GENERAL = "general";
public static final String FEEDBACK_TYPE_ACCIDENT = "accident";
public static final String FEEDBACK_TYPE_HAZARD = "hazard";
public static final String FEEDBACK_TYPE_ROAD_CLOSED = "road_closed";
public static final String FEEDBACK_TYPE_UNALLOWED_TURN = "unallowed_turn";
public static final String FEEDBACK_TYPE_ROUTING_ERROR = "routing_error";
public static final String FEEDBACK_TYPE_INSTRUCTION_TIMING = "instruction_timing";
public static final String FEEDBACK_TYPE_CONFUSING_INSTRUCTION = "confusing_instruction";
public static final String FEEDBACK_TYPE_INACCURATE_GPS = "inaccurate_gps";
public static final String FEEDBACK_TYPE_BAD_ROUTE = "bad_route";
public static final String FEEDBACK_TYPE_REPORT_TRAFFIC = "report_traffic";

FeedbackItem(String feedbackText,
int feedbackImage,
String feedbackType,
@FeedbackType String feedbackType,
String description) {
this.feedbackText = feedbackText;
this.feedbackImage = feedbackImage;
Expand All @@ -27,19 +60,12 @@ int getFeedbackImageId() {
return feedbackImage;
}

String getFeedbackType() {
@FeedbackType
public String getFeedbackType() {
return feedbackType;
}

public String getDescription() {
return description;
}

public String getFeedbackId() {
return feedbackId;
}

public void setFeedbackId(String feedbackId) {
this.feedbackId = feedbackId;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,15 @@ public void onProgressChange(Location location, RouteProgress routeProgress) {
}

public String recordFeedback(String feedbackType, String description) {
// TODO navigationService.recordFeedbackEvent(feedbackType, description);
return "some_feedback_id";
return navigationService.recordFeedbackEvent(feedbackType, description);
}

public void updateFeedback(String feedbackId, String feedbackType, String description) {
// TODO navigationService.updateFeedbackEvent(feedbackId, feedbackType, description);
navigationService.updateFeedbackEvent(feedbackId, feedbackType, description);
}

public void cancelFeedback(String feedbackId) {
navigationService.cancelFeedback(feedbackId);
}

DirectionsRoute getRoute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ static void feedbackEvent(SessionState sessionState, RouteProgress routeProgress
String description, String feedbackType, String screenshot) {
updateRouteProgressSessionData(routeProgress, sessionState);


MapboxTelemetry.getInstance().pushEvent(MapboxNavigationEvent.buildFeedbackEvent(sdkIdentifier,
BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME, sessionState.sessionIdentifier(), location.getLatitude(),
location.getLongitude(), sessionState.currentGeometry(), routeProgress.directionsRoute().routeOptions().profile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public class NavigationService extends Service implements LocationEngineListener
private boolean firstProgressUpdate = true;
private NavigationEngine thread;
private Location rawLocation;
private Runnable runnable;
private Handler handler;
private List<SessionState> queuedFeedbackEvents;
private boolean sendFeedback = true;
private String feedbackType;
private String description;


@Nullable
@Override
Expand All @@ -80,7 +87,9 @@ public void onCreate() {
thread.prepareHandler();
recentDistancesFromManeuverInMeters = new RingBuffer<>(3);
locationBuffer = new RingBuffer<>(20);
queuedFeedbackEvents = new ArrayList<>();
queuedRerouteEvents = new ArrayList<>();

}

/**
Expand All @@ -98,6 +107,9 @@ public void onDestroy() {
stopForeground(true);
}

for (SessionState sessionState : queuedFeedbackEvents) {
sendFeedbackEvent(sessionState);
}
for (SessionState sessionState : queuedRerouteEvents) {
sendRerouteEvent(sessionState);
}
Expand Down Expand Up @@ -307,6 +319,71 @@ public void rerouteOccurred() {
queuedRerouteEvents.add(mapboxNavigation.getSessionState());
}

//need to confirm working as reroute functions
public String recordFeedbackEvent(String feedbackType, String description) {
this.description = description;
this.feedbackType = feedbackType;

mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder()
.beforeRerouteLocations(Arrays.asList(
locationBuffer.toArray(new Location[locationBuffer.size()])))
.routeProgressBeforeReroute(routeProgress)
.build());
locationBuffer.clear();

handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder()
.afterRerouteLocations(Arrays.asList(
locationBuffer.toArray(new Location[locationBuffer.size()])))
.build());

locationBuffer.clear();

sendFeedbackEvent(mapboxNavigation.getSessionState());
}
};

handler.postDelayed(runnable, TWENTY_SECOND_INTERVAL);

return mapboxNavigation.getSessionState().sessionIdentifier();
}

public void updateFeedbackEvent(String feedbackId, String feedbackType, String description) {
this.feedbackType = feedbackType;
this.description = description;
}

public void cancelFeedback(String feedbackId) {
sendFeedback = false;
}

void sendFeedbackEvent(SessionState sessionState) {
sessionState = sessionState.toBuilder().afterRerouteLocations(Arrays.asList(
locationBuffer.toArray(new Location[locationBuffer.size()])))
.build();

if (sendFeedback) {
NavigationMetricsWrapper.feedbackEvent(mapboxNavigation.getSessionState(), routeProgress, rawLocation,
description, feedbackType, "screenshot");
} else {
sendFeedback = true;
}

for (SessionState session : queuedFeedbackEvents) {
queuedFeedbackEvents.set(queuedFeedbackEvents.indexOf(session),
session.toBuilder().lastRerouteDate(
sessionState.lastRerouteDate()
).build());
}

mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder().lastRerouteDate(
sessionState.lastRerouteDate()
).build());
}

void sendRerouteEvent(SessionState sessionState) {
sessionState = sessionState.toBuilder()
.afterRerouteLocations(Arrays.asList(
Expand All @@ -328,7 +405,6 @@ void sendRerouteEvent(SessionState sessionState) {
).build());
}


class LocalBinder extends Binder {
NavigationService getService() {
Timber.d("Local binder called.");
Expand Down