diff --git a/OsmAnd/res/layout/fragment_live_updates.xml b/OsmAnd/res/layout/fragment_live_updates.xml
index 3a254030a0..3d303286aa 100644
--- a/OsmAnd/res/layout/fragment_live_updates.xml
+++ b/OsmAnd/res/layout/fragment_live_updates.xml
@@ -1,7 +1,9 @@
-
+
diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java
index 90b46534f5..e5b10e9653 100644
--- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java
+++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java
@@ -1,11 +1,14 @@
package net.osmand.plus.activities;
-import java.io.File;
+import android.os.Parcel;
+import android.os.Parcelable;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
-public class LocalIndexInfo {
+import java.io.File;
+
+public class LocalIndexInfo implements Parcelable {
private LocalIndexType type;
private String description = "";
@@ -155,4 +158,52 @@ public class LocalIndexInfo {
return fileName;
}
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(this.type == null ? -1 : this.type.ordinal());
+ dest.writeString(this.description);
+ dest.writeString(this.name);
+ dest.writeByte(backupedData ? (byte) 1 : (byte) 0);
+ dest.writeByte(corrupted ? (byte) 1 : (byte) 0);
+ dest.writeByte(notSupported ? (byte) 1 : (byte) 0);
+ dest.writeByte(loaded ? (byte) 1 : (byte) 0);
+ dest.writeString(this.subfolder);
+ dest.writeString(this.pathToData);
+ dest.writeString(this.fileName);
+ dest.writeByte(singleFile ? (byte) 1 : (byte) 0);
+ dest.writeInt(this.kbSize);
+ dest.writeByte(expanded ? (byte) 1 : (byte) 0);
+ }
+
+ protected LocalIndexInfo(Parcel in) {
+ int tmpType = in.readInt();
+ this.type = tmpType == -1 ? null : LocalIndexType.values()[tmpType];
+ this.description = in.readString();
+ this.name = in.readString();
+ this.backupedData = in.readByte() != 0;
+ this.corrupted = in.readByte() != 0;
+ this.notSupported = in.readByte() != 0;
+ this.loaded = in.readByte() != 0;
+ this.subfolder = in.readString();
+ this.pathToData = in.readString();
+ this.fileName = in.readString();
+ this.singleFile = in.readByte() != 0;
+ this.kbSize = in.readInt();
+ this.expanded = in.readByte() != 0;
+ }
+
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public LocalIndexInfo createFromParcel(Parcel source) {
+ return new LocalIndexInfo(source);
+ }
+
+ public LocalIndexInfo[] newArray(int size) {
+ return new LocalIndexInfo[size];
+ }
+ };
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/download/AbstractDownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/AbstractDownloadActivity.java
new file mode 100644
index 0000000000..9bcb0ebb6c
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/download/AbstractDownloadActivity.java
@@ -0,0 +1,23 @@
+package net.osmand.plus.download;
+
+import android.os.Bundle;
+
+import net.osmand.plus.activities.ActionBarProgressActivity;
+
+public class AbstractDownloadActivity extends ActionBarProgressActivity {
+ protected DownloadValidationManager downloadValidationManager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ downloadValidationManager = new DownloadValidationManager(getMyApplication());
+ }
+
+ public void startDownload(IndexItem... indexItem) {
+ downloadValidationManager.startDownload(this, indexItem);
+ }
+
+ public void makeSureUserCancelDownload(IndexItem item) {
+ downloadValidationManager.makeSureUserCancelDownload(this, item);
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
index 69088ae2ec..ae984b84d1 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
@@ -41,7 +41,6 @@ import net.osmand.plus.OsmandSettings.DrivingRegion;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.Version;
-import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity;
@@ -68,7 +67,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
-public class DownloadActivity extends ActionBarProgressActivity implements DownloadEvents {
+public class DownloadActivity extends AbstractDownloadActivity implements DownloadEvents {
private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class);
public static final int UPDATES_TAB_NUMBER = 2;
@@ -98,7 +97,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
private String filterGroup;
protected Set> fragSet = new HashSet<>();
private DownloadIndexesThread downloadThread;
- private DownloadValidationManager downloadValidationManager;
protected WorldRegion downloadItem;
private boolean srtmDisabled;
@@ -110,7 +108,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
protected void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this);
super.onCreate(savedInstanceState);
- downloadValidationManager = new DownloadValidationManager(getMyApplication());
downloadThread = getMyApplication().getDownloadThread();
DownloadResources indexes = getDownloadThread().getIndexes();
if (!indexes.isDownloadedFromInternet) {
@@ -165,14 +162,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
return downloadThread;
}
- public void startDownload(IndexItem... indexItem) {
- downloadValidationManager.startDownload(this, indexItem);
- }
-
- public void makeSureUserCancelDownload(IndexItem item) {
- downloadValidationManager.makeSureUserCancelDownload(this, item);
- }
-
@Override
public void onAttachFragment(Fragment fragment) {
fragSet.add(new WeakReference(fragment));
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesActivity.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesActivity.java
index 65330dfba6..7c51a0e7e5 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesActivity.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesActivity.java
@@ -8,9 +8,9 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import net.osmand.plus.R;
-import net.osmand.plus.activities.ActionBarProgressActivity;
+import net.osmand.plus.download.AbstractDownloadActivity;
-public class LiveUpdatesActivity extends ActionBarProgressActivity {
+public class LiveUpdatesActivity extends AbstractDownloadActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -18,9 +18,8 @@ public class LiveUpdatesActivity extends ActionBarProgressActivity {
setContentView(R.layout.activity_livie_updates);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
- String basicTitle = getResources().getString(R.string.tab_title_basic);
- String extendedTitle = getResources().getString(R.string.tab_title_advanced);
- final MyAdapter pagerAdapter = new MyAdapter(getSupportFragmentManager());
+ final LiveUpdatesFragmentPagerAdapter pagerAdapter =
+ new LiveUpdatesFragmentPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter);
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
@@ -28,11 +27,11 @@ public class LiveUpdatesActivity extends ActionBarProgressActivity {
tabLayout.setupWithViewPager(viewPager);
}
- public static class MyAdapter extends FragmentPagerAdapter {
+ public static class LiveUpdatesFragmentPagerAdapter extends FragmentPagerAdapter {
private final Fragment[] fragments = new Fragment[]{new LiveUpdatesFragment()};
private final String[] titles = new String[]{LiveUpdatesFragment.TITILE};
- public MyAdapter(FragmentManager fm) {
+ public LiveUpdatesFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@@ -50,7 +49,5 @@ public class LiveUpdatesActivity extends ActionBarProgressActivity {
public CharSequence getPageTitle(int position) {
return titles[position];
}
-
-
}
}
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
index a1c74b5a34..1ed549d8de 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
@@ -1,40 +1,53 @@
package net.osmand.plus.liveupdates;
-
-import android.app.Dialog;
+import android.content.Context;
+import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
-import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
+import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ImageView;
-import android.widget.ListView;
import android.widget.TextView;
-import android.widget.ToggleButton;
+import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
-import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo;
-import net.osmand.plus.activities.OsmandActionBarActivity;
+import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
+import net.osmand.plus.download.AbstractDownloadActivity;
+import net.osmand.plus.download.DownloadActivityType;
+import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
+import net.osmand.plus.helpers.FileNameTranslationHelper;
+import net.osmand.plus.resources.IncrementalChangesManager;
+import net.osmand.util.Algorithms;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class LiveUpdatesFragment extends Fragment {
public static final String TITILE = "Live Updates";
+ public static final Comparator LOCAL_INDEX_INFO_COMPARATOR = new Comparator() {
+ @Override
+ public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
+ return lhs.getName().compareTo(rhs.getName());
+ }
+ };
+ private ExpandableListView listView;
+ private LocalIndexesAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -45,7 +58,7 @@ public class LiveUpdatesFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_live_updates, container, false);
- ListView listView = (ListView) view.findViewById(android.R.id.list);
+ listView = (ExpandableListView) view.findViewById(android.R.id.list);
View header = inflater.inflate(R.layout.live_updates_header, listView, false);
final OsmandSettings settings = getMyActivity().getMyApplication().getSettings();
@@ -69,35 +82,190 @@ public class LiveUpdatesFragment extends Fragment {
});
listView.addHeaderView(header);
- LiveUpdatesAdapter adapter = new LiveUpdatesAdapter(this);
+ adapter = new LocalIndexesAdapter(this);
listView.setAdapter(adapter);
- new LoadLocalIndexTask(adapter, (ActionBarProgressActivity) getActivity()).execute();
+ new LoadLocalIndexTask(adapter, this).execute();
return view;
}
- private OsmandActionBarActivity getMyActivity() {
- return (OsmandActionBarActivity) getActivity();
+ private AbstractDownloadActivity getMyActivity() {
+ return (AbstractDownloadActivity) getActivity();
}
- private static class LiveUpdatesAdapter extends ArrayAdapter {
+ protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
+ final ArrayList dataShouldUpdate = new ArrayList<>();
+ final ArrayList dataShouldNotUpdate = new ArrayList<>();
final LiveUpdatesFragment fragment;
- public LiveUpdatesAdapter(LiveUpdatesFragment fragment) {
- super(fragment.getActivity(), R.layout.local_index_list_item, R.id.nameTextView);
+ final Context ctx;
+
+ public LocalIndexesAdapter(LiveUpdatesFragment fragment) {
this.fragment = fragment;
+ ctx = fragment.getActivity();
+ }
+
+ public void add(LocalIndexInfo info) {
+ dataShouldNotUpdate.add(info);
+ }
+
+ public void sort() {
+ Collections.sort(dataShouldUpdate, LOCAL_INDEX_INFO_COMPARATOR);
+ Collections.sort(dataShouldNotUpdate, LOCAL_INDEX_INFO_COMPARATOR);
}
@Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = convertView;
- if (view == null) {
- LayoutInflater inflater = LayoutInflater.from(getContext());
- view = inflater.inflate(R.layout.local_index_list_item, parent, false);
- view.setTag(new LocalFullMapsViewHolder(view, fragment));
+ public LocalIndexInfo getChild(int groupPosition, int childPosition) {
+ if (groupPosition == 0) {
+ return dataShouldUpdate.get(childPosition);
+ } else if (groupPosition == 1) {
+ return dataShouldNotUpdate.get(childPosition);
+ } else {
+ throw new IllegalArgumentException("unexpected group position:" + groupPosition);
}
- LocalFullMapsViewHolder viewHolder = (LocalFullMapsViewHolder) view.getTag();
- viewHolder.bindLocalIndexInfo(getItem(position));
- return view;
}
+
+ @Override
+ public long getChildId(int groupPosition, int childPosition) {
+ // it would be unusable to have 10000 local indexes
+ return groupPosition * 10000 + childPosition;
+ }
+
+ @Override
+ public View getChildView(final int groupPosition, final int childPosition,
+ boolean isLastChild, View convertView, ViewGroup parent) {
+ LocalFullMapsViewHolder viewHolder;
+ if (convertView == null) {
+ LayoutInflater inflater = LayoutInflater.from(ctx);
+ convertView = inflater.inflate(R.layout.local_index_list_item, parent, false);
+ viewHolder = new LocalFullMapsViewHolder(convertView, fragment);
+ convertView.setTag(viewHolder);
+ } else {
+ viewHolder = (LocalFullMapsViewHolder) convertView.getTag();
+ }
+ viewHolder.bindLocalIndexInfo(getChild(groupPosition, childPosition));
+ return convertView;
+ }
+
+
+ private String getNameToDisplay(LocalIndexInfo child) {
+ String mapName = FileNameTranslationHelper.getFileName(ctx,
+ fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),
+ child.getFileName());
+ return mapName;
+ }
+
+ @Override
+ public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
+ View v = convertView;
+ String group = getGroup(groupPosition);
+ if (v == null) {
+ LayoutInflater inflater = LayoutInflater.from(ctx);
+ v = inflater.inflate(R.layout.download_item_list_section, parent, false);
+ }
+ TextView nameView = ((TextView) v.findViewById(R.id.section_name));
+ nameView.setText(group);
+
+ v.setOnClickListener(null);
+
+ TypedValue typedValue = new TypedValue();
+ Resources.Theme theme = ctx.getTheme();
+ theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
+ v.setBackgroundColor(typedValue.data);
+ return v;
+ }
+
+ @Override
+ public int getChildrenCount(int groupPosition) {
+ if (groupPosition == 0) {
+ return dataShouldUpdate.size();
+ } else if (groupPosition == 1) {
+ return dataShouldNotUpdate.size();
+ } else {
+ throw new IllegalArgumentException("unexpected group position:" + groupPosition);
+ }
+ }
+
+ @Override
+ public String getGroup(int groupPosition) {
+ if (groupPosition == 0) {
+ return "Live updates on";
+ } else if (groupPosition == 1) {
+ return "Love updates off";
+ } else {
+ throw new IllegalArgumentException("unexpected group position:" + groupPosition);
+ }
+ }
+
+ @Override
+ public int getGroupCount() {
+ return 2;
+ }
+
+ @Override
+ public long getGroupId(int groupPosition) {
+ return groupPosition;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public boolean isChildSelectable(int groupPosition, int childPosition) {
+ return true;
+ }
+
+ }
+
+ private void expandAllGroups() {
+ for (int i = 0; i < adapter.getGroupCount(); i++) {
+ listView.expandGroup(i);
+ }
+ }
+
+ void runLiveUpdate(final LocalIndexInfo info) {
+ final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
+ new AsyncTask