Search in sources :

Example 1 with DownloadItem

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;
}
Also used : DownloadItem(net.osmand.plus.download.DownloadItem)

Example 2 with DownloadItem

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;
}
Also used : SelectableItem(net.osmand.plus.base.SelectionBottomSheet.SelectableItem) ArrayList(java.util.ArrayList) DownloadItem(net.osmand.plus.download.DownloadItem) NonNull(androidx.annotation.NonNull)

Example 3 with DownloadItem

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);
    });
}
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 4 with DownloadItem

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;
}
Also used : DownloadResourceGroup(net.osmand.plus.download.DownloadResourceGroup) OnClickListener(android.view.View.OnClickListener) JSONObject(org.json.JSONObject) CustomIndexItem(net.osmand.plus.download.CustomIndexItem) DownloadItem(net.osmand.plus.download.DownloadItem) DownloadActivity(net.osmand.plus.download.DownloadActivity)

Example 5 with DownloadItem

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]);
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) IndexItem(net.osmand.plus.download.IndexItem) LayoutInflater(android.view.LayoutInflater) DownloadItem(net.osmand.plus.download.DownloadItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton)

Aggregations

DownloadItem (net.osmand.plus.download.DownloadItem)7 ArrayList (java.util.ArrayList)3 IndexItem (net.osmand.plus.download.IndexItem)3 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ProgressBar (android.widget.ProgressBar)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 SelectableItem (net.osmand.plus.base.SelectionBottomSheet.SelectableItem)2 CustomIndexItem (net.osmand.plus.download.CustomIndexItem)2 DownloadResourceGroup (net.osmand.plus.download.DownloadResourceGroup)2 Intent (android.content.Intent)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)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