Search in sources :

Example 11 with GpxDisplayGroup

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup in project Osmand by osmandapp.

the class DisplayGroupsBottomSheet method initSelectableItems.

private void initSelectableItems() {
    List<GpxDisplayGroup> displayGroups = displayHelper.getPointsOriginalGroups();
    DisplayGroupsHolder groupsHolder = DisplayPointsGroupsHelper.getGroups(app, displayGroups, null);
    uiItems.clear();
    for (GpxDisplayGroup group : groupsHolder.groups) {
        if (group.getType() != GpxDisplayItemType.TRACK_POINTS) {
            continue;
        }
        SelectableItem<GpxDisplayGroup> uiItem = new SelectableItem<>();
        List<GpxDisplayItem> groupItems = groupsHolder.itemGroups.get(group);
        String categoryName = group.getName();
        if (TextUtils.isEmpty(categoryName)) {
            categoryName = app.getString(R.string.shared_string_gpx_points);
        }
        uiItem.setTitle(categoryName);
        uiItem.setColor(group.getColor());
        int size = groupItems != null ? groupItems.size() : 0;
        uiItem.setDescription(String.valueOf(size));
        uiItem.setObject(group);
        uiItems.add(uiItem);
    }
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) DisplayGroupsHolder(net.osmand.plus.track.helpers.DisplayPointsGroupsHelper.DisplayGroupsHolder) SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem)

Example 12 with GpxDisplayGroup

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup in project Osmand by osmandapp.

the class DisplayGroupsBottomSheet method getGroupsNames.

private List<String> getGroupsNames() {
    List<String> names = new ArrayList<>();
    for (SelectableItem<GpxDisplayGroup> item : uiItems) {
        GpxDisplayGroup group = item.getObject();
        names.add(group.getName());
    }
    return names;
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) ArrayList(java.util.ArrayList)

Example 13 with GpxDisplayGroup

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup in project Osmand by osmandapp.

the class TrackMenuFragment method onCardButtonPressed.

