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.data.LocationPoint;
import net.osmand.plus.activities.*;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadActivity;
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$;
}
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);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
toString(downloadTypes)

View file

@ -19,7 +19,7 @@ import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode;
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.SQLiteAPIImpl;
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.Version;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.sherpafy.TourViewActivity;
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,
// R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS
// | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
// searchView = new com.actionbarsherlock.widget.SearchView(getMyActivity());
// searchView = new com.actionbarsherlock.widget.SearchView(getDownloadActivity());
// mi.setActionView(searchView);
// searchView.setOnQueryTextListener(new OnQueryTextListener() {
//

View file

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

View file

@ -1,5 +1,7 @@
package net.osmand.plus.download;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.TabHost;
@ -7,8 +9,13 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment;
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.
@ -37,7 +44,27 @@ public class DownloadActivity extends SherlockFragmentActivity {
LocalIndexesFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator("Downloads"),
DownloadIndexFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("UPDATES").setIndicator("Updates"),
UpdatesIndexFragment.class, null);
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;}
@ -51,4 +78,37 @@ public class DownloadActivity extends SherlockFragmentActivity {
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.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import android.content.Context;
import android.content.res.TypedArray;
@ -48,7 +47,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
format = downloadActivity.getMyApplication().getResourceManager().getDateFormat();
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));
ta.recycle();
updateColor = downloadActivity.getResources().getColor(R.color.color_update);
@ -62,7 +61,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
public void collapseTrees(final CharSequence constraint) {
downloadActivity.getMyActivity().runOnUiThread(new Runnable() {
downloadActivity.getDownloadActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (DownloadIndexAdapter.this) {
@ -125,7 +124,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
}
List<IndexItem> filter = new ArrayList<IndexItem>();
Context c = downloadActivity.getMyActivity();
Context c = downloadActivity.getDownloadActivity();
for (IndexItem item : indexFiles) {
boolean add = true;
String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename());
@ -218,7 +217,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
View v = convertView;
IndexItemCategory group = getGroup(groupPosition);
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);
}
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) {
View v = convertView;
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);
}
final View row = v;
@ -247,7 +246,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
description.setText(d.trim());
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() {
@Override
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;
@ -17,11 +17,11 @@ import com.actionbarsherlock.view.MenuInflater;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask;
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_CAT = "filter_cat";
public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
@ -78,7 +76,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final List<DownloadActivityType> downloadTypes = getDownloadTypes();
type = downloadTypes.get(0);
getDownloadActivity().setType(downloadTypes.get(0));
View view = inflater.inflate(R.layout.download_index, container, false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
List<IndexItem> list = new ArrayList<IndexItem>();
@ -142,13 +140,13 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (filterCat != null) {
DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
if (type != null) {
this.type = type;
getDownloadActivity().setType(type);
downloadTypes.remove(type);
downloadTypes.add(0, type);
}
}
}
getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getMyActivity().getSupportActionBar());
getMyApplication().getAppCustomization().preDownloadActivity(getDownloadActivity(), downloadTypes, getDownloadActivity().getSupportActionBar());
return view;
}
@ -156,16 +154,11 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = ((OsmandApplication) getMyApplication()).getSettings();
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(getActivity());
}
downloadListIndexThread.setUiActivity(this);
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
DownloadActivity.downloadListIndexThread.setUiActivity(this);
settings = getMyApplication().getSettings();
if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
boolean showedDialog = false;
@ -198,7 +191,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (currentDirectoryNotWritable) {
final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
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,
settings.getExternalStorageDirectory()));
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) {
MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(getMyActivity(),
new MoveFilesToDifferentDirectory(getDownloadActivity(),
new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
new File(newLoc, IndexConstants.APP_DIR)) {
protected Boolean doInBackground(Void[] params) {
@ -237,8 +230,8 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false);
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
View mainView = getView().findViewById(R.id.MainLayout);
if (mainView != null) {
@ -257,7 +250,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
int count = 0;
int sz = 0;
String s = "";
for (IndexItem i : downloadListIndexThread.getCachedIndexFiles()) {
for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) {
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));
@ -269,12 +262,12 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
s +=", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getEntriesToDownload().put(i, de);
getDownloadActivity().getEntriesToDownload().put(i, de);
}
}
}
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.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
@ -286,14 +279,14 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
getEntriesToDownload().clear();
getDownloadActivity().getEntriesToDownload().clear();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
getEntriesToDownload().clear();
getDownloadActivity().getEntriesToDownload().clear();
}
});
builder.show();
@ -304,7 +297,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
private void showDialogOfFreeDownloadsIfNeeded() {
if (Version.isFreeVersion(getMyApplication())) {
Builder msg = new AlertDialog.Builder(getMyActivity());
Builder msg = new AlertDialog.Builder(getDownloadActivity());
msg.setTitle(R.string.free_version_title);
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());
@ -332,7 +325,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) {
// re-create the thread
downloadListIndexThread.runReloadIndexFiles();
DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
return true;
} else if (item.getItemId() == SELECT_ALL_ID) {
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() {
return filterText.getText().toString();
}
public void deselectAll() {
downloadListIndexThread.getEntriesToDownload().clear();
DownloadActivity.downloadListIndexThread.getEntriesToDownload().clear();
listAdapter.notifyDataSetInvalidated();
getView().findViewById(R.id.DownloadButton).setVisibility(View.GONE);
@ -386,7 +368,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
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>();
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
@ -404,13 +386,14 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
for (int j = 0; j < listAdapter.getGroupCount(); j++) {
for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
IndexItem es = listAdapter.getChild(j, i);
if (!getEntriesToDownload().containsKey(es)) {
if (!getDownloadActivity().getEntriesToDownload().containsKey(es)) {
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();
if(selected > 0){
updateDownloadButton(true);
@ -422,14 +405,14 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
View view = getView();
int x = getExpandableListView().getScrollX();
int y = getExpandableListView().getScrollY();
if (getEntriesToDownload().isEmpty()) {
if (getDownloadActivity().getEntriesToDownload().isEmpty()) {
view.findViewById(R.id.DownloadButton).setVisibility(View.GONE);
} else {
BasicProgressAsyncTask<?, ?, ?> task = downloadListIndexThread.getCurrentRunningTask();
BasicProgressAsyncTask<?, ?, ?> task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
((Button) view.findViewById(R.id.DownloadButton)).setEnabled(!running);
String text;
int downloads = downloadListIndexThread.getDownloads();
int downloads = DownloadActivity.downloadListIndexThread.getDownloads();
if (!running) {
text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
} else {
@ -437,12 +420,12 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
}
view.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
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;
boolean excessLimit = left < 0;
if (left < 0)
left = 0;
if (DownloadActivityType.isCountedInDownloads(getType())) {
if (DownloadActivityType.isCountedInDownloads(getDownloadActivity().getType())) {
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
}
}
@ -468,24 +451,15 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
return items;
}
public void changeType(final DownloadActivityType tp) {
getMyActivity().invalidateOptionsMenu();
if (downloadListIndexThread != null && type != tp) {
type = tp;
downloadListIndexThread.runCategorization(tp);
}
}
private void makeSureUserCancelDownload() {
Builder bld = new AlertDialog.Builder(getMyActivity());
Builder bld = new AlertDialog.Builder(getDownloadActivity());
bld.setTitle(getString(R.string.default_buttons_cancel));
bld.setMessage(R.string.confirm_interrupt_download);
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t != null) {
t.setInterrupted(true);
}
@ -503,16 +477,16 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if(ch.isChecked()){
ch.setChecked(!ch.isChecked());
getEntriesToDownload().remove(e);
getDownloadActivity().getEntriesToDownload().remove(e);
updateDownloadButton(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(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
getEntriesToDownload().put(e, download);
getDownloadActivity().getEntriesToDownload().put(e, download);
updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
}
@ -558,7 +532,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (Version.isFreeVersion(getMyApplication()) ) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
boolean wiki = false;
for (IndexItem es : downloadListIndexThread.getEntriesToDownload().keySet()) {
for (IndexItem es : DownloadActivity.downloadListIndexThread.getEntriesToDownload().keySet()) {
if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
wiki = true;
break;
@ -568,7 +542,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
}
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
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.setMessage(msgTx);
msg.setPositiveButton(R.string.default_buttons_ok, null);
@ -584,46 +558,21 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
protected void downloadFilesCheckInternet() {
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.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadFilesPreCheckSpace();
getDownloadActivity().downloadFilesPreCheckSpace();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} 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
public void onDestroy() {
super.onDestroy();
@ -631,12 +580,12 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
EditText filterText = (EditText) getView().findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
downloadListIndexThread.setUiActivity(null);
DownloadActivity.downloadListIndexThread.setUiActivity(null);
}
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask();
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(updateOnlyProgress) {
if(!basicProgressAsyncTask.isIndeterminate()) {
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;}

View file

@ -23,7 +23,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.resources.ResourceManager;
@ -323,7 +322,7 @@ public class DownloadIndexesThread {
if (de.isAsset) {
try {
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);
if(!changedDate) {
log.error("Set last timestamp is not supported");
@ -385,8 +384,8 @@ public class DownloadIndexesThread {
List<DownloadEntry> downloadEntry = basemap
.createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE,
new ArrayList<DownloadEntry>());
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity.getMyActivity(), R.string.basemap_was_selected_to_download,
uiActivity.getDownloadActivity().getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity.getDownloadActivity(), R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show();
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
}
@ -400,7 +399,7 @@ public class DownloadIndexesThread {
currentRunningTask.remove(this);
if (uiActivity != null) {
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)
&& OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
&& !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.setMessage(R.string.srtm_paid_version_msg);
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 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")
@Override
public void onCreate(Bundle savedInstanceState) {
//requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
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();
listAdapter = new LocalIndexesAdapter(getActivity());
setAdapter(listAdapter);
updateDescriptionTextWithSize();
if (asyncLoader == null || asyncLoader.getResult() == null) {
// getLastNonConfigurationInstance method should be in onCreate() method
@ -191,7 +196,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
String newName = editText.getText().toString();
File dest = new File(f.getParentFile(), newName);
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 {
if(!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
@ -199,7 +204,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
if(f.renameTo(dest)){
reloadIndexes();
} 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
protected void onPreExecute() {
getMyActivity().setSupportProgressBarIndeterminateVisibility(true);
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
}
@Override
@ -253,7 +258,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
protected void onPostExecute(List<LocalIndexInfo> result) {
this.result = result;
getMyActivity().setSupportProgressBarIndeterminateVisibility(false);
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
}
public List<LocalIndexInfo> getResult() {
@ -358,13 +363,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
protected void onPreExecute() {
getMyActivity().setProgressBarIndeterminateVisibility(true);
getDownloadActivity().setProgressBarIndeterminateVisibility(true);
}
@Override
protected void onPostExecute(String result) {
getMyActivity().setProgressBarIndeterminateVisibility(false);
AccessibleToast.makeText(getMyActivity(), result, Toast.LENGTH_LONG).show();
getDownloadActivity().setProgressBarIndeterminateVisibility(false);
AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
listAdapter.clear();
reloadIndexes();
@ -447,7 +452,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
optionsMenuAdapter = new ContextMenuAdapter(getMyActivity());
optionsMenuAdapter = new ContextMenuAdapter(getDownloadActivity());
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
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)
.icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light)
.listen(listener).position(4).reg();
OsmandPlugin.onOptionsMenuActivity(getMyActivity(), null, optionsMenuAdapter);
OsmandPlugin.onOptionsMenuActivity(getDownloadActivity(), null, optionsMenuAdapter);
// doesn't work correctly
int max = getResources().getInteger(R.integer.abs__max_action_buttons);
SubMenu split = null;
@ -549,20 +554,20 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
final String actionButton = value;
if(listAdapter.getGroupCount() == 0){
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;
}
collapseAllGroups();
selectionMode = true;
selectedItems.clear();
actionMode = getMyActivity().startActionMode(new Callback() {
actionMode = getDownloadActivity().startActionMode(new Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
selectionMode = true;
MenuItem it = menu.add(actionResId);
if(actionIconId != 0) {
if (actionIconId != 0) {
it.setIcon(actionIconId);
}
it.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM |
@ -578,12 +583,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (selectedItems.isEmpty()) {
AccessibleToast.makeText(getMyActivity(),
AccessibleToast.makeText(getDownloadActivity(),
getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
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.setPositiveButton(actionButton, listener);
builder.setNegativeButton(R.string.default_buttons_cancel, null);
@ -624,7 +629,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
public void onClick(View widget) {
asyncLoader.setResult(null);
startActivity(new Intent(getMyActivity(), DownloadIndexFragment.class));
startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
}
@Override
@ -642,7 +647,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public void localOptionsMenu(final int itemId) {
if (itemId == R.string.local_index_download) {
asyncLoader.setResult(null);
startActivity(new Intent(getMyActivity(), DownloadIndexFragment.class));
startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
} else if (itemId == R.string.local_index_mi_reload) {
reloadIndexes();
} else if (itemId == R.string.local_index_mi_delete) {
@ -695,7 +700,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
protected void onPostExecute(List<String> warnings) {
getMyActivity().setProgressBarIndeterminateVisibility(false);
getDownloadActivity().setProgressBarIndeterminateVisibility(false);
if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder();
boolean f = true;
@ -707,17 +712,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
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) {
asyncLoader.execute(getMyActivity());
asyncLoader.execute(getDownloadActivity());
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
getMyActivity().setProgressBarIndeterminateVisibility(true);
getDownloadActivity().setProgressBarIndeterminateVisibility(true);
}
@Override
protected List<String> doInBackground(Void... params) {
@ -865,12 +870,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
View v = convertView;
final LocalIndexInfo child = (LocalIndexInfo) getChild(groupPosition, childPosition);
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);
}
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
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){
viewName.setText(mapDescr + " - " + mapName);
@ -939,10 +944,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
View v = convertView;
LocalIndexInfo group = getGroup(groupPosition);
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);
}
StringBuilder t = new StringBuilder(group.getType().getHumanString(getMyActivity()));
StringBuilder t = new StringBuilder(group.getType().getHumanString(getDownloadActivity()));
if(group.getSubfolder() != null) {
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.R;
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.MapActivityLayers;
import net.osmand.plus.activities.SelectedGPXFragment;
@ -107,8 +107,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase();
if(DownloadIndexFragment.downloadListIndexThread != null) {
DownloadIndexFragment.downloadListIndexThread.clear();
if(DownloadActivity.downloadListIndexThread != null) {
DownloadActivity.downloadListIndexThread.clear();
}
if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode);

View file

@ -5,7 +5,7 @@ import java.util.WeakHashMap;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
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.StageInformation;
import android.content.Intent;

View file

@ -12,7 +12,7 @@ import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions;
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.util.Algorithms;
import net.osmand.util.MapUtils;