Search in sources :

Example 1 with TracksSortByMode

use of net.osmand.plus.settings.enums.TracksSortByMode in project Osmand by osmandapp.

the class AvailableGPXFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    int itemId = item.getItemId();
    for (int i = 0; i < optionsMenuAdapter.length(); i++) {
        ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i);
        if (itemId == contextMenuItem.getTitleId()) {
            contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false, null);
            return true;
        }
    }
    if (itemId == R.id.action_sort) {
        Activity activity = getActivity();
        if (activity != null) {
            View menuSortItemView = getActivity().findViewById(R.id.action_sort);
            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) {
                        updateTracksSort(mode);
                        int iconColorId = ColorUtilities.getActiveButtonsAndLinksTextColorId(!isLightActionBar());
                        item.setIcon(getIcon(mode.getIconId(), iconColorId));
                    }
                }).setSelected(sortByMode == mode).create());
            }
            new PopUpMenuHelper.Builder(menuSortItemView, items, nightMode).show();
        }
    }
    return super.onOptionsItemSelected(item);
}
Also used : PopUpMenuHelper(net.osmand.plus.widgets.popup.PopUpMenuHelper) ContextMenuItem(net.osmand.plus.ContextMenuItem) TracksSortByMode(net.osmand.plus.settings.enums.TracksSortByMode) ArrayList(java.util.ArrayList) MapActivity(net.osmand.plus.activities.MapActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) ImageView(android.widget.ImageView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView)

Example 2 with TracksSortByMode

use of net.osmand.plus.settings.enums.TracksSortByMode in project Osmand by osmandapp.

the class FollowTrackFragment method setupSortButton.

private void setupSortButton(View view) {
    final ImageButton sortButton = view.findViewById(R.id.sort_button);
    int colorId = ColorUtilities.getInactiveButtonsAndLinksColorId(isNightMode());
    Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark, colorId);
    sortButton.setImageResource(sortByMode.getIconId());
    AndroidUtils.setBackground(sortButton, background);
    sortButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            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());
                        if (tracksCard != null) {
                            tracksCard.setSortByMode(mode);
                        }
                    }
                }).setSelected(sortByMode == mode).create());
            }
            new PopUpMenuHelper.Builder(v, items, isNightMode()).show();
        }
    });
}
Also used : ImageButton(android.widget.ImageButton) TracksSortByMode(net.osmand.plus.settings.enums.TracksSortByMode) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) Drawable(android.graphics.drawable.Drawable) List(java.util.List) ArrayList(java.util.ArrayList) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) View(android.view.View)

Example 3 with TracksSortByMode

use of net.osmand.plus.settings.enums.TracksSortByMode 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

View (android.view.View)3 ArrayList (java.util.ArrayList)3 TracksSortByMode (net.osmand.plus.settings.enums.TracksSortByMode)3 PopUpMenuItem (net.osmand.plus.widgets.popup.PopUpMenuItem)3 Drawable (android.graphics.drawable.Drawable)2 ImageButton (android.widget.ImageButton)2 TextView (android.widget.TextView)2 List (java.util.List)2 Activity (android.app.Activity)1 Context (android.content.Context)1 AbsListView (android.widget.AbsListView)1 ExpandableListView (android.widget.ExpandableListView)1 ImageView (android.widget.ImageView)1 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)1 SearchView (androidx.appcompat.widget.SearchView)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 File (java.io.File)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1