Search in sources :

Example 1 with SelectableItem

use of net.osmand.plus.base.SelectionBottomSheet.SelectableItem in project Osmand by osmandapp.

the class SuggestionsMapsDownloadWarningCard method getSelectableMaps.

@NonNull
private List<SelectableItem<DownloadItem>> getSelectableMaps() {
    List<SelectableItem<DownloadItem>> res = new ArrayList<>();
    List<DownloadItem> downloadItems;
    downloadItems = getSuggestedMapDownloadItems();
    for (DownloadItem di : downloadItems) {
        boolean isMap = di.getType().getTag().equals("map");
        SelectableItem<DownloadItem> si = createSelectableItem(di);
        if (isMap) {
            res.add(si);
        }
    }
    return res;
}
Also used : SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) ArrayList(java.util.ArrayList) DownloadItem(net.osmand.plus.download.DownloadItem) NonNull(androidx.annotation.NonNull)

Example 2 with SelectableItem

use of net.osmand.plus.base.SelectionBottomSheet.SelectableItem in project Osmand by osmandapp.

the class SuggestionsMapsDownloadWarningCard method showMultipleSelectionDialog.

private void showMultipleSelectionDialog() {
    DownloadIndexesThread downloadThread = app.getDownloadThread();
    boolean internetConnectionAvailable = mapActivity.getMyApplication().getSettings().isInternetConnectionAvailable();
    boolean downloadIndexes = false;
    if (!downloadThread.getIndexes().isDownloadedFromInternet) {
        if (internetConnectionAvailable) {
            downloadThread.runReloadIndexFiles();
            downloadIndexes = true;
        }
    }
    List<SelectableItem<DownloadItem>> allItems = new ArrayList<>();
    List<SelectableItem<DownloadItem>> selectedItems = new ArrayList<>();
    if (!downloadIndexes) {
        List<SelectableItem<DownloadItem>> mapItems = getSelectableMaps();
        allItems.addAll(mapItems);
        selectedItems.addAll(mapItems);
    }
    MultipleSelectionBottomSheet<DownloadItem> msDialog = MultipleSelectionBottomSheet.showInstance(mapActivity, allItems, selectedItems, true);
    this.dialog = msDialog;
    boolean downloadingIndexes = downloadIndexes;
    msDialog.setDialogStateListener(new DialogStateListener() {

        @Override
        public void onDialogCreated() {
            dialog.setTitle(app.getString(R.string.welmode_download_maps));
            if (!internetConnectionAvailable) {
                LayoutInflater inflater = UiUtilities.getInflater(dialog.getContext(), nightMode);
                View view = inflater.inflate(R.layout.bottom_sheet_no_internet_connection_view, null);
                View tryAgainButton = view.findViewById(R.id.try_again_button);
                UiUtilities.setupDialogButton(nightMode, tryAgainButton, UiUtilities.DialogButtonType.SECONDARY, R.string.try_again);
                tryAgainButton.setOnClickListener(v -> {
                    if (!downloadThread.getIndexes().isDownloadedFromInternet) {
                        if (mapActivity.getMyApplication().getSettings().isInternetConnectionAvailable()) {
                            downloadThread.runReloadIndexFiles();
                            setupDownoadingIndexesView();
                        }
                    }
                });
                AndroidUiHelper.updateVisibility(tryAgainButton, true);
                dialog.setCustomView(view);
            } else if (downloadingIndexes) {
                setupDownoadingIndexesView();
            }
        }

        private void setupDownoadingIndexesView() {
            LayoutInflater inflater = UiUtilities.getInflater(dialog.getContext(), nightMode);
            View view = inflater.inflate(R.layout.bottom_sheet_with_progress_bar, null);
            TextView title = view.findViewById(R.id.title);
            title.setVisibility(View.GONE);
            TextView description = view.findViewById(R.id.description);
            description.setText(R.string.downloading_list_indexes);
            view.findViewById(R.id.progress_bar).setVisibility(View.GONE);
            ProgressBar progressBar = view.findViewById(R.id.progress_bar_top);
            progressBar.setIndeterminate(true);
            progressBar.setVisibility(View.VISIBLE);
            dialog.setCustomView(view);
        }

        @Override
        public void onCloseDialog() {
        }
    });
    msDialog.setSelectionUpdateListener(this::updateSize);
    msDialog.setOnApplySelectionListener(selItems -> {
        mapActivity.getMapLayers().getMapControlsLayer().stopNavigationWithoutConfirm();
        mapActivity.getMapRouteInfoMenu().resetRouteCalculation();
        List<IndexItem> indexes = new ArrayList<>();
        for (SelectableItem<DownloadItem> item : selItems) {
            IndexItem index = getIndexItem(item.getObject());
            if (index != null) {
                indexes.add(index);
            }
        }
        IndexItem[] indexesArray = new IndexItem[indexes.size()];
        new DownloadValidationManager(app).startDownload(mapActivity, indexes.toArray(indexesArray));
        Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getDownloadActivity());
        newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        mapActivity.startActivity(newIntent);
    });
}
Also used : DialogStateListener(net.osmand.plus.base.SelectionBottomSheet.DialogStateListener) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) R(net.osmand.plus.R) Intent(android.content.Intent) IndexItem(net.osmand.plus.download.IndexItem) ArrayList(java.util.ArrayList) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread) UiUtilities(net.osmand.plus.utils.UiUtilities) View(android.view.View) MapRouteInfoMenu(net.osmand.plus.routepreparationmenu.MapRouteInfoMenu) Algorithms(net.osmand.util.Algorithms) DialogStateListener(net.osmand.plus.base.SelectionBottomSheet.DialogStateListener) DownloadValidationManager(net.osmand.plus.download.DownloadValidationManager) DateFormat(java.text.DateFormat) MultipleDownloadItem.getIndexItem(net.osmand.plus.download.MultipleDownloadItem.getIndexItem) LayoutInflater(android.view.LayoutInflater) AndroidUiHelper(net.osmand.plus.helpers.AndroidUiHelper) DownloadEvents(net.osmand.plus.download.DownloadIndexesThread.DownloadEvents) DownloadItem(net.osmand.plus.download.DownloadItem) List(java.util.List) TextView(android.widget.TextView) MultipleSelectionBottomSheet(net.osmand.plus.base.MultipleSelectionBottomSheet) WorldRegion(net.osmand.map.WorldRegion) SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) MapActivity(net.osmand.plus.activities.MapActivity) SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) IndexItem(net.osmand.plus.download.IndexItem) MultipleDownloadItem.getIndexItem(net.osmand.plus.download.MultipleDownloadItem.getIndexItem) LayoutInflater(android.view.LayoutInflater) DownloadItem(net.osmand.plus.download.DownloadItem) TextView(android.widget.TextView) DownloadValidationManager(net.osmand.plus.download.DownloadValidationManager) ProgressBar(android.widget.ProgressBar) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread)

