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