Search in sources :

Example 16 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class TracksCard method updateContent.

@SuppressLint("DefaultLocale")
@Override
protected void updateContent() {
    LinearLayout tracks = view.findViewById(R.id.items);
    tracks.removeAllViews();
    int minCardHeight = getDimen(R.dimen.route_info_card_item_height);
    int listContentPadding = getDimen(R.dimen.list_content_padding);
    int listTextPadding = getDimen(R.dimen.route_info_list_text_padding);
    int mainFontColor = getMainFontColor();
    int descriptionColor = getSecondaryColor();
    int dividerColor = ColorUtilities.getDividerColor(mapActivity, nightMode);
    boolean showLimitExceeds = gpxItems.size() > 4;
    ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    LayoutInflater inflater = LayoutInflater.from(ctx);
    for (int i = 0; i < gpxItems.size(); i++) {
        GpxItem item = gpxItems.get(i);
        if (showLimitExceeds && i >= 3 && showLimited) {
            break;
        }
        View v = inflater.inflate(R.layout.gpx_track_item, tracks, false);
        GpxDataItem dataItem = getDataItem(item.info);
        GPXTrackAnalysis analysis = null;
        if (dataItem != null) {
            analysis = dataItem.getAnalysis();
        }
        GpxUiHelper.updateGpxInfoView(v, item.title, item.info, analysis, app);
        View div = v.findViewById(R.id.divider);
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(div.getLayoutParams().width, div.getLayoutParams().height);
        p.setMargins(listTextPadding, 0, 0, 0);
        div.setBackgroundColor(dividerColor);
        div.setLayoutParams(p);
        div.setVisibility(i == 0 ? View.GONE : View.VISIBLE);
        ((TextView) v.findViewById(R.id.name)).setTextColor(mainFontColor);
        ((TextView) v.findViewById(R.id.distance)).setTextColor(descriptionColor);
        ((TextView) v.findViewById(R.id.points_count)).setTextColor(descriptionColor);
        ((TextView) v.findViewById(R.id.time)).setTextColor(descriptionColor);
        ImageView img = v.findViewById(R.id.icon);
        img.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
        img.setVisibility(View.VISIBLE);
        LinearLayout container = v.findViewById(R.id.container);
        container.setMinimumHeight(minCardHeight);
        AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0);
        v.setOnClickListener(v1 -> mapActivity.getMapRouteInfoMenu().selectTrack(item.file));
        tracks.addView(v);
    }
    View showAllButton = view.findViewById(R.id.show_all_button);
    if (showLimited && showLimitExceeds) {
        ((TextView) view.findViewById(R.id.show_all_title)).setText(String.format("%s — %d", app.getString(R.string.shared_string_show_all).toUpperCase(), gpxItems.size()));
        showAllButton.setVisibility(View.VISIBLE);
        showAllButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showLimited = false;
                updateContent();
                setLayoutNeeded();
            }
        });
    } else {
        showAllButton.setVisibility(View.GONE);
    }
    ((TextView) view.findViewById(R.id.gpx_card_title)).setText(String.format("%s (%d)", app.getString(R.string.tracks_on_map), gpxItems.size()));
}
Also used : GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) LayoutInflater(android.view.LayoutInflater) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 17 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class AddTracksGroupBottomSheetDialogFragment method onItemClick.

@Override
protected void onItemClick(int position) {
    GpxDataItem dataItem = gpxList.get(position - 1);
    GPXTrackAnalysis analysis = dataItem.getAnalysis();
    if (analysis != null && analysis.wptCategoryNames != null && analysis.wptCategoryNames.size() > 1) {
        Bundle args = new Bundle();
        args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, dataItem.getFile().getAbsolutePath());
        SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
        fragment.setArguments(args);
        fragment.setUsedOnMap(false);
        fragment.show(getParentFragment().getChildFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
    } else {
        OsmandApplication app = getMyApplication();
        if (app != null) {
            GpxSelectionHelper selectionHelper = app.getSelectedGpxHelper();
            File gpx = dataItem.getFile();
            if (selectionHelper.getSelectedFileByPath(gpx.getAbsolutePath()) == null) {
                GPXFile res = GPXUtilities.loadGPXFile(gpx);
                selectionHelper.selectGpxFile(res, true, false, false, false, false);
            }
            app.getMapMarkersHelper().addOrEnableGpxGroup(gpx);
        }
    }
    dismiss();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Example 18 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class MapMarkersHelper method updateGpxShowAsMarkers.

private void updateGpxShowAsMarkers(File file) {
    GpxDataItem dataItem = ctx.getGpxDbHelper().getItem(file);
    if (dataItem != null) {
        ctx.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
        dataItem.setShowAsMarkers(true);
    }
}
Also used : GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)

Example 19 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class GpxTrackAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    if (holder.getItemViewType() == TRACK_INFO_VIEW_TYPE) {
        TrackViewHolder trackViewHolder = (TrackViewHolder) holder;
        int listPosition = mapToListPosition(position);
        boolean currentlyRecordingTrack = (showCurrentGpx && isFirstListItem(position));
        if (currentlyRecordingTrack) {
            trackViewHolder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_track_recordable));
        } else {
            trackViewHolder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_polygom_dark));
        }
        GPXInfo info = gpxInfoList.get(listPosition);
        GpxDataItem dataItem = getDataItem(info);
        String itemTitle = GpxUiHelper.getGpxTitle(info.getFileName());
        if (!showFolderName) {
            itemTitle = Algorithms.getFileWithoutDirs(itemTitle);
        }
        updateGpxInfoView(trackViewHolder, itemTitle, info, dataItem, currentlyRecordingTrack, app);
        trackViewHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listPosition);
                }
            }
        });
    } else {
        TrackCategoriesViewHolder categoriesViewHolder = (TrackCategoriesViewHolder) holder;
        categoriesViewHolder.trackCategories.notifyDataSetChanged();
    }
}
Also used : GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) TextView(android.widget.TextView)

Example 20 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class GpsFiltersCard method fetchGpxDataItem.

@Nullable
private GpxDataItem fetchGpxDataItem() {
    File file = new File(filteredSelectedGpxFile.getGpxFile().path);
    GpxDataItemCallback callback = new GpxDataItemCallback() {

        @Override
        public boolean isCancelled() {
            return false;
        }

        @Override
        public void onGpxDataItemReady(GpxDataItem item) {
            if (item != null) {
                gpxDataItem = item;
            }
        }
    };
    return gpxDbHelper.getItem(file, callback);
}
Also used : GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) FilteredSelectedGpxFile(net.osmand.plus.track.helpers.FilteredSelectedGpxFile) File(java.io.File) Nullable(androidx.annotation.Nullable)

Aggregations

GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)28 File (java.io.File)18 GPXFile (net.osmand.GPXUtilities.GPXFile)18 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)16 GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)8 GpxDataItemCallback (net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback)6 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 View (android.view.View)4 AGpxFile (net.osmand.aidl.gpx.AGpxFile)4 ASelectedGpxFile (net.osmand.aidl.gpx.ASelectedGpxFile)4 ASqliteDbFile (net.osmand.aidl.tiles.ASqliteDbFile)4 SuppressLint (android.annotation.SuppressLint)3 ArrayList (java.util.ArrayList)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 LinearLayout (android.widget.LinearLayout)2 Nullable (androidx.annotation.Nullable)2 List (java.util.List)2