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

Delay initializing runtime styling on startup #423

Merged
merged 1 commit into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public NavigationView(Context context, @Nullable AttributeSet attrs, int defStyl

public void onCreate(@Nullable Bundle savedInstanceState) {
resumeState = savedInstanceState != null;
initMap(savedInstanceState);
mapView.onCreate(savedInstanceState);
}

public void onStart() {
Expand Down Expand Up @@ -158,13 +158,18 @@ public void onMapReady(MapboxMap mapboxMap) {
map = mapboxMap;
map.setOnScrollListener(this);
setMapPadding(0, 0, 0, summaryBehavior.getPeekHeight());
initRoute();
initCamera();
initLocationLayer();
initLifecycleObservers();
initNavigationPresenter();
subscribeViews();
navigationListener.onNavigationReady();
ThemeSwitcher.setMapStyle(getContext(), map, new MapboxMap.OnStyleLoadedListener() {
@Override
public void onStyleLoaded(String style) {
initRoute();
initCamera();
initLocationLayer();
initLifecycleObservers();
initNavigationPresenter();
subscribeViews();
navigationListener.onNavigationReady();
}
});
}

/**
Expand Down Expand Up @@ -414,16 +419,6 @@ public void onClick(View view) {
});
}

/**
* Sets up the {@link MapboxMap}.
*
* @param savedInstanceState from onCreate()
*/
private void initMap(Bundle savedInstanceState) {
mapView.onCreate(savedInstanceState);
ThemeSwitcher.setMapStyle(getContext(), mapView);
}

/**
* Initializes the {@link BottomSheetBehavior} for {@link SummaryBottomSheet}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;

/**
* This class is used to switch theme colors in {@link NavigationView}.
Expand Down Expand Up @@ -52,14 +53,14 @@ static void toggleTheme(Activity activity) {
* Sets the {@link MapView} style based on the current theme setting.
*
* @param context to retrieve {@link SharedPreferences}
* @param mapView the style will be set on
* @param map the style will be set on
*/
static void setMapStyle(Context context, MapView mapView) {
static void setMapStyle(Context context, MapboxMap map, MapboxMap.OnStyleLoadedListener listener) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean darkThemeEnabled = preferences.getBoolean(context.getString(R.string.dark_theme_enabled), false);
String nightThemeUrl = context.getString(R.string.navigation_guidance_night_v2);
String dayThemeUrl = context.getString(R.string.navigation_guidance_day_v2);
mapView.setStyleUrl(darkThemeEnabled ? nightThemeUrl : dayThemeUrl);
map.setStyleUrl(darkThemeEnabled ? nightThemeUrl : dayThemeUrl, listener);
}

/**
Expand Down