Search in sources :

Example 1 with GPXInfo

use of net.osmand.plus.helpers.GpxUiHelper.GPXInfo in project Osmand by osmandapp.

the class DashTrackFragment method setupGpxFiles.

private void setupGpxFiles() {
    View mainView = getView();
    final File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
    final OsmandApplication app = getMyApplication();
    if (app == null) {
        return;
    }
    final List<String> list = new ArrayList<String>();
    for (SelectedGpxFile sg : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
        if (!sg.isShowCurrentTrack()) {
            GPXFile gpxFile = sg.getGpxFile();
            if (gpxFile != null) {
                list.add(gpxFile.path);
            }
        }
    }
    int totalCount = 3 + list.size() / 2;
    if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
        totalCount--;
    }
    if (list.size() < totalCount) {
        final List<GPXInfo> res = GpxUiHelper.getSortedGPXFilesInfoByDate(dir, true);
        for (GPXInfo r : res) {
            String name = r.getFileName();
            if (!list.contains(name)) {
                list.add(name);
                if (list.size() >= totalCount) {
                    break;
                }
            }
        }
    }
    if (list.size() == 0 && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
        DashboardOnMap.handleNumberOfRows(list, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    }
    LinearLayout tracks = (LinearLayout) mainView.findViewById(R.id.items);
    tracks.removeAllViews();
    LayoutInflater inflater = getActivity().getLayoutInflater();
    if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
        View view = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
        createCurrentTrackView(view, app);
        ((TextView) view.findViewById(R.id.name)).setText(R.string.shared_string_currently_recording_track);
        updateCurrentTrack(view, getActivity(), app);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AvailableGPXFragment.openTrack(getActivity(), null);
            }
        });
        view.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
        tracks.addView(view);
        startHandler(view);
    }
    for (String filename : list) {
        final File f = new File(filename);
        AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
        info.subfolder = "";
        info.file = f;
        View v = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
        AvailableGPXFragment.updateGpxInfoView(v, info, app, true);
        v.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AvailableGPXFragment.openTrack(getActivity(), f);
            }
        });
        ImageButton showOnMap = ((ImageButton) v.findViewById(R.id.show_on_map));
        showOnMap.setVisibility(View.VISIBLE);
        showOnMap.setContentDescription(getString(R.string.shared_string_show_on_map));
        updateShowOnMap(app, f, v, showOnMap);
        tracks.addView(v);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageButton(android.widget.ImageButton) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) LinearLayout(android.widget.LinearLayout) AvailableGPXFragment(net.osmand.plus.myplaces.AvailableGPXFragment)

Aggregations

LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)1 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 GPXInfo (net.osmand.plus.helpers.GpxUiHelper.GPXInfo)1 AvailableGPXFragment (net.osmand.plus.myplaces.AvailableGPXFragment)1