use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class MapDataMenuController method updateData.
@Override
public void updateData() {
if (indexItem == null) {
otherIndexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(mapObject.getWorldRegion()));
Iterator<IndexItem> it = otherIndexItems.iterator();
while (it.hasNext()) {
IndexItem i = it.next();
if (i.getType() == DownloadActivityType.NORMAL_FILE) {
indexItem = i;
it.remove();
break;
}
}
}
if (indexItem != null) {
downloaded = indexItem.isDownloaded();
}
leftDownloadButtonController.visible = true;
leftDownloadButtonController.updateStateListDrawableIcon(R.drawable.ic_action_import, true);
if (backuped) {
leftDownloadButtonController.caption = getMapActivity().getString(R.string.local_index_mi_restore);
} else if (indexItem != null) {
if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
leftDownloadButtonController.caption = getMapActivity().getString(R.string.get_plugin);
leftDownloadButtonController.clearIcon(true);
} else if (indexItem.isOutdated()) {
leftDownloadButtonController.caption = getMapActivity().getString(R.string.shared_string_update);
} else if (!downloaded) {
leftDownloadButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
} else if (isLiveUpdatesOn()) {
leftDownloadButtonController.caption = getMapActivity().getString(R.string.live_update);
} else {
leftDownloadButtonController.visible = false;
}
} else {
leftDownloadButtonController.visible = false;
}
bottomTitleButtonController.visible = downloaded;
rightDownloadButtonController.visible = (otherIndexItems != null && otherIndexItems.size() > 0) || (otherLocalIndexInfos != null && otherLocalIndexInfos.size() > 0);
boolean internetConnectionAvailable = getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable();
boolean downloadIndexes = internetConnectionAvailable && !downloadThread.getIndexes().isDownloadedFromInternet && !downloadThread.getIndexes().downloadFromInternetFailed;
boolean isDownloading = indexItem != null && downloadThread.isDownloading(indexItem);
if (isDownloading) {
titleProgressController.setMapDownloadMode();
if (downloadThread.getCurrentDownloadingItem() == indexItem) {
titleProgressController.indeterminate = false;
titleProgressController.progress = downloadThread.getCurrentDownloadingItemProgress();
} else {
titleProgressController.indeterminate = true;
titleProgressController.progress = 0;
}
double mb = indexItem.getArchiveSizeMB();
String v;
if (titleProgressController.progress != -1) {
v = getMapActivity().getString(R.string.value_downloaded_of_max, mb * titleProgressController.progress / 100, mb);
} else {
v = getMapActivity().getString(R.string.file_size_in_mb, mb);
}
if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
titleProgressController.caption = indexItem.getType().getString(getMapActivity()) + " • " + v;
} else {
titleProgressController.caption = v;
}
titleProgressController.visible = true;
} else if (downloadIndexes) {
titleProgressController.setIndexesDownloadMode();
titleProgressController.visible = true;
} else if (!internetConnectionAvailable) {
titleProgressController.setNoInternetConnectionMode();
titleProgressController.visible = true;
} else {
titleProgressController.visible = false;
}
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class LocalIndexesFragment method openPopUpMenu.
private void openPopUpMenu(View v, final LocalIndexInfo info) {
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
final boolean restore = info.isBackupedData();
MenuItem item;
if ((info.getType() == LocalIndexType.MAP_DATA) || (info.getType() == LocalIndexType.DEACTIVATED)) {
item = optionsMenu.getMenu().add(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup).setIcon(iconsCache.getThemedIcon(R.drawable.ic_type_archive));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup, info);
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_rename).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.shared_string_rename, info);
return true;
}
});
if (info.getType() == LocalIndexType.TILES_DATA && (info.getAttachedObject() instanceof ITileSource) && ((ITileSource) info.getAttachedObject()).couldBeDownloadedFromInternet()) {
item = optionsMenu.getMenu().add(R.string.clear_tile_data).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.clear_tile_data, info);
return true;
}
});
}
final IndexItem update = filesToUpdate.get(info.getFileName());
if (update != null) {
item = optionsMenu.getMenu().add(R.string.update_tile).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_import));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getDownloadActivity().startDownload(update);
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.shared_string_delete, info);
return true;
}
});
optionsMenu.show();
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class UpdatesIndexFragment method updateUpdateAllButton.
private void updateUpdateAllButton() {
View view = getView();
if (view == null) {
return;
}
DownloadResources indexes = getMyActivity().getDownloadThread().getIndexes();
final List<IndexItem> indexItems = indexes.getItemsToUpdate();
final TextView updateAllButton = (TextView) view.findViewById(R.id.updateAllButton);
if (indexItems.size() == 0 || indexItems.get(0).getType() == null) {
if (!Algorithms.isEmpty(errorMessage)) {
updateAllButton.setText(errorMessage);
updateAllButton.setEnabled(false);
updateAllButton.setVisibility(View.VISIBLE);
} else {
updateAllButton.setVisibility(View.GONE);
}
} else {
updateAllButton.setVisibility(View.VISIBLE);
updateAllButton.setEnabled(true);
long downloadsSize = 0;
for (IndexItem indexItem : indexItems) {
downloadsSize += indexItem.getSize();
}
String updateAllText = getActivity().getString(R.string.update_all, downloadsSize >> 20);
updateAllButton.setText(updateAllText);
updateAllButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyActivity().startDownload(indexItems.toArray(new IndexItem[indexItems.size()]));
}
});
}
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class UpdatesIndexFragment method updateErrorMessage.
private void updateErrorMessage() {
final View view = getView();
if (view == null)
return;
DownloadResources indexes = getMyApplication().getDownloadThread().getIndexes();
List<IndexItem> indexItems = indexes.getItemsToUpdate();
if (getListAdapter() != null && indexItems.size() == 0) {
int messageId = indexes.isDownloadedFromInternet ? R.string.everything_up_to_date : R.string.no_index_file_to_download;
errorMessage = getString(messageId);
} else {
errorMessage = null;
}
updateUpdateAllButton();
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class FirstUsageWizardFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.first_usage_wizard_fragment, container, false);
AndroidUtils.addStatusBarPadding21v(getActivity(), view);
if (!AndroidUiHelper.isOrientationPortrait(getActivity()) && !AndroidUiHelper.isXLargeDevice(getActivity())) {
TextView wizardDescription = (TextView) view.findViewById(R.id.wizard_description);
wizardDescription.setMinimumHeight(0);
wizardDescription.setMinHeight(0);
}
AppCompatButton skipButton = (AppCompatButton) view.findViewById(R.id.skip_button);
skipButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (wizardType == WizardType.MAP_DOWNLOAD) {
if (location != null) {
showOnMap(new LatLon(location.getLatitude(), location.getLongitude()), 13);
} else {
closeWizard();
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getString(R.string.skip_map_downloading));
builder.setMessage(getString(R.string.skip_map_downloading_desc, getString(R.string.welmode_download_maps)));
builder.setNegativeButton(R.string.shared_string_skip, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (location != null) {
showOnMap(new LatLon(location.getLatitude(), location.getLongitude()), 13);
} else {
closeWizard();
}
}
});
builder.setNeutralButton(R.string.shared_string_cancel, null);
builder.setPositiveButton(R.string.shared_string_select, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
searchCountryMap();
}
});
builder.show();
}
}
});
view.findViewById(R.id.action_button).setVisibility(View.GONE);
switch(wizardType) {
case SEARCH_LOCATION:
view.findViewById(R.id.search_location_card).setVisibility(View.VISIBLE);
view.findViewById(R.id.search_location_action_button).setEnabled(false);
break;
case NO_INTERNET:
view.findViewById(R.id.no_inet_card).setVisibility(View.VISIBLE);
view.findViewById(R.id.no_inet_action_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startWizard(getActivity());
}
});
break;
case NO_LOCATION:
view.findViewById(R.id.no_location_card).setVisibility(View.VISIBLE);
view.findViewById(R.id.no_location_action_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
findLocation(getActivity(), false);
}
});
break;
case SEARCH_MAP:
view.findViewById(R.id.search_map_card).setVisibility(View.VISIBLE);
view.findViewById(R.id.search_map_action_button).setEnabled(false);
break;
case MAP_FOUND:
TextView mapTitle = (TextView) view.findViewById(R.id.map_download_title);
TextView mapDescription = (TextView) view.findViewById(R.id.map_download_desc);
final IndexItem indexItem = localMapIndexItem != null ? localMapIndexItem : baseMapIndexItem;
if (indexItem != null) {
mapTitle.setText(indexItem.getVisibleName(getContext(), getMyApplication().getRegions(), false));
mapDescription.setText(indexItem.getSizeDescription(getContext()));
}
view.findViewById(R.id.map_download_action_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean spaceEnoughForBoth = validationManager.isSpaceEnoughForDownload(getActivity(), false, localMapIndexItem, baseMapIndexItem);
boolean spaceEnoughForLocal = validationManager.isSpaceEnoughForDownload(getActivity(), true, localMapIndexItem);
if (!spaceEnoughForBoth) {
baseMapIndexItem = null;
}
if (spaceEnoughForLocal) {
showMapDownloadFragment(getActivity());
}
}
});
view.findViewById(R.id.map_download_card).setVisibility(View.VISIBLE);
final AppCompatButton searchCountryButton = (AppCompatButton) view.findViewById(R.id.search_country_button);
searchCountryButton.setVisibility(View.VISIBLE);
searchCountryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchCountryMap();
}
});
break;
case MAP_DOWNLOAD:
if (localMapIndexItem != null) {
indexItems.add(localMapIndexItem);
}
if (baseMapIndexItem != null) {
indexItems.add(baseMapIndexItem);
}
if (indexItems.size() > 0) {
final IndexItem item = indexItems.get(0);
String mapName = item.getVisibleName(getContext(), getMyApplication().getRegions(), false);
TextView mapNameTextView = (TextView) view.findViewById(R.id.map_downloading_title);
mapNameTextView.setText(mapName);
final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map_downloading_desc);
final View progressPadding = view.findViewById(R.id.map_download_padding);
final View progressLayout = view.findViewById(R.id.map_download_progress_layout);
mapDescriptionTextView.setText(item.getSizeDescription(getContext()));
final ImageButton redownloadButton = (ImageButton) view.findViewById(R.id.map_redownload_button);
redownloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!downloadThread.isDownloading(item) && !item.isDownloaded()) {
validationManager.startDownload(getActivity(), item);
firstMapDownloadCancelled = false;
}
}
});
view.findViewById(R.id.map_download_progress_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firstMapDownloadCancelled = true;
downloadThread.cancelDownload(item);
mapDescriptionTextView.setText(item.getSizeDescription(getContext()));
progressPadding.setVisibility(View.VISIBLE);
progressLayout.setVisibility(View.GONE);
redownloadButton.setVisibility(View.VISIBLE);
}
});
progressPadding.setVisibility(View.VISIBLE);
progressLayout.setVisibility(View.GONE);
redownloadButton.setVisibility(View.VISIBLE);
view.findViewById(R.id.map_downloading_layout).setVisibility(View.VISIBLE);
} else {
view.findViewById(R.id.map_downloading_layout).setVisibility(View.GONE);
view.findViewById(R.id.map_downloading_divider).setVisibility(View.GONE);
}
if (indexItems.size() > 1) {
final IndexItem item = indexItems.get(1);
String mapName = item.getVisibleName(getContext(), getMyApplication().getRegions(), false);
TextView mapNameTextView = (TextView) view.findViewById(R.id.map2_downloading_title);
mapNameTextView.setText(mapName);
final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map2_downloading_desc);
final View progressPadding = view.findViewById(R.id.map2_download_padding);
final View progressLayout = view.findViewById(R.id.map2_download_progress_layout);
mapDescriptionTextView.setText(item.getSizeDescription(getContext()));
final ImageButton redownloadButton = (ImageButton) view.findViewById(R.id.map2_redownload_button);
redownloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!downloadThread.isDownloading(item) && !item.isDownloaded()) {
validationManager.startDownload(getActivity(), item);
secondMapDownloadCancelled = false;
}
}
});
view.findViewById(R.id.map2_download_progress_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
secondMapDownloadCancelled = true;
downloadThread.cancelDownload(item);
mapDescriptionTextView.setText(item.getSizeDescription(getContext()));
progressPadding.setVisibility(View.VISIBLE);
progressLayout.setVisibility(View.GONE);
redownloadButton.setVisibility(View.VISIBLE);
}
});
progressPadding.setVisibility(View.VISIBLE);
progressLayout.setVisibility(View.GONE);
redownloadButton.setVisibility(View.VISIBLE);
view.findViewById(R.id.map2_downloading_layout).setVisibility(View.VISIBLE);
} else {
view.findViewById(R.id.map_downloading_divider).setVisibility(View.GONE);
view.findViewById(R.id.map2_downloading_layout).setVisibility(View.GONE);
}
view.findViewById(R.id.map_downloading_action_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (location != null) {
showOnMap(new LatLon(location.getLatitude(), location.getLongitude()), 13);
}
}
});
view.findViewById(R.id.map_downloading_card).setVisibility(View.VISIBLE);
break;
}
updateStorageView();
return view;
}
Aggregations