Skip to content

Commit

Permalink
Refactor BaseMapFragment check for dark mode into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbrethorst committed Mar 6, 2024
1 parent f7819c5 commit a912382
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,22 +331,24 @@ public void onMapReady(com.google.android.gms.maps.GoogleMap map) {
mMap.setOnMarkerClickListener(mapClickListeners);
mMap.setOnMapClickListener(mapClickListeners);

if (
AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES || (
AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO &&
(getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
)
) {
if (inDarkMode()) {
mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.dark_map));
}else{
// it's a light mode just remove POI
} else {
// When in light mode, just remove POIs.
String removePOIStyle = "[{\"featureType\":\"poi\",\"elementType\":\"all\",\"stylers\":[{\"visibility\":\"off\"}]}]";
mMap.setMapStyle(new MapStyleOptions(removePOIStyle));
}

initMap(mLastSavedInstanceState);
}

private boolean inDarkMode() {
return AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES || (
AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO &&
(getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
);
}

private void initMap(Bundle savedInstanceState) {
UiSettings uiSettings = mMap.getUiSettings();
mUserDeniedPermission = PreferenceUtils.userDeniedLocationPermission();
Expand Down

0 comments on commit a912382

Please sign in to comment.