Search in sources :

Example 1 with DialogStateListener

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

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

the class SelectIndexesHelper method showSrtmTypeSelectionDialog.

private void showSrtmTypeSelectionDialog() {
    SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
    final RadioItem meterBtn = createSrtmRadioBtn(true);
    final RadioItem feetBtn = createSrtmRadioBtn(false);
    List<RadioItem> radioItems = new ArrayList<>();
    radioItems.add(meterBtn);
    radioItems.add(feetBtn);
    SelectableItem<DownloadItem> preview = createSrtmSelectableItem(srtmItem);
    dialog = ModeSelectionBottomSheet.showInstance(activity, preview, radioItems, true);
    dialog.setDialogStateListener(new DialogStateListener() {

        @Override
        public void onDialogCreated() {
            dialog.setTitle(app.getString(R.string.srtm_unit_format));
            dialog.setPrimaryDescription(app.getString(R.string.srtm_download_single_help_message));
            updateSize();
            dialog.setSelectedMode(useMetricByDefault ? meterBtn : feetBtn);
        }

        @Override
        public void onCloseDialog() {
            resetUseMeters();
        }
    });
    dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
}
Also used : DialogStateListener(net.osmand.plus.base.SelectionBottomSheet.DialogStateListener) RadioItem(net.osmand.plus.widgets.multistatetoggle.RadioItem) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) ArrayList(java.util.ArrayList)

Example 3 with DialogStateListener

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

use of net.osmand.plus.base.SelectionBottomSheet.DialogStateListener 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)

Example 5 with DialogStateListener

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

the class SelectIndexesHelper method showMultipleSelectionDialog.

private void showMultipleSelectionDialog() {
    MultipleDownloadItem mdi = (MultipleDownloadItem) downloadItem;
    List<SelectableItem<DownloadItem>> allItems = new ArrayList<>();
    List<SelectableItem<DownloadItem>> selectedItems = new ArrayList<>();
    for (DownloadItem di : mdi.getAllItems()) {
        SelectableItem<DownloadItem> si = createSelectableItem(di);
        allItems.add(si);
        if (itemsToDownload.contains(di)) {
            selectedItems.add(si);
        }
    }
    MultipleSelectionBottomSheet<DownloadItem> msDialog = MultipleSelectionBottomSheet.showInstance(activity, allItems, selectedItems, true);
    this.dialog = msDialog;
    msDialog.setDialogStateListener(new DialogStateListener() {

        @Override
        public void onDialogCreated() {
            dialog.setTitle(app.getString(R.string.welmode_download_maps));
        }

        @Override
        public void onCloseDialog() {
        }
    });
    msDialog.setSelectionUpdateListener(this::updateSize);
    msDialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
}
Also used : DialogStateListener(net.osmand.plus.base.SelectionBottomSheet.DialogStateListener) SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)5 DialogStateListener (net.osmand.plus.base.SelectionBottomSheet.DialogStateListener)5 SelectableItem (net.osmand.plus.base.SelectionBottomSheet.SelectableItem)4 RadioItem (net.osmand.plus.widgets.multistatetoggle.RadioItem)2 TextRadioItem (net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem)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 NonNull (androidx.annotation.NonNull)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