Skip to content

Commit

Permalink
Updated hiding buttons to use API in NavigationView instead of option
Browse files Browse the repository at this point in the history
  • Loading branch information
Devota Aabel committed Sep 10, 2018
1 parent 12f0edb commit 8d1c28e
Show file tree
Hide file tree
Showing 17 changed files with 502 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ private void extractConfiguration(NavigationViewOptions.Builder options,
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SIMULATE_ROUTE, false));
options.directionsProfile(preferences
.getString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, DirectionsCriteria.PROFILE_DRIVING_TRAFFIC));
options.showFeedbackFab(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_FAB, true));
options.showSoundFab(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_SOUND_FAB, true));
options.showProblemAlertView(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_PROBLEM_ALERT_VIEW, true));
options.showFeedbackSubmittedAlertView(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_SUBMITTED_ALERT_VIEW,true));
navigationOptions.enableOffRouteDetection(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, true));
navigationOptions.snapToRoute(preferences
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mapbox.services.android.navigation.ui.v5;

import android.view.View;

public interface NavigationButton {

/**
* Adds an onClickListener to the button
*
* @param onClickListener to add
*/
void addOnClickListener(View.OnClickListener onClickListener);

/**
* Hides the widget
*/
void hide();

/**
* Shows the widget
*/
void show();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ private static void storeConfiguration(NavigationLauncherOptions options, Shared
editor.putString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, options.directionsProfile());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, options.enableOffRouteDetection());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SNAP_ENABLED_KEY, options.snapToRoute());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_FAB, options.showFeedbackFab());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_SOUND_FAB, options.showSoundFab());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_PROBLEM_ALERT_VIEW, options.showProblemAlertView());
editor.putBoolean(
NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_SUBMITTED_ALERT_VIEW, options.showFeedbackSubmittedAlertView());
}

