Fix getting type of content (light/dark)

This commit is contained in:
alex 2017-10-30 13:47:35 +02:00
parent f88b554709
commit d7bc5c840d
11 changed files with 32 additions and 52 deletions

View file

@ -3,6 +3,7 @@ package net.osmand.plus.base;
import android.app.Activity; import android.app.Activity;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
@ -15,6 +16,18 @@ import net.osmand.plus.helpers.AndroidUiHelper;
public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment { public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment {
private static final String USED_ON_MAP_KEY = "used_on_map";
protected boolean usedOnMap;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null) {
usedOnMap = savedInstanceState.getBoolean(USED_ON_MAP_KEY);
}
}
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
@ -26,6 +39,12 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
} }
} }
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(USED_ON_MAP_KEY, usedOnMap);
}
@Override @Override
protected Drawable getContentIcon(@DrawableRes int id) { protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, isNightMode() ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); return getIcon(id, isNightMode() ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
@ -77,5 +96,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}); });
} }
protected abstract boolean isNightMode(); protected boolean isNightMode() {
if (usedOnMap) {
getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
return !getMyApplication().getSettings().isLightContent();
}
} }

View file

@ -632,6 +632,7 @@ public class GpxImportHelper {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
usedOnMap = true;
boolean night = isNightMode(); boolean night = isNightMode();
final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@ -678,10 +679,5 @@ public class GpxImportHelper {
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
} }
} }

View file

@ -162,11 +162,6 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
} }
} }
@Override
protected boolean isNightMode() {
return !getMyApplication().getSettings().isLightContent();
}
private void highlightSelectedItem(boolean check) { private void highlightSelectedItem(boolean check) {
int iconColor = check ? R.color.dashboard_blue : night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color; int iconColor = check ? R.color.dashboard_blue : night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color;
int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black); int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black);

View file

@ -35,6 +35,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
usedOnMap = true;
final boolean nightMode = isNightMode(); final boolean nightMode = isNightMode();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@ -92,11 +93,6 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
interface HistoryMarkerMenuFragmentListener { interface HistoryMarkerMenuFragmentListener {
void onMakeMarkerActive(int pos); void onMakeMarkerActive(int pos);

View file

@ -147,11 +147,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return !getMyApplication().getSettings().isLightContent();
}
interface MarkerOptionsFragmentListener { interface MarkerOptionsFragmentListener {
void sortByOnClick(); void sortByOnClick();

View file

@ -64,11 +64,6 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return !getMyApplication().getSettings().isLightContent();
}
private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() {
@Override @Override

View file

@ -33,8 +33,9 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
usedOnMap = true;
boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
boolean night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); boolean night = isNightMode();
final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_options_bottom_sheet_dialog, container); final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_options_bottom_sheet_dialog, container);
@ -116,11 +117,6 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
interface PlanRouteOptionsFragmentListener { interface PlanRouteOptionsFragmentListener {
void selectOnClick(); void selectOnClick();

View file

@ -134,11 +134,6 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return !getMyApplication().getSettings().isLightContent();
}
private MapActivity getMapActivity() { private MapActivity getMapActivity() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) { if (activity != null) {

View file

@ -36,6 +36,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
usedOnMap = true;
boolean nightMode = isNightMode(); boolean nightMode = isNightMode();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@ -122,11 +123,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
interface OptionsFragmentListener { interface OptionsFragmentListener {
void snapToRoadOnCLick(); void snapToRoadOnCLick();

View file

@ -26,6 +26,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
usedOnMap = true;
boolean nightMode = isNightMode(); boolean nightMode = isNightMode();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@ -103,11 +104,6 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
} }
}; };
@Override
protected boolean isNightMode() {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
interface SaveAsNewTrackFragmentListener { interface SaveAsNewTrackFragmentListener {
void saveAsRoutePointOnClick(); void saveAsRoutePointOnClick();

View file

@ -34,6 +34,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
usedOnMap = true;
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
boolean nightMode = isNightMode(); boolean nightMode = isNightMode();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
@ -145,11 +146,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
return mainView; return mainView;
} }
@Override
protected boolean isNightMode() {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
@Override @Override
public void dismiss() { public void dismiss() {
if (listener != null) { if (listener != null) {