diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index ef567fa1b1..ae12a2e3f8 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -32,6 +32,7 @@ public class WorldRegion { private String regionId; private String downloadsId; private String name; + private String searchText; // Hierarchy private WorldRegion superregion; @@ -95,10 +96,11 @@ public class WorldRegion { private WorldRegion init(String regionId, OsmandRegions osmandRegions, String name) { this.regionId = regionId; String downloadName = osmandRegions.getDownloadName(regionId); + this.searchText = osmandRegions.getDownloadNameIndexLowercase(downloadName); if (downloadName != null) { downloadsId = downloadName.toLowerCase(); } else { - this.downloadsId = regionId.toLowerCase(); + downloadsId = regionId.toLowerCase(); } if (name != null) { this.name = name; @@ -110,6 +112,10 @@ public class WorldRegion { } return this; } + + public String getSearchText() { + return searchText; + } private void addSubregion(WorldRegion subregion, WorldRegion world) { subregion.superregion = this; diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ActiveDownloadsDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/ActiveDownloadsDialogFragment.java index 91b665743a..07631a7170 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ActiveDownloadsDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ActiveDownloadsDialogFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.download.ui; import java.util.ArrayList; +import java.util.List; import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivity; @@ -8,7 +9,6 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.IndexItem; import android.app.AlertDialog; import android.app.Dialog; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; @@ -26,7 +26,7 @@ public class ActiveDownloadsDialogFragment extends DialogFragment implements Dow public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_dismiss, null); - adapter = new IndexItemAdapter(getDownloadActivity()); + adapter = new IndexItemAdapter(this, getDownloadActivity()); builder.setAdapter(adapter, null); return builder.create(); } @@ -50,20 +50,22 @@ public class ActiveDownloadsDialogFragment extends DialogFragment implements Dow } public static class IndexItemAdapter extends ArrayAdapter { - private final Drawable deleteDrawable; private final DownloadActivity context; + private DialogFragment dlgFragment; - public IndexItemAdapter(DownloadActivity context) { + public IndexItemAdapter(DialogFragment dlgFragment, DownloadActivity context) { super(context, R.layout.two_line_with_images_list_item, new ArrayList()); + this.dlgFragment = dlgFragment; this.context = context; - deleteDrawable = context.getMyApplication().getIconsCache() - .getPaintedContentIcon(R.drawable.ic_action_remove_dark, - context.getResources().getColor(R.color.dash_search_icon_dark)); refreshAllData(); } public void refreshAllData() { clear(); + List items = context.getDownloadThread().getCurrentDownloadingItems(); + if(items.isEmpty()) { + dlgFragment.dismissAllowingStateLoss(); + } addAll(context.getDownloadThread().getCurrentDownloadingItems()); } @@ -72,70 +74,20 @@ public class ActiveDownloadsDialogFragment extends DialogFragment implements Dow if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.two_line_with_images_list_item, parent, false); - DownloadEntryViewHolder viewHolder = - new DownloadEntryViewHolder(convertView, context, deleteDrawable, this); + ItemViewHolder viewHolder = + new ItemViewHolder(convertView, context); + viewHolder.setSilentCancelDownload(true); + viewHolder.setShowProgressInDescr(true); convertView.setTag(viewHolder); } - DownloadEntryViewHolder viewHolder = (DownloadEntryViewHolder) convertView.getTag(); + ItemViewHolder viewHolder = (ItemViewHolder) convertView.getTag(); IndexItem item = getItem(position); - IndexItem cdi = context.getDownloadThread().getCurrentDownloadingItem(); - viewHolder.bindDownloadEntry(getItem(position), - cdi == item ? context.getDownloadThread().getCurrentDownloadingItemProgress() : -1, - context.getDownloadThread().isDownloading(item)); + viewHolder.bindIndexItem(item); return convertView; } } - // FIXME review view holder - private static class DownloadEntryViewHolder extends ItemViewHolder { - private final Drawable deleteDrawable; - private final IndexItemAdapter adapter; - - private DownloadEntryViewHolder(View convertView, final DownloadActivity context, - Drawable deleteDrawable, IndexItemAdapter adapter) { - super(convertView, context); - this.deleteDrawable = deleteDrawable; - this.adapter = adapter; - progressBar.setVisibility(View.VISIBLE); - rightImageButton.setImageDrawable(deleteDrawable); - } - - public void bindDownloadEntry(final IndexItem item, final int progress, - boolean isDownloaded) { - nameTextView.setText(item.getVisibleName(context, - context.getMyApplication().getRegions())); - rightImageButton.setVisibility(View.VISIBLE); - - int localProgress = progress; - boolean isIndeterminate = true; - if (progress != -1) { - isIndeterminate = false; - double downloaded = item.getContentSizeMB() * progress / 100; - descrTextView.setText(context.getString(R.string.value_downloaded_from_max, downloaded, - item.getContentSizeMB())); - } else if (isDownloaded) { - isIndeterminate = false; - localProgress = progressBar.getMax(); - descrTextView.setText(context.getString(R.string.file_size_in_mb, - item.getContentSizeMB())); - rightImageButton.setVisibility(View.GONE); - } else { - descrTextView.setText(context.getString(R.string.file_size_in_mb, - item.getContentSizeMB())); - } - rightImageButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - context.getDownloadThread().cancelDownload(item); - adapter.refreshAllData(); - } - }); - progressBar.setIndeterminate(isIndeterminate); - progressBar.setProgress(localProgress); - - } - - } + } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index 040558e2db..4f5e9126d0 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -36,6 +36,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.View.OnClickListener; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.TextView; @@ -170,16 +171,27 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow return true; } else if (child instanceof IndexItem) { IndexItem indexItem = (IndexItem) child; - if (indexItem.getType() == DownloadActivityType.ROADS_FILE) { - // FIXME - // if (regularMap.getType() == DownloadActivityType.NORMAL_FILE - // && regularMap.isAlreadyDownloaded(getMyActivity().getIndexFileNames())) { - // ConfirmDownloadUnneededMapDialogFragment.createInstance(indexItem) - // .show(getChildFragmentManager(), "dialog"); - // return true; - // } + DownloadResourceGroup groupObj = listAdapter.getGroupObj(groupPosition); + boolean handled = false; + if (indexItem.getType() == DownloadActivityType.ROADS_FILE && groupObj != null + && !activity.getDownloadThread().isDownloading(indexItem)) { + for (IndexItem ii : groupObj.getIndividualResources()) { + if (ii.getType() == DownloadActivityType.NORMAL_FILE) { + if (ii.isDownloaded()) { + handled = true; + ConfirmDownloadUnneededMapDialogFragment.createInstance(indexItem).show( + getChildFragmentManager(), "dialog"); + } + break; + } + } } ((DownloadActivity) getActivity()).startDownload(indexItem); + if (!handled) { + ItemViewHolder vh = (ItemViewHolder) v.getTag(); + OnClickListener ls = vh.getRightButtonAction(indexItem, vh.getClickAction(indexItem)); + ls.onClick(v); + } return true; } return false; @@ -220,8 +232,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow getDownloadActivity().getDownloadThread().runReloadIndexFiles(); return true; case SEARCH_ID: - // FIXME - //getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance("")); + getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance("")); return true; default: return super.onOptionsItemSelected(item); @@ -237,7 +248,6 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow } public static class ConfirmDownloadUnneededMapDialogFragment extends DialogFragment { - private static final String INDEX_ITEM = "index_item"; private static IndexItem item = null; @NonNull @@ -421,6 +431,10 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow public int getChildrenCount(int groupPosition) { return data.get(groupPosition).size(); } + + public DownloadResourceGroup getGroupObj(int groupPosition) { + return data.get(groupPosition); + } @Override public String getGroup(int groupPosition) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 29ad64ec75..06393476a6 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -16,6 +16,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.util.TypedValue; import android.view.View; +import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.ProgressBar; @@ -24,7 +25,6 @@ import android.widget.Toast; public class ItemViewHolder { - private final java.text.DateFormat dateFormat; protected final TextView nameTextView; protected final TextView descrTextView; @@ -42,10 +42,11 @@ public class ItemViewHolder { private int textColorPrimary; private int textColorSecondary; - private RightButtonAction clickAction; boolean showTypeInDesc; boolean showRemoteDate; + boolean silentCancelDownload; + boolean showProgressInDesc; @@ -67,7 +68,6 @@ public class ItemViewHolder { rightImageButton = (ImageView) view.findViewById(R.id.rightImageButton); nameTextView = (TextView) view.findViewById(R.id.name); - this.dateFormat = context.getMyApplication().getResourceManager().getDateFormat(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); @@ -81,6 +81,14 @@ public class ItemViewHolder { this.showRemoteDate = showRemoteDate; } + public void setShowProgressInDescr(boolean b) { + showProgressInDesc = b; + } + + public void setSilentCancelDownload(boolean silentCancelDownload) { + this.silentCancelDownload = silentCancelDownload; + } + public void setShowTypeInDesc(boolean showTypeInDesc) { this.showTypeInDesc = showTypeInDesc; } @@ -111,7 +119,7 @@ public class ItemViewHolder { nameTextView.setTextColor(textColorSecondary); } int color = textColorSecondary; - if(indexItem.isDownloaded()) { + if(indexItem.isDownloaded() && !isDownloading) { int colorId = indexItem.isOutdated() ? R.color.color_distance : R.color.color_ok; color = context.getResources().getColor(colorId); } @@ -125,11 +133,9 @@ public class ItemViewHolder { leftImageView.setImageDrawable(getContentIcon(context, indexItem.getType().getIconResource())); } - + descrTextView.setTextColor(color); if (!isDownloading) { progressBar.setVisibility(View.GONE); - - descrTextView.setTextColor(color); descrTextView.setVisibility(View.VISIBLE); if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) { @@ -151,15 +157,31 @@ public class ItemViewHolder { }); } else { progressBar.setVisibility(View.VISIBLE); + progressBar.setIndeterminate(progress == -1); progressBar.setProgress(progress); - descrTextView.setVisibility(View.GONE); + if (showProgressInDesc) { + double mb = indexItem.getContentSizeMB(); + if (progress != -1) { + descrTextView.setText(context.getString(R.string.value_downloaded_from_max, mb * progress / 100, + mb)); + } else { + descrTextView.setText(context.getString(R.string.file_size_in_mb, mb)); + } + descrTextView.setVisibility(View.VISIBLE); + } else { + descrTextView.setVisibility(View.GONE); + } rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark)); rightImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - context.makeSureUserCancelDownload(indexItem); + if(silentCancelDownload) { + context.getDownloadThread().cancelDownload(indexItem); + } else { + context.makeSureUserCancelDownload(indexItem); + } } }); } @@ -167,12 +189,26 @@ public class ItemViewHolder { private boolean checkDisabledAndClickAction(final IndexItem indexItem) { - boolean disabled = false; - clickAction = RightButtonAction.DOWNLOAD; + RightButtonAction clickAction = getClickAction(indexItem); + boolean disabled = clickAction != RightButtonAction.DOWNLOAD; + if (clickAction != RightButtonAction.DOWNLOAD) { + rightButton.setText(R.string.get_plugin); + rightButton.setVisibility(View.VISIBLE); + rightImageButton.setVisibility(View.GONE); + rightButton.setOnClickListener(getRightButtonAction(indexItem, clickAction)); + } else { + rightButton.setVisibility(View.GONE); + rightImageButton.setVisibility(View.VISIBLE); + } + + return disabled; + } + + public RightButtonAction getClickAction(final IndexItem indexItem) { + RightButtonAction clickAction = RightButtonAction.DOWNLOAD; if (indexItem.getBasename().toLowerCase().equals(DownloadResources.WORLD_SEAMARKS_KEY) && nauticalPluginDisabled) { clickAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN; - disabled = true; } else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) { if (srtmNeedsInstallation) { @@ -181,55 +217,61 @@ public class ItemViewHolder { clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE; } - disabled = true; } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) { clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE; - disabled = true; } - - if (clickAction != RightButtonAction.DOWNLOAD) { - rightButton.setText(R.string.get_plugin); - rightButton.setVisibility(View.VISIBLE); - rightImageButton.setVisibility(View.GONE); - final RightButtonAction action = clickAction; + return clickAction; + } - rightButton.setOnClickListener(new View.OnClickListener() { + public OnClickListener getRightButtonAction(final IndexItem item, final RightButtonAction clickAction) { + if (clickAction != RightButtonAction.DOWNLOAD) { + return new View.OnClickListener() { @Override public void onClick(View v) { - switch (action) { - case ASK_FOR_FULL_VERSION_PURCHASE: - Intent intent = new Intent(Intent.ACTION_VIEW, - Uri.parse(Version.marketPrefix(context.getMyApplication()) - + "net.osmand.plus")); - context.startActivity(intent); - break; - case ASK_FOR_SEAMARKS_PLUGIN: - context.startActivity(new Intent(context, - context.getMyApplication().getAppCustomization().getPluginsActivity())); - AccessibleToast.makeText(context.getApplicationContext(), - context.getString(R.string.activate_seamarks_plugin), Toast.LENGTH_SHORT).show(); - break; - case ASK_FOR_SRTM_PLUGIN_PURCHASE: - OsmandPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class); - context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); - break; - case ASK_FOR_SRTM_PLUGIN_ENABLE: - context.startActivity(new Intent(context, - context.getMyApplication().getAppCustomization().getPluginsActivity())); - AccessibleToast.makeText(context, - context.getString(R.string.activate_srtm_plugin), Toast.LENGTH_SHORT).show(); - break; - case DOWNLOAD: - break; + switch (clickAction) { + case ASK_FOR_FULL_VERSION_PURCHASE: + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(context + .getMyApplication()) + "net.osmand.plus")); + context.startActivity(intent); + break; + case ASK_FOR_SEAMARKS_PLUGIN: + context.startActivity(new Intent(context, context.getMyApplication().getAppCustomization() + .getPluginsActivity())); + AccessibleToast.makeText(context.getApplicationContext(), + context.getString(R.string.activate_seamarks_plugin), Toast.LENGTH_SHORT).show(); + break; + case ASK_FOR_SRTM_PLUGIN_PURCHASE: + OsmandPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class); + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); + break; + case ASK_FOR_SRTM_PLUGIN_ENABLE: + context.startActivity(new Intent(context, context.getMyApplication().getAppCustomization() + .getPluginsActivity())); + AccessibleToast.makeText(context, context.getString(R.string.activate_srtm_plugin), + Toast.LENGTH_SHORT).show(); + break; + case DOWNLOAD: + break; } } - }); + }; } else { - rightButton.setVisibility(View.GONE); - rightImageButton.setVisibility(View.VISIBLE); + final boolean isDownloading = context.getDownloadThread().isDownloading(item); + return new View.OnClickListener() { + @Override + public void onClick(View v) { + if(isDownloading) { + if(silentCancelDownload) { + context.getDownloadThread().cancelDownload(item); + } else { + context.makeSureUserCancelDownload(item); + } + } else { + context.startDownload(item); + } + } + }; } - - return disabled; } private Drawable getContentIcon(DownloadActivity context, int resourceId) { @@ -240,7 +282,5 @@ public class ItemViewHolder { return context.getMyApplication().getIconsCache().getPaintedContentIcon(resourceId, color); } - public boolean isItemAvailable() { - return clickAction == RightButtonAction.DOWNLOAD; - } + } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java index 01f83740d5..4208fd283c 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java @@ -16,7 +16,16 @@ import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; -public class SearchDialogFragment { /*extends DialogFragment implements DownloadEvents { +// FIXME +public class SearchDialogFragment extends DialogFragment { + + public static DialogFragment createInstance(String tg) { + return new SearchDialogFragment(); + } + + + + /*extends DialogFragment implements DownloadEvents { public static final String TAG = "SearchDialogFragment"; private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key"; diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java index 6ef6e9b7c3..35b6acf0bb 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java @@ -29,6 +29,7 @@ import android.widget.Filter; import android.widget.Filterable; import android.widget.ListView; +//FIXME merge into search dialog fragment public class SearchItemsFragment { /*extends Fragment implements DownloadEvents { public static final String TAG = "SearchItemsFragment"; diff --git a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java index 0daeb47e63..c41fad496d 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java @@ -20,6 +20,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; @@ -118,7 +119,9 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download @Override public void onListItemClick(ListView l, View v, int position, long id) { final IndexItem e = (IndexItem) getListAdapter().getItem(position); - getMyActivity().startDownload(e); + ItemViewHolder vh = (ItemViewHolder) v.getTag(); + OnClickListener ls = vh.getRightButtonAction(e, vh.getClickAction(e)); + ls.onClick(v); } public DownloadActivity getMyActivity() {