Example 3 with SelectableItem

use of net.osmand.plus.base.SelectionBottomSheet.SelectableItem 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 4 with SelectableItem

use of net.osmand.plus.base.SelectionBottomSheet.SelectableItem in project Osmand by osmandapp.

the class AvailableGPXFragment method showUploadConfirmationDialog.

private void showUploadConfirmationDialog(@NonNull FragmentActivity activity, @NonNull String actionButton, @Nullable SelectionModeListener listener) {
    long[] size = new long[1];
    List<SelectableItem<GpxInfo>> items = new ArrayList<>();
    for (GpxInfo gpxInfo : selectedItems) {
        SelectableItem<GpxInfo> item = new SelectableItem<>();
        item.setObject(gpxInfo);
        item.setTitle(gpxInfo.getName());
        item.setIconId(R.drawable.ic_notification_track);
        items.add(item);
        size[0] += gpxInfo.getSize();
    }
    List<SelectableItem<GpxInfo>> selectedItems = new ArrayList<>(items);
    FragmentManager manager = activity.getSupportFragmentManager();
    UploadMultipleGPXBottomSheet dialog = UploadMultipleGPXBottomSheet.showInstance(manager, items, selectedItems);
    if (dialog != null) {
        dialog.setDialogStateListener(new DialogStateListener() {

            @Override
            public void onDialogCreated() {
                dialog.setTitle(actionButton);
                dialog.setApplyButtonTitle(getString(R.string.shared_string_continue));
                String total = getString(R.string.shared_string_total);
                dialog.setTitleDescription(getString(R.string.ltr_or_rtl_combine_via_colon, total, AndroidUtils.formatSize(app, size[0])));
            }

            @Override
            public void onCloseDialog() {
            }
        });
        dialog.setOnApplySelectionListener(selItems -> {
            List<GpxInfo> gpxInfos = new ArrayList<>();
            for (SelectableItem<GpxInfo> item : selItems) {
                gpxInfos.add(item.getObject());
            }
            if (listener != null) {
                listener.onItemsSelected(gpxInfos);
            }
        });
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) DialogStateListener(net.osmand.plus.base.SelectionBottomSheet.DialogStateListener) SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) ArrayList(java.util.ArrayList) UploadMultipleGPXBottomSheet(net.osmand.plus.plugins.osmedit.dialogs.UploadMultipleGPXBottomSheet)

