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.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -16,6 +18,10 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
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();
@Override
@ -39,9 +45,9 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment target = getTargetFragment();
if (target instanceof ExitFragmentListener) {
((ExitFragmentListener) target).exitOnClick();
Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
targetFragment.onActivityResult(REQUEST_CODE, EXIT_RESULT_CODE, null);
}
dismiss();
}
@ -57,9 +63,9 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment target = getTargetFragment();
if (target instanceof ExitFragmentListener) {
((ExitFragmentListener) target).saveOnClick();
Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
targetFragment.onActivityResult(REQUEST_CODE, SAVE_RESULT_CODE, null);
}
dismiss();
}
@ -72,19 +78,11 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
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()) {
ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment();
fragment.setUsedOnMap(true);
fragment.setTargetFragment(target, 0);
fragment.setTargetFragment(targetFragment, REQUEST_CODE);
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.StartPlanRouteBottomSheet.StartPlanRouteListener;
public class MeasurementToolFragment extends BaseOsmAndFragment
implements ExitBottomSheetDialogFragment.ExitFragmentListener {
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
GpxApproximationFragmentListener, OptionsFragmentListener {
@ -222,14 +220,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
downIcon = getContentIcon(R.drawable.ic_action_arrow_down);
pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase();
View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.fragment_measurement_tool,
container,false);
View view = UiUtilities.getInflater(getContext(), nightMode)
.inflate(R.layout.fragment_measurement_tool, container, false);
mainView = view.findViewById(R.id.main_view);
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);
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);
}
@ -605,16 +605,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
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() {
ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
progressBar.setVisibility(View.VISIBLE);
@ -659,25 +649,38 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SnapTrackWarningBottomSheet.REQUEST_CODE) {
switch (requestCode) {
case SnapTrackWarningBottomSheet.REQUEST_CODE:
switch (resultCode) {
case SnapTrackWarningBottomSheet.CANCEL_REQUEST_CODE:
case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE:
toolBarController.setSaveViewVisible(true);
updateToolbar();
break;
case SnapTrackWarningBottomSheet.CONTINUE_REQUEST_CODE:
case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE:
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
try {
gpxApproximator = new GpxApproximator(requireMyApplication(), new LocationsHolder(editingCtx.getPoints()));
gpxApproximator = new GpxApproximator(requireMyApplication(),
new LocationsHolder(editingCtx.getPoints()));
GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, gpxApproximator.getMode(), (int) gpxApproximator.getPointApproximation());
this, gpxApproximator.getMode(),
(int) gpxApproximator.getPointApproximation());
} catch (IOException e) {
}
}
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
public void saveAsNewTrackOnClick() {
openSaveAsNewTrackMenu(mapActivity);
openSaveAsNewTrackMenu(getMapActivity());
}
@Override
@ -857,6 +860,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void openLastEditTrackOnClick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName));
saved = true;
}
@Override
@ -871,6 +875,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void selectFileOnCLick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName));
saved = true;
}
@Override

View file

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