Fix
This commit is contained in:
parent
e2bc3b9221
commit
a827bfe325
9 changed files with 302 additions and 230 deletions
|
@ -1,18 +1,5 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.tools.bzip2.CBZip2OutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -25,6 +12,19 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.tools.bzip2.CBZip2OutputStream;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
|
||||
public class FavouritesDbHelper {
|
||||
|
||||
public interface FavoritesUpdatedListener {
|
||||
|
@ -582,6 +582,8 @@ public class FavouritesDbHelper {
|
|||
if(renamedGroup == null) {
|
||||
renamedGroup = gr;
|
||||
flatGroups.put(gr.name, gr);
|
||||
} else {
|
||||
favoriteGroups.remove(gr);
|
||||
}
|
||||
for(FavouritePoint p : gr.points) {
|
||||
p.setCategory(newName);
|
||||
|
|
|
@ -1,5 +1,37 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -35,38 +67,6 @@ import android.widget.ImageView;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
|
||||
public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||
|
@ -527,7 +527,6 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
});
|
||||
builder.show();
|
||||
|
||||
}
|
||||
|
||||
private void deleteFavoritesAction() {
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.activities;
|
|||
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
@ -19,7 +18,6 @@ import net.osmand.plus.SQLiteTileSource;
|
|||
import net.osmand.plus.download.ui.LocalIndexesFragment.LoadLocalIndexTask;
|
||||
import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
||||
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
|
|
|
@ -34,13 +34,11 @@ import net.osmand.plus.activities.EditPOIFilterActivity;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandListActivity;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.poi.NominatimPoiFilter;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.poi.PoiUIFilter.AmenityNameFilter;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.views.DirectionDrawable;
|
||||
import net.osmand.plus.views.POIMapLayer;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
|
@ -58,10 +56,7 @@ import android.support.v4.view.MenuItemCompat;
|
|||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
|
|
@ -7,6 +7,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -36,6 +38,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class DownloadActivity extends BaseDownloadActivity {
|
||||
private List<LocalIndexInfo> localIndexInfos = new ArrayList<>();
|
||||
|
@ -345,6 +348,44 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadLocalIndexes() {
|
||||
AsyncTask<Void, String, List<String>> task = new AsyncTask<Void, String, List<String>>() {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> doInBackground(Void... params) {
|
||||
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
|
||||
new ArrayList<String>()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<String> warnings) {
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
if (!warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if (f) {
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
b.append(w);
|
||||
}
|
||||
AccessibleToast.makeText(DownloadActivity.this, b.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
newDownloadIndexes();
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -126,7 +126,7 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
return type.getBasename(this);
|
||||
}
|
||||
|
||||
private File getTargetFile(OsmandApplication ctx) {
|
||||
public File getTargetFile(OsmandApplication ctx) {
|
||||
String basename;
|
||||
if (type == DownloadActivityType.HILLSHADE_FILE) {
|
||||
basename = (FileNameTranslationHelper.HILL_SHADE + getBasename()).replace("_", " ");
|
||||
|
@ -171,7 +171,7 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
}
|
||||
|
||||
public boolean isOutdated() {
|
||||
return outdated;
|
||||
return outdated && getType() != DownloadActivityType.HILLSHADE_FILE ;
|
||||
}
|
||||
|
||||
public void setOutdated(boolean outdated) {
|
||||
|
|
|
@ -1,26 +1,34 @@
|
|||
package net.osmand.plus.download.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadResourceGroup;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
@ -137,8 +145,7 @@ public class ItemViewHolder {
|
|||
}
|
||||
int color = textColorSecondary;
|
||||
if(indexItem.isDownloaded() && !isDownloading) {
|
||||
int colorId = indexItem.getType() != DownloadActivityType.HILLSHADE_FILE &&
|
||||
indexItem.isOutdated() ? R.color.color_distance : R.color.color_ok;
|
||||
int colorId = indexItem.isOutdated() ? R.color.color_distance : R.color.color_ok;
|
||||
color = context.getResources().getColor(colorId);
|
||||
}
|
||||
if (indexItem.isDownloaded()) {
|
||||
|
@ -170,14 +177,7 @@ public class ItemViewHolder {
|
|||
descrTextView.setText(indexItem.getSizeDescription(context) + " • " +
|
||||
(showRemoteDate ? indexItem.getRemoteDate(dateFormat) : indexItem.getLocalDate(dateFormat)));
|
||||
}
|
||||
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
|
||||
rightImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
download(indexItem, parentOptional);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
progressBar.setIndeterminate(progress == -1);
|
||||
|
@ -201,17 +201,6 @@ public class ItemViewHolder {
|
|||
descrTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark));
|
||||
rightImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (silentCancelDownload) {
|
||||
context.getDownloadThread().cancelDownload(indexItem);
|
||||
} else {
|
||||
context.makeSureUserCancelDownload(indexItem);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,17 +238,27 @@ public class ItemViewHolder {
|
|||
builder.show();
|
||||
}
|
||||
|
||||
private boolean checkDisabledAndClickAction(final IndexItem indexItem) {
|
||||
RightButtonAction clickAction = getClickAction(indexItem);
|
||||
private boolean checkDisabledAndClickAction(final IndexItem item) {
|
||||
RightButtonAction clickAction = getClickAction(item);
|
||||
boolean disabled = clickAction != RightButtonAction.DOWNLOAD;
|
||||
OnClickListener action = getRightButtonAction(item, clickAction, null);
|
||||
if (clickAction != RightButtonAction.DOWNLOAD) {
|
||||
rightButton.setText(R.string.get_plugin);
|
||||
rightButton.setVisibility(View.VISIBLE);
|
||||
rightImageButton.setVisibility(View.GONE);
|
||||
rightButton.setOnClickListener(getRightButtonAction(indexItem, clickAction, null));
|
||||
rightButton.setOnClickListener(action);
|
||||
} else {
|
||||
rightButton.setVisibility(View.GONE);
|
||||
rightImageButton.setVisibility(View.VISIBLE);
|
||||
final boolean isDownloading = context.getDownloadThread().isDownloading(item);
|
||||
if (isDownloading) {
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark));
|
||||
} else if(item.isDownloaded() && !item.isOutdated()) {
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_overflow_menu_white));
|
||||
} else {
|
||||
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
|
||||
}
|
||||
rightImageButton.setOnClickListener(action);
|
||||
}
|
||||
|
||||
return disabled;
|
||||
|
@ -328,6 +327,8 @@ public class ItemViewHolder {
|
|||
} else {
|
||||
context.makeSureUserCancelDownload(item);
|
||||
}
|
||||
} else if(item.isDownloaded() && !item.isOutdated()){
|
||||
contextMenu(v, item, parentOptional);
|
||||
} else {
|
||||
download(item, parentOptional);
|
||||
}
|
||||
|
@ -336,6 +337,61 @@ public class ItemViewHolder {
|
|||
}
|
||||
}
|
||||
|
||||
protected void contextMenu(View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) {
|
||||
final PopupMenu optionsMenu = new PopupMenu(context, v);
|
||||
MenuItem item;
|
||||
|
||||
final File fl = indexItem.getTargetFile(context.getMyApplication());
|
||||
if (fl.exists()) {
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(
|
||||
context.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
LocalIndexType tp = LocalIndexType.MAP_DATA;
|
||||
if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
|
||||
tp = LocalIndexType.TILES_DATA;
|
||||
} else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
|
||||
tp = LocalIndexType.MAP_DATA;
|
||||
} else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
tp = LocalIndexType.SRTM_DATA;
|
||||
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
|
||||
tp = LocalIndexType.MAP_DATA;
|
||||
} else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
|
||||
tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA
|
||||
: LocalIndexType.VOICE_DATA;
|
||||
}
|
||||
final LocalIndexInfo info = new LocalIndexInfo(tp, fl, false);
|
||||
Builder confirm = new Builder(context);
|
||||
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new LocalIndexOperationTask(context, null, LocalIndexOperationTask.DELETE_OPERATION)
|
||||
.execute(info);
|
||||
}
|
||||
});
|
||||
confirm.setNegativeButton(R.string.shared_string_no, null);
|
||||
String fn = FileNameTranslationHelper.getFileName(context, context.getMyApplication().getRegions(),
|
||||
indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
|
||||
confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn));
|
||||
confirm.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_download)
|
||||
.setIcon(context.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_import));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
download(indexItem, parentOptional);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
optionsMenu.show();
|
||||
}
|
||||
|
||||
private Drawable getContentIcon(DownloadActivity context, int resourceId) {
|
||||
return context.getMyApplication().getIconsCache().getContentIcon(resourceId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,41 @@
|
|||
package net.osmand.plus.download.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.Collator;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.LocalIndexHelper;
|
||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -11,6 +47,7 @@ import android.graphics.PorterDuff;
|
|||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.AsyncTask.Status;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
|
@ -35,43 +72,6 @@ import android.widget.ImageButton;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.LocalIndexHelper;
|
||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.Collator;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents {
|
||||
|
@ -83,9 +83,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
private boolean selectionMode = false;
|
||||
private Set<LocalIndexInfo> selectedItems = new LinkedHashSet<LocalIndexInfo>();
|
||||
|
||||
protected static int DELETE_OPERATION = 1;
|
||||
protected static int BACKUP_OPERATION = 2;
|
||||
protected static int RESTORE_OPERATION = 3;
|
||||
|
||||
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
||||
private ContextMenuAdapter optionsMenuAdapter;
|
||||
|
@ -118,8 +115,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
// getLastNonConfigurationInstance method should be in onCreate() method
|
||||
// (onResume() doesn't work)
|
||||
Object indexes = getActivity().getLastNonConfigurationInstance();
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
if (indexes instanceof List<?>) {
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
asyncLoader.setResult((List<LocalIndexInfo>) indexes);
|
||||
}
|
||||
}
|
||||
|
@ -160,8 +157,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
|
||||
public void reloadData() {
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
asyncLoader.execute(getActivity());
|
||||
LoadLocalIndexTask current = asyncLoader;
|
||||
if(current == null || current.getStatus() == Status.FINISHED ||
|
||||
current.isCancelled() || current.getResult() != null) {
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
asyncLoader.execute(getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -216,17 +217,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
reloadIndexes();
|
||||
getDownloadActivity().reloadLocalIndexes();
|
||||
}
|
||||
});
|
||||
} else if (resId == R.string.local_index_mi_restore) {
|
||||
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
|
||||
new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.RESTORE_OPERATION).execute(info);
|
||||
} else if (resId == R.string.shared_string_delete) {
|
||||
Builder confirm = new Builder(getActivity());
|
||||
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new LocalIndexOperationTask(DELETE_OPERATION).execute(info);
|
||||
new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.DELETE_OPERATION).execute(info);
|
||||
}
|
||||
});
|
||||
confirm.setNegativeButton(R.string.shared_string_no, null);
|
||||
|
@ -236,7 +237,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
confirm.setMessage(getString(R.string.delete_confirmation_msg, fn));
|
||||
confirm.show();
|
||||
} else if (resId == R.string.local_index_mi_backup) {
|
||||
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
|
||||
new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.BACKUP_OPERATION).execute(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -311,9 +312,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
|
||||
public void setResult(List<LocalIndexInfo> result) {
|
||||
this.result = result;
|
||||
if (result == null) {
|
||||
listAdapter.clear();
|
||||
} else {
|
||||
listAdapter.clear();
|
||||
if (result != null) {
|
||||
for (LocalIndexInfo v : result) {
|
||||
listAdapter.addLocalIndexInfo(v);
|
||||
}
|
||||
|
@ -339,52 +339,67 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
|
||||
}
|
||||
|
||||
private File getFileToRestore(LocalIndexInfo i) {
|
||||
if (i.isBackupedData()) {
|
||||
File parent = new File(i.getPathToData()).getParentFile();
|
||||
if (i.getType() == LocalIndexType.SRTM_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR);
|
||||
} else if (i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.ROADS_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.WIKI_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.MAP_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH);
|
||||
} else if (i.getType() == LocalIndexType.TILES_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.VOICE_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.TTS_VOICE_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
}
|
||||
return new File(parent, i.getFileName());
|
||||
}
|
||||
return new File(i.getPathToData());
|
||||
}
|
||||
|
||||
|
||||
private File getFileToBackup(LocalIndexInfo i) {
|
||||
if (!i.isBackupedData()) {
|
||||
return new File(getMyApplication().getAppPath(IndexConstants.BACKUP_INDEX_DIR), i.getFileName());
|
||||
}
|
||||
return new File(i.getPathToData());
|
||||
}
|
||||
|
||||
|
||||
private boolean move(File from, File to) {
|
||||
if (!to.getParentFile().exists()) {
|
||||
to.getParentFile().mkdirs();
|
||||
}
|
||||
return from.renameTo(to);
|
||||
}
|
||||
|
||||
|
||||
public class LocalIndexOperationTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, String> {
|
||||
public static class LocalIndexOperationTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, String> {
|
||||
protected static int DELETE_OPERATION = 1;
|
||||
protected static int BACKUP_OPERATION = 2;
|
||||
protected static int RESTORE_OPERATION = 3;
|
||||
|
||||
private final int operation;
|
||||
private DownloadActivity a;
|
||||
private LocalIndexesAdapter listAdapter;
|
||||
|
||||
public LocalIndexOperationTask(int operation) {
|
||||
public LocalIndexOperationTask(DownloadActivity a, LocalIndexesAdapter listAdapter, int operation) {
|
||||
this.a = a;
|
||||
this.listAdapter = listAdapter;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
|
||||
private boolean move(File from, File to) {
|
||||
if (!to.getParentFile().exists()) {
|
||||
to.getParentFile().mkdirs();
|
||||
}
|
||||
return from.renameTo(to);
|
||||
}
|
||||
|
||||
private File getFileToBackup(LocalIndexInfo i) {
|
||||
if (!i.isBackupedData()) {
|
||||
return new File(getMyApplication().getAppPath(IndexConstants.BACKUP_INDEX_DIR), i.getFileName());
|
||||
}
|
||||
return new File(i.getPathToData());
|
||||
}
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) a.getApplication();
|
||||
}
|
||||
|
||||
|
||||
private File getFileToRestore(LocalIndexInfo i) {
|
||||
if (i.isBackupedData()) {
|
||||
File parent = new File(i.getPathToData()).getParentFile();
|
||||
if (i.getType() == LocalIndexType.SRTM_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR);
|
||||
} else if (i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.ROADS_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.WIKI_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.MAP_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH);
|
||||
} else if (i.getType() == LocalIndexType.TILES_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.VOICE_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
} else if (i.getType() == LocalIndexType.TTS_VOICE_DATA) {
|
||||
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
}
|
||||
return new File(parent, i.getFileName());
|
||||
}
|
||||
return new File(i.getPathToData());
|
||||
}
|
||||
@Override
|
||||
protected String doInBackground(LocalIndexInfo... params) {
|
||||
int count = 0;
|
||||
|
@ -395,6 +410,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
if (operation == DELETE_OPERATION) {
|
||||
File f = new File(info.getPathToData());
|
||||
successfull = Algorithms.removeAllFiles(f);
|
||||
if (successfull) {
|
||||
getMyApplication().getResourceManager().closeFile(info.getFileName());
|
||||
}
|
||||
} else if (operation == RESTORE_OPERATION) {
|
||||
successfull = move(new File(info.getPathToData()), getFileToRestore(info));
|
||||
if (successfull) {
|
||||
|
@ -415,11 +433,14 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
}
|
||||
if (operation == DELETE_OPERATION) {
|
||||
return getString(R.string.local_index_items_deleted, count, total);
|
||||
a.getDownloadThread().updateLoadedFiles();
|
||||
}
|
||||
if (operation == DELETE_OPERATION) {
|
||||
return a.getString(R.string.local_index_items_deleted, count, total);
|
||||
} else if (operation == BACKUP_OPERATION) {
|
||||
return getString(R.string.local_index_items_backuped, count, total);
|
||||
return a.getString(R.string.local_index_items_backuped, count, total);
|
||||
} else if (operation == RESTORE_OPERATION) {
|
||||
return getString(R.string.local_index_items_restored, count, total);
|
||||
return a.getString(R.string.local_index_items_restored, count, total);
|
||||
}
|
||||
|
||||
return "";
|
||||
|
@ -428,34 +449,38 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
|
||||
@Override
|
||||
protected void onProgressUpdate(LocalIndexInfo... values) {
|
||||
if (operation == DELETE_OPERATION) {
|
||||
listAdapter.delete(values);
|
||||
} else if (operation == BACKUP_OPERATION) {
|
||||
listAdapter.move(values, false);
|
||||
} else if (operation == RESTORE_OPERATION) {
|
||||
listAdapter.move(values, true);
|
||||
if (listAdapter != null) {
|
||||
if (operation == DELETE_OPERATION) {
|
||||
listAdapter.delete(values);
|
||||
} else if (operation == BACKUP_OPERATION) {
|
||||
listAdapter.move(values, false);
|
||||
} else if (operation == RESTORE_OPERATION) {
|
||||
listAdapter.move(values, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
getDownloadActivity().setProgressBarIndeterminateVisibility(true);
|
||||
a.setProgressBarIndeterminateVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
getDownloadActivity().setProgressBarIndeterminateVisibility(false);
|
||||
AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
|
||||
a.setProgressBarIndeterminateVisibility(false);
|
||||
AccessibleToast.makeText(a, result, Toast.LENGTH_LONG).show();
|
||||
if (operation == RESTORE_OPERATION || operation == BACKUP_OPERATION) {
|
||||
listAdapter.clear();
|
||||
reloadIndexes();
|
||||
a.reloadLocalIndexes();
|
||||
} else {
|
||||
a.newDownloadIndexes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
reloadData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -585,11 +610,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
|
||||
public void doAction(int actionResId) {
|
||||
if (actionResId == R.string.local_index_mi_backup) {
|
||||
operationTask = new LocalIndexOperationTask(BACKUP_OPERATION);
|
||||
operationTask = new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.BACKUP_OPERATION);
|
||||
} else if (actionResId == R.string.shared_string_delete) {
|
||||
operationTask = new LocalIndexOperationTask(DELETE_OPERATION);
|
||||
operationTask = new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.DELETE_OPERATION);
|
||||
} else if (actionResId == R.string.local_index_mi_restore) {
|
||||
operationTask = new LocalIndexOperationTask(RESTORE_OPERATION);
|
||||
operationTask = new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.RESTORE_OPERATION);
|
||||
} else {
|
||||
operationTask = null;
|
||||
}
|
||||
|
@ -676,7 +701,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
|
||||
public void localOptionsMenu(final int itemId) {
|
||||
if (itemId == R.string.local_index_mi_reload) {
|
||||
reloadIndexes();
|
||||
getDownloadActivity().reloadLocalIndexes();
|
||||
} else if (itemId == R.string.shared_string_delete) {
|
||||
openSelectionMode(itemId, R.drawable.ic_action_delete_dark,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
@ -720,50 +745,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
|
||||
|
||||
public void reloadIndexes() {
|
||||
listAdapter.clear();
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
AsyncTask<Void, String, List<String>> task = new AsyncTask<Void, String, List<String>>() {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> doInBackground(Void... params) {
|
||||
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
|
||||
new ArrayList<String>()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<String> warnings) {
|
||||
if (getDownloadActivity() == null) {
|
||||
return;
|
||||
}
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
if (!warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if (f) {
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
b.append(w);
|
||||
}
|
||||
AccessibleToast.makeText(getDownloadActivity(), b.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (asyncLoader.getStatus() == Status.PENDING) {
|
||||
asyncLoader.execute(getDownloadActivity());
|
||||
}
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
|
|
|
@ -10,12 +10,10 @@ import java.text.MessageFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -963,6 +961,7 @@ public class ResourceManager {
|
|||
log.error(e, e);
|
||||
}
|
||||
}
|
||||
indexFileNames.remove(fileName);
|
||||
renderer.closeConnection(fileName);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue