Fix review

This commit is contained in:
Dima-1 2020-08-28 18:44:12 +03:00
parent f2a664c5ab
commit dc425e7b6e
4 changed files with 55 additions and 46 deletions

View file

@ -20,7 +20,7 @@
<string name="disable_recording_once_app_killed_descrp">Will pause track logging when the app is killed (via recent apps). (OsmAnd background indication disappears from the Android notification bar.)</string> <string name="disable_recording_once_app_killed_descrp">Will pause track logging when the app is killed (via recent apps). (OsmAnd background indication disappears from the Android notification bar.)</string>
<string name="monitoring_control_start">REC</string> <string name="monitoring_control_start">REC</string>
<string name="number_of_gpx_files_selected_pattern">%s track files selected</string> <string name="number_of_gpx_files_selected_pattern">%s track files selected</string>
<string name="file_name">File name:</string> <string name="shared_string_file_name">File name</string>
<string name="simplified_track_description">Only the route line will be saved, the waypoints will be deleted.</string> <string name="simplified_track_description">Only the route line will be saved, the waypoints will be deleted.</string>
<string name="simplified_track">Simplified track</string> <string name="simplified_track">Simplified track</string>
<string name="plan_route_change_route_type_after">Change route type after</string> <string name="plan_route_change_route_type_after">Change route type after</string>

View file

