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="monitoring_control_start">REC</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">Simplified track</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
public void inflate(Context context, ViewGroup container, boolean nightMode) {
super.inflate(context, container, nightMode);
descriptionTv = (TextView) view.findViewById(R.id.description);
descriptionTv = view.findViewById(R.id.description);
if (descriptionTv != null) {
if(Algorithms.isEmpty(description) && descriptionTv.getText().length() == 0){
if (Algorithms.isEmpty(description)) {
descriptionTv.setVisibility(View.GONE);
}else{
} else {
descriptionTv.setVisibility(View.VISIBLE);
}
descriptionTv.setText(description);

View file

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

View file

@ -65,7 +65,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
R.layout.track_name_edit_text, null);
final TextInputLayout nameTextBox = editNameView.findViewById(R.id.name_text_box);
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
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
nameTextBox.setDefaultHintTextColor(colorStateList);
@ -96,19 +97,20 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
items.add(new DividerSpaceItem(app, contentPaddingSmall));
FolderListAdapter adapter = new FolderListAdapter(app, nightMode, folderName);
adapter.setListener(createFolderSelectListener());
View view = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.bottom_sheet_item_recyclerview,
null);
View recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setPadding(contentPaddingHalf, 0, contentPaddingHalf, 0);
BaseBottomSheetItem scrollItem = new HorizontalRecyclerBottomSheetItem.Builder()
.setAdapter(adapter)
.setCustomView(view)
.create();
this.items.add(scrollItem);
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin)));
if (adapter.getItemCount() > 0) {
adapter.setListener(createFolderSelectListener());
View view = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.bottom_sheet_item_recyclerview,
null);
View recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setPadding(contentPaddingHalf, 0, contentPaddingHalf, 0);
BaseBottomSheetItem scrollItem = new HorizontalRecyclerBottomSheetItem.Builder()
.setAdapter(adapter)
.setCustomView(view)
.create();
this.items.add(scrollItem);
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 backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode),
R.attr.activity_background_color);