@@ -583,47 +583,35 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
583583 eventWithAttributes .put (MapboxEvent .KEY_CELLULAR_NETWORK_TYPE , TelemetryUtils .getCellularNetworkType (context ));
584584 eventWithAttributes .put (MapboxEvent .KEY_WIFI , TelemetryUtils .getConnectedToWifi (context ));
585585 putEventOnQueue (eventWithAttributes );
586- } else if (eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_DEPART )) {
587- // User started a route
588- eventWithAttributes .put (MapboxNavigationEvent .KEY_VOLUME_LEVEL , TelemetryUtils .getVolumeLevel (context ));
589- eventWithAttributes .put (MapboxNavigationEvent .KEY_SCREEN_BRIGHTNESS , TelemetryUtils .getScreenBrightness (context ));
590- eventWithAttributes .put (MapboxNavigationEvent .KEY_APPLICATION_STATE , TelemetryUtils .getApplicationState (context ));
591- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_PLUGGED_IN , isPluggedIn ());
592- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_LEVEL , getBatteryLevel ());
593- eventWithAttributes .put (MapboxNavigationEvent .KEY_CONNECTIVITY , TelemetryUtils .getCellularNetworkType (context ));
594- putEventOnQueue (eventWithAttributes );
595- } else if (eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_FEEDBACK )) {
596- // User feedback/reroute event
597- eventWithAttributes .put (MapboxNavigationEvent .KEY_VOLUME_LEVEL , TelemetryUtils .getVolumeLevel (context ));
598- eventWithAttributes .put (MapboxNavigationEvent .KEY_SCREEN_BRIGHTNESS , TelemetryUtils .getScreenBrightness (context ));
599- eventWithAttributes .put (MapboxNavigationEvent .KEY_APPLICATION_STATE , TelemetryUtils .getApplicationState (context ));
600- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_PLUGGED_IN , isPluggedIn ());
601- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_LEVEL , getBatteryLevel ());
602- eventWithAttributes .put (MapboxNavigationEvent .KEY_CONNECTIVITY , TelemetryUtils .getCellularNetworkType (context ));
603- putEventOnQueue (eventWithAttributes );
604- } else if (eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_ARRIVE )) {
605- // User arrived
606- eventWithAttributes .put (MapboxNavigationEvent .KEY_VOLUME_LEVEL , TelemetryUtils .getVolumeLevel (context ));
607- eventWithAttributes .put (MapboxNavigationEvent .KEY_SCREEN_BRIGHTNESS , TelemetryUtils .getScreenBrightness (context ));
608- eventWithAttributes .put (MapboxNavigationEvent .KEY_APPLICATION_STATE , TelemetryUtils .getApplicationState (context ));
609- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_PLUGGED_IN , isPluggedIn ());
610- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_LEVEL , getBatteryLevel ());
611- eventWithAttributes .put (MapboxNavigationEvent .KEY_CONNECTIVITY , TelemetryUtils .getCellularNetworkType (context ));
612- putEventOnQueue (eventWithAttributes );
613- } else if (eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_CANCEL )) {
614- // User canceled navigation
615- eventWithAttributes .put (MapboxNavigationEvent .KEY_VOLUME_LEVEL , TelemetryUtils .getVolumeLevel (context ));
616- eventWithAttributes .put (MapboxNavigationEvent .KEY_SCREEN_BRIGHTNESS , TelemetryUtils .getScreenBrightness (context ));
617- eventWithAttributes .put (MapboxNavigationEvent .KEY_APPLICATION_STATE , TelemetryUtils .getApplicationState (context ));
618- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_PLUGGED_IN , isPluggedIn ());
619- eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_LEVEL , getBatteryLevel ());
620- eventWithAttributes .put (MapboxNavigationEvent .KEY_CONNECTIVITY , TelemetryUtils .getCellularNetworkType (context ));
586+ } else if (isANavigationEvent (eventType )) {
587+ addGeneralNavigationMetadataTo (eventWithAttributes );
621588 putEventOnQueue (eventWithAttributes );
622589 } else {
623590 Log .w (LOG_TAG , String .format ("Unknown event type provided: %s." , eventType ));
624591 }
625592 }
626593
594+ private boolean isANavigationEvent (String eventType ) {
595+ boolean isDepart = eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_DEPART );
596+ boolean isFeedback = eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_FEEDBACK );
597+ boolean isArrived = eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_ARRIVE );
598+ boolean isCanceled = eventType .equalsIgnoreCase (MapboxNavigationEvent .TYPE_CANCEL );
599+
600+ boolean isANavigationEvent = isDepart || isFeedback || isArrived || isCanceled ;
601+
602+ return isANavigationEvent ;
603+ }
604+
605+ private void addGeneralNavigationMetadataTo (Hashtable <String , Object > eventWithAttributes ) {
606+ eventWithAttributes .put (MapboxEvent .KEY_DEVICE , Build .MODEL );
607+ eventWithAttributes .put (MapboxNavigationEvent .KEY_VOLUME_LEVEL , TelemetryUtils .getVolumeLevel (context ));
608+ eventWithAttributes .put (MapboxNavigationEvent .KEY_SCREEN_BRIGHTNESS , TelemetryUtils .getScreenBrightness (context ));
609+ eventWithAttributes .put (MapboxNavigationEvent .KEY_APPLICATION_STATE , TelemetryUtils .getApplicationState (context ));
610+ eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_PLUGGED_IN , isPluggedIn ());
611+ eventWithAttributes .put (MapboxNavigationEvent .KEY_BATTERY_LEVEL , getBatteryLevel ());
612+ eventWithAttributes .put (MapboxNavigationEvent .KEY_CONNECTIVITY , TelemetryUtils .getCellularNetworkType (context ));
613+ }
614+
627615 /**
628616 * Immediately attempt to send all events data in the queue to the server.
629617 */
0 commit comments