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);
});
}
Aggregations