use of net.osmand.plus.download.DownloadItem in project Osmand by osmandapp.
the class SuggestionsMapsDownloadWarningCard method getDownloadSizeInMb.
private double getDownloadSizeInMb(@NonNull List<SelectableItem<DownloadItem>> selectableItems) {
double totalSizeMb = 0.0d;
for (SelectableItem<DownloadItem> i : selectableItems) {
DownloadItem downloadItem = i.getObject();
totalSizeMb += downloadItem.getSizeToDownloadInMb();
}
return totalSizeMb;
}
use of net.osmand.plus.download.DownloadItem 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.download.DownloadItem 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.download.DownloadItem in project Osmand by osmandapp.
the class DownloadResourceGroupFragment method onChildClick.
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Object child = listAdapter.getChild(groupPosition, childPosition);
if (child instanceof DownloadResourceGroup) {
String uniqueId = ((DownloadResourceGroup) child).getUniqueId();
final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment.createInstance(uniqueId);
((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
return true;
} else if (child instanceof CustomIndexItem) {
String regionId = group.getGroupByIndex(groupPosition).getUniqueId();
DownloadItemFragment downloadItemFragment = DownloadItemFragment.createInstance(regionId, childPosition);
((DownloadActivity) getActivity()).showDialog(getActivity(), downloadItemFragment);
} else if (child instanceof DownloadItem) {
DownloadItem downloadItem = (DownloadItem) child;
ItemViewHolder vh = (ItemViewHolder) v.getTag();
OnClickListener ls = vh.getRightButtonAction(downloadItem, vh.getClickAction(downloadItem));
ls.onClick(v);
return true;
}
return false;
}
use of net.osmand.plus.download.DownloadItem in project Osmand by osmandapp.
the class VoiceLanguageBottomSheetFragment method createSuggestedVoiceItemsView.
private void createSuggestedVoiceItemsView(List<DownloadItem> suggestedVoicePrompts) {
OsmandPreference<String> voiceProvider = settings.VOICE_PROVIDER;
int defaultLanguagePosition = items.size();
boolean isTTS = selectedVoiceType == InfoType.TTS;
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
for (final DownloadItem downloadItem : suggestedVoicePrompts) {
final IndexItem indexItem = (IndexItem) downloadItem;
View container = createVoiceItemView(indexItem, inflater);
boolean isDefault = isDefaultTTS(indexItem);
String title = isDefault ? getString(R.string.use_system_language) : indexItem.getVisibleName(app, app.getRegions(), false);
String description = getVoiceIndexDescription(indexItem);
final TextView textDescription = container.findViewById(R.id.description);
final ProgressBar progressBar = container.findViewById(R.id.ProgressBar);
final ImageView secondaryIcon = container.findViewById(R.id.secondary_icon);
boolean selected = indexItem.getBasename().equals(voiceProvider.getModeValue(getAppMode()));
final BottomSheetItemWithCompoundButton[] voiceDownloadedItem = new BottomSheetItemWithCompoundButton[1];
voiceDownloadedItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setCompoundButtonColorId(getActiveColorId()).setChecked(selected).setDescription(description).setIconHidden(true).setTitle(title).setPosition(isDefault ? defaultLanguagePosition : -1).setOnClickListener(v -> {
if (indexItem.isDownloaded()) {
updateVoiceProvider(indexItem, true);
} else if (isTTS) {
if (!downloadThread.isDownloading(indexItem)) {
downloadIndexItem(indexItem);
}
} else {
if (downloadThread.isDownloading(indexItem)) {
cancelIndexDownload(indexItem, progressBar, textDescription, secondaryIcon);
} else {
startIndexDownload(indexItem, progressBar, textDescription, secondaryIcon);
}
}
}).setCustomView(container).create();
items.add(voiceDownloadedItem[0]);
}
}
Aggregations