Search in sources :

Example 1 with GpxTrackAdapter

use of net.osmand.plus.track.GpxTrackAdapter in project Osmand by osmandapp.

the class SelectTrackFileDialogFragment method setupRecyclerView.

private void setupRecyclerView(@NonNull View root) {
    OsmandApplication app = getMyApplication();
    Context context = root.getContext();
    File gpxRootDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    List<GPXInfo> gpxInfoList = GpxUiHelper.getSortedGPXFilesInfo(gpxRootDir, null, false);
    boolean showCurrentGpx = OsmandPlugin.isActive(OsmandMonitoringPlugin.class);
    if (showCurrentGpx) {
        gpxInfoList.add(0, new GPXInfo(getString(R.string.current_track), 0, 0));
    }
    GpxTrackAdapter adapter = new GpxTrackAdapter(context, gpxInfoList, showCurrentGpx, true);
    adapter.setAdapterListener(position -> {
        Fragment target = getTargetFragment();
        CallbackWithObject<Object> listener = target instanceof CallbackWithObject<?> ? ((CallbackWithObject<Object>) target) : null;
        if (listener != null) {
            boolean currentTrack = position == 0 && showCurrentGpx;
            if (currentTrack) {
                listener.processResult("");
            } else {
                GPXInfo selectedGpxInfo = gpxInfoList.get(position);
                String fileName = selectedGpxInfo.getFileName();
                String gpxFilePath = gpxRootDir.getAbsolutePath() + "/" + fileName;
                listener.processResult(gpxFilePath);
            }
        }
        dismiss();
    });
    RecyclerView recyclerView = root.findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    recyclerView.setAdapter(adapter);
}
Also used : Context(android.content.Context) OsmandApplication(net.osmand.plus.OsmandApplication) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) BaseOsmAndDialogFragment(net.osmand.plus.base.BaseOsmAndDialogFragment) Fragment(androidx.fragment.app.Fragment) GpxTrackAdapter(net.osmand.plus.track.GpxTrackAdapter) CallbackWithObject(net.osmand.CallbackWithObject) CallbackWithObject(net.osmand.CallbackWithObject) RecyclerView(androidx.recyclerview.widget.RecyclerView) File(java.io.File)

Example 2 with GpxTrackAdapter

use of net.osmand.plus.track.GpxTrackAdapter in project Osmand by osmandapp.

