From 3e6a495139167ffba15bd879ec8f5d5f2e9ccbcb Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 25 Aug 2020 23:01:17 +0300 Subject: [PATCH] SaveAsNewTrack UI --- .../main/java/net/osmand/util/Algorithms.java | 21 ++ ...bottom_sheet_item_with_switch_outlined.xml | 64 ++++++ OsmAnd/res/values/sizes.xml | 2 + OsmAnd/res/values/strings.xml | 3 + .../BottomSheetItemWithDescription.java | 6 + .../measurementtool/FolderListAdapter.java | 144 +++++++++++++ .../MeasurementToolFragment.java | 31 +-- ...veAsNewTrackBottomSheetDialogFragment.java | 199 +++++++++++------- .../SelectFileBottomSheet.java | 16 +- .../plus/myplaces/AvailableGPXFragment.java | 30 +-- 10 files changed, 381 insertions(+), 135 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_switch_outlined.xml create mode 100644 OsmAnd/src/net/osmand/plus/measurementtool/FolderListAdapter.java diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index 7dd69b9be4..21e7fbd58c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -26,6 +26,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -139,6 +140,26 @@ public class Algorithms { return name; } + public static List collectDirs(File parentDir, List dirs) { + return collectDirs(parentDir, dirs, null); + } + + public static List collectDirs(File parentDir, List dirs, File exclDir) { + File[] listFiles = parentDir.listFiles(); + if (listFiles != null) { + Arrays.sort(listFiles); + for (File f : listFiles) { + if (f.isDirectory()) { + if (!f.equals(exclDir)) { + dirs.add(f); + } + Algorithms.collectDirs(f, dirs); + } + } + } + return dirs; + } + public static File[] getSortedFilesVersions(File dir) { File[] listFiles = dir.listFiles(); if (listFiles != null) { diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_switch_outlined.xml b/OsmAnd/res/layout/bottom_sheet_item_with_switch_outlined.xml new file mode 100644 index 0000000000..513fd09d59 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_switch_outlined.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index beba6fe553..8d403a7133 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -262,6 +262,8 @@ 6dp 14dp 16dp + 100dp + 60dp 8dp 8dp 10dp diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4b18a95b7c..efd2f8e957 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,9 @@ Thx - Hardy --> + File name: + Only the route line will be saved, the waypoints will be deleted. + Simplified track Change route type after Change route type before Trim after diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index 0593f6c519..d4f9defedc 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -12,6 +12,7 @@ import androidx.annotation.LayoutRes; import androidx.core.content.ContextCompat; import net.osmand.plus.R; +import net.osmand.util.Algorithms; public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { @@ -75,6 +76,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { super.inflate(context, container, nightMode); descriptionTv = (TextView) view.findViewById(R.id.description); if (descriptionTv != null) { + if(Algorithms.isEmpty(description) && descriptionTv.getText().length() == 0){ + descriptionTv.setVisibility(View.GONE); + }else{ + descriptionTv.setVisibility(View.VISIBLE); + } descriptionTv.setText(description); if (descriptionColorId != INVALID_ID) { descriptionTv.setTextColor(ContextCompat.getColor(context, descriptionColorId)); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/FolderListAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/FolderListAdapter.java new file mode 100644 index 0000000000..e4ce603b8a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/measurementtool/FolderListAdapter.java @@ -0,0 +1,144 @@ +package net.osmand.plus.measurementtool; + +import android.graphics.drawable.GradientDrawable; +import android.os.Build; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + +import net.osmand.AndroidUtils; +import net.osmand.IndexConstants; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.util.Algorithms; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class FolderListAdapter extends RecyclerView.Adapter { + + List items = new ArrayList<>(); + + void setSelectedItemName(String selectedItemName) { + this.selectedItemName = selectedItemName; + } + + String selectedItemName; + OsmandApplication app; + boolean nightMode; + + FolderListAdapter(OsmandApplication app, boolean nightMode) { + this.app = app; + this.nightMode = nightMode; + fillGroups(); + } + + private void fillGroups() { + items.clear(); + items.addAll(getFolders()); + } + + private Collection getFolders() { + List dirs = new ArrayList<>(); + final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); + Algorithms.collectDirs(gpxDir, dirs); + List dirItems = new ArrayList<>(); + for (File dir : dirs) { + dirItems.add(dir.getName()); + } + return dirItems; + } + + @NonNull + @Override + public GroupsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.point_editor_group_select_item, + parent, false); + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + params.width = app.getResources().getDimensionPixelSize(R.dimen.measurement_tool_folder_select_width); + params.height = app.getResources().getDimensionPixelSize(R.dimen.measurement_tool_folder_select_height); + TextView groupName = view.findViewById(R.id.groupName); + groupName.setMaxLines(1); + groupName.setEllipsize(TextUtils.TruncateAt.END); + groupName.setTextColor(ContextCompat.getColor(app, activeColorRes)); + return new FolderListAdapter.GroupsViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull final GroupsViewHolder holder, int position) { + + holder.groupButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int previousSelectedPosition = getItemPosition(selectedItemName); + selectedItemName = items.get(holder.getAdapterPosition()); + notifyItemChanged(holder.getAdapterPosition()); + notifyItemChanged(previousSelectedPosition); + } + }); + final String group = Algorithms.capitalizeFirstLetter(items.get(position)); + holder.groupName.setText(group); + int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; + int strokeColor; + int strokeWidth; + if (selectedItemName != null && selectedItemName.equals(items.get(position))) { + strokeColor = activeColorRes; + strokeWidth = 2; + } else { + strokeColor = nightMode ? R.color.stroked_buttons_and_links_outline_dark + : R.color.stroked_buttons_and_links_outline_light; + strokeWidth = 1; + } + GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app, + R.drawable.bg_select_group_button_outline); + if (rectContourDrawable != null) { + rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), ContextCompat.getColor(app, strokeColor)); + holder.groupButton.setImageDrawable(rectContourDrawable); + } + int iconID; + iconID = R.drawable.ic_action_folder; + holder.groupIcon.setImageDrawable(app.getUIUtilities().getIcon(iconID, activeColorRes)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light_6dp, + R.drawable.ripple_solid_dark_6dp); + } + } + + @Override + public int getItemCount() { + return items == null ? 0 : items.size(); + } + + String getSelectedItem() { + return selectedItemName; + } + + int getItemPosition(String name) { + return items.indexOf(name); + } + + static class GroupsViewHolder extends RecyclerView.ViewHolder { + + final TextView groupName; + final ImageView groupIcon; + final ImageView groupButton; + + GroupsViewHolder(View itemView) { + super(itemView); + groupName = itemView.findViewById(R.id.groupName); + groupIcon = itemView.findViewById(R.id.groupIcon); + groupButton = itemView.findViewById(R.id.outlineRect); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 7e577a19cc..498f0116c4 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -64,7 +64,6 @@ import net.osmand.plus.measurementtool.GpxApproximationFragment.GpxApproximation import net.osmand.plus.measurementtool.GpxData.ActionType; import net.osmand.plus.measurementtool.OptionsBottomSheetDialogFragment.OptionsFragmentListener; import net.osmand.plus.measurementtool.RouteBetweenPointsBottomSheetDialogFragment.RouteBetweenPointsFragmentListener; -import net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener; import net.osmand.plus.measurementtool.SelectedPointBottomSheetDialogFragment.SelectedPointFragmentListener; import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter; import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.MeasurementAdapterListener; @@ -97,6 +96,7 @@ import java.util.Locale; import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode; import static net.osmand.plus.measurementtool.MeasurementEditingContext.SnapToRoadProgressListener; +import static net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.*; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.ADD_TO_TRACK; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener; @@ -105,7 +105,8 @@ import static net.osmand.plus.measurementtool.command.ClearPointsCommand.*; import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.*; public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, - OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener { + OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener, + SaveAsNewTrackFragmentListener { public static final String TAG = MeasurementToolFragment.class.getSimpleName(); @@ -194,11 +195,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route measurementLayer.setEditingCtx(editingCtx); - // Handling screen rotation - Fragment saveAsNewTrackFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SaveAsNewTrackBottomSheetDialogFragment.TAG); - if (saveAsNewTrackFragment != null) { - ((SaveAsNewTrackBottomSheetDialogFragment) saveAsNewTrackFragment).setListener(createSaveAsNewTrackFragmentListener()); - } // If rotate the screen from landscape to portrait when the list of points is displayed then // the RecyclerViewFragment will exist without view. This is necessary to remove it. if (!portrait) { @@ -908,18 +904,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } } - private SaveAsNewTrackFragmentListener createSaveAsNewTrackFragmentListener() { - return new SaveAsNewTrackFragmentListener() { - @Override - public void saveAsRoutePointOnClick() { - saveAsGpx(SaveType.ROUTE_POINT); - } - - @Override - public void saveAsLineOnClick() { - saveAsGpx(SaveType.LINE); - } - }; + @Override + public void onSaveAsNewTrack(String fileName, boolean showOnMap, boolean simplifiedTrack) { + //todo implement + saveAsGpx(SaveType.ROUTE_POINT); } private MeasurementAdapterListener createMeasurementAdapterListener(final ItemTouchHelper touchHelper) { @@ -1045,10 +1033,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route private void openSaveAsNewTrackMenu(MapActivity mapActivity) { if (mapActivity != null) { if (editingCtx.getPointsCount() > 0) { - SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); - fragment.setListener(createSaveAsNewTrackFragmentListener()); - fragment.show(mapActivity.getSupportFragmentManager(), SaveAsNewTrackBottomSheetDialogFragment.TAG); + SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), this); } else { Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index a3a1741192..ba69f3ed02 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -1,31 +1,42 @@ package net.osmand.plus.measurementtool; -import android.graphics.drawable.Drawable; -import android.os.Build; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.graphics.drawable.GradientDrawable; import android.os.Bundle; -import android.view.ContextThemeWrapper; -import android.view.MotionEvent; import android.view.View; -import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.textfield.TextInputLayout; import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import org.apache.commons.logging.Log; + public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { - public final static String TAG = "SaveAsNewTrackBottomSheetDialogFragment"; + public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class); - private SaveAsNewTrackFragmentListener listener; - - public void setListener(SaveAsNewTrackFragmentListener listener) { - this.listener = listener; - } + boolean showOnMap; + boolean simplifiedTrack; + String fileName; @Override public void createMenuItems(Bundle savedInstanceState) { @@ -33,84 +44,122 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial if (app == null) { return; } + int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx))); - items.add(new ShortDescriptionItem(getString(R.string.measurement_tool_save_as_new_track_descr))); - - if (Build.VERSION.SDK_INT >= 18) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - View imagesRow = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.fragment_save_as_new_track_images_row, null); - - final ImageView routePointImage = (ImageView) imagesRow.findViewById(R.id.route_point_image); - final ImageView lineImage = (ImageView) imagesRow.findViewById(R.id.line_image); - Drawable routePointDrawable = app.getUIUtilities().getIcon(nightMode - ? R.drawable.img_help_trip_route_points_night - : R.drawable.img_help_trip_route_points_day); - Drawable lineDrawable = app.getUIUtilities().getIcon(nightMode - ? R.drawable.img_help_trip_track_night - : R.drawable.img_help_trip_track_day); - if (routePointDrawable != null && lineDrawable != null) { - routePointImage.setImageDrawable(AndroidUtils.getDrawableForDirection(app, routePointDrawable)); - lineImage.setImageDrawable(AndroidUtils.getDrawableForDirection(app, lineDrawable)); - } - routePointImage.setOnClickListener(saveAsRoutePointOnClickListener); - lineImage.setOnClickListener(saveAsLineOnClickListener); - - View.OnTouchListener textOnTouchListener = new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - return false; - } - }; - imagesRow.findViewById(R.id.line_text).setOnTouchListener(textOnTouchListener); - imagesRow.findViewById(R.id.route_point_text).setOnTouchListener(textOnTouchListener); - - items.add(new BaseBottomSheetItem.Builder().setCustomView(imagesRow).create()); + View editNameView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.markers_track_name_edit_text, + null, false); + 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)); + ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat + .getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)); + nameTextBox.setDefaultHintTextColor(colorStateList); + if (nameTextBox.getEditText() != null) { + AndroidUtils.setHintTextSecondaryColor(app, nameTextBox.getEditText(), nightMode); } - - BaseBottomSheetItem saveAsRoutePointsItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_route_points)) - .setTitle(getString(R.string.save_as_route_point)) - .setLayoutId(R.layout.bottom_sheet_item_simple) - .setOnClickListener(saveAsRoutePointOnClickListener) + BaseBottomSheetItem editFileName = new BaseBottomSheetItem.Builder() + .setCustomView(editNameView) .create(); - items.add(saveAsRoutePointsItem); + this.items.add(editFileName); - BaseBottomSheetItem saveAsLineItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_split_interval)) - .setTitle(getString(R.string.save_as_line)) - .setLayoutId(R.layout.bottom_sheet_item_simple) - .setOnClickListener(saveAsLineOnClickListener) + int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); + int contentPaddingHalf = app.getResources().getDimensionPixelSize(R.dimen.content_padding_half); + + items.add(new DividerSpaceItem(app, contentPaddingSmall)); + + FolderListAdapter adapter = new FolderListAdapter(app, nightMode); + View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_recyclerview, + null, false); + View recyclerView = view.findViewById(R.id.recycler_view); + recyclerView.setPadding(contentPaddingHalf, 0, contentPaddingHalf, 0); + BaseBottomSheetItem scrollItem = new HorizontalRecyclerBottomSheetItem.Builder() + .setAdapter(adapter) + .setCustomView(view) .create(); - items.add(saveAsLineItem); + this.items.add(scrollItem); + + items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin))); + + GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app, + R.drawable.bg_select_group_button_outline); + if (background != null) { + background = (GradientDrawable) background.mutate(); + background.setStroke(0, Color.TRANSPARENT); + int color = AndroidUtils.getColorFromAttr(app, R.attr.activity_background_color); + background.setColor(color); + } + final BottomSheetItemWithCompoundButton[] simplifiedTrackItem = new BottomSheetItemWithCompoundButton[1]; + simplifiedTrackItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() + .setChecked(simplifiedTrack) + .setCompoundButtonColorId(activeColorRes) + .setDescription(getString(R.string.simplified_track_description)) + .setBackground(background) + .setTitle(getString(R.string.simplified_track)) + .setLayoutId(R.layout.bottom_sheet_item_with_switch_outlined) + + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + simplifiedTrack = !simplifiedTrack; + simplifiedTrackItem[0].setChecked(simplifiedTrack); + } + }) + .create(); + items.add(simplifiedTrackItem[0]); + + items.add(new DividerSpaceItem(app, contentPadding)); + + final BottomSheetItemWithCompoundButton[] showOnMapItem = new BottomSheetItemWithCompoundButton[1]; + showOnMapItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() + .setCompoundButtonColorId(activeColorRes) + .setChecked(showOnMap) + .setTitle(getString(R.string.shared_string_show_on_map)) + .setLayoutId(R.layout.bottom_sheet_item_with_switch_outlined) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showOnMap = !showOnMap; + showOnMapItem[0].setChecked(showOnMap); + } + }) + .create(); + items.add(showOnMapItem[0]); + + items.add(new DividerSpaceItem(app, contentPaddingSmall)); } - private View.OnClickListener saveAsLineOnClickListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.saveAsLineOnClick(); + public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) { + try { + if (!fm.isStateSaved()) { + SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment(); + fragment.setTargetFragment(targetFragment, 0); + fragment.show(fm, TAG); } - dismiss(); + } catch (RuntimeException e) { + LOG.error("showInstance", e); } - }; + } - private View.OnClickListener saveAsRoutePointOnClickListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.saveAsRoutePointOnClick(); - } - dismiss(); + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_save; + } + + @Override + protected void onRightBottomButtonClick() { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SaveAsNewTrackFragmentListener) { + ((SaveAsNewTrackFragmentListener) targetFragment).onSaveAsNewTrack(fileName, showOnMap, simplifiedTrack); } - }; + dismiss(); + } interface SaveAsNewTrackFragmentListener { - void saveAsRoutePointOnClick(); + void onSaveAsNewTrack(String fileName, boolean showOnMap, boolean simplifiedTrack); - void saveAsLineOnClick(); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java index 60565b7839..711129094b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java @@ -25,12 +25,12 @@ import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.Horizonta import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import static net.osmand.plus.helpers.GpxUiHelper.getSortedGPXFilesInfo; +import static net.osmand.util.Algorithms.collectDirs; public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment { @@ -149,19 +149,6 @@ public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment { : IndexConstants.GPX_INDEX_DIR.substring(0, IndexConstants.GPX_INDEX_DIR.length() - 1); } - private void collectDirs(File dir, List dirs) { - File[] listFiles = dir.listFiles(); - if (listFiles != null) { - Arrays.sort(listFiles); - for (File f : listFiles) { - if (f.isDirectory()) { - dirs.add(f); - collectDirs(f, dirs); - } - } - } - } - @Override protected int getCustomHeight() { return AndroidUtils.dpToPx(mainView.getContext(), BOTTOM_SHEET_HEIGHT_DP); @@ -170,7 +157,6 @@ public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment { public static void showInstance(FragmentManager fragmentManager, SelectFileListener listener, Mode mode) { if (!fragmentManager.isStateSaved()) { SelectFileBottomSheet fragment = new SelectFileBottomSheet(); - fragment.setUsedOnMap(true); fragment.setRetainInstance(true); fragment.setListener(listener); fragment.setFragmentMode(mode); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index e570ca400b..00e7910271 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -81,7 +81,6 @@ import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.util.Algorithms; import java.io.File; import java.text.Collator; @@ -103,6 +102,7 @@ import java.util.regex.Pattern; import static net.osmand.plus.GpxSelectionHelper.CURRENT_TRACK; import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; +import static net.osmand.util.Algorithms.*; public class AvailableGPXFragment extends OsmandExpandableListFragment implements FavoritesFragmentStateHolder { @@ -742,20 +742,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement } } - private void collectDirs(File dir, List dirs, File exclDir) { - File[] listFiles = dir.listFiles(); - if (listFiles != null) { - for (File f : listFiles) { - if (f.isDirectory()) { - if (!exclDir.equals(f)) { - dirs.add(f); - } - collectDirs(f, dirs, exclDir); - } - } - } - } - private void moveGpx(final GpxInfo info) { final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(app); @@ -777,7 +763,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement dirName = dirName.substring(gpxDir.length() + 1); } } - menuAdapter.addItem(itemBuilder.setTitle(Algorithms.capitalizeFirstLetter(dirName)) + menuAdapter.addItem(itemBuilder.setTitle(capitalizeFirstLetter(dirName)) .setIcon(R.drawable.ic_action_folder_stroke).setTag(i).createItem()); i++; } @@ -1111,7 +1097,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement // search from end for (int i = category.size() - 1; i >= 0; i--) { String cat = category.get(i); - if (Algorithms.objectEquals(catName, cat)) { + if (objectEquals(catName, cat)) { found = i; break; } @@ -1249,14 +1235,14 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement if (groupName.length() == 0) { groupName = getString(R.string.shared_string_tracks); } - t.append(Algorithms.capitalizeFirstLetter(groupName)); + t.append(capitalizeFirstLetter(groupName)); boolean light = app.getSettings().isLightContent(); if (selectionMode) { final CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item); // Issue 6187: No selection box for Visible group header //ch.setVisibility(View.VISIBLE); - ch.setVisibility((selectionMode && !(groupPosition == 0 && isShowingSelection()))? View.VISIBLE : View.GONE); + ch.setVisibility((selectionMode && !(groupPosition == 0 && isShowingSelection())) ? View.VISIBLE : View.GONE); ch.setChecked(selectedGroups.contains(groupPosition)); ch.setOnClickListener(new View.OnClickListener() { @@ -1361,7 +1347,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement // local_indexes_cat_gpx now obsolete in new UI screen which shows only GPX data // if (Algorithms.objectEquals(getActivity().getString(R.string.local_indexes_cat_gpx) + " " + // g.subfolder, cat)) { - if (Algorithms.objectEquals("" + g.subfolder, cat)) { + if (objectEquals("" + g.subfolder, cat)) { found = i; break; } @@ -1591,7 +1577,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement for (GpxInfo info : params) { if (!isCancelled() && (info.gpx == null || !info.gpx.showCurrentTrack)) { boolean successfull; - successfull = Algorithms.removeAllFiles(info.file); + successfull = removeAllFiles(info.file); app.getGpxDbHelper().remove(info.file); total++; if (successfull) { @@ -1854,7 +1840,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement // if (analysis.isTimeMoving()) { // time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + ""); // } else { - time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000), app.accessibilityEnabled()) + ""); + time.setText(formatDuration((int) (analysis.timeSpan / 1000), app.accessibilityEnabled()) + ""); // } } else { time.setText("");