diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index f066c81f62..c3d4cb5add 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -1,6 +1,8 @@ package net.osmand.plus.download; import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; @@ -24,34 +26,53 @@ import java.util.Map; import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT; -public class DownloadActivityType { +public class DownloadActivityType implements Parcelable { private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy"); - private static Map byTag = new HashMap(); + private static Map byTag = new HashMap<>(); public static final DownloadActivityType NORMAL_FILE = new DownloadActivityType(R.string.download_regular_maps, "map"); - public static final DownloadActivityType VOICE_FILE = new DownloadActivityType(R.string.voices, "voice"); + public static final DownloadActivityType VOICE_FILE = + new DownloadActivityType(R.string.voices, R.drawable.ic_action_volume_up, "voice"); public static final DownloadActivityType ROADS_FILE = new DownloadActivityType(R.string.download_roads_only_maps, "road_map"); - public static final DownloadActivityType SRTM_COUNTRY_FILE = new DownloadActivityType(R.string.download_srtm_maps, "srtm_map"); - public static final DownloadActivityType HILLSHADE_FILE = new DownloadActivityType(R.string.download_hillshade_maps, "hillshade"); - public static final DownloadActivityType WIKIPEDIA_FILE = new DownloadActivityType(R.string.download_wikipedia_maps, "wikimap"); + public static final DownloadActivityType SRTM_COUNTRY_FILE = + new DownloadActivityType(R.string.download_srtm_maps, + R.drawable.ic_plugin_srtm, "srtm_map"); + public static final DownloadActivityType HILLSHADE_FILE = + new DownloadActivityType(R.string.download_hillshade_maps, + R.drawable.ic_action_hillshade_dark, "hillshade"); + public static final DownloadActivityType WIKIPEDIA_FILE = + new DownloadActivityType(R.string.download_wikipedia_maps, + R.drawable.ic_world_globe_dark, "wikimap"); public static final DownloadActivityType LIVE_UPDATES_FILE = new DownloadActivityType(R.string.download_live_updates, "live_updates"); - private int resource; - private String[] tags; + private final int stringResource; + private final int iconResource; - public DownloadActivityType(int resource, String... tags) { - this.resource = resource; - this.tags = tags; - for(String st : tags) { - byTag.put(st, this); - } + private String tag; + + public DownloadActivityType(int stringResource, int iconResource, String tag) { + this.stringResource = stringResource; + this.tag = tag; + byTag.put(tag, this); + this.iconResource = iconResource; } - public int getResource(){ - return resource; + public DownloadActivityType(int stringResource, String tag) { + this.stringResource = stringResource; + this.tag = tag; + byTag.put(tag, this); + iconResource = R.drawable.ic_map; } - + + public int getStringResource(){ + return stringResource; + } + + public int getIconResource() { + return iconResource; + } + public String getTag() { - return tags[0]; + return tag; } @@ -66,7 +87,7 @@ public class DownloadActivityType { } public String getString(Context c) { - return c.getString(resource); + return c.getString(stringResource); } public static DownloadActivityType getIndexType(String tagName) { @@ -271,8 +292,7 @@ public class DownloadActivityType { if (l == -1) { l = fileName.length(); } - String s = fileName.substring(0, l); - return s; + return fileName.substring(0, l); } else if (this == HILLSHADE_FILE) { return fileName.replace('_', ' '); } else if (this == LIVE_UPDATES_FILE) { @@ -322,8 +342,7 @@ public class DownloadActivityType { if (l == -1) { l = fileName.length(); } - String s = fileName.substring(0, l); - return s; + return fileName.substring(0, l); } if (this == LIVE_UPDATES_FILE) { if(fileName.indexOf('.') > 0){ @@ -341,5 +360,32 @@ public class DownloadActivityType { } + @Override + public int describeContents() { + return 0; + } + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(this.stringResource); + dest.writeInt(this.iconResource); + dest.writeString(this.tag); + } + + protected DownloadActivityType(Parcel in) { + this.stringResource = in.readInt(); + this.iconResource = in.readInt(); + this.tag = in.readString(); + byTag.put(tag, this); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public DownloadActivityType createFromParcel(Parcel source) { + return new DownloadActivityType(source); + } + + public DownloadActivityType[] newArray(int size) { + return new DownloadActivityType[size]; + } + }; } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index f46e2d6f1d..32cd89b083 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -1,6 +1,8 @@ package net.osmand.plus.download; import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; import android.support.annotation.NonNull; import net.osmand.IndexConstants; @@ -18,7 +20,7 @@ import java.util.Date; import java.util.List; import java.util.Map; -public class IndexItem implements Comparable, HasName { +public class IndexItem implements Comparable, HasName, Parcelable { private static final Log log = PlatformUtil.getLog(IndexItem.class); String description; @@ -114,9 +116,9 @@ public class IndexItem implements Comparable, HasName { @Override public int compareTo(@NonNull IndexItem another) { - if(another == null) { - return -1; - } +// if(another == null) { +// return -1; +// } return getFileName().compareTo(another.getFileName()); } @@ -146,7 +148,7 @@ public class IndexItem implements Comparable, HasName { @Override public String getName() { - return initializedName; + return initializedName + " must be fixed"; } public void setName(String initializedName) { @@ -166,4 +168,44 @@ public class IndexItem implements Comparable, HasName { ", extra=" + extra + '}'; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.description); + dest.writeString(this.fileName); + dest.writeString(this.size); + dest.writeLong(this.timestamp); + dest.writeLong(this.contentSize); + dest.writeLong(this.containerSize); + dest.writeParcelable(this.type, flags); + dest.writeByte(extra ? (byte) 1 : (byte) 0); + dest.writeString(this.initializedName); + } + + protected IndexItem(Parcel in) { + this.description = in.readString(); + this.fileName = in.readString(); + this.size = in.readString(); + this.timestamp = in.readLong(); + this.contentSize = in.readLong(); + this.containerSize = in.readLong(); + this.type = in.readParcelable(DownloadActivityType.class.getClassLoader()); + this.extra = in.readByte() != 0; + this.initializedName = in.readString(); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public IndexItem createFromParcel(Parcel source) { + return new IndexItem(source); + } + + public IndexItem[] newArray(int size) { + return new IndexItem[size]; + } + }; } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index ed80abada6..e57954d7a7 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -40,7 +40,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment { private OsmandRegions osmandRegions; private java.text.DateFormat format; private UpdateIndexAdapter listAdapter; - List indexItems = new ArrayList(); + List indexItems = new ArrayList<>(); @Override @@ -233,7 +233,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment { private void filterExisting() { final Map listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames(); - final List filtered = new ArrayList(); + final List filtered = new ArrayList<>(); for (IndexItem fileItem : listAdapter.getIndexFiles()) { if (fileItem.isAlreadyDownloaded(listAlreadyDownloaded)) { filtered.add(fileItem); @@ -329,7 +329,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment { } private String getMapDescription(IndexItem item){ - String typeName = getTypeName(item, item.getType().getResource()); + String typeName = getTypeName(item, item.getType().getStringResource()); String date = item.getDate(format); String size = item.getSizeDescription(getActivity()); return typeName + " " + date + " " + size; diff --git a/OsmAnd/src/net/osmand/plus/download/newimplementation/IndexItemCategoryWithSubcat.java b/OsmAnd/src/net/osmand/plus/download/newimplementation/IndexItemCategoryWithSubcat.java index 22e5f6b3f6..1b7610fd34 100644 --- a/OsmAnd/src/net/osmand/plus/download/newimplementation/IndexItemCategoryWithSubcat.java +++ b/OsmAnd/src/net/osmand/plus/download/newimplementation/IndexItemCategoryWithSubcat.java @@ -9,7 +9,6 @@ import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.map.OsmandRegions; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.IndexItem; @@ -133,30 +132,32 @@ public class IndexItemCategoryWithSubcat implements Comparable parent, View view, int position, long id) { - LOG.debug("onItemClick()"); - - } - }); View header = inflater.inflate(R.layout.local_index_fragment_header, listView, false); initMemoryConsumedCard(header); @@ -116,7 +108,6 @@ public class NewLocalIndexesFragment extends OsmAndListFragment { fragmentTransaction.addToBackStack(null); MapsInCategoryFragment.createInstance(mAdapter.getItem(position-1)) .show(fragmentTransaction, MapsInCategoryFragment.TAG); - LOG.debug("onListItemClick()"); } private DownloadActivity getDownloadActivity() { @@ -124,7 +115,6 @@ public class NewLocalIndexesFragment extends OsmAndListFragment { } public void onCategorizationFinished(List filtered, List cats) { - LOG.debug("cats=" + cats); mAdapter.clear(); mAdapter.addAll(cats); } diff --git a/OsmAnd/src/net/osmand/plus/download/newimplementation/SubcategoriesFragment.java b/OsmAnd/src/net/osmand/plus/download/newimplementation/SubcategoriesFragment.java index 169f242ced..145cb42e59 100644 --- a/OsmAnd/src/net/osmand/plus/download/newimplementation/SubcategoriesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/newimplementation/SubcategoriesFragment.java @@ -20,6 +20,7 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.HasName; @@ -38,8 +39,9 @@ public class SubcategoriesFragment extends Fragment { assert category != null; ListView listView = new ListView(getActivity()); + final OsmandApplication application = (OsmandApplication) getActivity().getApplication(); final MapFilesAdapter mAdapter = new MapFilesAdapter(getActivity(), - ((OsmandApplication) getActivity().getApplication()).getIconsCache()); + application.getIconsCache(), application); listView.setAdapter(mAdapter); mAdapter.addAll(category.items); mAdapter.addAll(category.subcats); @@ -51,8 +53,7 @@ public class SubcategoriesFragment extends Fragment { }); View freeVersionBanner = inflater.inflate(R.layout.free_version_banner, listView, false); - final OsmandSettings settings = - ((OsmandApplication) getActivity().getApplication()).getSettings(); + final OsmandSettings settings = application.getSettings(); DownloadsUiInitHelper.initFreeVersionBanner(freeVersionBanner, settings, getResources()); listView.addHeaderView(freeVersionBanner); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -85,10 +86,12 @@ public class SubcategoriesFragment extends Fragment { private static class MapFilesAdapter extends ArrayAdapter { private final IconsCache iconsCache; + private final OsmandApplication application; - public MapFilesAdapter(Context context, IconsCache iconsCache) { + public MapFilesAdapter(Context context, IconsCache iconsCache, OsmandApplication application) { super(context, R.layout.two_line_with_images_list_item); this.iconsCache = iconsCache; + this.application = application; } @Override @@ -117,20 +120,28 @@ public class SubcategoriesFragment extends Fragment { stringBuilder.append(resources.getString(mapType)); stringBuilder.append(", "); } - LOG.debug("stringBuilder=" + stringBuilder); - stringBuilder.delete(stringBuilder.capacity() - 3, stringBuilder.capacity()); + stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.capacity()); viewHolder.descrTextView.setText(stringBuilder.toString()); } else { // TODO replace with string constant viewHolder.descrTextView.setText("Others"); } + viewHolder.leftImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_map)); LOG.debug("category.types=" + category.types); + } else if (item instanceof IndexItem) { + IndexItem indexItem = (IndexItem) item; + if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { + viewHolder.nameTextView.setText(indexItem.getVisibleName(getContext(), + application.getRegions())); + } else { + viewHolder.nameTextView.setText(indexItem.getType().getString(getContext())); + } + viewHolder.descrTextView.setText(indexItem.getSizeDescription(getContext())); + viewHolder.leftImageView.setImageResource(indexItem.getType().getIconResource()); } else { - viewHolder.nameTextView.setText(item.getName()); - // TODO replace with real values - viewHolder.descrTextView.setText("Temp values"); + throw new IllegalArgumentException("Item must be of type IndexItem or " + + "IndexItemCategory but is of type:" + item.getClass()); } - viewHolder.leftImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_map)); return convertView; }