@Override
public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
    GPXFile gpxFile = getGpx();
    if (card instanceof OptionsCard || card instanceof OverviewCard || card instanceof SegmentsCard) {
        if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) {
            if (FileUtils.isTempFile(app, getGpx().path)) {
                File srcFile = displayHelper.getFile();
                File destFIle = new File(app.getAppPath(IndexConstants.GPX_TRAVEL_DIR), srcFile.getName());
                onFileMove(srcFile, destFIle);
                gpxFile = getGpx();
            } else {
                boolean gpxFileSelected = !isGpxFileSelected(app, gpxFile);
                app.getSelectedGpxHelper().selectGpxFile(gpxFile, gpxFileSelected, false);
            }
            updateContent();
            mapActivity.refreshMap();
        } else if (buttonIndex == APPEARANCE_BUTTON_INDEX) {
            TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this);
        } else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) {
            GPXFile gpxFileToDisplay = displayHelper.getGpxFileToDisplay();
            if (gpxFileToDisplay != null) {
                if (gpxFileToDisplay.getNonEmptySegmentsCount() > 1) {
                    TrackSelectSegmentBottomSheet.showInstance(fragmentManager, gpxFileToDisplay, this);
                } else {
                    GpxNavigationHelper.startNavigationForGpx(gpxFileToDisplay, mapActivity);
                    dismiss();
                }
            }
        }
        if (buttonIndex == JOIN_GAPS_BUTTON_INDEX) {
            displayHelper.setJoinSegments(!displayHelper.isJoinSegments());
            mapActivity.refreshMap();
            if (segmentsCard != null) {
                segmentsCard.updateContent();
            }
        } else if (buttonIndex == ANALYZE_ON_MAP_BUTTON_INDEX) {
            new OpenGpxDetailsTask(selectedGpxFile, null, mapActivity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            dismiss();
        } else if (buttonIndex == ANALYZE_BY_INTERVALS_BUTTON_INDEX) {
            TrkSegment segment = gpxFile.getGeneralSegment();
            if (segment == null) {
                List<TrkSegment> segments = gpxFile.getNonEmptyTrkSegments(false);
                if (!Algorithms.isEmpty(segments)) {
                    segment = segments.get(0);
                }
            }
            GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] { GpxDisplayItemType.TRACK_SEGMENT };
            List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
            if (segment != null && !Algorithms.isEmpty(items)) {
                SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
            }
        } else if (buttonIndex == SHARE_BUTTON_INDEX) {
            OsmandApplication app = mapActivity.getMyApplication();
            if (gpxFile.showCurrentTrack) {
                GpxUiHelper.saveAndShareCurrentGpx(app, gpxFile);
            } else if (!Algorithms.isEmpty(gpxFile.path)) {
                GpxUiHelper.saveAndShareGpxWithAppearance(app, gpxFile);
            }
        } else if (buttonIndex == UPLOAD_OSM_BUTTON_INDEX) {
            OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
            if (osmEditingPlugin != null) {
                GpxInfo gpxInfo = new GpxInfo();
                gpxInfo.gpx = gpxFile;
                gpxInfo.file = new File(gpxFile.path);
                osmEditingPlugin.sendGPXFiles(mapActivity, this, gpxInfo);
            }
        } else if (buttonIndex == EDIT_BUTTON_INDEX) {
            app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
            dismiss();
            String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
            MeasurementToolFragment.showInstance(fragmentManager, fileName, false);
        } else if (buttonIndex == RENAME_BUTTON_INDEX) {
            FileUtils.renameFile(mapActivity, new File(gpxFile.path), this, true);
        } else if (buttonIndex == CHANGE_FOLDER_BUTTON_INDEX) {
            MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true, false);
        } else if (buttonIndex == GPS_FILTER_BUTTON_INDEX) {
            GpsFilterFragment.showInstance(fragmentManager, selectedGpxFile, this);
        } else if (buttonIndex == DELETE_BUTTON_INDEX) {
            String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
            AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(mapActivity, isNightMode()));
            builder.setTitle(getString(R.string.delete_confirmation_msg, fileName));
            builder.setMessage(R.string.are_you_sure);
            final String gpxFilePath = gpxFile.path;
            builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (FileUtils.removeGpxFile(app, new File(gpxFilePath))) {
                        dismiss();
                    }
                }
            });
            builder.show();
        }
    } else if (card instanceof TrackPointsCard) {
        if (buttonIndex == ADD_WAYPOINT_INDEX) {
            PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, app.getString(R.string.add_waypoint));
            QuadRect rect = displayHelper.getRect();
            NewGpxPoint newGpxPoint = new NewGpxPoint(gpxFile, pointDescription, rect);
            mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, (int) rect.width(), (int) rect.height(), 0);
            mapActivity.getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
            hide();
        } else if (buttonIndex == DELETE_WAYPOINTS_INDEX) {
            TrackPointsCard pointsCard = (TrackPointsCard) card;
            if (pointsCard.isSelectionMode()) {
                pointsCard.deleteItemsAction();
            } else {
                pointsCard.setSelectionMode(true);
            }
        } else if (buttonIndex == OPEN_WAYPOINT_INDEX) {
            dismiss();
        }
    } else if (card instanceof PointsGroupsCard) {
        PointsGroupsCard groupsCard = (PointsGroupsCard) card;
        GpxDisplayGroup group = groupsCard.getSelectedGroup();
        if (pointsCard != null) {
            pointsCard.setSelectedGroup(group);
            if (group != null) {
                fitSelectedPointsGroupOnMap(group);
            } else {
                fitTrackOnMap();
            }
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) OsmandApplication(net.osmand.plus.OsmandApplication) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) DialogInterface(android.content.DialogInterface) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) OpenGpxDetailsTask(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.OpenGpxDetailsTask) QuadRect(net.osmand.data.QuadRect) PointsGroupsCard(net.osmand.plus.track.cards.PointsGroupsCard) SegmentsCard(net.osmand.plus.track.cards.SegmentsCard) TrackPointsCard(net.osmand.plus.track.cards.TrackPointsCard) MapActivity(net.osmand.plus.activities.MapActivity) OptionsCard(net.osmand.plus.track.cards.OptionsCard) OverviewCard(net.osmand.plus.track.cards.OverviewCard) GpxInfo(net.osmand.plus.myplaces.ui.AvailableGPXFragment.GpxInfo) TrkSegment(net.osmand.GPXUtilities.TrkSegment) GpxDisplayItemType(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItemType) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) FragmentManager(androidx.fragment.app.FragmentManager) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 14 with GpxDisplayGroup

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup in project Osmand by osmandapp.

the class TrackPointsAdapter method getChildView.

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
    if (view == null) {
        view = inflater.inflate(R.layout.track_point_item, parent, false);
    }
    GpxDisplayGroup group = getGroup(groupPosition);
    WptPt point = getChild(groupPosition, childPosition);
    TextView title = view.findViewById(R.id.title);
    title.setText(point.name);
    CompoundButton compoundButton = view.findViewById(R.id.compound_button);
    compoundButton.setChecked(selectedPoints.contains(point));
    UiUtilities.setupCompoundButton(compoundButton, nightMode, CompoundButtonType.GLOBAL);
    view.setOnClickListener(v -> {
        boolean selected = !compoundButton.isChecked();
        if (listener != null) {
            listener.onItemSelected(point, selected);
        }
        notifyDataSetChanged();
    });
    int color = point.getColor(group.getColor());
    if (color == 0) {
        color = ContextCompat.getColor(app, R.color.gpx_color_point);
    }
    ImageView icon = view.findViewById(R.id.icon);
    icon.setImageDrawable(PointImageDrawable.getFromWpt(app, color, false, point));
    setupLocationData(viewCache, view, point);
    AndroidUiHelper.updateVisibility(view.findViewById(R.id.list_divider), childPosition != 0);
    AndroidUiHelper.updateVisibility(view.findViewById(R.id.card_bottom_divider), isLastChild);
    return view;
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) WptPt(net.osmand.GPXUtilities.WptPt) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 15 with GpxDisplayGroup

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup in project Osmand by osmandapp.

the class SelectPointsFragment method setupListView.

protected void setupListView(@NonNull View view) {
    GPXFile gpxFile = trackItem.selectedGpxFile.getGpxFile();
    GpxDisplayGroup group = app.getSelectedGpxHelper().buildPointsDisplayGroup(gpxFile, points, trackItem.name);
    adapter = new TrackPointsAdapter(app, selectedPoints, nightMode);
    adapter.setListener(this);
    adapter.synchronizeGroups(Collections.singletonList(group));
    listView = view.findViewById(R.id.list);
    listView.setAdapter(adapter);
    if (!Algorithms.isEmpty(trackItem.suggestedPoints) && listView.getHeaderViewsCount() == 0) {
        listView.addHeaderView(getHeaderView());
    }
    BaseSettingsListFragment.setupListView(listView);
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) GPXFile(net.osmand.GPXUtilities.GPXFile)

Aggregations

GpxDisplayGroup (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup)22 ArrayList (java.util.ArrayList)7 GpxDisplayItem (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem)7 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)5 CompoundButton (android.widget.CompoundButton)4 View (android.view.View)3 GPXFile (net.osmand.GPXUtilities.GPXFile)3 WptPt (net.osmand.GPXUtilities.WptPt)3 Paint (android.graphics.Paint)2 AbsListView (android.widget.AbsListView)2 File (java.io.File)2 List (java.util.List)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 DisplayGroupsHolder (net.osmand.plus.track.helpers.DisplayPointsGroupsHelper.DisplayGroupsHolder)2 DialogInterface (android.content.DialogInterface)1 Drawable (android.graphics.drawable.Drawable)1 SpannableString (android.text.SpannableString)1 OnClickListener (android.view.View.OnClickListener)1