Online Routing UI - refactoring part 1
This commit is contained in:
parent
677a2c888b
commit
079da7b219
10 changed files with 59 additions and 36 deletions
|
@ -110,6 +110,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:maxLines="4"
|
||||
android:saveEnabled="false"
|
||||
android:scrollHorizontally="false"
|
||||
tools:text="Text" />
|
||||
|
||||
|
|
|
@ -102,6 +102,14 @@ public class AndroidUiHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setVisibility(int visibility, View ... views) {
|
||||
for (View view : views) {
|
||||
if (view != null && view.getVisibility() != visibility) {
|
||||
view.setVisibility(visibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isXLargeDevice(@NonNull Activity ctx) {
|
||||
int lt = (ctx.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
|
||||
|
|
|
@ -183,7 +183,7 @@ public class SelectProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getActivity() != null) {
|
||||
OnlineRoutingEngineFragment.showInstance(getActivity(), false);
|
||||
OnlineRoutingEngineFragment.showInstance(getActivity(), getAppMode(), false);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
@ -367,6 +367,7 @@ public class SelectProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
public static void showInstance(@NonNull FragmentActivity activity,
|
||||
@NonNull DialogMode dialogMode,
|
||||
@Nullable Fragment target,
|
||||
ApplicationMode appMode,
|
||||
String selectedItemKey,
|
||||
boolean usedOnMap) {
|
||||
SelectProfileBottomSheet fragment = new SelectProfileBottomSheet();
|
||||
|
@ -375,6 +376,7 @@ public class SelectProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
args.putString(SELECTED_KEY, selectedItemKey);
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(activity.getSupportFragmentManager(), TAG);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener;
|
||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem;
|
||||
|
@ -41,9 +42,9 @@ public class OnlineRoutingSegmentCard extends BaseCard {
|
|||
private View resultContainer;
|
||||
private OnTextChangedListener onTextChangedListener;
|
||||
|
||||
public OnlineRoutingSegmentCard(@NonNull MapActivity mapActivity) {
|
||||
public OnlineRoutingSegmentCard(@NonNull MapActivity mapActivity, boolean nightMode) {
|
||||
super(mapActivity);
|
||||
build(mapActivity);
|
||||
this.nightMode = nightMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,19 +158,11 @@ public class OnlineRoutingSegmentCard extends BaseCard {
|
|||
}
|
||||
|
||||
private void showElements(View... views) {
|
||||
changeVisibility(View.VISIBLE, views);
|
||||
AndroidUiHelper.setVisibility(View.VISIBLE, views);
|
||||
}
|
||||
|
||||
private void hideElements(View... views) {
|
||||
changeVisibility(View.GONE, views);
|
||||
}
|
||||
|
||||
private void changeVisibility(int visibility, View... views) {
|
||||
for (View v : views) {
|
||||
if (visibility != v.getVisibility()) {
|
||||
v.setVisibility(visibility);
|
||||
}
|
||||
}
|
||||
AndroidUiHelper.setVisibility(View.GONE, views);
|
||||
}
|
||||
|
||||
public void setOnTextChangedListener(OnTextChangedListener onTextChangedListener) {
|
||||
|
|
|
@ -38,12 +38,12 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
|||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
|
||||
applyQueryType = ApplyQueryType.valueOf(savedInstanceState.getString(APPLY_QUERY_TYPE));
|
||||
profileDependent = savedInstanceState.getBoolean(PROFILE_DEPENDENT, false);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -125,8 +125,9 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
|
|||
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId())) {
|
||||
if (getActivity() != null) {
|
||||
String defaultModeKey = settings.DEFAULT_APPLICATION_MODE.get().getStringKey();
|
||||
SelectProfileBottomSheet.showInstance(getActivity(),
|
||||
DialogMode.DEFAULT_PROFILE, this, defaultModeKey, false);
|
||||
SelectProfileBottomSheet.showInstance(
|
||||
getActivity(), DialogMode.DEFAULT_PROFILE, this,
|
||||
getSelectedAppMode(), defaultModeKey, false);
|
||||
}
|
||||
} else if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId) && !settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
|
|
|
@ -119,8 +119,9 @@ public class MainSettingsFragment extends BaseSettingsFragment implements OnSele
|
|||
return true;
|
||||
} else if (CREATE_PROFILE.equals(prefId)) {
|
||||
if (getActivity() != null) {
|
||||
SelectProfileBottomSheet.showInstance(getActivity(),
|
||||
DialogMode.BASE_PROFILE, this, null, false);
|
||||
SelectProfileBottomSheet.showInstance(
|
||||
getActivity(), DialogMode.BASE_PROFILE, this,
|
||||
getSelectedAppMode(), null, false);
|
||||
}
|
||||
} else if (IMPORT_PROFILE.equals(prefId)) {
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
|
|
|
@ -126,7 +126,7 @@ public class NavigationFragment extends BaseSettingsFragment implements OnSelect
|
|||
if (getActivity() != null) {
|
||||
SelectProfileBottomSheet.showInstance(
|
||||
getActivity(), SelectProfileBottomSheet.DialogMode.NAVIGATION_PROFILE,
|
||||
this, routingProfileKey, false);
|
||||
this, getSelectedAppMode(), routingProfileKey, false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.osmand.plus.profiles.onlinerouting.ServerType;
|
|||
import net.osmand.plus.profiles.onlinerouting.ExampleLocation;
|
||||
import net.osmand.plus.profiles.onlinerouting.VehicleType;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -48,6 +49,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
private static final String ENGINE_API_KEY_KEY = "engine_api_key";
|
||||
private static final String ENGINE_NAME_CHANGED_BY_USER_KEY = "engine_name_changed_by_user_key";
|
||||
private static final String EXAMPLE_LOCATION_KEY = "example_location";
|
||||
private static final String APP_MODE_KEY = "app_mode";
|
||||
|
||||
private OnlineRoutingSegmentCard nameCard;
|
||||
private OnlineRoutingSegmentCard serverCard;
|
||||
|
@ -56,7 +58,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
private OnlineRoutingSegmentCard exampleCard;
|
||||
|
||||
private boolean isEditingMode;
|
||||
private boolean nightMode;
|
||||
private ApplicationMode appMode;
|
||||
|
||||
private OnlineRoutingEngineObject engine;
|
||||
private ExampleLocation selectedLocation;
|
||||
|
@ -82,7 +84,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
if (mapActivity == null) {
|
||||
return null;
|
||||
}
|
||||
nightMode = !app.getSettings().isLightContent();
|
||||
boolean nightMode = isNightMode(app);
|
||||
|
||||
View view = UiUtilities.getInflater(getContext(), nightMode)
|
||||
.inflate(R.layout.online_routing_engine_preference, container, false);
|
||||
|
@ -95,7 +97,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
ViewGroup segmentsContainer = (ViewGroup) view.findViewById(R.id.segments_container);
|
||||
|
||||
// create name card
|
||||
nameCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||
nameCard = new OnlineRoutingSegmentCard(mapActivity, nightMode);
|
||||
nameCard.build(mapActivity);
|
||||
nameCard.setDescription(getString(R.string.select_nav_profile_dialog_message));
|
||||
nameCard.setFieldBoxLabelText(getString(R.string.shared_string_name));
|
||||
nameCard.setOnTextChangedListener(new OnTextChangedListener() {
|
||||
|
@ -111,7 +114,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
segmentsContainer.addView(nameCard.getView());
|
||||
|
||||
// create server card
|
||||
serverCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||
serverCard = new OnlineRoutingSegmentCard(mapActivity, nightMode);
|
||||
serverCard.build(mapActivity);
|
||||
serverCard.setHeaderTitle(getString(R.string.shared_string_type));
|
||||
List<HorizontalSelectionItem> serverItems = new ArrayList<>();
|
||||
for (ServerType server : ServerType.values()) {
|
||||
|
@ -141,7 +145,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
segmentsContainer.addView(serverCard.getView());
|
||||
|
||||
// create vehicle card
|
||||
vehicleCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||
vehicleCard = new OnlineRoutingSegmentCard(mapActivity, nightMode);
|
||||
vehicleCard.build(mapActivity);
|
||||
vehicleCard.setHeaderTitle(getString(R.string.shared_string_vehicle));
|
||||
List<HorizontalSelectionItem> vehicleItems = new ArrayList<>();
|
||||
for (VehicleType vehicle : VehicleType.values()) {
|
||||
|
@ -173,7 +178,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
segmentsContainer.addView(vehicleCard.getView());
|
||||
|
||||
// create api key card
|
||||
apiKeyCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||
apiKeyCard = new OnlineRoutingSegmentCard(mapActivity, nightMode);
|
||||
apiKeyCard.build(mapActivity);
|
||||
apiKeyCard.setHeaderTitle(getString(R.string.shared_string_api_key));
|
||||
apiKeyCard.setFieldBoxLabelText(getString(R.string.keep_it_empty_if_not));
|
||||
apiKeyCard.setEditedText(engine.apiKey);
|
||||
|
@ -188,7 +194,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
segmentsContainer.addView(apiKeyCard.getView());
|
||||
|
||||
// create example card
|
||||
exampleCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||
exampleCard = new OnlineRoutingSegmentCard(mapActivity, nightMode);
|
||||
exampleCard.build(mapActivity);
|
||||
exampleCard.setHeaderTitle(getString(R.string.shared_string_example));
|
||||
List<HorizontalSelectionItem> locationItems = new ArrayList<>();
|
||||
for (ExampleLocation location : ExampleLocation.values()) {
|
||||
|
@ -330,14 +337,6 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static void showInstance(FragmentActivity activity, boolean isEditingMode) {
|
||||
OnlineRoutingEngineFragment fragment = new OnlineRoutingEngineFragment();
|
||||
fragment.isEditingMode = isEditingMode;
|
||||
activity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, TAG)
|
||||
.addToBackStack(TAG).commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -353,6 +352,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
outState.putString(ENGINE_API_KEY_KEY, engine.apiKey);
|
||||
outState.putBoolean(ENGINE_NAME_CHANGED_BY_USER_KEY, engine.wasNameChangedByUser);
|
||||
outState.putString(EXAMPLE_LOCATION_KEY, selectedLocation.name());
|
||||
if (appMode != null) {
|
||||
outState.putString(APP_MODE_KEY, appMode.getStringKey());
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreState(Bundle savedState) {
|
||||
|
@ -364,9 +366,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
engine.apiKey = savedState.getString(ENGINE_API_KEY_KEY);
|
||||
engine.wasNameChangedByUser = savedState.getBoolean(ENGINE_NAME_CHANGED_BY_USER_KEY);
|
||||
selectedLocation = ExampleLocation.valueOf(savedState.getString(EXAMPLE_LOCATION_KEY));
|
||||
appMode = ApplicationMode.valueOfStringKey(savedState.getString(APP_MODE_KEY), null);
|
||||
}
|
||||
|
||||
|
||||
private void initEngineState() {
|
||||
engine.serverType = ServerType.values()[0];
|
||||
engine.vehicleType = VehicleType.values()[0];
|
||||
|
@ -380,6 +382,10 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean isNightMode(@NonNull OsmandApplication app) {
|
||||
return !app.getSettings().isLightContentForMode(appMode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MapActivity getMapActivity() {
|
||||
FragmentActivity activity = getActivity();
|
||||
|
@ -390,6 +396,17 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentActivity activity,
|
||||
@NonNull ApplicationMode appMode,
|
||||
boolean isEditingMode) {
|
||||
OnlineRoutingEngineFragment fragment = new OnlineRoutingEngineFragment();
|
||||
fragment.isEditingMode = isEditingMode;
|
||||
fragment.appMode = appMode;
|
||||
activity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, TAG)
|
||||
.addToBackStack(TAG).commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
private static class OnlineRoutingEngineObject {
|
||||
private String name;
|
||||
private ServerType serverType;
|
||||
|
|
|
@ -403,7 +403,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
|
|||
if (getActivity() != null) {
|
||||
SelectProfileBottomSheet.showInstance(
|
||||
getActivity(), DialogMode.BASE_PROFILE, ProfileAppearanceFragment.this,
|
||||
selectedAppModeKey, false);
|
||||
getSelectedAppMode(), selectedAppModeKey, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue