Fix merge conflicts, small refactoring

This commit is contained in:
Dima-1 2020-08-11 16:34:08 +03:00
parent 9c9a11bab6
commit 89fa1bea31
3 changed files with 56 additions and 53 deletions

View file

@ -3,6 +3,8 @@ package net.osmand.plus.measurementtool;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -16,6 +18,10 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final int REQUEST_CODE = 1001;
public static final int SAVE_RESULT_CODE = 2;
public static final int EXIT_RESULT_CODE = 3;
public static final String TAG = ExitBottomSheetDialogFragment.class.getSimpleName(); public static final String TAG = ExitBottomSheetDialogFragment.class.getSimpleName();
@Override @Override
@ -39,9 +45,9 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Fragment target = getTargetFragment(); Fragment targetFragment = getTargetFragment();
if (target instanceof ExitFragmentListener) { if (targetFragment != null) {
((ExitFragmentListener) target).exitOnClick(); targetFragment.onActivityResult(REQUEST_CODE, EXIT_RESULT_CODE, null);
} }
dismiss(); dismiss();
} }
@ -57,9 +63,9 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Fragment target = getTargetFragment(); Fragment targetFragment = getTargetFragment();
if (target instanceof ExitFragmentListener) { if (targetFragment != null) {
((ExitFragmentListener) target).saveOnClick(); targetFragment.onActivityResult(REQUEST_CODE, SAVE_RESULT_CODE, null);
} }
dismiss(); dismiss();
} }
@ -72,19 +78,11 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
return R.string.shared_string_close; return R.string.shared_string_close;
} }
public static void showInstance(FragmentManager fragmentManager, Fragment target) { public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) {
if (!fragmentManager.isStateSaved()) { if (!fragmentManager.isStateSaved()) {
ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment(); ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment();
fragment.setUsedOnMap(true); fragment.setTargetFragment(targetFragment, REQUEST_CODE);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
} }
} }
interface ExitFragmentListener {
void exitOnClick();
void saveOnClick();
}
} }

View file

@ -103,8 +103,6 @@ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TR
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener;
import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener; import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener;
public class MeasurementToolFragment extends BaseOsmAndFragment
implements ExitBottomSheetDialogFragment.ExitFragmentListener {
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
GpxApproximationFragmentListener, OptionsFragmentListener { GpxApproximationFragmentListener, OptionsFragmentListener {
@ -222,14 +220,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
downIcon = getContentIcon(R.drawable.ic_action_arrow_down); downIcon = getContentIcon(R.drawable.ic_action_arrow_down);
pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase(); pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase();
View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.fragment_measurement_tool, View view = UiUtilities.getInflater(getContext(), nightMode)
container,false); .inflate(R.layout.fragment_measurement_tool, container, false);
mainView = view.findViewById(R.id.main_view); mainView = view.findViewById(R.id.main_view);
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
pointsListContainer = view.findViewById(R.id.points_list_container); pointsListContainer = view.findViewById(R.id.points_list_container);
if (portrait && pointsListContainer != null) { if (portrait && pointsListContainer != null) {
final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light); final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode
? R.color.activity_background_color_dark
: R.color.activity_background_color_light);
pointsListContainer.setBackgroundColor(backgroundColor); pointsListContainer.setBackgroundColor(backgroundColor);
} }
@ -605,16 +605,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
} }
@Override
public void exitOnClick() {
dismiss(getMapActivity());
}
@Override
public void saveOnClick() {
openSaveAsNewTrackMenu(getMapActivity());
}
private void showProgressBar() { private void showProgressBar() {
ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar); ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
@ -659,25 +649,38 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SnapTrackWarningBottomSheet.REQUEST_CODE) { switch (requestCode) {
switch (resultCode) { case SnapTrackWarningBottomSheet.REQUEST_CODE:
case SnapTrackWarningBottomSheet.CANCEL_REQUEST_CODE: switch (resultCode) {
toolBarController.setSaveViewVisible(true); case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE:
updateToolbar(); toolBarController.setSaveViewVisible(true);
break; updateToolbar();
case SnapTrackWarningBottomSheet.CONTINUE_REQUEST_CODE: break;
MapActivity mapActivity = getMapActivity(); case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE:
if (mapActivity != null) { MapActivity mapActivity = getMapActivity();
try { if (mapActivity != null) {
gpxApproximator = new GpxApproximator(requireMyApplication(), new LocationsHolder(editingCtx.getPoints())); try {
GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(), gpxApproximator = new GpxApproximator(requireMyApplication(),
this, gpxApproximator.getMode(), (int) gpxApproximator.getPointApproximation()); new LocationsHolder(editingCtx.getPoints()));
} catch (IOException e) { GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, gpxApproximator.getMode(),
(int) gpxApproximator.getPointApproximation());
} catch (IOException e) {
}
} }
} break;
break; }
} break;
case ExitBottomSheetDialogFragment.REQUEST_CODE:
switch (resultCode) {
case ExitBottomSheetDialogFragment.EXIT_RESULT_CODE:
dismiss(getMapActivity());
break;
case ExitBottomSheetDialogFragment.SAVE_RESULT_CODE:
openSaveAsNewTrackMenu(getMapActivity());
break;
}
} }
} }
@ -725,7 +728,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void saveAsNewTrackOnClick() { public void saveAsNewTrackOnClick() {
openSaveAsNewTrackMenu(mapActivity); openSaveAsNewTrackMenu(getMapActivity());
} }
@Override @Override
@ -857,6 +860,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void openLastEditTrackOnClick(String gpxFileName) { public void openLastEditTrackOnClick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName)); addNewGpxData(getGpxFile(gpxFileName));
saved = true;
} }
@Override @Override
@ -871,6 +875,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void selectFileOnCLick(String gpxFileName) { public void selectFileOnCLick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName)); addNewGpxData(getGpxFile(gpxFileName));
saved = true;
} }
@Override @Override

View file

@ -23,8 +23,8 @@ import org.apache.commons.logging.Log;
public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment { public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment {
public static final int REQUEST_CODE = 1000; public static final int REQUEST_CODE = 1000;
public static final int CANCEL_REQUEST_CODE = 2; public static final int CANCEL_RESULT_CODE = 2;
public static final int CONTINUE_REQUEST_CODE = 3; public static final int CONTINUE_RESULT_CODE = 3;
public static final String TAG = SnapTrackWarningBottomSheet.class.getSimpleName(); public static final String TAG = SnapTrackWarningBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SnapTrackWarningBottomSheet.class); private static final Log LOG = PlatformUtil.getLog(SnapTrackWarningBottomSheet.class);
@ -58,7 +58,7 @@ public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment {
protected void onRightBottomButtonClick() { protected void onRightBottomButtonClick() {
Fragment fragment = getTargetFragment(); Fragment fragment = getTargetFragment();
if (fragment != null) { if (fragment != null) {
fragment.onActivityResult(REQUEST_CODE, CONTINUE_REQUEST_CODE, null); fragment.onActivityResult(REQUEST_CODE, CONTINUE_RESULT_CODE, null);
} }
dismiss(); dismiss();
} }
@ -77,7 +77,7 @@ public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment {
} }
Fragment fragment = getTargetFragment(); Fragment fragment = getTargetFragment();
if (fragment != null) { if (fragment != null) {
fragment.onActivityResult(REQUEST_CODE, CANCEL_REQUEST_CODE, null); fragment.onActivityResult(REQUEST_CODE, CANCEL_RESULT_CODE, null);
} }
} }