Refactor to localindexfragment

This commit is contained in:
Denis 2014-09-09 16:01:15 +03:00
parent 9b6b51579f
commit 836169da20
14 changed files with 186 additions and 155 deletions

View file

@ -11,7 +11,6 @@ import net.osmand.IndexConstants;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.*; import net.osmand.plus.activities.*;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
@ -111,7 +110,7 @@ public class OsmAndAppCustomization {
return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$; return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$;
} }
public void preDownloadActivity(final DownloadIndexFragment da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar ) { public void preDownloadActivity(final DownloadActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar ) {
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item, ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
toString(downloadTypes) toString(downloadTypes)

View file

@ -19,7 +19,7 @@ import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.activities.*; import net.osmand.plus.activities.*;
import net.osmand.plus.activities.DownloadIndexFragment; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;

View file

@ -11,6 +11,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.sherpafy.TourViewActivity; import net.osmand.plus.sherpafy.TourViewActivity;
import android.app.Activity; import android.app.Activity;

View file

@ -248,7 +248,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
// MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_light, // MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_light,
// R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS // R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS
// | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); // | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
// searchView = new com.actionbarsherlock.widget.SearchView(getMyActivity()); // searchView = new com.actionbarsherlock.widget.SearchView(getDownloadActivity());
// mi.setActionView(searchView); // mi.setActionView(searchView);
// searchView.setOnQueryTextListener(new OnQueryTextListener() { // searchView.setOnQueryTextListener(new OnQueryTextListener() {
// //

View file

@ -23,6 +23,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;

View file

@ -1,5 +1,7 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.widget.TabHost; import android.widget.TabHost;
@ -7,8 +9,13 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.FavouritesActivity; import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* Created by Denis on 08.09.2014. * Created by Denis on 08.09.2014.
@ -37,7 +44,27 @@ public class DownloadActivity extends SherlockFragmentActivity {
LocalIndexesFragment.class, null); LocalIndexesFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator("Downloads"), mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator("Downloads"),
DownloadIndexFragment.class, null); DownloadIndexFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("UPDATES").setIndicator("Updates"),
UpdatesIndexFragment.class, null);
tabHost.setCurrentTab(0); tabHost.setCurrentTab(0);
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
}
@Override
protected void onResume() {
super.onResume();
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
}
} }
public DownloadActivityType getType() { return type;} public DownloadActivityType getType() { return type;}
@ -51,4 +78,37 @@ public class DownloadActivity extends SherlockFragmentActivity {
downloadListIndexThread.runCategorization(tp); downloadListIndexThread.runCategorization(tp);
} }
} }
public void downloadFilesPreCheckSpace() {
double sz = 0;
List<DownloadEntry> list = downloadListIndexThread.flattenDownloadEntries();
for (DownloadEntry es : list) {
sz += es.sizeMB;
}
// get availabile space
double asz = downloadListIndexThread.getAvailableSpace();
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz, asz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadListIndexThread.runDownloadFiles();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} else {
downloadListIndexThread.runDownloadFiles();
}
}
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
if(downloadListIndexThread == null) {
return new LinkedHashMap<IndexItem, List<DownloadEntry>>();
}
return downloadListIndexThread.getEntriesToDownload();
}
} }

View file

