Search in sources :

Example 1 with MultipleSelectionBottomSheet

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

Aggregations

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 DateFormat (java.text.DateFormat)1 ArrayList (java.util.ArrayList)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 DialogStateListener (net.osmand.plus.base.SelectionBottomSheet.DialogStateListener)1 SelectableItem (net.osmand.plus.base.SelectionBottomSheet.SelectableItem)1 DownloadIndexesThread (net.osmand.plus.download.DownloadIndexesThread)1 DownloadEvents (net.osmand.plus.download.DownloadIndexesThread.DownloadEvents)1 DownloadItem (net.osmand.plus.download.DownloadItem)1 DownloadValidationManager (net.osmand.plus.download.DownloadValidationManager)1 IndexItem (net.osmand.plus.download.IndexItem)1