the class StartPlanRouteBottomSheet method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    importHelper = new ImportHelper((AppCompatActivity) getActivity(), getMyApplication());
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_plan_route_start, null);
    items.add(new TitleItem(getString(R.string.plan_route)));
    BaseBottomSheetItem createNewRouteItem = new BottomSheetItemWithDescription.Builder().setIcon(getContentIcon(R.drawable.ic_notification_track)).setTitle(getString(R.string.plan_route_create_new_route)).setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentActivity activity = getActivity();
            if (activity != null) {
                MeasurementToolFragment.showInstance(activity.getSupportFragmentManager());
            }
            dismiss();
        }
    }).create();
    items.add(createNewRouteItem);
    BaseBottomSheetItem openExistingTrackItem = new BottomSheetItemWithDescription.Builder().setIcon(getContentIcon(R.drawable.ic_action_folder)).setTitle(getString(R.string.plan_route_open_existing_track)).setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = (MapActivity) getActivity();
            if (mapActivity != null) {
                hideBottomSheet();
                SelectFileBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), createSelectFileListener(), OPEN_TRACK);
            }
        }
    }).create();
    items.add(openExistingTrackItem);
    BaseBottomSheetItem importTrackItem = new BottomSheetItemWithDescription.Builder().setIcon(getContentIcon(R.drawable.ic_action_import_to)).setTitle(getString(R.string.plan_route_import_track)).setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            importTrack();
        }
    }).create();
    items.add(importTrackItem);
    items.add(new DividerItem(getContext()));
    final RecyclerView recyclerView = mainView.findViewById(R.id.gpx_track_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    OsmandApplication app = getMyApplication();
    if (app == null) {
        return;
    }
    File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    List<GPXInfo> gpxList = getSortedGPXFilesInfo(gpxDir, null, false);
    Collections.sort(gpxList, new Comparator<GPXInfo>() {

        @Override
        public int compare(GPXInfo lhs, GPXInfo rhs) {
            return lhs.getLastModified() > rhs.getLastModified() ? -1 : (lhs.getLastModified() == rhs.getLastModified() ? 0 : 1);
        }
    });
    final List<GPXInfo> gpxTopList = gpxList.subList(0, Math.min(5, gpxList.size()));
    adapter = new GpxTrackAdapter(requireContext(), gpxTopList, false, true);
    adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position) {
            StartPlanRouteBottomSheet.this.onItemClick(position, gpxTopList);
        }
    });
    recyclerView.setAdapter(adapter);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription) GpxTrackAdapter(net.osmand.plus.track.GpxTrackAdapter) FragmentActivity(androidx.fragment.app.FragmentActivity) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) RecyclerView(androidx.recyclerview.widget.RecyclerView) DividerItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem) File(java.io.File) ImportHelper(net.osmand.plus.importfiles.ImportHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Example 3 with GpxTrackAdapter

use of net.osmand.plus.track.GpxTrackAdapter in project Osmand by osmandapp.

the class TracksToFollowCard method setupTracksItems.

private void setupTracksItems() {
    final RecyclerView filesRecyclerView = view.findViewById(R.id.track_list);
    filesRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
    filesRecyclerView.setNestedScrollingEnabled(false);
    filesRecyclerView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            if (target instanceof FollowTrackFragment) {
                boolean scrollToBottomAvailable = filesRecyclerView.canScrollVertically(1);
                FollowTrackFragment followTrackFragment = (FollowTrackFragment) target;
                if (scrollToBottomAvailable) {
                    followTrackFragment.showShadowButton();
                } else {
                    followTrackFragment.hideShadowButton();
                }
            }
        }
    });
    tracksAdapter = new GpxTrackAdapter(view.getContext(), gpxInfoList, false, showFoldersName());
    tracksAdapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position) {
            if (position != RecyclerView.NO_POSITION) {
                GPXInfo gpxInfo = tracksAdapter.getGpxInfoList().get(position);
                int index = gpxInfoList.indexOf(gpxInfo);
                notifyButtonPressed(index);
            }
        }
    });
    tracksAdapter.setCategoriesChipView(createCategoriesChipsView());
    filesRecyclerView.setAdapter(tracksAdapter);
}
Also used : GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) FollowTrackFragment(net.osmand.plus.routepreparationmenu.FollowTrackFragment) ViewTreeObserver(android.view.ViewTreeObserver) GpxTrackAdapter(net.osmand.plus.track.GpxTrackAdapter)

Example 4 with GpxTrackAdapter

use of net.osmand.plus.track.GpxTrackAdapter in project Osmand by osmandapp.

the class SelectGpxTrackBottomSheet method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.gpx_track_select_dialog, null);
    final RecyclerView recyclerView = mainView.findViewById(R.id.gpx_track_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    adapter = new GpxTrackAdapter(requireContext(), gpxInfoList, showCurrentGpx, true);
    adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position) {
            if (position != RecyclerView.NO_POSITION) {
                SelectGpxTrackBottomSheet.this.onItemClick(position);
            }
        }
    });
    recyclerView.setAdapter(adapter);
    TextView gpxCounter = mainView.findViewById(R.id.counter);
    gpxCounter.setText(String.valueOf(adapter.getItemCount()));
    items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) GpxTrackAdapter(net.osmand.plus.track.GpxTrackAdapter)

Example 5 with GpxTrackAdapter

use of net.osmand.plus.track.GpxTrackAdapter in project Osmand by osmandapp.

the class SelectFileBottomSheet method createMenuItems.