@ -8,7 +8,6 @@ import java.util.Map;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@ -48,7 +47,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} }
format = downloadActivity.getMyApplication().getResourceManager().getDateFormat(); format = downloadActivity.getMyApplication().getResourceManager().getDateFormat();
okColor = downloadActivity.getResources().getColor(R.color.color_ok); okColor = downloadActivity.getResources().getColor(R.color.color_ok);
TypedArray ta = downloadActivity.getMyActivity().getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); TypedArray ta = downloadActivity.getDownloadActivity().getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown)); defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown));
ta.recycle(); ta.recycle();
updateColor = downloadActivity.getResources().getColor(R.color.color_update); updateColor = downloadActivity.getResources().getColor(R.color.color_update);
@ -62,7 +61,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} }
public void collapseTrees(final CharSequence constraint) { public void collapseTrees(final CharSequence constraint) {
downloadActivity.getMyActivity().runOnUiThread(new Runnable() { downloadActivity.getDownloadActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
synchronized (DownloadIndexAdapter.this) { synchronized (DownloadIndexAdapter.this) {
@ -125,7 +124,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} }
} }
List<IndexItem> filter = new ArrayList<IndexItem>(); List<IndexItem> filter = new ArrayList<IndexItem>();
Context c = downloadActivity.getMyActivity(); Context c = downloadActivity.getDownloadActivity();
for (IndexItem item : indexFiles) { for (IndexItem item : indexFiles) {
boolean add = true; boolean add = true;
String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename()); String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename());
@ -218,7 +217,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
View v = convertView; View v = convertView;
IndexItemCategory group = getGroup(groupPosition); IndexItemCategory group = getGroup(groupPosition);
if (v == null) { if (v == null) {
LayoutInflater inflater = (LayoutInflater) downloadActivity.getMyActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE ); LayoutInflater inflater = (LayoutInflater) downloadActivity.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false);
} }
final View row = v; final View row = v;
@ -233,7 +232,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
if (v == null) { if (v == null) {
LayoutInflater inflater = (LayoutInflater) downloadActivity.getMyActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE ); LayoutInflater inflater = (LayoutInflater) downloadActivity.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false);
} }
final View row = v; final View row = v;
@ -247,7 +246,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
description.setText(d.trim()); description.setText(d.trim());
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item); CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);
ch.setChecked(downloadActivity.getEntriesToDownload().containsKey(e)); ch.setChecked(downloadActivity.getDownloadActivity().getEntriesToDownload().containsKey(e));
ch.setOnClickListener(new View.OnClickListener() { ch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {

View file

@ -1,4 +1,4 @@
package net.osmand.plus.activities; package net.osmand.plus.download;
import java.io.File; import java.io.File;
@ -17,11 +17,11 @@ import com.actionbarsherlock.view.MenuInflater;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory; import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.base.SuggestExternalDirectoryDialog;
@ -57,8 +57,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public static final String FILTER_KEY = "filter"; public static final String FILTER_KEY = "filter";
public static final String FILTER_CAT = "filter_cat"; public static final String FILTER_CAT = "filter_cat";
public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10; public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
@ -78,7 +76,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final List<DownloadActivityType> downloadTypes = getDownloadTypes(); final List<DownloadActivityType> downloadTypes = getDownloadTypes();
type = downloadTypes.get(0); getDownloadActivity().setType(downloadTypes.get(0));
View view = inflater.inflate(R.layout.download_index, container, false); View view = inflater.inflate(R.layout.download_index, container, false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list); ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
List<IndexItem> list = new ArrayList<IndexItem>(); List<IndexItem> list = new ArrayList<IndexItem>();
@ -142,13 +140,13 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (filterCat != null) { if (filterCat != null) {
DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase()); DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
if (type != null) { if (type != null) {
this.type = type; getDownloadActivity().setType(type);
downloadTypes.remove(type); downloadTypes.remove(type);
downloadTypes.add(0, type); downloadTypes.add(0, type);
} }
} }
} }
getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getMyActivity().getSupportActionBar()); getMyApplication().getAppCustomization().preDownloadActivity(getDownloadActivity(), downloadTypes, getDownloadActivity().getSupportActionBar());
return view; return view;
} }
@ -156,16 +154,11 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
settings = ((OsmandApplication) getMyApplication()).getSettings();
if(downloadListIndexThread == null) { DownloadActivity.downloadListIndexThread.setUiActivity(this);
downloadListIndexThread = new DownloadIndexesThread(getActivity());
} settings = getMyApplication().getSettings();
downloadListIndexThread.setUiActivity(this);
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) { if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
boolean showedDialog = false; boolean showedDialog = false;
@ -198,7 +191,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (currentDirectoryNotWritable) { if (currentDirectoryNotWritable) {
final String newLoc = settings.getMatchingExternalFilesDir(currentStorage); final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
if (newLoc != null && newLoc.length() != 0) { if (newLoc != null && newLoc.length() != 0) {
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(getMyActivity()); AccessibleAlertBuilder ab = new AccessibleAlertBuilder(getDownloadActivity());
ab.setMessage(getString(R.string.android_19_location_disabled, ab.setMessage(getString(R.string.android_19_location_disabled,
settings.getExternalStorageDirectory())); settings.getExternalStorageDirectory()));
ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@ -217,7 +210,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
private void copyFilesForAndroid19(final String newLoc) { private void copyFilesForAndroid19(final String newLoc) {
MoveFilesToDifferentDirectory task = MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(getMyActivity(), new MoveFilesToDifferentDirectory(getDownloadActivity(),
new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR), new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
new File(newLoc, IndexConstants.APP_DIR)) { new File(newLoc, IndexConstants.APP_DIR)) {
protected Boolean doInBackground(Void[] params) { protected Boolean doInBackground(Void[] params) {
@ -237,8 +230,8 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getMyApplication().setDownloadActivity(this); getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false); updateProgress(false);
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) { if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
View mainView = getView().findViewById(R.id.MainLayout); View mainView = getView().findViewById(R.id.MainLayout);
if (mainView != null) { if (mainView != null) {
@ -257,7 +250,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
int count = 0; int count = 0;
int sz = 0; int sz = 0;
String s = ""; String s = "";
for (IndexItem i : downloadListIndexThread.getCachedIndexFiles()) { for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) { for (String map : maps) {
if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) { if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) {
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1)); final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
@ -269,12 +262,12 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
s +=", "; s +=", ";
} }
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions()); s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getEntriesToDownload().put(i, de); getDownloadActivity().getEntriesToDownload().put(i, de);
} }
} }
} }
if(count > 0){ if(count > 0){
Builder builder = new AlertDialog.Builder(getMyActivity()); Builder builder = new AlertDialog.Builder(getDownloadActivity());
builder.setMessage(getString(R.string.download_additional_maps, s, sz)); builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override @Override
@ -286,14 +279,14 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
getEntriesToDownload().clear(); getDownloadActivity().getEntriesToDownload().clear();
} }
}); });
builder.setOnCancelListener(new DialogInterface.OnCancelListener() { builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
getEntriesToDownload().clear(); getDownloadActivity().getEntriesToDownload().clear();
} }
}); });
builder.show(); builder.show();
@ -304,7 +297,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
private void showDialogOfFreeDownloadsIfNeeded() { private void showDialogOfFreeDownloadsIfNeeded() {
if (Version.isFreeVersion(getMyApplication())) { if (Version.isFreeVersion(getMyApplication())) {
Builder msg = new AlertDialog.Builder(getMyActivity()); Builder msg = new AlertDialog.Builder(getDownloadActivity());
msg.setTitle(R.string.free_version_title); msg.setTitle(R.string.free_version_title);
String m = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "") + "\n"; String m = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "") + "\n";
m += getString(R.string.available_downloads_left, MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get()); m += getString(R.string.available_downloads_left, MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get());
@ -332,7 +325,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) { if (item.getItemId() == RELOAD_ID) {
// re-create the thread // re-create the thread
downloadListIndexThread.runReloadIndexFiles(); DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
return true; return true;
} else if (item.getItemId() == SELECT_ALL_ID) { } else if (item.getItemId() == SELECT_ALL_ID) {
selectAll(); selectAll();
@ -361,24 +354,13 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
} }
} }
public DownloadActivityType getType() {
return type;
}
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
if(downloadListIndexThread == null) {
return new LinkedHashMap<IndexItem, List<DownloadEntry>>();
}
return downloadListIndexThread.getEntriesToDownload();
}
public String getFilterText() { public String getFilterText() {
return filterText.getText().toString(); return filterText.getText().toString();
} }
public void deselectAll() { public void deselectAll() {
downloadListIndexThread.getEntriesToDownload().clear(); DownloadActivity.downloadListIndexThread.getEntriesToDownload().clear();
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
getView().findViewById(R.id.DownloadButton).setVisibility(View.GONE); getView().findViewById(R.id.DownloadButton).setVisibility(View.GONE);
@ -386,7 +368,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
private void filterExisting() { private void filterExisting() {
final Map<String, String> listAlreadyDownloaded = downloadListIndexThread.getDownloadedIndexFileNames(); final Map<String, String> listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames();
final List<IndexItem> filtered = new ArrayList<IndexItem>(); final List<IndexItem> filtered = new ArrayList<IndexItem>();
for (IndexItem fileItem : listAdapter.getIndexFiles()) { for (IndexItem fileItem : listAdapter.getIndexFiles()) {
@ -404,13 +386,14 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
for (int j = 0; j < listAdapter.getGroupCount(); j++) { for (int j = 0; j < listAdapter.getGroupCount(); j++) {
for (int i = 0; i < listAdapter.getChildrenCount(j); i++) { for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
IndexItem es = listAdapter.getChild(j, i); IndexItem es = listAdapter.getChild(j, i);
if (!getEntriesToDownload().containsKey(es)) { if (!getDownloadActivity().getEntriesToDownload().containsKey(es)) {
selected++; selected++;
getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>(1))); getDownloadActivity().getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(),
getDownloadActivity().getType(), new ArrayList<DownloadEntry>(1)));
} }
} }
} }
AccessibleToast.makeText(getMyActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show(); AccessibleToast.makeText(getDownloadActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
if(selected > 0){ if(selected > 0){
updateDownloadButton(true); updateDownloadButton(true);
@ -422,14 +405,14 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
View view = getView(); View view = getView();
int x = getExpandableListView().getScrollX(); int x = getExpandableListView().getScrollX();
int y = getExpandableListView().getScrollY(); int y = getExpandableListView().getScrollY();
if (getEntriesToDownload().isEmpty()) { if (getDownloadActivity().getEntriesToDownload().isEmpty()) {
view.findViewById(R.id.DownloadButton).setVisibility(View.GONE); view.findViewById(R.id.DownloadButton).setVisibility(View.GONE);
} else { } else {
BasicProgressAsyncTask<?, ?, ?> task = downloadListIndexThread.getCurrentRunningTask(); BasicProgressAsyncTask<?, ?, ?> task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask; boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
((Button) view.findViewById(R.id.DownloadButton)).setEnabled(!running); ((Button) view.findViewById(R.id.DownloadButton)).setEnabled(!running);
String text; String text;
int downloads = downloadListIndexThread.getDownloads(); int downloads = DownloadActivity.downloadListIndexThread.getDownloads();
if (!running) { if (!running) {
text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$ text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
} else { } else {
@ -437,12 +420,12 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
} }
view.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE); view.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
if (Version.isFreeVersion(getMyApplication())) { if (Version.isFreeVersion(getMyApplication())) {
int countedDownloads = downloadListIndexThread.getDownloads(); int countedDownloads = DownloadActivity.downloadListIndexThread.getDownloads();
int left = MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads; int left = MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
boolean excessLimit = left < 0; boolean excessLimit = left < 0;
if (left < 0) if (left < 0)
left = 0; left = 0;
if (DownloadActivityType.isCountedInDownloads(getType())) { if (DownloadActivityType.isCountedInDownloads(getDownloadActivity().getType())) {
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")"; text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
} }
} }
@ -468,24 +451,15 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
return items; return items;
} }
public void changeType(final DownloadActivityType tp) {
getMyActivity().invalidateOptionsMenu();
if (downloadListIndexThread != null && type != tp) {
type = tp;
downloadListIndexThread.runCategorization(tp);
}
}
private void makeSureUserCancelDownload() { private void makeSureUserCancelDownload() {
Builder bld = new AlertDialog.Builder(getMyActivity()); Builder bld = new AlertDialog.Builder(getDownloadActivity());
bld.setTitle(getString(R.string.default_buttons_cancel)); bld.setTitle(getString(R.string.default_buttons_cancel));
bld.setMessage(R.string.confirm_interrupt_download); bld.setMessage(R.string.confirm_interrupt_download);
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() { bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); dialog.dismiss();
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask(); BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t != null) { if(t != null) {
t.setInterrupted(true); t.setInterrupted(true);
} }
@ -503,16 +477,16 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if(ch.isChecked()){ if(ch.isChecked()){
ch.setChecked(!ch.isChecked()); ch.setChecked(!ch.isChecked());
getEntriesToDownload().remove(e); getDownloadActivity().getEntriesToDownload().remove(e);
updateDownloadButton(true); updateDownloadButton(true);
return true; return true;
} }
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>()); List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) { if (download.size() > 0) {
// if(!fileToUnzip.exists()){ // if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue()))); // builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
getEntriesToDownload().put(e, download); getDownloadActivity().getEntriesToDownload().put(e, download);
updateDownloadButton(true); updateDownloadButton(true);
ch.setChecked(!ch.isChecked()); ch.setChecked(!ch.isChecked());
} }
@ -558,7 +532,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (Version.isFreeVersion(getMyApplication()) ) { if (Version.isFreeVersion(getMyApplication()) ) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get(); int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
boolean wiki = false; boolean wiki = false;
for (IndexItem es : downloadListIndexThread.getEntriesToDownload().keySet()) { for (IndexItem es : DownloadActivity.downloadListIndexThread.getEntriesToDownload().keySet()) {
if (es.getBasename() != null && es.getBasename().contains("_wiki")) { if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
wiki = true; wiki = true;
break; break;
@ -568,7 +542,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
} }
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) { if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + ""); String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
Builder msg = new AlertDialog.Builder(getMyActivity()); Builder msg = new AlertDialog.Builder(getDownloadActivity());
msg.setTitle(R.string.free_version_title); msg.setTitle(R.string.free_version_title);
msg.setMessage(msgTx); msg.setMessage(msgTx);
msg.setPositiveButton(R.string.default_buttons_ok, null); msg.setPositiveButton(R.string.default_buttons_ok, null);
@ -584,46 +558,21 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
protected void downloadFilesCheckInternet() { protected void downloadFilesCheckInternet() {
if(!getMyApplication().getSettings().isWifiConnected()) { if(!getMyApplication().getSettings().isWifiConnected()) {
Builder builder = new AlertDialog.Builder(getMyActivity()); Builder builder = new AlertDialog.Builder(getDownloadActivity());
builder.setMessage(getString(R.string.download_using_mobile_internet)); builder.setMessage(getString(R.string.download_using_mobile_internet));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
downloadFilesPreCheckSpace(); getDownloadActivity().downloadFilesPreCheckSpace();
} }
}); });
builder.setNegativeButton(R.string.default_buttons_no, null); builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show(); builder.show();
} else { } else {
downloadFilesPreCheckSpace(); getDownloadActivity().downloadFilesPreCheckSpace();
} }
} }
protected void downloadFilesPreCheckSpace() {
double sz = 0;
List<DownloadEntry> list = downloadListIndexThread.flattenDownloadEntries();
for (DownloadEntry es : list) {
sz += es.sizeMB;
}
// get availabile space
double asz = downloadListIndexThread.getAvailableSpace();
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
Builder builder = new AlertDialog.Builder(getMyActivity());
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz, asz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadListIndexThread.runDownloadFiles();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} else {
downloadListIndexThread.runDownloadFiles();
}
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -631,12 +580,12 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
EditText filterText = (EditText) getView().findViewById(R.id.search_box); EditText filterText = (EditText) getView().findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher); filterText.removeTextChangedListener(textWatcher);
} }
downloadListIndexThread.setUiActivity(null); DownloadActivity.downloadListIndexThread.setUiActivity(null);
} }
public void updateProgress(boolean updateOnlyProgress) { public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask(); BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(updateOnlyProgress) { if(updateOnlyProgress) {
if(!basicProgressAsyncTask.isIndeterminate()) { if(!basicProgressAsyncTask.isIndeterminate()) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%"); progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
@ -662,7 +611,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
} }
} }
public DownloadActivity getMyActivity(){ return (DownloadActivity)getActivity();} public DownloadActivity getDownloadActivity(){ return (DownloadActivity)getActivity();}
public ExpandableListAdapter getExpandableListAdapter(){ return listAdapter;} public ExpandableListAdapter getExpandableListAdapter(){ return listAdapter;}