Example 5 with SelectableItem

use of net.osmand.plus.base.SelectionBottomSheet.SelectableItem in project Osmand by osmandapp.

the class SelectIndexesHelper method showSrtmMultipleSelectionDialog.

private void showSrtmMultipleSelectionDialog() {
    MultipleDownloadItem mdi = (MultipleDownloadItem) downloadItem;
    List<SelectableItem<DownloadItem>> allItems = new ArrayList<>();
    List<SelectableItem<DownloadItem>> selectedItems = new ArrayList<>();
    for (DownloadItem di : mdi.getAllItems()) {
        SelectableItem<DownloadItem> si = createSrtmSelectableItem((SrtmDownloadItem) di);
        allItems.add(si);
        if (itemsToDownload.contains(di)) {
            selectedItems.add(si);
        }
    }
    final RadioItem meterBtn = createSrtmRadioBtn(true);
    final RadioItem feetBtn = createSrtmRadioBtn(false);
    List<RadioItem> radioItems = new ArrayList<>();
    radioItems.add(meterBtn);
    radioItems.add(feetBtn);
    MultipleSelectionBottomSheet<DownloadItem> msDialog = MultipleSelectionWithModeBottomSheet.showInstance(activity, allItems, selectedItems, radioItems, true);
    this.dialog = msDialog;
    msDialog.setDialogStateListener(new DialogStateListener() {

        @Override
        public void onDialogCreated() {
            dialog.setTitle(app.getString(R.string.welmode_download_maps));
            dialog.setSelectedMode(useMetricByDefault ? meterBtn : feetBtn);
            dialog.setSecondaryDescription(app.getString(R.string.srtm_download_list_help_message));
        }

        @Override
        public void onCloseDialog() {
            resetUseMeters();
        }
    });
    msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {

        @Override
        public void onSelectionUpdate() {
            updateSize();
        }
    });
    msDialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
}
Also used : DialogStateListener(net.osmand.plus.base.SelectionBottomSheet.DialogStateListener) SelectionUpdateListener(net.osmand.plus.base.MultipleSelectionBottomSheet.SelectionUpdateListener) RadioItem(net.osmand.plus.widgets.multistatetoggle.RadioItem) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) ArrayList(java.util.ArrayList)

Aggregations

SelectableItem (net.osmand.plus.base.SelectionBottomSheet.SelectableItem)6 ArrayList (java.util.ArrayList)5 DialogStateListener (net.osmand.plus.base.SelectionBottomSheet.DialogStateListener)4 NonNull (androidx.annotation.NonNull)2 DownloadItem (net.osmand.plus.download.DownloadItem)2 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 FragmentManager (androidx.fragment.app.FragmentManager)1 DateFormat (java.text.DateFormat)1 List (java.util.List)1 WorldRegion (net.osmand.map.WorldRegion)1 R (net.osmand.plus.R)1 MapActivity (net.osmand.plus.activities.MapActivity)1 MultipleSelectionBottomSheet (net.osmand.plus.base.MultipleSelectionBottomSheet)1 SelectionUpdateListener (net.osmand.plus.base.MultipleSelectionBottomSheet.SelectionUpdateListener)1 DownloadIndexesThread (net.osmand.plus.download.DownloadIndexesThread)1 DownloadEvents (net.osmand.plus.download.DownloadIndexesThread.DownloadEvents)1