@ -74,11 +74,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
@Override @Override
public void inflate(Context context, ViewGroup container, boolean nightMode) { public void inflate(Context context, ViewGroup container, boolean nightMode) {
super.inflate(context, container, nightMode); super.inflate(context, container, nightMode);
descriptionTv = (TextView) view.findViewById(R.id.description); descriptionTv = view.findViewById(R.id.description);
if (descriptionTv != null) { if (descriptionTv != null) {
if(Algorithms.isEmpty(description) && descriptionTv.getText().length() == 0){ if (Algorithms.isEmpty(description)) {
descriptionTv.setVisibility(View.GONE); descriptionTv.setVisibility(View.GONE);
}else{ } else {
descriptionTv.setVisibility(View.VISIBLE); descriptionTv.setVisibility(View.VISIBLE);
} }
descriptionTv.setText(description); descriptionTv.setText(description);

View file

@ -147,6 +147,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
LINE LINE
} }
private enum SaveAction {
SHOW_SNACK_BAR_AND_CLOSE,
SHOW_TOAST,
SHOW_IS_SAVED_FRAGMENT
}
private void setEditingCtx(MeasurementEditingContext editingCtx) { private void setEditingCtx(MeasurementEditingContext editingCtx) {
this.editingCtx = editingCtx; this.editingCtx = editingCtx;
} }
@ -391,7 +397,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setOnSaveViewClickListener(new OnClickListener() { toolBarController.setOnSaveViewClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
saveChanges(true, true); saveChanges(SaveAction.SHOW_SNACK_BAR_AND_CLOSE);
} }
}); });
updateToolbar(); updateToolbar();
@ -584,17 +590,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
} }
public void saveChanges(boolean close, boolean done) { public void saveChanges(SaveAction saveAction) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
if (editingCtx.getPointsCount() > 0) { if (editingCtx.getPointsCount() > 0) {
GpxData gpxData = editingCtx.getGpxData(); GpxData gpxData = editingCtx.getGpxData();
if (editingCtx.isNewData()) { if (editingCtx.isNewData()) {
saveAsGpx(SaveType.ROUTE_POINT, close, done); saveAsGpx(SaveType.ROUTE_POINT, saveAction);
} else if (isInEditMode() && gpxData.getActionType() == ActionType.EDIT_SEGMENT) { } else if (isInEditMode() && gpxData.getActionType() == ActionType.EDIT_SEGMENT) {
openSaveAsNewTrackMenu(mapActivity); openSaveAsNewTrackMenu(mapActivity);
} else { } else {
addToGpx(mapActivity, close, done); addToGpx(mapActivity, saveAction);
} }
} else { } else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
@ -655,7 +661,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void saveChangesOnClick() { public void saveChangesOnClick() {
saveChanges(false, false); saveChanges(SaveAction.SHOW_TOAST);
} }
@Override @Override
@ -875,7 +881,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
.getSelectedFileByPath(gpxFile.path); .getSelectedFileByPath(gpxFile.path);
boolean showOnMap = selectedGpxFile != null; boolean showOnMap = selectedGpxFile != null;
saveExistingGpx(gpxFile, showOnMap, ActionType.ADD_SEGMENT, saveExistingGpx(gpxFile, showOnMap, ActionType.ADD_SEGMENT,
editingCtx.hasRoute() ? SaveType.ROUTE_POINT : SaveType.LINE, false, false); editingCtx.hasRoute() ? SaveType.ROUTE_POINT : SaveType.LINE, SaveAction.SHOW_TOAST);
} }
} }
@ -919,7 +925,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
fileName = fileName + GPX_FILE_EXT; fileName = fileName + GPX_FILE_EXT;
SaveType saveType = simplifiedTrack ? SaveType.LINE : SaveType.ROUTE_POINT; SaveType saveType = simplifiedTrack ? SaveType.LINE : SaveType.ROUTE_POINT;
saveNewGpx(dir, fileName, showOnMap, saveType, true, false); saveNewGpx(dir, fileName, showOnMap, saveType, SaveAction.SHOW_IS_SAVED_FRAGMENT);
} }
private MeasurementAdapterListener createMeasurementAdapterListener(final ItemTouchHelper touchHelper) { private MeasurementAdapterListener createMeasurementAdapterListener(final ItemTouchHelper touchHelper) {
@ -1313,7 +1319,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
} }
private void addToGpx(MapActivity mapActivity, boolean close, boolean done) { private void addToGpx(MapActivity mapActivity, SaveAction saveAction) {
GpxData gpxData = editingCtx.getGpxData(); GpxData gpxData = editingCtx.getGpxData();
GPXFile gpx = gpxData != null ? gpxData.getGpxFile() : null; GPXFile gpx = gpxData != null ? gpxData.getGpxFile() : null;
if (gpx != null) { if (gpx != null) {
@ -1321,11 +1327,11 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path); mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
boolean showOnMap = selectedGpxFile != null; boolean showOnMap = selectedGpxFile != null;
saveExistingGpx(gpx, showOnMap, gpxData.getActionType(), saveExistingGpx(gpx, showOnMap, gpxData.getActionType(),
editingCtx.hasRoute() ? SaveType.ROUTE_POINT : SaveType.LINE, close, done); editingCtx.hasRoute() ? SaveType.ROUTE_POINT : SaveType.LINE, saveAction);
} }
} }
private void saveAsGpx(final SaveType saveType, final boolean close, final boolean done) { private void saveAsGpx(final SaveType saveType, final SaveAction saveAction) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
@ -1364,7 +1370,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
fout = new File(dir, fileName); fout = new File(dir, fileName);
} }
} }
saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, close, done); saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, saveAction);
} }
}) })
.setNegativeButton(R.string.shared_string_cancel, null); .setNegativeButton(R.string.shared_string_cancel, null);
@ -1424,12 +1430,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return displayedName; return displayedName;
} }
private void saveNewGpx(File dir, String fileName, boolean showOnMap, SaveType saveType, boolean close, boolean done) { private void saveNewGpx(File dir, String fileName, boolean showOnMap, SaveType saveType, SaveAction saveAction) {
saveGpx(dir, fileName, showOnMap, null, null, saveType, close, done); saveGpx(dir, fileName, showOnMap, null, null, saveType, saveAction);
} }
private void saveExistingGpx(GPXFile gpx, boolean showOnMap, ActionType actionType, SaveType saveType, boolean close, boolean done) { private void saveExistingGpx(GPXFile gpx, boolean showOnMap, ActionType actionType, SaveType saveType,
saveGpx(null, null, showOnMap, gpx, actionType, saveType, close, done); SaveAction saveAction) {
saveGpx(null, null, showOnMap, gpx, actionType, saveType, saveAction);
} }
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
@ -1439,8 +1446,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
final GPXFile gpxFile, final GPXFile gpxFile,
final ActionType actionType, final ActionType actionType,
final SaveType saveType, final SaveType saveType,
final boolean close, final SaveAction saveAction) {
final boolean done) {
new AsyncTask<Void, Void, Exception>() { new AsyncTask<Void, Void, Exception>() {
@ -1611,8 +1617,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (isInEditMode()) { if (isInEditMode()) {
dismiss(mapActivity); dismiss(mapActivity);
} else { } else {
if (close) { switch (saveAction) {
if (done) { case SHOW_SNACK_BAR_AND_CLOSE:
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity); final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
snackbar = Snackbar.make(mapActivity.getLayout(), snackbar = Snackbar.make(mapActivity.getLayout(),
MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getName()), MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getName()),
@ -1625,7 +1631,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
FileUtils.renameFile(mapActivity, toSave, new FileUtils.RenameCallback() { FileUtils.renameFile(mapActivity, toSave, new FileUtils.RenameCallback() {
@Override @Override
public void renamedTo(File file) { public void renamedTo(File file) {
} }
}); });
} }
@ -1635,12 +1640,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
.setAllCaps(false); .setAllCaps(false);
UiUtilities.setupSnackbar(snackbar, nightMode); UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show(); snackbar.show();
} else { dismiss(mapActivity);
break;
case SHOW_IS_SAVED_FRAGMENT:
SavedTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), SavedTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
toSave.getName()); toSave.getName());
}
dismiss(mapActivity); dismiss(mapActivity);
} else { break;
case SHOW_TOAST:
if (!savedGpxFile.showCurrentTrack) { if (!savedGpxFile.showCurrentTrack) {
Toast.makeText(mapActivity, Toast.makeText(mapActivity,
MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()),

View file

@ -65,7 +65,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
R.layout.track_name_edit_text, null); R.layout.track_name_edit_text, null);
final TextInputLayout nameTextBox = editNameView.findViewById(R.id.name_text_box); final TextInputLayout nameTextBox = editNameView.findViewById(R.id.name_text_box);
nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg); nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg);
nameTextBox.setHint(getString(R.string.file_name)); nameTextBox.setHint(app.getString(R.string.ltr_or_rtl_combine_via_colon,
app.getString(R.string.shared_string_file_name), "").trim());
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)); .getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
nameTextBox.setDefaultHintTextColor(colorStateList); nameTextBox.setDefaultHintTextColor(colorStateList);
@ -96,6 +97,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
items.add(new DividerSpaceItem(app, contentPaddingSmall)); items.add(new DividerSpaceItem(app, contentPaddingSmall));
FolderListAdapter adapter = new FolderListAdapter(app, nightMode, folderName); FolderListAdapter adapter = new FolderListAdapter(app, nightMode, folderName);
if (adapter.getItemCount() > 0) {
adapter.setListener(createFolderSelectListener()); adapter.setListener(createFolderSelectListener());
View view = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.bottom_sheet_item_recyclerview, View view = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.bottom_sheet_item_recyclerview,
null); null);
@ -108,7 +110,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
this.items.add(scrollItem); this.items.add(scrollItem);
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin))); items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin)));
}
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode), int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode),
R.attr.activity_background_color); R.attr.activity_background_color);