View file

@ -23,7 +23,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
@ -323,7 +322,7 @@ public class DownloadIndexesThread {
if (de.isAsset) { if (de.isAsset) {
try { try {
if (uiActivity != null) { if (uiActivity != null) {
ResourceManager.copyAssets(uiActivity.getMyActivity().getAssets(), de.assetName, de.targetFile); ResourceManager.copyAssets(uiActivity.getDownloadActivity().getAssets(), de.assetName, de.targetFile);
boolean changedDate = de.targetFile.setLastModified(de.dateModified); boolean changedDate = de.targetFile.setLastModified(de.dateModified);
if(!changedDate) { if(!changedDate) {
log.error("Set last timestamp is not supported"); log.error("Set last timestamp is not supported");
@ -385,8 +384,8 @@ public class DownloadIndexesThread {
List<DownloadEntry> downloadEntry = basemap List<DownloadEntry> downloadEntry = basemap
.createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE, .createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE,
new ArrayList<DownloadEntry>()); new ArrayList<DownloadEntry>());
uiActivity.getEntriesToDownload().put(basemap, downloadEntry); uiActivity.getDownloadActivity().getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity.getMyActivity(), R.string.basemap_was_selected_to_download, AccessibleToast.makeText(uiActivity.getDownloadActivity(), R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE); uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
} }
@ -400,7 +399,7 @@ public class DownloadIndexesThread {
currentRunningTask.remove(this); currentRunningTask.remove(this);
if (uiActivity != null) { if (uiActivity != null) {
uiActivity.updateProgress(false); uiActivity.updateProgress(false);
runCategorization(uiActivity.getType()); runCategorization(uiActivity.getDownloadActivity().getType());
} }
} }
@ -507,7 +506,7 @@ public class DownloadIndexesThread {
if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE) if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE)
&& OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin && OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
&& !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) { && !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
Builder msg = new AlertDialog.Builder(uiActivity.getMyActivity()); Builder msg = new AlertDialog.Builder(uiActivity.getDownloadActivity());
msg.setTitle(R.string.srtm_paid_version_title); msg.setTitle(R.string.srtm_paid_version_title);
msg.setMessage(R.string.srtm_paid_version_msg); msg.setMessage(R.string.srtm_paid_version_msg);
msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() { msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() {

View file

@ -67,24 +67,29 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
private ContextMenuAdapter optionsMenuAdapter; private ContextMenuAdapter optionsMenuAdapter;
private ActionMode actionMode; private ActionMode actionMode;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.local_index, container, false);
getDownloadActivity().getSupportActionBar().setTitle(R.string.local_index_descr_title);
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
listAdapter = new LocalIndexesAdapter(getActivity());
listView.setAdapter(listAdapter);
setListView(listView);
//getDownloadActivity().getSupportActionBar().setLogo(R.drawable.tab_download_screen_icon);
return view;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
//requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//setContentView(R.layout.local_index);
//getSupportActionBar().setTitle(R.string.local_index_descr_title);
//setSupportProgressBarIndeterminateVisibility(false);
// getSupportActionBar().setLogo(R.drawable.tab_download_screen_icon);
descriptionLoader = new LoadLocalIndexDescriptionTask(); descriptionLoader = new LoadLocalIndexDescriptionTask();
listAdapter = new LocalIndexesAdapter(getActivity());
setAdapter(listAdapter);
updateDescriptionTextWithSize(); updateDescriptionTextWithSize();
if (asyncLoader == null || asyncLoader.getResult() == null) { if (asyncLoader == null || asyncLoader.getResult() == null) {
// getLastNonConfigurationInstance method should be in onCreate() method // getLastNonConfigurationInstance method should be in onCreate() method
@ -191,7 +196,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
String newName = editText.getText().toString(); String newName = editText.getText().toString();
File dest = new File(f.getParentFile(), newName); File dest = new File(f.getParentFile(), newName);
if (dest.exists()) { if (dest.exists()) {
AccessibleToast.makeText(getMyActivity(), R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
} else { } else {
if(!f.getParentFile().exists()) { if(!f.getParentFile().exists()) {
f.getParentFile().mkdirs(); f.getParentFile().mkdirs();
@ -199,7 +204,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
if(f.renameTo(dest)){ if(f.renameTo(dest)){
reloadIndexes(); reloadIndexes();
} else { } else {
AccessibleToast.makeText(getMyActivity(), R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
} }
} }
@ -226,7 +231,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
getMyActivity().setSupportProgressBarIndeterminateVisibility(true); getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
} }
@Override @Override
@ -253,7 +258,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
protected void onPostExecute(List<LocalIndexInfo> result) { protected void onPostExecute(List<LocalIndexInfo> result) {
this.result = result; this.result = result;
getMyActivity().setSupportProgressBarIndeterminateVisibility(false); getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
} }
public List<LocalIndexInfo> getResult() { public List<LocalIndexInfo> getResult() {
@ -358,13 +363,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
getMyActivity().setProgressBarIndeterminateVisibility(true); getDownloadActivity().setProgressBarIndeterminateVisibility(true);
} }
@Override @Override
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
getMyActivity().setProgressBarIndeterminateVisibility(false); getDownloadActivity().setProgressBarIndeterminateVisibility(false);
AccessibleToast.makeText(getMyActivity(), result, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
listAdapter.clear(); listAdapter.clear();
reloadIndexes(); reloadIndexes();
@ -447,7 +452,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
optionsMenuAdapter = new ContextMenuAdapter(getMyActivity()); optionsMenuAdapter = new ContextMenuAdapter(getDownloadActivity());
OnContextMenuClick listener = new OnContextMenuClick() { OnContextMenuClick listener = new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
@ -466,7 +471,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
optionsMenuAdapter.item(R.string.local_index_mi_delete) optionsMenuAdapter.item(R.string.local_index_mi_delete)
.icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light) .icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light)
.listen(listener).position(4).reg(); .listen(listener).position(4).reg();
OsmandPlugin.onOptionsMenuActivity(getMyActivity(), null, optionsMenuAdapter); OsmandPlugin.onOptionsMenuActivity(getDownloadActivity(), null, optionsMenuAdapter);
// doesn't work correctly // doesn't work correctly
int max = getResources().getInteger(R.integer.abs__max_action_buttons); int max = getResources().getInteger(R.integer.abs__max_action_buttons);
SubMenu split = null; SubMenu split = null;
@ -549,20 +554,20 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
final String actionButton = value; final String actionButton = value;
if(listAdapter.getGroupCount() == 0){ if(listAdapter.getGroupCount() == 0){
listAdapter.cancelFilter(); listAdapter.cancelFilter();
AccessibleToast.makeText(getMyActivity(), getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show(); AccessibleToast.makeText(getDownloadActivity(), getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return; return;
} }
collapseAllGroups(); collapseAllGroups();
selectionMode = true; selectionMode = true;
selectedItems.clear(); selectedItems.clear();
actionMode = getMyActivity().startActionMode(new Callback() { actionMode = getDownloadActivity().startActionMode(new Callback() {
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
selectionMode = true; selectionMode = true;
MenuItem it = menu.add(actionResId); MenuItem it = menu.add(actionResId);
if(actionIconId != 0) { if (actionIconId != 0) {
it.setIcon(actionIconId); it.setIcon(actionIconId);
} }
it.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | it.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM |
@ -578,12 +583,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (selectedItems.isEmpty()) { if (selectedItems.isEmpty()) {
AccessibleToast.makeText(getMyActivity(), AccessibleToast.makeText(getDownloadActivity(),
getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show(); getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return true; return true;
} }
Builder builder = new AlertDialog.Builder(getMyActivity()); Builder builder = new AlertDialog.Builder(getDownloadActivity());
builder.setMessage(getString(R.string.local_index_action_do, actionButton.toLowerCase(), selectedItems.size())); builder.setMessage(getString(R.string.local_index_action_do, actionButton.toLowerCase(), selectedItems.size()));
builder.setPositiveButton(actionButton, listener); builder.setPositiveButton(actionButton, listener);
builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.setNegativeButton(R.string.default_buttons_cancel, null);
@ -624,7 +629,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
public void onClick(View widget) { public void onClick(View widget) {
asyncLoader.setResult(null); asyncLoader.setResult(null);
startActivity(new Intent(getMyActivity(), DownloadIndexFragment.class)); startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
} }
@Override @Override
@ -642,7 +647,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public void localOptionsMenu(final int itemId) { public void localOptionsMenu(final int itemId) {
if (itemId == R.string.local_index_download) { if (itemId == R.string.local_index_download) {
asyncLoader.setResult(null); asyncLoader.setResult(null);
startActivity(new Intent(getMyActivity(), DownloadIndexFragment.class)); startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
} else if (itemId == R.string.local_index_mi_reload) { } else if (itemId == R.string.local_index_mi_reload) {
reloadIndexes(); reloadIndexes();
} else if (itemId == R.string.local_index_mi_delete) { } else if (itemId == R.string.local_index_mi_delete) {
@ -695,7 +700,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
protected void onPostExecute(List<String> warnings) { protected void onPostExecute(List<String> warnings) {
getMyActivity().setProgressBarIndeterminateVisibility(false); getDownloadActivity().setProgressBarIndeterminateVisibility(false);
if (!warnings.isEmpty()) { if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
boolean f = true; boolean f = true;
@ -707,17 +712,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
} }
b.append(w); b.append(w);
} }
AccessibleToast.makeText(getMyActivity(), b.toString(), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), b.toString(), Toast.LENGTH_LONG).show();
} }
if(asyncLoader.getStatus() == Status.PENDING) { if(asyncLoader.getStatus() == Status.PENDING) {
asyncLoader.execute(getMyActivity()); asyncLoader.execute(getDownloadActivity());
} }
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
getMyActivity().setProgressBarIndeterminateVisibility(true); getDownloadActivity().setProgressBarIndeterminateVisibility(true);
} }
@Override @Override
protected List<String> doInBackground(Void... params) { protected List<String> doInBackground(Void... params) {
@ -865,12 +870,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
View v = convertView; View v = convertView;
final LocalIndexInfo child = (LocalIndexInfo) getChild(groupPosition, childPosition); final LocalIndexInfo child = (LocalIndexInfo) getChild(groupPosition, childPosition);
if (v == null ) { if (v == null ) {
LayoutInflater inflater = (LayoutInflater) getMyActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE ); LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
} }
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name)); TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
String mapDescr = getMapDescription(child.getFileName()); String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getMyActivity().getApplication()).getResourceManager().getOsmandRegions(), child.getFileName()); String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getDownloadActivity().getApplication()).getResourceManager().getOsmandRegions(), child.getFileName());
if (mapDescr.length() > 0){ if (mapDescr.length() > 0){
viewName.setText(mapDescr + " - " + mapName); viewName.setText(mapDescr + " - " + mapName);
@ -939,10 +944,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
View v = convertView; View v = convertView;
LocalIndexInfo group = getGroup(groupPosition); LocalIndexInfo group = getGroup(groupPosition);
if (v == null) { if (v == null) {
LayoutInflater inflater = (LayoutInflater) getMyActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE ); LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false);
} }
StringBuilder t = new StringBuilder(group.getType().getHumanString(getMyActivity())); StringBuilder t = new StringBuilder(group.getType().getHumanString(getDownloadActivity()));
if(group.getSubfolder() != null) { if(group.getSubfolder() != null) {
t.append(" ").append(group.getSubfolder()); t.append(" ").append(group.getSubfolder());
} }
@ -1024,5 +1029,5 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
} }
} }
private DownloadActivity getMyActivity(){ return (DownloadActivity)getActivity();} private DownloadActivity getDownloadActivity(){ return (DownloadActivity)getActivity();}
} }

View file

@ -0,0 +1,18 @@
package net.osmand.plus.download;
import android.view.View;
import android.widget.ExpandableListView;
import net.osmand.plus.activities.OsmandExpandableListFragment;
/**
* Created by Denis on 09.09.2014.
*/
public class UpdatesIndexFragment extends OsmandExpandableListFragment {
@Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
return false;
}
}

View file

@ -31,7 +31,7 @@ import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.DownloadIndexFragment; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.SelectedGPXFragment; import net.osmand.plus.activities.SelectedGPXFragment;
@ -107,8 +107,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) { public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase(); acCode = acCode.toUpperCase();
if(DownloadIndexFragment.downloadListIndexThread != null) { if(DownloadActivity.downloadListIndexThread != null) {
DownloadIndexFragment.downloadListIndexThread.clear(); DownloadActivity.downloadListIndexThread.clear();
} }
if(validate(acCode) || Algorithms.isEmpty(acCode)) { if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode); accessCodePref.set(acCode);

View file

@ -5,7 +5,7 @@ import java.util.WeakHashMap;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
import net.osmand.plus.sherpafy.TourInformation.StageInformation; import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import android.content.Intent; import android.content.Intent;

View file

@ -12,7 +12,7 @@ import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;