@Override
public void createMenuItems(final Bundle savedInstanceState) {
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    Context context = requireContext();
    final OsmandApplication app = requiredMyApplication();
    mainView = View.inflate(new ContextThemeWrapper(context, themeRes), R.layout.bottom_sheet_plan_route_select_file, null);
    TextView titleView = mainView.findViewById(R.id.title);
    titleView.setText(fragmentMode.title);
    final TextView descriptionView = mainView.findViewById(R.id.description);
    descriptionView.setText(fragmentMode.description);
    final RecyclerView filesRecyclerView = mainView.findViewById(R.id.gpx_track_list);
    filesRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    if (fragmentMode == Mode.OPEN_TRACK) {
        titleView.setText(AndroidUtils.addColon(app, fragmentMode.title));
        updateDescription(descriptionView);
    }
    final ImageButton sortButton = mainView.findViewById(R.id.sort_button);
    int backgroundColorId = ColorUtilities.getInactiveButtonsAndLinksColorId(nightMode);
    Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark, backgroundColorId);
    AndroidUtils.setBackground(sortButton, background);
    sortButton.setImageResource(sortByMode.getIconId());
    sortButton.setVisibility(View.VISIBLE);
    sortButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final List<PopUpMenuItem> items = new ArrayList<>();
            for (final TracksSortByMode mode : TracksSortByMode.values()) {
                items.add(new PopUpMenuItem.Builder(app).setTitleId(mode.getNameId()).setIcon(app.getUIUtilities().getThemedIcon(mode.getIconId())).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        sortByMode = mode;
                        sortButton.setImageResource(mode.getIconId());
                        updateDescription(descriptionView);
                        sortFolderList();
                        folderSelector.setItems(getFolderChips());
                        folderSelector.notifyDataSetChanged();
                        sortFileList();
                        adapter.notifyDataSetChanged();
                    }
                }).setSelected(sortByMode == mode).create());
            }
            new PopUpMenuHelper.Builder(v, items, nightMode).show();
        }
    });
    final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    allFilesFolder = context.getString(R.string.shared_string_all);
    if (savedInstanceState == null) {
        selectedFolder = allFilesFolder;
    }
    final List<GPXInfo> allGpxList = getSortedGPXFilesInfo(gpxDir, null, false);
    currentlyRecording = new GPXInfo(getString(R.string.shared_string_currently_recording_track), 0, 0);
    if (isShowCurrentGpx()) {
        allGpxList.add(0, currentlyRecording);
    }
    gpxInfoMap = new HashMap<>();
    gpxInfoMap.put(allFilesFolder, allGpxList);
    for (GPXInfo gpxInfo : allGpxList) {
        String folderName = getFolderName(gpxInfo);
        List<GPXInfo> gpxList = gpxInfoMap.get(folderName);
        if (gpxList == null) {
            gpxList = new ArrayList<>();
            gpxInfoMap.put(folderName, gpxList);
        }
        gpxList.add(gpxInfo);
    }
    adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx(), showFoldersName());
    adapter.setAdapterListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position) {
            List<GPXInfo> gpxList = adapter.getGpxInfoList();
            if (position != RecyclerView.NO_POSITION && position < gpxList.size()) {
                String fileName;
                if (isShowCurrentGpx() && position == 0) {
                    fileName = null;
                } else {
                    fileName = gpxList.get(position).getFileName();
                }
                if (listener != null) {
                    listener.selectFileOnCLick(fileName);
                }
            }
            dismiss();
        }
    });
    filesRecyclerView.setAdapter(adapter);
    folderSelector = mainView.findViewById(R.id.folder_list);
    folders = new ArrayList<>();
    collectDirs(gpxDir, folders);
    sortFolderList();
    folderSelector.setItems(getFolderChips());
    ChipItem selected = folderSelector.getChipById(selectedFolder);
    folderSelector.setSelected(selected);
    folderSelector.setOnSelectChipListener(chip -> {
        selectedFolder = chip.id;
        folderSelector.smoothScrollTo(chip);
        updateFileList();
        return true;
    });
    items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
    updateFileList();
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) GpxTrackAdapter(net.osmand.plus.track.GpxTrackAdapter) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) Context(android.content.Context) OnItemClickListener(net.osmand.plus.track.GpxTrackAdapter.OnItemClickListener) TracksSortByMode(net.osmand.plus.settings.enums.TracksSortByMode) Drawable(android.graphics.drawable.Drawable) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) TextView(android.widget.TextView) ChipItem(net.osmand.plus.widgets.chips.ChipItem) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) RecyclerView(androidx.recyclerview.widget.RecyclerView) File(java.io.File)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 GpxTrackAdapter (net.osmand.plus.track.GpxTrackAdapter)5 GPXInfo (net.osmand.plus.helpers.GpxUiHelper.GPXInfo)4 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)3 File (java.io.File)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)3 Context (android.content.Context)2 View (android.view.View)2 TextView (android.widget.TextView)2 Drawable (android.graphics.drawable.Drawable)1 ViewTreeObserver (android.view.ViewTreeObserver)1 ImageButton (android.widget.ImageButton)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 Fragment (androidx.fragment.app.Fragment)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CallbackWithObject (net.osmand.CallbackWithObject)1