Downdload map design in progress. Voice now has no aggreagation. Icons. Back is now working.

This commit is contained in:
GaidamakUA 2015-09-28 14:56:08 +03:00
parent 3114e2187a
commit 80798e4f8e
7 changed files with 166 additions and 77 deletions

View file

@ -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<String, DownloadActivityType> byTag = new HashMap<String, DownloadActivityType>();
private static Map<String, DownloadActivityType> 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<DownloadActivityType> CREATOR = new Parcelable.Creator<DownloadActivityType>() {
public DownloadActivityType createFromParcel(Parcel source) {
return new DownloadActivityType(source);
}
public DownloadActivityType[] newArray(int size) {
return new DownloadActivityType[size];
}
};
}

View file

@ -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<IndexItem>, HasName {
public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
private static final Log log = PlatformUtil.getLog(IndexItem.class);
String description;
@ -114,9 +116,9 @@ public class IndexItem implements Comparable<IndexItem>, 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<IndexItem>, 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<IndexItem>, 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<IndexItem> CREATOR = new Parcelable.Creator<IndexItem>() {
public IndexItem createFromParcel(Parcel source) {
return new IndexItem(source);
}
public IndexItem[] newArray(int size) {
return new IndexItem[size];
}
};
}

View file

@ -40,7 +40,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
private OsmandRegions osmandRegions;
private java.text.DateFormat format;
private UpdateIndexAdapter listAdapter;
List<IndexItem> indexItems = new ArrayList<IndexItem>();
List<IndexItem> indexItems = new ArrayList<>();
@Override
@ -233,7 +233,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
private void filterExisting() {
final Map<String, String> listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames();
final List<IndexItem> filtered = new ArrayList<IndexItem>();
final List<IndexItem> 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;

View file

@ -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<IndexItemCategory
}
}
IndexItemCategoryWithSubcat region;
region = cats.get(i.getBasename());
final String visibleName = i.getVisibleName(ctx, ctx.getRegions());
i.setName(visibleName);
if (region == null) {
final CategoryStaticData regionStaticData = new CategoryStaticData(0, 0);
regionStaticData.setName(visibleName);
region = new IndexItemCategoryWithSubcat(regionStaticData);
cats.put(i.getBasename(), region);
category.subcats.add(region);
if (i.getType() == DownloadActivityType.VOICE_FILE){
// TODO remove
final String visibleName = i.getVisibleName(ctx, ctx.getRegions());
i.setName(visibleName);
category.items.add(i);
} else {
IndexItemCategoryWithSubcat region;
region = cats.get(i.getBasename());
// TODO remove
final String visibleName = i.getVisibleName(ctx, ctx.getRegions());
i.setName(visibleName);
if (region == null) {
final CategoryStaticData regionStaticData = new CategoryStaticData(0, 0);
regionStaticData.setName(visibleName);
region = new IndexItemCategoryWithSubcat(regionStaticData);
cats.put(i.getBasename(), region);
category.subcats.add(region);
}
region.items.add(i);
if (i.getType() == DownloadActivityType.NORMAL_FILE
|| i.getType() == DownloadActivityType.WIKIPEDIA_FILE
|| i.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| i.getType() == DownloadActivityType.HILLSHADE_FILE) {
region.types.add(i.getType().getStringResource());
}
}
region.items.add(i);
if (i.getType() == DownloadActivityType.NORMAL_FILE) {
region.types.add(R.string.shared_string_map);
}
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
region.types.add(R.string.shared_string_wikipedia);
}
if (i.getType() == DownloadActivityType.ROADS_FILE) {
region.types.add(R.string.roads);
}
final CategoryStaticData parent = category.categoryStaticData.getParent();
}
final Collator collator = OsmAndCollator.primaryCollator();
for (IndexItemCategoryWithSubcat ct : mainList) {

View file

@ -57,8 +57,7 @@ public class MapsInCategoryFragment extends DialogFragment {
public void onCategorySelected(@NonNull IndexItemCategoryWithSubcat category) {
LOG.debug("onCategorySelected()");
getChildFragmentManager().beginTransaction().replace(R.id.fragmentContainer,
SubcategoriesFragment.createInstance(category)).addToBackStack(null).commit();
createInstance(category).show(getChildFragmentManager(), TAG);
}
public void onIndexItemSelected(@NonNull IndexItem indexItem) {

View file

@ -14,7 +14,6 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
@ -55,13 +54,6 @@ public class NewLocalIndexesFragment extends OsmAndListFragment {
ListView listView = (ListView) view.findViewById(android.R.id.list);
mAdapter = new CategoriesAdapter(getActivity(), getMyApplication());
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> 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<IndexItem> filtered, List<IndexItemCategoryWithSubcat> cats) {
LOG.debug("cats=" + cats);
mAdapter.clear();
mAdapter.addAll(cats);
}

View file

@ -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<HasName> {
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;
}