private static void storeThemePreferences(NavigationLauncherOptions options, SharedPreferences.Editor editor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ public abstract static class Builder {

public abstract Builder waynameChipEnabled(boolean waynameChipEnabled);

public abstract Builder showFeedbackFab(boolean showFeedbackFab);

public abstract Builder showSoundFab(boolean showSoundFab);

public abstract Builder showProblemAlertView(boolean showProblemAlertView);

public abstract Builder showFeedbackSubmittedAlertView(boolean showFeedbackSubmittedAlertView);

public abstract Builder enableOffRouteDetection(boolean enableOffRouteDetection);

public abstract Builder snapToRoute(boolean snapToRoute);
Expand All @@ -46,10 +38,6 @@ public static NavigationLauncherOptions.Builder builder() {
.shouldSimulateRoute(false)
.enableOffRouteDetection(true)
.snapToRoute(true)
.waynameChipEnabled(true)
.showFeedbackFab(true)
.showSoundFab(true)
.showProblemAlertView(true)
.showFeedbackSubmittedAlertView(true);
.waynameChipEnabled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,4 @@ public abstract class NavigationUiOptions {
public abstract boolean shouldSimulateRoute();

public abstract boolean waynameChipEnabled();

public abstract boolean showFeedbackFab();

public abstract boolean showSoundFab();

public abstract boolean showProblemAlertView();

public abstract boolean showFeedbackSubmittedAlertView();
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,24 @@ public MapboxNavigation retrieveMapboxNavigation() {
return navigationViewModel.retrieveNavigation();
}

/**
* Returns the sound button used for muting instructions
*
* @return sound button
*/
public NavigationButton retrieveSoundButton() {
return instructionView.retrieveSoundButton();
}

/**
* Returns the feedback button for sending feedback about the maps
*
* @return feedback button
*/
public NavigationButton retrieveFeedbackButton() {
return instructionView.retrieveFeedbackButton();
}

private void initializeView() {
inflate(getContext(), R.layout.navigation_view_layout, this);
bind();
Expand Down Expand Up @@ -544,12 +562,6 @@ private void establish(NavigationViewOptions options) {
establishLanguage(localeUtils, options);
establishUnitType(localeUtils, options);
establishTimeFormat(options);
setupInstructionView(options);
}

private void setupInstructionView(NavigationViewOptions options) {
instructionView.setupHiddenViews(options.showFeedbackFab(), options.showSoundFab(), options.showProblemAlertView(),
options.showFeedbackSubmittedAlertView());
}

private void establishLanguage(LocaleUtils localeUtils, NavigationViewOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class NavigationViewModel extends AndroidViewModel {
public final MutableLiveData<BannerInstructionModel> bannerInstructionModel = new MutableLiveData<>();
public final MutableLiveData<SummaryModel> summaryModel = new MutableLiveData<>();
public final MutableLiveData<Boolean> isOffRoute = new MutableLiveData<>();
public final MutableLiveData<Boolean> isFeedbackShowing = new MutableLiveData<>();
final MutableLiveData<Location> navigationLocation = new MutableLiveData<>();
final MutableLiveData<DirectionsRoute> route = new MutableLiveData<>();
final MutableLiveData<Point> destination = new MutableLiveData<>();
Expand Down Expand Up @@ -149,7 +148,6 @@ public void updateFeedback(FeedbackItem feedbackItem) {
*/
public void cancelFeedback() {
if (!TextUtils.isEmpty(feedbackId)) {
isFeedbackShowing.setValue(false);
navigation.cancelFeedback(feedbackId);
feedbackId = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ public abstract static class Builder {

public abstract Builder waynameChipEnabled(boolean waynameChipEnabled);

public abstract Builder showFeedbackFab(boolean showFeedbackFab);

public abstract Builder showSoundFab(boolean showSoundFab);

public abstract Builder showProblemAlertView(boolean showProblemAlertView);

public abstract Builder showFeedbackSubmittedAlertView(boolean showFeedbackSubmittedAlertView);

public abstract Builder navigationOptions(MapboxNavigationOptions navigationOptions);

public abstract Builder feedbackListener(FeedbackListener feedbackListener);
Expand Down Expand Up @@ -112,10 +104,6 @@ public static Builder builder() {
return new AutoValue_NavigationViewOptions.Builder()
.navigationOptions(MapboxNavigationOptions.builder().build())
.shouldSimulateRoute(false)
.waynameChipEnabled(true)
.showFeedbackFab(true)
.showSoundFab(true)
.showProblemAlertView(true)
.showFeedbackSubmittedAlertView(true);
.waynameChipEnabled(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.mapbox.services.android.navigation.ui.v5.instruction;

import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.FloatingActionButton;
import android.util.AttributeSet;
import android.view.View;

import com.mapbox.services.android.navigation.ui.v5.NavigationButton;
import com.mapbox.services.android.navigation.ui.v5.R;

import java.util.ArrayList;
import java.util.List;

public class FeedbackButton extends ConstraintLayout implements NavigationButton {
private FloatingActionButton feedbackFab;
private List<OnClickListener> onClickListeners;

public FeedbackButton(Context context) {
this(context, null);
}

public FeedbackButton(Context context, AttributeSet attrs) {
this(context, attrs, -1);
}

public FeedbackButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context);
}

/**
* Adds an onClickListener to the button
*
* @param onClickListener to add
*/
@Override
public void addOnClickListener(OnClickListener onClickListener) {
if (!onClickListeners.contains(onClickListener)) {
onClickListeners.add(onClickListener);
}
}

/**
* Hides the widget
*/
@Override
public void hide() {
setVisibility(GONE);
}

/**
* Shows the widget
*/
@Override
public void show() {
setVisibility(VISIBLE);
}

@Override
protected void onFinishInflate() {
super.onFinishInflate();
bind();
setupOnClickListeners();
}

private void initialize(Context context) {
inflate(context, R.layout.feedback_button_layout, this);
}

private void bind() {
feedbackFab = findViewById(R.id.feedbackFab);
}

private void setupOnClickListeners() {
onClickListeners = new ArrayList<>();

feedbackFab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
for (OnClickListener onClickListener : onClickListeners) {
onClickListener.onClick(view);
}
}
});
}
}
Loading

0 comments on commit 8d1c28e

Please sign in to comment.