Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
dc11724955
11 changed files with 948 additions and 161 deletions
|
@ -15,13 +15,14 @@
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/list_world_regions_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="World Regions"
|
android:text="World Regions"
|
||||||
android:textSize="@dimen/default_list_text_size"/>
|
android:textSize="@dimen/default_desc_text_size"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/list_world_regions"
|
android:id="@+id/list_world_regions"
|
||||||
|
@ -32,16 +33,17 @@
|
||||||
android:scrollbars="none"/>
|
android:scrollbars="none"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/list_world_maps_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="World Map"
|
android:text="World Maps"
|
||||||
android:textSize="@dimen/default_list_text_size"/>
|
android:textSize="@dimen/default_desc_text_size"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/list_world_map"
|
android:id="@+id/list_world_maps"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:groupIndicator="@android:color/transparent"
|
android:groupIndicator="@android:color/transparent"
|
||||||
|
@ -49,13 +51,14 @@
|
||||||
android:scrollbars="none"/>
|
android:scrollbars="none"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/list_voice_promts_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="Voice Promts"
|
android:text="Voice Promts"
|
||||||
android:textSize="@dimen/default_list_text_size"/>
|
android:textSize="@dimen/default_desc_text_size"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/list_voice_promts"
|
android:id="@+id/list_voice_promts"
|
||||||
|
|
|
@ -7,6 +7,7 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.map.OsmandRegions;
|
import net.osmand.map.OsmandRegions;
|
||||||
import net.osmand.plus.download.DownloadActivityType;
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -14,7 +15,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class WorldRegion {
|
public class WorldRegion implements Serializable {
|
||||||
|
|
||||||
public static final String AFRICA_REGION_ID = "africa";
|
public static final String AFRICA_REGION_ID = "africa";
|
||||||
public static final String ASIA_REGION_ID = "asia";
|
public static final String ASIA_REGION_ID = "asia";
|
||||||
|
@ -127,14 +128,14 @@ public class WorldRegion {
|
||||||
this.regionId = regionId;
|
this.regionId = regionId;
|
||||||
String downloadName = osmandRegions.getDownloadName(regionId);
|
String downloadName = osmandRegions.getDownloadName(regionId);
|
||||||
if (downloadName != null) {
|
if (downloadName != null) {
|
||||||
downloadsIdPrefix = downloadName + ".";
|
downloadsIdPrefix = downloadName.toLowerCase() + ".";
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
} else {
|
} else {
|
||||||
this.name = osmandRegions.getLocaleName(downloadName);
|
this.name = osmandRegions.getLocaleName(downloadName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.downloadsIdPrefix = regionId + ".";
|
this.downloadsIdPrefix = regionId.toLowerCase() + ".";
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -144,10 +145,10 @@ public class WorldRegion {
|
||||||
this.regionId = regionId;
|
this.regionId = regionId;
|
||||||
String downloadName = osmandRegions.getDownloadName(regionId);
|
String downloadName = osmandRegions.getDownloadName(regionId);
|
||||||
if (downloadName != null) {
|
if (downloadName != null) {
|
||||||
downloadsIdPrefix = downloadName + ".";
|
downloadsIdPrefix = downloadName.toLowerCase() + ".";
|
||||||
this.name = osmandRegions.getLocaleName(regionId);
|
this.name = osmandRegions.getLocaleName(downloadName);
|
||||||
} else {
|
} else {
|
||||||
this.downloadsIdPrefix = regionId + ".";
|
this.downloadsIdPrefix = regionId.toLowerCase() + ".";
|
||||||
this.name = regionId;
|
this.name = regionId;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -155,7 +156,7 @@ public class WorldRegion {
|
||||||
|
|
||||||
private WorldRegion init(String regionId, String name) {
|
private WorldRegion init(String regionId, String name) {
|
||||||
this.regionId = regionId;
|
this.regionId = regionId;
|
||||||
this.downloadsIdPrefix = regionId + ".";
|
this.downloadsIdPrefix = regionId.toLowerCase() + ".";
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||||
import net.osmand.plus.activities.TabActivity;
|
import net.osmand.plus.activities.TabActivity;
|
||||||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||||
import net.osmand.plus.download.items.DownloadItemsFragment;
|
import net.osmand.plus.download.items.WorldItemsFragment;
|
||||||
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
|
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
|
||||||
import net.osmand.plus.download.newimplementation.NewLocalIndexesFragment;
|
import net.osmand.plus.download.newimplementation.NewLocalIndexesFragment;
|
||||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||||
|
@ -123,7 +123,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
// mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
|
// mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
|
||||||
// getString(R.string.download_tab_local), NewLocalIndexesFragment.class));
|
// getString(R.string.download_tab_local), NewLocalIndexesFragment.class));
|
||||||
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
|
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
|
||||||
getString(R.string.download_tab_local), DownloadItemsFragment.class));
|
getString(R.string.download_tab_local), WorldItemsFragment.class));
|
||||||
|
|
||||||
viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs));
|
viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs));
|
||||||
mSlidingTabLayout.setViewPager(viewPager);
|
mSlidingTabLayout.setViewPager(viewPager);
|
||||||
|
@ -343,9 +343,9 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
public void onCategorizationFinished() {
|
public void onCategorizationFinished() {
|
||||||
for (WeakReference<Fragment> ref : fragSet) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof DownloadItemsFragment) {
|
if (f instanceof WorldItemsFragment) {
|
||||||
if (f.isAdded()) {
|
if (f.isAdded()) {
|
||||||
((DownloadItemsFragment) f).onCategorizationFinished();
|
((WorldItemsFragment) f).onCategorizationFinished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,16 +413,14 @@ public class DownloadIndexesThread {
|
||||||
@Override
|
@Override
|
||||||
protected IndexFileList doInBackground(Void... params) {
|
protected IndexFileList doInBackground(Void... params) {
|
||||||
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
|
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
|
||||||
indexFiles = indexFileList;
|
|
||||||
if (indexFileList != null) {
|
if (indexFileList != null) {
|
||||||
ItemsListBuilder builder = new ItemsListBuilder(app, app.getWorldRegion());
|
ItemsListBuilder.prepareData(app, indexFileList.getIndexFiles());
|
||||||
builder.invalidate();
|
|
||||||
builder.build();
|
|
||||||
}
|
}
|
||||||
return indexFileList;
|
return indexFileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(IndexFileList result) {
|
protected void onPostExecute(IndexFileList result) {
|
||||||
|
indexFiles = result;
|
||||||
if (indexFiles != null && uiActivity != null) {
|
if (indexFiles != null && uiActivity != null) {
|
||||||
prepareFilesToUpdate();
|
prepareFilesToUpdate();
|
||||||
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||||
|
|
||||||
String description;
|
String description;
|
||||||
String fileName;
|
String fileName;
|
||||||
|
String simplifiedFileName;
|
||||||
String size;
|
String size;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
long contentSize;
|
long contentSize;
|
||||||
|
@ -37,6 +38,7 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||||
public IndexItem(String fileName, String description, long timestamp, String size, long contentSize,
|
public IndexItem(String fileName, String description, long timestamp, String size, long contentSize,
|
||||||
long containerSize, DownloadActivityType tp) {
|
long containerSize, DownloadActivityType tp) {
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
this.simplifiedFileName = fileName.toLowerCase().replace("_2.", ".");
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
|
@ -53,6 +55,10 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSimplifiedFileName() {
|
||||||
|
return simplifiedFileName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
@ -160,6 +166,7 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||||
return "IndexItem{" +
|
return "IndexItem{" +
|
||||||
"description='" + description + '\'' +
|
"description='" + description + '\'' +
|
||||||
", fileName='" + fileName + '\'' +
|
", fileName='" + fileName + '\'' +
|
||||||
|
", simplifiedFileName='" + simplifiedFileName + '\'' +
|
||||||
", size='" + size + '\'' +
|
", size='" + size + '\'' +
|
||||||
", timestamp=" + timestamp +
|
", timestamp=" + timestamp +
|
||||||
", contentSize=" + contentSize +
|
", contentSize=" + contentSize +
|
||||||
|
@ -185,6 +192,7 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||||
dest.writeParcelable(this.type, flags);
|
dest.writeParcelable(this.type, flags);
|
||||||
dest.writeByte(extra ? (byte) 1 : (byte) 0);
|
dest.writeByte(extra ? (byte) 1 : (byte) 0);
|
||||||
dest.writeString(this.initializedName);
|
dest.writeString(this.initializedName);
|
||||||
|
dest.writeString(this.simplifiedFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IndexItem(Parcel in) {
|
protected IndexItem(Parcel in) {
|
||||||
|
@ -197,6 +205,7 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||||
this.type = in.readParcelable(DownloadActivityType.class.getClassLoader());
|
this.type = in.readParcelable(DownloadActivityType.class.getClassLoader());
|
||||||
this.extra = in.readByte() != 0;
|
this.extra = in.readByte() != 0;
|
||||||
this.initializedName = in.readString();
|
this.initializedName = in.readString();
|
||||||
|
this.simplifiedFileName = in.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<IndexItem> CREATOR = new Parcelable.Creator<IndexItem>() {
|
public static final Parcelable.Creator<IndexItem> CREATOR = new Parcelable.Creator<IndexItem>() {
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
package net.osmand.plus.download.items;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.WorldRegion;
|
||||||
|
import net.osmand.plus.download.BaseDownloadActivity;
|
||||||
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
|
||||||
|
public class ItemViewHolder {
|
||||||
|
private final TextView nameTextView;
|
||||||
|
private final TextView descrTextView;
|
||||||
|
private final ImageView leftImageView;
|
||||||
|
private final ImageView rightImageButton;
|
||||||
|
private final ProgressBar progressBar;
|
||||||
|
|
||||||
|
public ItemViewHolder(View convertView) {
|
||||||
|
nameTextView = (TextView) convertView.findViewById(R.id.name);
|
||||||
|
descrTextView = (TextView) convertView.findViewById(R.id.description);
|
||||||
|
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
|
||||||
|
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
|
||||||
|
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context, boolean showTypeInTitle, boolean showTypeInDesc) {
|
||||||
|
if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
|
||||||
|
nameTextView.setText(indexItem.getVisibleName(context,
|
||||||
|
context.getMyApplication().getRegions()));
|
||||||
|
} else {
|
||||||
|
if (showTypeInTitle) {
|
||||||
|
nameTextView.setText(indexItem.getType().getString(context));
|
||||||
|
} else {
|
||||||
|
nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (showTypeInDesc) {
|
||||||
|
descrTextView.setText(indexItem.getType().getString(context) + " • " + indexItem.getSizeDescription(context));
|
||||||
|
} else {
|
||||||
|
descrTextView.setText(indexItem.getSizeDescription(context));
|
||||||
|
}
|
||||||
|
leftImageView.setImageDrawable(getContextIcon(context,
|
||||||
|
indexItem.getType().getIconResource()));
|
||||||
|
rightImageButton.setVisibility(View.VISIBLE);
|
||||||
|
rightImageButton.setImageDrawable(getContextIcon(context,
|
||||||
|
R.drawable.ic_action_import));
|
||||||
|
rightImageButton.setTag(R.id.index_item, indexItem);
|
||||||
|
rightImageButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
((BaseDownloadActivity) v.getContext())
|
||||||
|
.startDownload((IndexItem) v.getTag(R.id.index_item));
|
||||||
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
rightImageButton.setImageDrawable(getContextIcon(context,
|
||||||
|
R.drawable.ic_action_remove_dark));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindRegion(WorldRegion region, DownloadActivity context) {
|
||||||
|
nameTextView.setText(region.getName());
|
||||||
|
if (region.getResourceTypes().size() > 0) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (DownloadActivityType activityType : region.getResourceTypes()) {
|
||||||
|
if (stringBuilder.length() > 0) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
}
|
||||||
|
stringBuilder.append(activityType.getString(context));
|
||||||
|
}
|
||||||
|
descrTextView.setText(stringBuilder.toString());
|
||||||
|
} else {
|
||||||
|
descrTextView.setText(R.string.shared_string_others);
|
||||||
|
}
|
||||||
|
leftImageView.setImageDrawable(getContextIcon(context, R.drawable.ic_map));
|
||||||
|
rightImageButton.setVisibility(View.GONE);
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable getContextIcon(DownloadActivity context, int resourceId) {
|
||||||
|
return context.getMyApplication().getIconsCache().getContentIcon(resourceId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import net.osmand.plus.WorldRegion;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
import net.osmand.plus.download.DownloadActivityType;
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
import net.osmand.plus.mapcontextmenu.editors.PointEditor;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -17,6 +18,8 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
public class ItemsListBuilder {
|
public class ItemsListBuilder {
|
||||||
|
|
||||||
|
@ -92,16 +95,16 @@ public class ItemsListBuilder {
|
||||||
String str2;
|
String str2;
|
||||||
|
|
||||||
if (obj1 instanceof WorldRegion) {
|
if (obj1 instanceof WorldRegion) {
|
||||||
str1 = ((WorldRegion)obj1).getName();
|
str1 = ((WorldRegion) obj1).getName();
|
||||||
} else {
|
} else {
|
||||||
ResourceItem item = (ResourceItem)obj1;
|
ResourceItem item = (ResourceItem) obj1;
|
||||||
str1 = item.title + item.getIndexItem().getType().getTag();
|
str1 = item.title + item.getIndexItem().getType().getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj2 instanceof WorldRegion) {
|
if (obj2 instanceof WorldRegion) {
|
||||||
str2 = ((WorldRegion)obj2).getName();
|
str2 = ((WorldRegion) obj2).getName();
|
||||||
} else {
|
} else {
|
||||||
ResourceItem item = (ResourceItem)obj2;
|
ResourceItem item = (ResourceItem) obj2;
|
||||||
str2 = item.title + item.getIndexItem().getType().getTag();
|
str2 = item.title + item.getIndexItem().getType().getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +117,8 @@ public class ItemsListBuilder {
|
||||||
private static Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions =
|
private static Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions =
|
||||||
new HashMap<>();
|
new HashMap<>();
|
||||||
private static List<WorldRegion> searchableWorldwideRegionItems = new LinkedList<>();
|
private static List<WorldRegion> searchableWorldwideRegionItems = new LinkedList<>();
|
||||||
|
private static final Lock lock = new ReentrantLock();
|
||||||
|
|
||||||
|
|
||||||
private List<ResourceItem> regionMapItems;
|
private List<ResourceItem> regionMapItems;
|
||||||
private List allResourceItems;
|
private List allResourceItems;
|
||||||
|
@ -122,7 +127,6 @@ public class ItemsListBuilder {
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private WorldRegion region;
|
private WorldRegion region;
|
||||||
|
|
||||||
private boolean invalidated;
|
|
||||||
private boolean srtmDisabled;
|
private boolean srtmDisabled;
|
||||||
private boolean hasSrtm;
|
private boolean hasSrtm;
|
||||||
|
|
||||||
|
@ -138,7 +142,7 @@ public class ItemsListBuilder {
|
||||||
List<WorldRegion> list = new LinkedList<>();
|
List<WorldRegion> list = new LinkedList<>();
|
||||||
for (Object obj : allResourceItems) {
|
for (Object obj : allResourceItems) {
|
||||||
if (obj instanceof WorldRegion) {
|
if (obj instanceof WorldRegion) {
|
||||||
list.add((WorldRegion)obj);
|
list.add((WorldRegion) obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
@ -157,18 +161,20 @@ public class ItemsListBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean build() {
|
public boolean build() {
|
||||||
return obtainDataAndItems();
|
if (lock.tryLock()) {
|
||||||
|
try {
|
||||||
|
return obtainDataAndItems();
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean obtainDataAndItems() {
|
private boolean obtainDataAndItems() {
|
||||||
if (invalidated) {
|
if (resourcesByRegions.isEmpty() || region == null) {
|
||||||
resourcesByRegions.clear();
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (resourcesByRegions.isEmpty()) {
|
|
||||||
if (!prepareData()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
collectSubregionsDataAndItems();
|
collectSubregionsDataAndItems();
|
||||||
|
@ -182,97 +188,99 @@ public class ItemsListBuilder {
|
||||||
LOG.warn("getAllResourceItems >>>");
|
LOG.warn("getAllResourceItems >>>");
|
||||||
for (Object obj : getAllResourceItems()) {
|
for (Object obj : getAllResourceItems()) {
|
||||||
if (obj instanceof WorldRegion) {
|
if (obj instanceof WorldRegion) {
|
||||||
WorldRegion item = (WorldRegion)obj;
|
WorldRegion item = (WorldRegion) obj;
|
||||||
LOG.warn("W resId=" + item.getRegionId() + " title=" + item.getName());
|
LOG.warn("W resId=" + item.getRegionId() + " title=" + item.getName());
|
||||||
} else if (obj instanceof ResourceItem) {
|
} else if (obj instanceof ResourceItem) {
|
||||||
ResourceItem resourceItem = (ResourceItem)obj;
|
ResourceItem resourceItem = (ResourceItem) obj;
|
||||||
LOG.warn("R resId=" + resourceItem.getIndexItem().getFileName() + " title=" + resourceItem.getTitle());
|
LOG.warn("R resId=" + resourceItem.getIndexItem().getFileName() + " title=" + resourceItem.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidated = false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidate() {
|
public static boolean prepareData(OsmandApplication app, List<IndexItem> resources) {
|
||||||
invalidated = true;
|
lock.lock();
|
||||||
}
|
try {
|
||||||
|
List<IndexItem> resourcesInRepository;
|
||||||
|
if (resources != null) {
|
||||||
|
resourcesInRepository = resources;
|
||||||
|
} else {
|
||||||
|
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
|
||||||
|
}
|
||||||
|
if (resourcesInRepository == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean prepareData() {
|
boolean doInit = resourcesByRegions.isEmpty();
|
||||||
List<IndexItem> resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
|
boolean initSearchableRegions = searchableWorldwideRegionItems.isEmpty() || doInit;
|
||||||
if (resourcesInRepository == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean doInit = resourcesByRegions.isEmpty();
|
|
||||||
boolean initSearchableRegions = searchableWorldwideRegionItems.isEmpty() || doInit;
|
|
||||||
|
|
||||||
if (initSearchableRegions) {
|
|
||||||
searchableWorldwideRegionItems.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
|
|
||||||
mergedRegions.add(app.getWorldRegion());
|
|
||||||
for(WorldRegion region : mergedRegions)
|
|
||||||
{
|
|
||||||
if (initSearchableRegions) {
|
if (initSearchableRegions) {
|
||||||
searchableWorldwideRegionItems.add(region);
|
searchableWorldwideRegionItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
String downloadsIdPrefix = region.getDownloadsIdPrefix().toLowerCase();
|
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
|
||||||
|
mergedRegions.add(app.getWorldRegion());
|
||||||
Map<String, IndexItem> regionResources = new HashMap<>();
|
for (WorldRegion region : mergedRegions) {
|
||||||
|
if (initSearchableRegions) {
|
||||||
if (!doInit)
|
searchableWorldwideRegionItems.add(region);
|
||||||
{
|
|
||||||
regionResources.putAll(resourcesByRegions.get(region));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doInit)
|
|
||||||
{
|
|
||||||
List<DownloadActivityType> typesArray = new LinkedList<>();
|
|
||||||
boolean hasSrtm = false;
|
|
||||||
for (IndexItem resource : resourcesInRepository)
|
|
||||||
{
|
|
||||||
if (!resource.getFileName().startsWith(downloadsIdPrefix))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (resource.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
|
||||||
hasSrtm = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
typesArray.add(resource.getType());
|
|
||||||
|
|
||||||
regionResources.put(resource.getFileName(), resource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region.getSuperregion() != null && hasSrtm && region.getSuperregion().getSuperregion() != app.getWorldRegion())
|
String downloadsIdPrefix = region.getDownloadsIdPrefix();
|
||||||
{
|
|
||||||
if (!region.getSuperregion().getResourceTypes().contains(DownloadActivityType.SRTM_COUNTRY_FILE))
|
Map<String, IndexItem> regionResources = new HashMap<>();
|
||||||
{
|
|
||||||
region.getSuperregion().getResourceTypes().add(DownloadActivityType.SRTM_COUNTRY_FILE);
|
if (!doInit) {
|
||||||
Collections.sort(region.getSuperregion().getResourceTypes(), new Comparator<DownloadActivityType>() {
|
regionResources.putAll(resourcesByRegions.get(region));
|
||||||
@Override
|
|
||||||
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
|
|
||||||
return dat1.getTag().compareTo(dat2.getTag());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(typesArray, new Comparator<DownloadActivityType>() {
|
if (doInit) {
|
||||||
@Override
|
List<DownloadActivityType> typesArray = new LinkedList<>();
|
||||||
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
|
boolean hasSrtm = false;
|
||||||
return dat1.getTag().compareTo(dat2.getTag());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
region.setResourceTypes(typesArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
resourcesByRegions.put(region, regionResources);
|
for (IndexItem resource : resourcesInRepository) {
|
||||||
|
|
||||||
|
if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||||
|
hasSrtm = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
typesArray.add(resource.getType());
|
||||||
|
|
||||||
|
regionResources.put(resource.getSimplifiedFileName(), resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (region.getSuperregion() != null && hasSrtm && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
|
||||||
|
if (!region.getSuperregion().getResourceTypes().contains(DownloadActivityType.SRTM_COUNTRY_FILE)) {
|
||||||
|
region.getSuperregion().getResourceTypes().add(DownloadActivityType.SRTM_COUNTRY_FILE);
|
||||||
|
Collections.sort(region.getSuperregion().getResourceTypes(), new Comparator<DownloadActivityType>() {
|
||||||
|
@Override
|
||||||
|
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
|
||||||
|
return dat1.getTag().compareTo(dat2.getTag());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(typesArray, new Comparator<DownloadActivityType>() {
|
||||||
|
@Override
|
||||||
|
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
|
||||||
|
return dat1.getTag().compareTo(dat2.getTag());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
region.setResourceTypes(typesArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
resourcesByRegions.put(region, regionResources);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectSubregionsDataAndItems() {
|
private void collectSubregionsDataAndItems() {
|
||||||
|
@ -286,10 +294,8 @@ public class ItemsListBuilder {
|
||||||
allSubregionItems.clear();
|
allSubregionItems.clear();
|
||||||
regionMapItems.clear();
|
regionMapItems.clear();
|
||||||
|
|
||||||
for (WorldRegion subregion : region.getFlattenedSubregions())
|
for (WorldRegion subregion : region.getFlattenedSubregions()) {
|
||||||
{
|
if (subregion.getSuperregion() == region) {
|
||||||
if (subregion.getSuperregion() == region)
|
|
||||||
{
|
|
||||||
if (subregion.getFlattenedSubregions().size() > 0) {
|
if (subregion.getFlattenedSubregions().size() > 0) {
|
||||||
allSubregionItems.add(subregion);
|
allSubregionItems.add(subregion);
|
||||||
} else {
|
} else {
|
||||||
|
@ -316,27 +322,25 @@ public class ItemsListBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceItem resItem = new ResourceItem(indexItem, region);
|
ResourceItem resItem = new ResourceItem(indexItem, region);
|
||||||
resItem.setResourceId(indexItem.getFileName());
|
resItem.setResourceId(indexItem.getSimplifiedFileName());
|
||||||
resItem.setTitle(name);
|
resItem.setTitle(name);
|
||||||
resItem.setContentSize(indexItem.getContentSize());
|
resItem.setContentSize(indexItem.getContentSize());
|
||||||
resItem.setContainerSize(indexItem.getSize());
|
resItem.setContainerSize(indexItem.getSize());
|
||||||
|
|
||||||
if (region != this.region && srtmDisabled)
|
if (region != this.region && srtmDisabled) {
|
||||||
{
|
if (hasSrtm && indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE)
|
||||||
if (hasSrtm && indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE)
|
if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||||
{
|
resItem.setTitle("srtm_disabled"); // todo: constant
|
||||||
resItem.setTitle("srtm_disabled"); // todo: constant
|
resItem.setContentSize(0);
|
||||||
resItem.setContentSize(0);
|
resItem.setContainerSize(0);
|
||||||
resItem.setContainerSize(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasSrtm && indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE)
|
|
||||||
hasSrtm = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasSrtm && indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE)
|
||||||
|
hasSrtm = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (region == this.region) {
|
if (region == this.region) {
|
||||||
regionMapArray.add(resItem);
|
regionMapArray.add(resItem);
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
package net.osmand.plus.download.items;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.WorldRegion;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
public class LocalDialogFragment extends DialogFragment {
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(LocalDialogFragment.class);
|
||||||
|
public static final String TAG = "LocalDialogFragment";
|
||||||
|
private static final String REGION_DLG_KEY = "world_region_dialog_key";
|
||||||
|
private WorldRegion region;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
boolean isLightTheme = ((OsmandApplication) getActivity().getApplication())
|
||||||
|
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||||
|
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
|
||||||
|
setStyle(STYLE_NO_FRAME, themeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
|
||||||
|
|
||||||
|
WorldRegion region = null;
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
Object regionObj = savedInstanceState.getSerializable(REGION_DLG_KEY);
|
||||||
|
if (regionObj != null) {
|
||||||
|
region = (WorldRegion)regionObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (region == null) {
|
||||||
|
Object regionObj = getArguments().getSerializable(REGION_DLG_KEY);
|
||||||
|
if (regionObj != null) {
|
||||||
|
region = (WorldRegion)regionObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.region = region;
|
||||||
|
|
||||||
|
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||||
|
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
||||||
|
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.region != null) {
|
||||||
|
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
|
||||||
|
LocalItemsFragment.createInstance(region)).commit();
|
||||||
|
toolbar.setTitle(this.region.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putSerializable(REGION_DLG_KEY, region);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OsmandApplication getMyApplication() {
|
||||||
|
return (OsmandApplication) getActivity().getApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onRegionSelected(WorldRegion region) {
|
||||||
|
createInstance(region).show(getChildFragmentManager(), TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDialogFragment createInstance(WorldRegion region) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putSerializable(REGION_DLG_KEY, region);
|
||||||
|
LocalDialogFragment fragment = new LocalDialogFragment();
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,281 @@
|
||||||
|
package net.osmand.plus.download.items;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.WorldRegion;
|
||||||
|
import net.osmand.plus.download.BaseDownloadActivity;
|
||||||
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class LocalItemsFragment extends Fragment {
|
||||||
|
public static final String TAG = "LocalItemsFragment";
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(LocalItemsFragment.class);
|
||||||
|
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
|
||||||
|
|
||||||
|
private ItemsListBuilder builder;
|
||||||
|
private RegionsAdapter regionsAdapter;
|
||||||
|
private MapsAdapter mapsAdapter;
|
||||||
|
private VoicePromtsAdapter voicePromtsAdapter;
|
||||||
|
|
||||||
|
private TextView mapsTextView;
|
||||||
|
private ListView mapsListView;
|
||||||
|
private TextView regionsTextView;
|
||||||
|
private ListView regionsListView;
|
||||||
|
private TextView voicePromtsTextView;
|
||||||
|
private ListView voicePromtsListView;
|
||||||
|
|
||||||
|
private static final String REGION_KEY = "world_region_key";
|
||||||
|
private WorldRegion region;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
WorldRegion region = null;
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
Object regionObj = savedInstanceState.getSerializable(REGION_KEY);
|
||||||
|
if (regionObj != null) {
|
||||||
|
region = (WorldRegion)regionObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (region == null) {
|
||||||
|
Object regionObj = getArguments().getSerializable(REGION_KEY);
|
||||||
|
if (regionObj != null) {
|
||||||
|
region = (WorldRegion)regionObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.region = region;
|
||||||
|
|
||||||
|
View view = inflater.inflate(R.layout.download_index_fragment, container, false);
|
||||||
|
|
||||||
|
builder = new ItemsListBuilder(getMyApplication(), this.region);
|
||||||
|
|
||||||
|
mapsTextView = (TextView) view.findViewById(R.id.list_world_regions_title);
|
||||||
|
mapsTextView.setText("Region maps".toUpperCase());
|
||||||
|
mapsListView = (ListView) view.findViewById(R.id.list_world_regions);
|
||||||
|
mapsAdapter = new MapsAdapter(getActivity());
|
||||||
|
mapsListView.setAdapter(mapsAdapter);
|
||||||
|
|
||||||
|
regionsTextView = (TextView) view.findViewById(R.id.list_world_maps_title);
|
||||||
|
regionsTextView.setText("Additional maps".toUpperCase());
|
||||||
|
regionsListView = (ListView) view.findViewById(R.id.list_world_maps);
|
||||||
|
regionsAdapter = new RegionsAdapter(getActivity());
|
||||||
|
regionsListView.setAdapter(regionsAdapter);
|
||||||
|
regionsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
Object obj = regionsAdapter.getItem(position);
|
||||||
|
if (obj instanceof WorldRegion) {
|
||||||
|
WorldRegion region = (WorldRegion) obj;
|
||||||
|
((LocalDialogFragment) getParentFragment())
|
||||||
|
.onRegionSelected(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
voicePromtsTextView = (TextView) view.findViewById(R.id.list_voice_promts_title);
|
||||||
|
voicePromtsTextView.setText("Voice promts".toUpperCase());
|
||||||
|
voicePromtsListView = (ListView) view.findViewById(R.id.list_voice_promts);
|
||||||
|
voicePromtsAdapter = new VoicePromtsAdapter(getActivity(), getMyApplication());
|
||||||
|
voicePromtsListView.setAdapter(voicePromtsAdapter);
|
||||||
|
|
||||||
|
if (builder.build()) {
|
||||||
|
fillMapsAdapter();
|
||||||
|
fillRegionsAdapter();
|
||||||
|
fillVoicePromtsAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setListViewHeightBasedOnChildren(ListView listView) {
|
||||||
|
ListAdapter listAdapter = listView.getAdapter();
|
||||||
|
if (listAdapter == null) {
|
||||||
|
// pre-condition
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalHeight = 0;
|
||||||
|
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||||
|
View listItem = listAdapter.getView(i, null, listView);
|
||||||
|
listItem.measure(0, 0);
|
||||||
|
totalHeight += listItem.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
||||||
|
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
||||||
|
listView.setLayoutParams(params);
|
||||||
|
listView.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putSerializable(REGION_KEY, region);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsmandApplication getMyApplication() {
|
||||||
|
return (OsmandApplication)getActivity().getApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillRegionsAdapter() {
|
||||||
|
if (regionsAdapter != null) {
|
||||||
|
regionsAdapter.clear();
|
||||||
|
regionsAdapter.addAll(builder.getAllResourceItems());
|
||||||
|
updateVisibility(regionsAdapter, regionsTextView, regionsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillMapsAdapter() {
|
||||||
|
if (mapsAdapter != null) {
|
||||||
|
mapsAdapter.clear();
|
||||||
|
mapsAdapter.addAll(builder.getRegionMapItems());
|
||||||
|
updateVisibility(mapsAdapter, mapsTextView, mapsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillVoicePromtsAdapter() {
|
||||||
|
if (voicePromtsAdapter != null) {
|
||||||
|
voicePromtsAdapter.clear();
|
||||||
|
//voicePromtsAdapter.addAll(cats);
|
||||||
|
updateVisibility(voicePromtsAdapter, voicePromtsTextView, voicePromtsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVisibility(ArrayAdapter adapter, TextView textView, ListView listView) {
|
||||||
|
if (adapter.isEmpty()) {
|
||||||
|
textView.setVisibility(View.GONE);
|
||||||
|
listView.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
textView.setVisibility(View.VISIBLE);
|
||||||
|
listView.setVisibility(View.VISIBLE);
|
||||||
|
setListViewHeightBasedOnChildren(listView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DownloadActivity getDownloadActivity() {
|
||||||
|
return (DownloadActivity) getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalItemsFragment createInstance(WorldRegion region) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putSerializable(REGION_KEY, region);
|
||||||
|
LocalItemsFragment fragment = new LocalItemsFragment();
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MapsAdapter extends ArrayAdapter<ItemsListBuilder.ResourceItem> {
|
||||||
|
|
||||||
|
public MapsAdapter(Context context) {
|
||||||
|
super(context, R.layout.simple_list_menu_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ItemViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.two_line_with_images_list_item, parent, false);
|
||||||
|
viewHolder = new ItemViewHolder(convertView);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ItemViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
ItemsListBuilder.ResourceItem item = getItem(position);
|
||||||
|
viewHolder.bindIndexItem(item.getIndexItem(), (DownloadActivity) getContext(), true, false);
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RegionsAdapter extends ArrayAdapter {
|
||||||
|
|
||||||
|
public RegionsAdapter(Context context) {
|
||||||
|
super(context, R.layout.two_line_with_images_list_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ItemViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.two_line_with_images_list_item, parent, false);
|
||||||
|
viewHolder = new ItemViewHolder(convertView);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ItemViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
Object item = getItem(position);
|
||||||
|
if (item instanceof WorldRegion) {
|
||||||
|
viewHolder.bindRegion((WorldRegion) item, (DownloadActivity) getContext());
|
||||||
|
} else if (item instanceof ItemsListBuilder.ResourceItem) {
|
||||||
|
viewHolder.bindIndexItem(((ItemsListBuilder.ResourceItem) item).getIndexItem(),
|
||||||
|
(DownloadActivity) getContext(), false, true);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Item must be of type WorldRegion or " +
|
||||||
|
"IndexItem but is of type:" + item.getClass());
|
||||||
|
}
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class VoicePromtsAdapter extends ArrayAdapter {
|
||||||
|
private final OsmandApplication osmandApplication;
|
||||||
|
|
||||||
|
public VoicePromtsAdapter(Context context, OsmandApplication osmandApplication) {
|
||||||
|
super(context, R.layout.simple_list_menu_item);
|
||||||
|
this.osmandApplication = osmandApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
RegionItemViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.simple_list_menu_item, parent, false);
|
||||||
|
viewHolder = new RegionItemViewHolder();
|
||||||
|
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (RegionItemViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
Drawable iconLeft = osmandApplication.getIconsCache()
|
||||||
|
.getContentIcon(R.drawable.ic_world_globe_dark);
|
||||||
|
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
|
||||||
|
viewHolder.textView.setText(getItem(position).toString());
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RegionItemViewHolder {
|
||||||
|
TextView textView;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -11,6 +12,7 @@ import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -21,26 +23,34 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.WorldRegion;
|
import net.osmand.plus.WorldRegion;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
|
<<<<<<< HEAD:OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java
|
||||||
|
import net.osmand.plus.download.newimplementation.MapsInCategoryFragment;
|
||||||
|
=======
|
||||||
import net.osmand.plus.download.newimplementation.DownloadsUiInitHelper;
|
import net.osmand.plus.download.newimplementation.DownloadsUiInitHelper;
|
||||||
|
>>>>>>> 380dcbe6d79e0f54421d0b67ce3688dfe910e78e:OsmAnd/src/net/osmand/plus/download/items/DownloadItemsFragment.java
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class DownloadItemsFragment extends Fragment {
|
public class WorldItemsFragment extends Fragment {
|
||||||
private static final Log LOG = PlatformUtil.getLog(DownloadItemsFragment.class);
|
public static final String TAG = "WorldItemsFragment";
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
|
||||||
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
|
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
|
||||||
|
|
||||||
public static final int RELOAD_ID = 0;
|
public static final int RELOAD_ID = 0;
|
||||||
|
|
||||||
private ItemsListBuilder builder;
|
private ItemsListBuilder builder;
|
||||||
private WorldRegionsAdapter worldRegionsAdapter;
|
private WorldRegionsAdapter worldRegionsAdapter;
|
||||||
private WorldMapAdapter worldMapAdapter;
|
private WorldMapsAdapter worldMapsAdapter;
|
||||||
private VoicePromtsAdapter voicePromtsAdapter;
|
private VoicePromtsAdapter voicePromtsAdapter;
|
||||||
|
|
||||||
|
private TextView worldRegionsTextView;
|
||||||
private ListView worldRegionsListView;
|
private ListView worldRegionsListView;
|
||||||
private ListView worldMapListView;
|
private TextView worldMapsTextView;
|
||||||
|
private ListView worldMapsListView;
|
||||||
|
private TextView voicePromtsTextView;
|
||||||
private ListView voicePromtsListView;
|
private ListView voicePromtsListView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,28 +64,37 @@ public class DownloadItemsFragment extends Fragment {
|
||||||
View view = inflater.inflate(R.layout.download_index_fragment, container, false);
|
View view = inflater.inflate(R.layout.download_index_fragment, container, false);
|
||||||
|
|
||||||
builder = new ItemsListBuilder(getMyApplication(), getMyApplication().getWorldRegion());
|
builder = new ItemsListBuilder(getMyApplication(), getMyApplication().getWorldRegion());
|
||||||
boolean hasBuilt = builder.build();
|
|
||||||
|
|
||||||
|
worldRegionsTextView = (TextView) view.findViewById(R.id.list_world_regions_title);
|
||||||
|
worldRegionsTextView.setText("World regions".toUpperCase());
|
||||||
worldRegionsListView = (ListView) view.findViewById(R.id.list_world_regions);
|
worldRegionsListView = (ListView) view.findViewById(R.id.list_world_regions);
|
||||||
worldRegionsAdapter = new WorldRegionsAdapter(getActivity(), getMyApplication());
|
worldRegionsAdapter = new WorldRegionsAdapter(getActivity(), getMyApplication());
|
||||||
worldRegionsListView.setAdapter(worldRegionsAdapter);
|
worldRegionsListView.setAdapter(worldRegionsAdapter);
|
||||||
if (hasBuilt) {
|
worldRegionsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
fillWorldRegionsAdapter();
|
@Override
|
||||||
}
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
WorldRegion region = worldRegionsAdapter.getItem(position);
|
||||||
|
|
||||||
worldMapListView = (ListView) view.findViewById(R.id.list_world_map);
|
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
||||||
worldMapAdapter = new WorldMapAdapter(getActivity(), getMyApplication());
|
fragmentTransaction.addToBackStack(null);
|
||||||
worldMapListView.setAdapter(worldMapAdapter);
|
LocalDialogFragment.createInstance(region)
|
||||||
if (hasBuilt) {
|
.show(fragmentTransaction, MapsInCategoryFragment.TAG);
|
||||||
fillWorldMapAdapter();
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
worldMapsTextView = (TextView) view.findViewById(R.id.list_world_maps_title);
|
||||||
|
worldMapsTextView.setText("World maps".toUpperCase());
|
||||||
|
worldMapsListView = (ListView) view.findViewById(R.id.list_world_maps);
|
||||||
|
worldMapsAdapter = new WorldMapsAdapter(getActivity());
|
||||||
|
worldMapsListView.setAdapter(worldMapsAdapter);
|
||||||
|
|
||||||
|
voicePromtsTextView = (TextView) view.findViewById(R.id.list_voice_promts_title);
|
||||||
|
voicePromtsTextView.setText("Voice promts".toUpperCase());
|
||||||
voicePromtsListView = (ListView) view.findViewById(R.id.list_voice_promts);
|
voicePromtsListView = (ListView) view.findViewById(R.id.list_voice_promts);
|
||||||
voicePromtsAdapter = new VoicePromtsAdapter(getActivity(), getMyApplication());
|
voicePromtsAdapter = new VoicePromtsAdapter(getActivity(), getMyApplication());
|
||||||
voicePromtsListView.setAdapter(voicePromtsAdapter);
|
voicePromtsListView.setAdapter(voicePromtsAdapter);
|
||||||
if (hasBuilt) {
|
|
||||||
fillVoicePromtsAdapter();
|
onCategorizationFinished();
|
||||||
}
|
|
||||||
|
|
||||||
DownloadsUiInitHelper.initFreeVersionBanner(view,
|
DownloadsUiInitHelper.initFreeVersionBanner(view,
|
||||||
getMyApplication().getSettings(), getResources());
|
getMyApplication().getSettings(), getResources());
|
||||||
|
@ -111,15 +130,15 @@ public class DownloadItemsFragment extends Fragment {
|
||||||
if (worldRegionsAdapter != null) {
|
if (worldRegionsAdapter != null) {
|
||||||
worldRegionsAdapter.clear();
|
worldRegionsAdapter.clear();
|
||||||
worldRegionsAdapter.addAll(builder.getRegionsFromAllItems());
|
worldRegionsAdapter.addAll(builder.getRegionsFromAllItems());
|
||||||
setListViewHeightBasedOnChildren(worldRegionsListView);
|
updateVisibility(worldRegionsAdapter, worldRegionsTextView, worldRegionsListView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillWorldMapAdapter() {
|
private void fillWorldMapsAdapter() {
|
||||||
if (worldMapAdapter != null) {
|
if (worldMapsAdapter != null) {
|
||||||
worldMapAdapter.clear();
|
worldMapsAdapter.clear();
|
||||||
worldMapAdapter.addAll(builder.getRegionMapItems());
|
worldMapsAdapter.addAll(builder.getRegionMapItems());
|
||||||
setListViewHeightBasedOnChildren(worldMapListView);
|
updateVisibility(worldMapsAdapter, worldMapsTextView, worldMapsListView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +146,18 @@ public class DownloadItemsFragment extends Fragment {
|
||||||
if (voicePromtsAdapter != null) {
|
if (voicePromtsAdapter != null) {
|
||||||
voicePromtsAdapter.clear();
|
voicePromtsAdapter.clear();
|
||||||
//voicePromtsAdapter.addAll(cats);
|
//voicePromtsAdapter.addAll(cats);
|
||||||
|
updateVisibility(voicePromtsAdapter, voicePromtsTextView, voicePromtsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVisibility(ArrayAdapter adapter, TextView textView, ListView listView) {
|
||||||
|
if (adapter.isEmpty()) {
|
||||||
|
textView.setVisibility(View.GONE);
|
||||||
|
listView.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
textView.setVisibility(View.VISIBLE);
|
||||||
|
listView.setVisibility(View.VISIBLE);
|
||||||
|
setListViewHeightBasedOnChildren(listView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +185,7 @@ public class DownloadItemsFragment extends Fragment {
|
||||||
public void onCategorizationFinished() {
|
public void onCategorizationFinished() {
|
||||||
if (builder.build()) {
|
if (builder.build()) {
|
||||||
fillWorldRegionsAdapter();
|
fillWorldRegionsAdapter();
|
||||||
fillWorldMapAdapter();
|
fillWorldMapsAdapter();
|
||||||
fillVoicePromtsAdapter();
|
fillVoicePromtsAdapter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,30 +222,25 @@ public class DownloadItemsFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class WorldMapAdapter extends ArrayAdapter<ItemsListBuilder.ResourceItem> {
|
private static class WorldMapsAdapter extends ArrayAdapter<ItemsListBuilder.ResourceItem> {
|
||||||
private final OsmandApplication osmandApplication;
|
|
||||||
|
|
||||||
public WorldMapAdapter(Context context, OsmandApplication osmandApplication) {
|
public WorldMapsAdapter(Context context) {
|
||||||
super(context, R.layout.simple_list_menu_item);
|
super(context, R.layout.simple_list_menu_item);
|
||||||
this.osmandApplication = osmandApplication;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
ViewHolder viewHolder;
|
ItemViewHolder viewHolder;
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(parent.getContext())
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.simple_list_menu_item, parent, false);
|
.inflate(R.layout.two_line_with_images_list_item, parent, false);
|
||||||
viewHolder = new ViewHolder();
|
viewHolder = new ItemViewHolder(convertView);
|
||||||
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
|
|
||||||
convertView.setTag(viewHolder);
|
convertView.setTag(viewHolder);
|
||||||
} else {
|
} else {
|
||||||
viewHolder = (ViewHolder) convertView.getTag();
|
viewHolder = (ItemViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
Drawable iconLeft = osmandApplication.getIconsCache()
|
ItemsListBuilder.ResourceItem item = getItem(position);
|
||||||
.getContentIcon(R.drawable.ic_world_globe_dark);
|
viewHolder.bindIndexItem(item.getIndexItem(), (DownloadActivity) getContext(), false, false);
|
||||||
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
|
|
||||||
viewHolder.textView.setText(getItem(position).getTitle());
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,284 @@
|
||||||
|
package net.osmand.plus.download.items;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
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.ListAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.WorldRegion;
|
||||||
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
|
<<<<<<< HEAD:OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java
|
||||||
|
import net.osmand.plus.download.newimplementation.MapsInCategoryFragment;
|
||||||
|
=======
|
||||||
|
import net.osmand.plus.download.newimplementation.DownloadsUiInitHelper;
|
||||||
|
>>>>>>> 380dcbe6d79e0f54421d0b67ce3688dfe910e78e:OsmAnd/src/net/osmand/plus/download/items/DownloadItemsFragment.java
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class WorldItemsFragment extends Fragment {
|
||||||
|
public static final String TAG = "WorldItemsFragment";
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
|
||||||
|
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
|
||||||
|
|
||||||
|
public static final int RELOAD_ID = 0;
|
||||||
|
|
||||||
|
private ItemsListBuilder builder;
|
||||||
|
private WorldRegionsAdapter worldRegionsAdapter;
|
||||||
|
private WorldMapsAdapter worldMapsAdapter;
|
||||||
|
private VoicePromtsAdapter voicePromtsAdapter;
|
||||||
|
|
||||||
|
private TextView worldRegionsTextView;
|
||||||
|
private ListView worldRegionsListView;
|
||||||
|
private TextView worldMapsTextView;
|
||||||
|
private ListView worldMapsListView;
|
||||||
|
private TextView voicePromtsTextView;
|
||||||
|
private ListView voicePromtsListView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.download_index_fragment, container, false);
|
||||||
|
|
||||||
|
builder = new ItemsListBuilder(getMyApplication(), getMyApplication().getWorldRegion());
|
||||||
|
|
||||||
|
worldRegionsTextView = (TextView) view.findViewById(R.id.list_world_regions_title);
|
||||||
|
worldRegionsTextView.setText("World regions".toUpperCase());
|
||||||
|
worldRegionsListView = (ListView) view.findViewById(R.id.list_world_regions);
|
||||||
|
worldRegionsAdapter = new WorldRegionsAdapter(getActivity(), getMyApplication());
|
||||||
|
worldRegionsListView.setAdapter(worldRegionsAdapter);
|
||||||
|
worldRegionsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
WorldRegion region = worldRegionsAdapter.getItem(position);
|
||||||
|
|
||||||
|
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
||||||
|
fragmentTransaction.addToBackStack(null);
|
||||||
|
LocalDialogFragment.createInstance(region)
|
||||||
|
.show(fragmentTransaction, MapsInCategoryFragment.TAG);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
worldMapsTextView = (TextView) view.findViewById(R.id.list_world_maps_title);
|
||||||
|
worldMapsTextView.setText("World maps".toUpperCase());
|
||||||
|
worldMapsListView = (ListView) view.findViewById(R.id.list_world_maps);
|
||||||
|
worldMapsAdapter = new WorldMapsAdapter(getActivity());
|
||||||
|
worldMapsListView.setAdapter(worldMapsAdapter);
|
||||||
|
|
||||||
|
voicePromtsTextView = (TextView) view.findViewById(R.id.list_voice_promts_title);
|
||||||
|
voicePromtsTextView.setText("Voice promts".toUpperCase());
|
||||||
|
voicePromtsListView = (ListView) view.findViewById(R.id.list_voice_promts);
|
||||||
|
voicePromtsAdapter = new VoicePromtsAdapter(getActivity(), getMyApplication());
|
||||||
|
voicePromtsListView.setAdapter(voicePromtsAdapter);
|
||||||
|
|
||||||
|
onCategorizationFinished();
|
||||||
|
|
||||||
|
DownloadsUiInitHelper.initFreeVersionBanner(view,
|
||||||
|
getMyApplication().getSettings(), getResources());
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setListViewHeightBasedOnChildren(ListView listView) {
|
||||||
|
ListAdapter listAdapter = listView.getAdapter();
|
||||||
|
if (listAdapter == null) {
|
||||||
|
// pre-condition
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalHeight = 0;
|
||||||
|
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||||
|
View listItem = listAdapter.getView(i, null, listView);
|
||||||
|
listItem.measure(0, 0);
|
||||||
|
totalHeight += listItem.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
||||||
|
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
||||||
|
listView.setLayoutParams(params);
|
||||||
|
listView.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsmandApplication getMyApplication() {
|
||||||
|
return (OsmandApplication)getActivity().getApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillWorldRegionsAdapter() {
|
||||||
|
if (worldRegionsAdapter != null) {
|
||||||
|
worldRegionsAdapter.clear();
|
||||||
|
worldRegionsAdapter.addAll(builder.getRegionsFromAllItems());
|
||||||
|
updateVisibility(worldRegionsAdapter, worldRegionsTextView, worldRegionsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillWorldMapsAdapter() {
|
||||||
|
if (worldMapsAdapter != null) {
|
||||||
|
worldMapsAdapter.clear();
|
||||||
|
worldMapsAdapter.addAll(builder.getRegionMapItems());
|
||||||
|
updateVisibility(worldMapsAdapter, worldMapsTextView, worldMapsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillVoicePromtsAdapter() {
|
||||||
|
if (voicePromtsAdapter != null) {
|
||||||
|
voicePromtsAdapter.clear();
|
||||||
|
//voicePromtsAdapter.addAll(cats);
|
||||||
|
updateVisibility(voicePromtsAdapter, voicePromtsTextView, voicePromtsListView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVisibility(ArrayAdapter adapter, TextView textView, ListView listView) {
|
||||||
|
if (adapter.isEmpty()) {
|
||||||
|
textView.setVisibility(View.GONE);
|
||||||
|
listView.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
textView.setVisibility(View.VISIBLE);
|
||||||
|
listView.setVisibility(View.VISIBLE);
|
||||||
|
setListViewHeightBasedOnChildren(listView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
MenuItem item = menu.add(0, RELOAD_ID, 0, R.string.shared_string_refresh);
|
||||||
|
item.setIcon(R.drawable.ic_action_refresh_dark);
|
||||||
|
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == RELOAD_ID) {
|
||||||
|
// re-create the thread
|
||||||
|
DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DownloadActivity getDownloadActivity() {
|
||||||
|
return (DownloadActivity) getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCategorizationFinished() {
|
||||||
|
if (builder.build()) {
|
||||||
|
fillWorldRegionsAdapter();
|
||||||
|
fillWorldMapsAdapter();
|
||||||
|
fillVoicePromtsAdapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class WorldRegionsAdapter extends ArrayAdapter<WorldRegion> {
|
||||||
|
private final OsmandApplication osmandApplication;
|
||||||
|
|
||||||
|
public WorldRegionsAdapter(Context context, OsmandApplication osmandApplication) {
|
||||||
|
super(context, R.layout.simple_list_menu_item);
|
||||||
|
this.osmandApplication = osmandApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.simple_list_menu_item, parent, false);
|
||||||
|
viewHolder = new ViewHolder();
|
||||||
|
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
Drawable iconLeft = osmandApplication.getIconsCache()
|
||||||
|
.getContentIcon(R.drawable.ic_world_globe_dark);
|
||||||
|
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
|
||||||
|
viewHolder.textView.setText(getItem(position).getName());
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
TextView textView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class WorldMapsAdapter extends ArrayAdapter<ItemsListBuilder.ResourceItem> {
|
||||||
|
|
||||||
|
public WorldMapsAdapter(Context context) {
|
||||||
|
super(context, R.layout.simple_list_menu_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ItemViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.two_line_with_images_list_item, parent, false);
|
||||||
|
viewHolder = new ItemViewHolder(convertView);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ItemViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
ItemsListBuilder.ResourceItem item = getItem(position);
|
||||||
|
viewHolder.bindIndexItem(item.getIndexItem(), (DownloadActivity) getContext(), false, false);
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
TextView textView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class VoicePromtsAdapter extends ArrayAdapter {
|
||||||
|
private final OsmandApplication osmandApplication;
|
||||||
|
|
||||||
|
public VoicePromtsAdapter(Context context, OsmandApplication osmandApplication) {
|
||||||
|
super(context, R.layout.simple_list_menu_item);
|
||||||
|
this.osmandApplication = osmandApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.simple_list_menu_item, parent, false);
|
||||||
|
viewHolder = new ViewHolder();
|
||||||
|
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
Drawable iconLeft = osmandApplication.getIconsCache()
|
||||||
|
.getContentIcon(R.drawable.ic_world_globe_dark);
|
||||||
|
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
|
||||||
|
viewHolder.textView.setText(getItem(position).toString());
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
TextView textView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue