diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml
index a6ca9541ad..0529ef42f0 100644
--- a/OsmAnd/AndroidManifest.xml
+++ b/OsmAnd/AndroidManifest.xml
@@ -132,7 +132,6 @@
-
@@ -220,7 +219,7 @@
-
+
diff --git a/OsmAnd/res/layout/download_index.xml b/OsmAnd/res/layout/download_index.xml
index c6fd22271f..f36b0549b0 100644
--- a/OsmAnd/res/layout/download_index.xml
+++ b/OsmAnd/res/layout/download_index.xml
@@ -5,77 +5,6 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/OsmAnd/res/layout/tab_content.xml b/OsmAnd/res/layout/tab_content.xml
index 874655b5c3..7812a9efac 100644
--- a/OsmAnd/res/layout/tab_content.xml
+++ b/OsmAnd/res/layout/tab_content.xml
@@ -9,14 +9,88 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java
index 18972ee086..8a1db01948 100644
--- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java
+++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java
@@ -10,14 +10,9 @@ import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.data.LocationPoint;
-import net.osmand.plus.activities.DownloadIndexActivity;
-import net.osmand.plus.activities.FavouritesActivity;
-import net.osmand.plus.activities.LocalIndexesActivity;
-import net.osmand.plus.activities.MainMenuActivity;
-import net.osmand.plus.activities.MapActivity;
-import net.osmand.plus.activities.PluginsActivity;
-import net.osmand.plus.activities.SettingsActivity;
+import net.osmand.plus.activities.*;
import net.osmand.plus.activities.search.SearchActivity;
+import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.routing.RouteCalculationResult;
@@ -79,15 +74,15 @@ public class OsmAndAppCustomization {
}
public Class extends Activity> getDownloadIndexActivity() {
- return DownloadIndexActivity.class;
+ return DownloadActivity.class;
}
public Class extends Activity> getPluginsActivity() {
return PluginsActivity.class;
}
- public Class extends Activity> getLocalIndexActivity() {
- return LocalIndexesActivity.class;
+ public Class extends Activity> getDownloadActivity() {
+ return DownloadActivity.class;
}
// Download screen
@@ -115,30 +110,6 @@ public class OsmAndAppCustomization {
return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$;
}
- public void preDownloadActivity(final DownloadIndexActivity da, final List downloadTypes, ActionBar actionBar ) {
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
- ArrayAdapter spinnerAdapter = new ArrayAdapter(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
- toString(downloadTypes)
- );
- spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
- actionBar.setListNavigationCallbacks(spinnerAdapter, new OnNavigationListener() {
-
- @Override
- public boolean onNavigationItemSelected(int itemPosition, long itemId) {
- da.changeType(downloadTypes.get(itemPosition));
- return true;
- }
- });
- }
-
- private List toString(List t) {
- ArrayList items = new ArrayList();
- for(DownloadActivityType ts : t) {
- items.add(ts.getString(app));
- }
- return items;
- }
-
public boolean showDownloadExtraActions() {
return true;
}
diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
index b25fd1ce98..3b1c2da2fd 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
@@ -18,11 +18,8 @@ import net.osmand.access.AccessibilityPlugin;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode;
-import net.osmand.plus.activities.DayNightHelper;
-import net.osmand.plus.activities.DownloadIndexActivity;
-import net.osmand.plus.activities.MapActivity;
-import net.osmand.plus.activities.SavingTrackHelper;
-import net.osmand.plus.activities.SettingsActivity;
+import net.osmand.plus.activities.*;
+import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.helpers.WaypointHelper;
@@ -114,7 +111,7 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
- DownloadIndexActivity downloadActivity;
+ DownloadIndexFragment downloadActivity;
@Override
public void onCreate() {
@@ -882,11 +879,11 @@ public class OsmandApplication extends Application {
this.mapActivity = mapActivity;
}
- public void setDownloadActivity(DownloadIndexActivity downloadActivity) {
+ public void setDownloadActivity(DownloadIndexFragment downloadActivity) {
this.downloadActivity = downloadActivity;
}
- public DownloadIndexActivity getDownloadActivity() {
+ public DownloadIndexFragment getDownloadActivity() {
return downloadActivity;
}
}
diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
index e30775ffc6..d87d5fe613 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
@@ -10,7 +10,7 @@ import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.plus.activities.LocalIndexInfo;
-import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
+import net.osmand.plus.download.LocalIndexesFragment.LoadLocalIndexTask;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
@@ -19,7 +19,6 @@ import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmo.OsMoPlugin;
-import net.osmand.plus.osmodroid.OsMoDroidPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.routepointsnavigation.RoutePointsPlugin;
diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java
deleted file mode 100644
index d5b6a92354..0000000000
--- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java
+++ /dev/null
@@ -1,681 +0,0 @@
-package net.osmand.plus.activities;
-
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-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.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
-import net.osmand.plus.base.BasicProgressAsyncTask;
-import net.osmand.plus.base.SuggestExternalDirectoryDialog;
-import net.osmand.plus.download.DownloadActivityType;
-import net.osmand.plus.download.DownloadEntry;
-import net.osmand.plus.download.DownloadIndexAdapter;
-import net.osmand.plus.download.DownloadIndexesThread;
-import net.osmand.plus.download.IndexItem;
-import net.osmand.plus.download.IndexItemCategory;
-import net.osmand.plus.srtmplugin.SRTMPlugin;
-import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
-import android.content.ActivityNotFoundException;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.AsyncTask.Status;
-import android.os.Build;
-import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.View;
-import android.widget.Button;
-import android.widget.CheckBox;
-import android.widget.EditText;
-import android.widget.ExpandableListAdapter;
-import android.widget.ExpandableListView;
-import android.widget.ImageView;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.view.SubMenu;
-
-public class DownloadIndexActivity extends OsmandExpandableListActivity {
-
- /** menus **/
- private static final int MORE_ID = 10;
- private static final int RELOAD_ID = 0;
- private static final int SELECT_ALL_ID = 1;
- private static final int DESELECT_ALL_ID = 2;
- private static final int FILTER_EXISTING_REGIONS = 3;
-
- 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;
-
-
- private TextWatcher textWatcher ;
- private EditText filterText;
- private OsmandSettings settings;
-
- private View progressView;
- private ProgressBar indeterminateProgressBar;
- private ProgressBar determinateProgressBar;
- private TextView progressMessage;
- private TextView progressPercent;
- private ImageView cancel;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- final List downloadTypes = getDownloadTypes();
- type = downloadTypes.get(0);
- settings = ((OsmandApplication) getApplication()).getSettings();
- if(downloadListIndexThread == null) {
- downloadListIndexThread = new DownloadIndexesThread(this);
- }
- setContentView(R.layout.download_index);
- indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
- determinateProgressBar = (ProgressBar) findViewById(R.id.DeterminateProgressBar);
- progressView = findViewById(R.id.ProgressView);
- progressMessage = (TextView) findViewById(R.id.ProgressMessage);
- progressPercent = (TextView) findViewById(R.id.ProgressPercent);
- cancel = (ImageView) findViewById(R.id.Cancel);
- int d = settings.isLightContent() ? R.drawable.a_1_navigation_cancel_small_light : R.drawable.a_1_navigation_cancel_small_dark;
- cancel.setImageDrawable(getResources().getDrawable(d));
- cancel.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- makeSureUserCancelDownload();
- }
- });
- getSupportActionBar().setTitle(R.string.local_index_download);
- // recreation upon rotation is pgetaprevented in manifest file
- findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
-
- @Override
- public void onClick(View v) {
- downloadFilesCheckFreeVersion();
- }
-
- });
-
- filterText = (EditText) findViewById(R.id.search_box);
- textWatcher = new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before,
- int count) {
- DownloadIndexAdapter adapter = ((DownloadIndexAdapter)getExpandableListAdapter());
- if(adapter != null){
- adapter.getFilter().filter(s);
- }
- }
-
- };
- filterText.addTextChangedListener(textWatcher);
- final Intent intent = getIntent();
- if (intent != null && intent.getExtras() != null) {
- final String filter = intent.getExtras().getString(FILTER_KEY);
- if (filter != null) {
- filterText.setText(filter);
- }
- final String filterCat = intent.getExtras().getString(FILTER_CAT);
- if (filterCat != null) {
- DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
- if (type != null) {
- this.type = type;
- downloadTypes.remove(type);
- downloadTypes.add(0, type);
- }
- }
- }
- List list = new ArrayList();
- downloadListIndexThread.setUiActivity(this);
- if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
- downloadListIndexThread.runCategorization(type);
- } else {
- downloadListIndexThread.runReloadIndexFiles();
- }
- DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list);
- setListAdapter(adapter);
- if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
- boolean showedDialog = false;
- if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
- SuggestExternalDirectoryDialog.showDialog(this, null, null);
- }
- if(!showedDialog) {
- showDialogOfFreeDownloadsIfNeeded();
- }
- } else {
- showDialogOfFreeDownloadsIfNeeded();
- }
-
- getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getSupportActionBar());
- if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
- final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
- String primaryStorage = settings.getDefaultExternalStorageLocation();
- if (!currentStorage.startsWith(primaryStorage)) {
- // secondary storage
- boolean currentDirectoryNotWritable = true;
- for (String writeableDirectory : settings.getWritableSecondaryStorageDirectorys()) {
- if (currentStorage.startsWith(writeableDirectory)) {
- currentDirectoryNotWritable = false;
- break;
- }
- }
- if (currentDirectoryNotWritable) {
- currentDirectoryNotWritable = !OsmandSettings.isWritable(settings.getExternalStorageDirectory());
- }
- if (currentDirectoryNotWritable) {
- final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
- if (newLoc != null && newLoc.length() != 0) {
- AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this);
- ab.setMessage(getString(R.string.android_19_location_disabled,
- settings.getExternalStorageDirectory()));
- ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- copyFilesForAndroid19(newLoc);
- }
- });
- ab.setNegativeButton(R.string.default_buttons_cancel, null);
- ab.show();
- }
- }
- }
- }
- }
-
- private void copyFilesForAndroid19(final String newLoc) {
- MoveFilesToDifferentDirectory task =
- new MoveFilesToDifferentDirectory(DownloadIndexActivity.this,
- new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
- new File(newLoc, IndexConstants.APP_DIR)) {
- protected Boolean doInBackground(Void[] params) {
- Boolean result = super.doInBackground(params);
- if(result) {
- settings.setExternalStorageDirectory(newLoc);
- getMyApplication().getResourceManager().resetStoreDirectory();
- getMyApplication().getResourceManager().reloadIndexes(progress) ;
- }
- return result;
- };
- };
- task.execute();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- getMyApplication().setDownloadActivity(this);
- BasicProgressAsyncTask, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
- updateProgress(false);
- if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
- View mainView = findViewById(R.id.MainLayout);
- if (mainView != null) {
- mainView.setKeepScreenOn(true);
- }
- }
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- getMyApplication().setDownloadActivity(null);
- }
-
- public void showDialogToDownloadMaps(Collection maps) {
- int count = 0;
- int sz = 0;
- String s = "";
- for (IndexItem i : downloadListIndexThread.getCachedIndexFiles()) {
- for (String map : maps) {
- if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) {
- final List de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList(1));
- for(DownloadEntry d : de ) {
- count++;
- sz += d.sizeMB;
- }
- if(s.length() > 0) {
- s +=", ";
- }
- s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
- getEntriesToDownload().put(i, de);
- }
- }
- }
- if(count > 0){
- Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(getString(R.string.download_additional_maps, s, sz));
- builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- downloadFilesCheckInternet();
- }
- });
- builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- getEntriesToDownload().clear();
- }
- });
- builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
-
- @Override
- public void onCancel(DialogInterface dialog) {
- getEntriesToDownload().clear();
- }
- });
- builder.show();
-
- }
- }
-
-
- private void showDialogOfFreeDownloadsIfNeeded() {
- if (Version.isFreeVersion(getMyApplication())) {
- Builder msg = new AlertDialog.Builder(this);
- 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());
- msg.setMessage(m);
- if (Version.isMarketEnabled(getMyApplication())) {
- msg.setNeutralButton(R.string.install_paid, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication()) + "net.osmand.plus"));
- try {
- startActivity(intent);
- } catch (ActivityNotFoundException e) {
- }
- }
- });
- }
- msg.setPositiveButton(R.string.default_buttons_ok, null);
- msg.show();
- }
- }
-
-
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == RELOAD_ID) {
- // re-create the thread
- downloadListIndexThread.runReloadIndexFiles();
- return true;
- } else if (item.getItemId() == SELECT_ALL_ID) {
- selectAll();
- return true;
- } else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
- filterExisting();
- return true;
- } else if (item.getItemId() == DESELECT_ALL_ID) {
- deselectAll();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
- SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
- s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
- s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
- s.add(0, SELECT_ALL_ID, 0, R.string.select_all);
- s.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all);
-
- s.setIcon(isLightActionBar() ? R.drawable.abs__ic_menu_moreoverflow_holo_light
- : R.drawable.abs__ic_menu_moreoverflow_holo_dark);
- s.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
- }
- return super.onCreateOptionsMenu(menu);
- }
-
- public DownloadActivityType getType() {
- return type;
- }
-
- public Map> getEntriesToDownload() {
- if(downloadListIndexThread == null) {
- return new LinkedHashMap>();
- }
- return downloadListIndexThread.getEntriesToDownload();
- }
-
- public String getFilterText() {
- return filterText.getText().toString();
- }
-
-
- public void deselectAll() {
- final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
- downloadListIndexThread.getEntriesToDownload().clear();
- listAdapter.notifyDataSetInvalidated();
-
- findViewById(R.id.DownloadButton).setVisibility(View.GONE);
- }
-
-
- private void filterExisting() {
- final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
- final Map listAlreadyDownloaded = downloadListIndexThread.getDownloadedIndexFileNames();
-
- final List filtered = new ArrayList();
- for (IndexItem fileItem : listAdapter.getIndexFiles()) {
- if(fileItem.isAlreadyDownloaded(listAlreadyDownloaded)){
- filtered.add(fileItem);
- }
- }
- listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getMyApplication(), filtered));
- listAdapter.notifyDataSetChanged();
- }
-
-
- private void selectAll() {
- final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
- int selected = 0;
- 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)) {
- selected++;
- getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(), type, new ArrayList(1)));
- }
- }
- }
- AccessibleToast.makeText(this, MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
- listAdapter.notifyDataSetInvalidated();
- if(selected > 0){
- updateDownloadButton(true);
- }
- }
-
-
- public void updateDownloadButton(boolean scroll) {
- int x = getListView().getScrollX();
- int y = getListView().getScrollY();
- if (getEntriesToDownload().isEmpty()) {
- findViewById(R.id.DownloadButton).setVisibility(View.GONE);
- } else {
- BasicProgressAsyncTask, ?, ?> task = downloadListIndexThread.getCurrentRunningTask();
- boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
- ((Button) findViewById(R.id.DownloadButton)).setEnabled(!running);
- String text;
- int downloads = downloadListIndexThread.getDownloads();
- if (!running) {
- text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
- } else {
- text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
- }
- findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
- if (Version.isFreeVersion(getMyApplication())) {
- int countedDownloads = 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())) {
- text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
- }
- }
- ((Button) findViewById(R.id.DownloadButton)).setText(text);
- }
- if (scroll) {
- getListView().scrollTo(x, y);
- }
- }
-
-
-
- private List getDownloadTypes() {
- List items = new ArrayList();
- items.add(DownloadActivityType.NORMAL_FILE);
- items.add(DownloadActivityType.VOICE_FILE);
- items.add(DownloadActivityType.ROADS_FILE);
- if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){
- items.add(DownloadActivityType.HILLSHADE_FILE);
- items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
- }
- getMyApplication().getAppCustomization().getDownloadTypes(items);
- return items;
- }
-
-
- public void changeType(final DownloadActivityType tp) {
- invalidateOptionsMenu();
- if (downloadListIndexThread != null && type != tp) {
- type = tp;
- downloadListIndexThread.runCategorization(tp);
- }
- }
-
-
- public ExpandableListView getListView() {
- return super.getExpandableListView();
- }
-
- public ExpandableListAdapter getListAdapter() {
- return super.getExpandableListAdapter();
- }
-
- private void makeSureUserCancelDownload() {
- Builder bld = new AlertDialog.Builder(this);
- 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();
- if(t != null) {
- t.setInterrupted(true);
- }
- }
- });
- bld.setNegativeButton(R.string.default_buttons_no, null);
- bld.show();
- }
-
-
- @Override
- public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
- final IndexItem e = (IndexItem) ((DownloadIndexAdapter)getListAdapter()).getChild(groupPosition, childPosition);
- final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
-
- if(ch.isChecked()){
- ch.setChecked(!ch.isChecked());
- getEntriesToDownload().remove(e);
- updateDownloadButton(true);
- return true;
- }
-
- List download = e.createDownloadEntry(getMyApplication(), type, new ArrayList());
- if (download.size() > 0) {
- // if(!fileToUnzip.exists()){
- // builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
- getEntriesToDownload().put(e, download);
- updateDownloadButton(true);
- ch.setChecked(!ch.isChecked());
- }
- return true;
- }
-
-
- public static Map listWithAlternatives(final java.text.DateFormat dateFormat, File file, final String ext,
- final Map files) {
- if (file.isDirectory()) {
- file.list(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String filename) {
- if (filename.endsWith(ext)) {
- String date = dateFormat.format(findFileInDir(new File(dir, filename)).lastModified());
- files.put(filename, date);
- return true;
- } else {
- return false;
- }
- }
- });
-
- }
- return files;
- }
-
- public static File findFileInDir(File file) {
- if(file.isDirectory()) {
- File[] lf = file.listFiles();
- if(lf != null) {
- for(File f : lf) {
- if(f.isFile()) {
- return f;
- }
- }
- }
- }
- return file;
- }
-
- protected void downloadFilesCheckFreeVersion() {
- if (Version.isFreeVersion(getMyApplication()) ) {
- int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
- boolean wiki = false;
- for (IndexItem es : downloadListIndexThread.getEntriesToDownload().keySet()) {
- if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
- wiki = true;
- break;
- } else if (DownloadActivityType.isCountedInDownloads(es.getType())) {
- total++;
- }
- }
- if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
- String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
- Builder msg = new AlertDialog.Builder(this);
- msg.setTitle(R.string.free_version_title);
- msg.setMessage(msgTx);
- msg.setPositiveButton(R.string.default_buttons_ok, null);
- msg.show();
- } else {
- downloadFilesCheckInternet();
- }
- } else {
- downloadFilesCheckInternet();
- }
- }
-
-
- protected void downloadFilesCheckInternet() {
- if(!getMyApplication().getSettings().isWifiConnected()) {
- Builder builder = new AlertDialog.Builder(this);
- 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();
- }
- });
- builder.setNegativeButton(R.string.default_buttons_no, null);
- builder.show();
- } else {
- downloadFilesPreCheckSpace();
- }
- }
-
- protected void downloadFilesPreCheckSpace() {
- double sz = 0;
- List 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(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();
- }
-
- }
-
-
-
-
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (textWatcher != null) {
- EditText filterText = (EditText) findViewById(R.id.search_box);
- filterText.removeTextChangedListener(textWatcher);
- }
- downloadListIndexThread.setUiActivity(null);
- }
-
-
-
-
- public void updateProgress(boolean updateOnlyProgress) {
- BasicProgressAsyncTask, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask();
- if(updateOnlyProgress) {
- if(!basicProgressAsyncTask.isIndeterminate()) {
- progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
- determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
- }
- } else {
- boolean visible = basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != Status.FINISHED;
- progressView.setVisibility(visible ? View.VISIBLE : View.GONE);
- if (visible) {
- boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
- indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
- determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
- cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
- progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
-
- progressMessage.setText(basicProgressAsyncTask.getDescription());
- if (!indeterminate) {
- progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
- determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
- }
- }
- updateDownloadButton(false);
- }
- }
-}
diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java
index 8f50bca585..15fd1714ba 100644
--- a/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java
@@ -130,7 +130,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
if(favouritesAdapter.getGroupCount() > 0 &&
"".equals(favouritesAdapter.getGroup(0).name)) {
- getListView().expandGroup(0);
+ getExpandableListView().expandGroup(0);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java
index fdf2812a25..e47d2b468b 100644
--- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java
+++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java
@@ -31,7 +31,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
-import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
+import net.osmand.plus.download.LocalIndexesFragment.LoadLocalIndexTask;
import net.osmand.plus.voice.MediaCommandPlayerImpl;
import net.osmand.plus.voice.TTSCommandPlayerImpl;
import net.osmand.util.MapUtils;
diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java
index 5bfc1ae457..4b777361de 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java
@@ -11,8 +11,8 @@ 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.SherpafyCustomization;
import net.osmand.plus.sherpafy.TourViewActivity;
import android.app.Activity;
import android.app.AlertDialog.Builder;
@@ -376,7 +376,7 @@ public class MainMenuActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
- startActivity(new Intent(MainMenuActivity.this, DownloadIndexActivity.class));
+ startActivity(new Intent(MainMenuActivity.this, DownloadIndexFragment.class));
}
});
diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandExpandableListFragment.java b/OsmAnd/src/net/osmand/plus/activities/OsmandExpandableListFragment.java
index a2465a2d2e..54be00901a 100644
--- a/OsmAnd/src/net/osmand/plus/activities/OsmandExpandableListFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/OsmandExpandableListFragment.java
@@ -61,14 +61,10 @@ public abstract class OsmandExpandableListFragment extends SherlockFragment impl
}
}
}
-
- public ExpandableListView getListView() {
- return listView;
- }
-
- public ExpandableListView getExpandableListView() {
- return listView;
- }
+
+ public ExpandableListView getExpandableListView() { return listView; }
+
+ public void setListView(ExpandableListView listView) { this.listView = listView;}
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) {
int r = isLightActionBar() ? iconLight : iconDark;
diff --git a/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java
index 1ff824010a..27965245cf 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java
@@ -104,10 +104,10 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
public void setContent() {
- getListView().setFastScrollEnabled(true);
+ getExpandableListView().setFastScrollEnabled(true);
lightContent = app.getSettings().isLightContent();
if (adapter == null) {
- adapter = new SelectedGPXAdapter(getListView());
+ adapter = new SelectedGPXAdapter(getExpandableListView());
setAdapter(adapter);
}
List groups = selectedGpxHelper.getDisplayGroups();
@@ -131,7 +131,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
adapter.setDisplayGroups(groups);
if(isArgumentTrue(ARG_TO_EXPAND_TRACK_INFO)){
for(int i = 0; i < groups.size(); i++) {
- getListView().expandGroup(i);
+ getExpandableListView().expandGroup(i);
}
}
}
@@ -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() {
//
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
index afa3dd6d1c..2ed6c0aef4 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
@@ -101,7 +101,7 @@ public class SettingsActivity extends SettingsBaseActivity {
if (empty) {
startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadIndexActivity()));
} else {
- startActivity(new Intent(this, getMyApplication().getAppCustomization().getLocalIndexActivity()));
+ startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadActivity()));
}
return true;
} else if (preference == bidforfix) {
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
index 7ba65d0c87..35a5a7ef08 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
@@ -22,7 +22,9 @@ import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
+import net.osmand.plus.download.DownloadActivity;
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;
@@ -372,8 +374,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
if (id.equals(settings.VOICE_PROVIDER.getId())) {
if (MORE_VALUE.equals(newValue)) {
// listPref.set(oldValue); // revert the change..
- final Intent intent = new Intent(this, DownloadIndexActivity.class);
- intent.putExtra(DownloadIndexActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
+ final Intent intent = new Intent(this, DownloadIndexFragment.class);
+ intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
startActivity(intent);
} else {
super.onPreferenceChange(preference, newValue);
diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java
index b96e3b440e..10e6123538 100644
--- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java
@@ -34,11 +34,11 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
-import net.osmand.plus.activities.LocalIndexesActivity;
-import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
+import net.osmand.plus.download.LocalIndexesFragment.LoadLocalIndexTask;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
+import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
@@ -1094,8 +1094,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override
public void contextMenuLocalIndexes(Activity activity, SherlockFragment fragment, Object obj,
ContextMenuAdapter adapter) {
- if (activity instanceof LocalIndexesActivity) {
- final LocalIndexesActivity la = (LocalIndexesActivity) activity;
+ if (activity instanceof DownloadActivity) {
+ final DownloadActivity la = (DownloadActivity) activity;
LocalIndexInfo info = (LocalIndexInfo) obj;
if (info.getType() == LocalIndexType.AV_DATA) {
final RecordingLocalIndexInfo ri = (RecordingLocalIndexInfo) info;
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
new file mode 100644
index 0000000000..10252e8ceb
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
@@ -0,0 +1,377 @@
+package net.osmand.plus.download;
+
+import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.view.ViewPager;
+import android.view.View;
+import android.widget.*;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import net.osmand.plus.*;
+import net.osmand.plus.activities.FavouritesActivity;
+import net.osmand.plus.base.BasicProgressAsyncTask;
+import net.osmand.plus.srtmplugin.SRTMPlugin;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by Denis on 08.09.2014.
+ */
+public class DownloadActivity extends SherlockFragmentActivity {
+
+ private TabHost tabHost;
+ private FavouritesActivity.TabsAdapter mTabsAdapter;
+ public static DownloadIndexesThread downloadListIndexThread;
+ private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
+ public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
+
+ private OsmandSettings settings;
+
+ private View progressView;
+ private ProgressBar indeterminateProgressBar;
+ private ProgressBar determinateProgressBar;
+ private TextView progressMessage;
+ private TextView progressPercent;
+ private ImageView cancel;
+
+ public static final String FILTER_KEY = "filter";
+ public static final String FILTER_CAT = "filter_cat";
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ getMyApplication().applyTheme(this);
+ super.onCreate(savedInstanceState);
+
+
+ setContentView(R.layout.tab_content);
+ OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
+ tabHost = (TabHost) findViewById(android.R.id.tabhost);
+ tabHost.setup();
+ ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
+ mTabsAdapter = new FavouritesActivity.TabsAdapter(this, tabHost, viewPager, settings);
+ mTabsAdapter.addTab(tabHost.newTabSpec("LOCAL_INDEX").setIndicator("Local"),
+ 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();
+ }
+
+ settings = ((OsmandApplication)getApplication()).getSettings();
+
+ indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
+ determinateProgressBar = (ProgressBar) findViewById(R.id.DeterminateProgressBar);
+ progressView = findViewById(R.id.ProgressView);
+ progressMessage = (TextView) findViewById(R.id.ProgressMessage);
+ progressPercent = (TextView) findViewById(R.id.ProgressPercent);
+ cancel = (ImageView) findViewById(R.id.Cancel);
+ int d = settings.isLightContent() ? R.drawable.a_1_navigation_cancel_small_light : R.drawable.a_1_navigation_cancel_small_dark;
+ cancel.setImageDrawable(getResources().getDrawable(d));
+ cancel.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ makeSureUserCancelDownload();
+ }
+ });
+
+ findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
+
+ @Override
+ public void onClick(View v) {
+ downloadFilesCheckFreeVersion();
+ }
+
+ });
+
+ final List downloadTypes = getDownloadTypes();
+ final Intent intent = getIntent();
+ setType(downloadTypes.get(0));
+ if (intent != null && intent.getExtras() != null) {
+ final String filter = intent.getExtras().getString(FILTER_KEY);
+// if (filter != null) {
+// filterText.setText(filter);
+// }
+ final String filterCat = intent.getExtras().getString(FILTER_CAT);
+ if (filterCat != null) {
+ DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
+ if (type != null) {
+ setType(type);
+ downloadTypes.remove(type);
+ downloadTypes.add(0, type);
+ }
+ }
+ }
+
+ getSupportActionBar().setHomeButtonEnabled(true);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ BasicProgressAsyncTask, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
+ int itemId = item.getItemId();
+ switch (itemId) {
+ case android.R.id.home:
+ finish();
+ return true;
+
+ }
+ return false;
+ }
+
+
+ public DownloadActivityType getType() { return type;}
+
+ public void setType(DownloadActivityType type) { this.type = type;}
+
+ public void changeType(final DownloadActivityType tp) {
+ invalidateOptionsMenu();
+ if (downloadListIndexThread != null && type != tp) {
+ type = tp;
+ downloadListIndexThread.runCategorization(tp);
+ }
+ }
+
+ public void downloadFilesPreCheckSpace() {
+ double sz = 0;
+ List 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> getEntriesToDownload() {
+ if(downloadListIndexThread == null) {
+ return new LinkedHashMap>();
+ }
+ return downloadListIndexThread.getEntriesToDownload();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ (getMyApplication()).setDownloadActivity(null);
+ }
+
+ protected void downloadFilesCheckFreeVersion() {
+ if (Version.isFreeVersion(getMyApplication()) ) {
+ int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
+ boolean wiki = false;
+ for (IndexItem es : DownloadActivity.downloadListIndexThread.getEntriesToDownload().keySet()) {
+ if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
+ wiki = true;
+ break;
+ } else if (DownloadActivityType.isCountedInDownloads(es.getType())) {
+ total++;
+ }
+ }
+ if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
+ String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
+ AlertDialog.Builder msg = new AlertDialog.Builder(this);
+ msg.setTitle(R.string.free_version_title);
+ msg.setMessage(msgTx);
+ msg.setPositiveButton(R.string.default_buttons_ok, null);
+ msg.show();
+ } else {
+ downloadFilesCheckInternet();
+ }
+ } else {
+ downloadFilesCheckInternet();
+ }
+ }
+
+ protected void downloadFilesCheckInternet() {
+ if(!getMyApplication().getSettings().isWifiConnected()) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ 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();
+ }
+ });
+ builder.setNegativeButton(R.string.default_buttons_no, null);
+ builder.show();
+ } else {
+ downloadFilesPreCheckSpace();
+ }
+ }
+
+ public OsmandApplication getMyApplication(){ return (OsmandApplication)getApplication();}
+
+ public void showDialogOfFreeDownloadsIfNeeded() {
+ if (Version.isFreeVersion(getMyApplication())) {
+ AlertDialog.Builder msg = new AlertDialog.Builder(this);
+ 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());
+ msg.setMessage(m);
+ if (Version.isMarketEnabled(getMyApplication())) {
+ msg.setNeutralButton(R.string.install_paid, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication()) + "net.osmand.plus"));
+ try {
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ }
+ }
+ });
+ }
+ msg.setPositiveButton(R.string.default_buttons_ok, null);
+ msg.show();
+ }
+ }
+
+ public void updateProgress(boolean updateOnlyProgress) {
+ BasicProgressAsyncTask, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
+ //needed when rotation is performed and progress can be null
+ if (progressView == null){
+ return;
+ }
+ if(updateOnlyProgress) {
+ if(!basicProgressAsyncTask.isIndeterminate()) {
+ progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
+ determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
+ }
+ } else {
+ boolean visible = basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != AsyncTask.Status.FINISHED;
+ progressView.setVisibility(visible ? View.VISIBLE : View.GONE);
+ if (visible) {
+ boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
+ indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
+ determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
+ cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
+ progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
+
+ progressMessage.setText(basicProgressAsyncTask.getDescription());
+ if (!indeterminate) {
+ progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
+ determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
+ }
+ }
+ updateDownloadButton(false);
+
+ }
+ }
+
+ private void makeSureUserCancelDownload() {
+ AlertDialog.Builder bld = new AlertDialog.Builder(this);
+ bld.setTitle(getString(R.string.default_buttons_cancel));
+ bld.setMessage(R.string.confirm_interrupt_download);
+ bld.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ BasicProgressAsyncTask, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
+ if(t != null) {
+ t.setInterrupted(true);
+ }
+ }
+ });
+ bld.setNegativeButton(R.string.default_buttons_no, null);
+ bld.show();
+ }
+
+ public void updateDownloadList(List list){
+ Fragment fragment = mTabsAdapter.getItem(2);
+ //will fall if change tab order
+ ((UpdatesIndexFragment) fragment).updateItemsList(list);
+ }
+
+ public void updateDownloadButton(boolean scroll) {
+// View view = getView();
+// if (view == null || getExpandableListView() == null){
+// return;
+// }
+// int x = getExpandableListView().getScrollX();
+// int y = getExpandableListView().getScrollY();
+ if (getEntriesToDownload().isEmpty()) {
+ findViewById(R.id.DownloadButton).setVisibility(View.GONE);
+ } else {
+ BasicProgressAsyncTask, ?, ?> task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
+ boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
+ ((Button) findViewById(R.id.DownloadButton)).setEnabled(!running);
+ String text;
+ int downloads = DownloadActivity.downloadListIndexThread.getDownloads();
+ if (!running) {
+ text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
+ } else {
+ text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
+ }
+ findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
+ if (Version.isFreeVersion(getMyApplication())) {
+ int countedDownloads = DownloadActivity.downloadListIndexThread.getDownloads();
+ int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
+ boolean excessLimit = left < 0;
+ if (left < 0)
+ left = 0;
+ if (DownloadActivityType.isCountedInDownloads(getType())) {
+ text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
+ }
+ }
+ ((Button) findViewById(R.id.DownloadButton)).setText(text);
+ }
+// if (scroll) {
+// getExpandableListView().scrollTo(x, y);
+// }
+ }
+
+ public List getDownloadTypes() {
+ List items = new ArrayList();
+ items.add(DownloadActivityType.NORMAL_FILE);
+ items.add(DownloadActivityType.VOICE_FILE);
+ items.add(DownloadActivityType.ROADS_FILE);
+ if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){
+ items.add(DownloadActivityType.HILLSHADE_FILE);
+ items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
+ }
+ getMyApplication().getAppCustomization().getDownloadTypes(items);
+ return items;
+ }
+
+
+}
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java
index 55c55c6422..ae7ef61480 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java
@@ -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.DownloadIndexActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import android.content.Context;
import android.content.res.TypedArray;
@@ -28,7 +27,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private DownloadIndexFilter myFilter;
private final List indexFiles;
private final List list = new ArrayList();
- private DownloadIndexActivity downloadActivity;
+ private DownloadIndexFragment downloadFragment;
private Map indexFileNames = null;
private Map indexActivatedFileNames = null;
@@ -38,21 +37,21 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private OsmandRegions osmandRegions;
private java.text.DateFormat format;
- public DownloadIndexAdapter(DownloadIndexActivity downloadActivity, List indexFiles) {
- this.downloadActivity = downloadActivity;
+ public DownloadIndexAdapter(DownloadIndexFragment downloadFragment, List indexFiles) {
+ this.downloadFragment = downloadFragment;
this.indexFiles = new ArrayList(indexFiles);
- List cats = IndexItemCategory.categorizeIndexItems(downloadActivity.getMyApplication(), indexFiles);
+ List cats = IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), indexFiles);
synchronized (this) {
list.clear();
list.addAll(cats);
}
- format = downloadActivity.getMyApplication().getResourceManager().getDateFormat();
- okColor = downloadActivity.getResources().getColor(R.color.color_ok);
- TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
- defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown));
+ format = downloadFragment.getMyApplication().getResourceManager().getDateFormat();
+ okColor = downloadFragment.getResources().getColor(R.color.color_ok);
+ TypedArray ta = downloadFragment.getDownloadActivity().getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
+ defaultColor = ta.getColor(0, downloadFragment.getResources().getColor(R.color.color_unknown));
ta.recycle();
- updateColor = downloadActivity.getResources().getColor(R.color.color_update);
- osmandRegions = downloadActivity.getMyApplication().getResourceManager().getOsmandRegions();
+ updateColor = downloadFragment.getResources().getColor(R.color.color_update);
+ osmandRegions = downloadFragment.getMyApplication().getResourceManager().getOsmandRegions();
}
public void setLoadedFiles(Map indexActivatedFileNames, Map indexFileNames) {
@@ -62,11 +61,11 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
public void collapseTrees(final CharSequence constraint) {
- downloadActivity.runOnUiThread(new Runnable() {
+ downloadFragment.getDownloadActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (DownloadIndexAdapter.this) {
- final ExpandableListView expandableListView = downloadActivity.getExpandableListView();
+ final ExpandableListView expandableListView = downloadFragment.getExpandableListView();
for (int i = 0; i < getGroupCount(); i++) {
int cp = getChildrenCount(i);
if (cp < 7) {
@@ -125,7 +124,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
}
List filter = new ArrayList();
- Context c = downloadActivity;
+ Context c = downloadFragment.getDownloadActivity();
for (IndexItem item : indexFiles) {
boolean add = true;
String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename());
@@ -166,11 +165,11 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
list.clear();
Collection items = (Collection) results.values;
if (items != null && !items.isEmpty()) {
- list.addAll(IndexItemCategory.categorizeIndexItems(downloadActivity.getMyApplication(), items));
+ list.addAll(IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), items));
} else if(DownloadIndexAdapter.this.indexFiles.isEmpty()){
- list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.no_index_file_to_download), 1));
+ list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.no_index_file_to_download), 1));
} else {
- list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.select_index_file_to_download), 1));
+ list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.select_index_file_to_download), 1));
}
}
notifyDataSetChanged();
@@ -218,7 +217,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
View v = convertView;
IndexItemCategory group = getGroup(groupPosition);
if (v == null) {
- LayoutInflater inflater = downloadActivity.getLayoutInflater();
+ LayoutInflater inflater = (LayoutInflater) downloadFragment.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,27 +232,27 @@ 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 = downloadActivity.getLayoutInflater();
+ LayoutInflater inflater = (LayoutInflater) downloadFragment.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false);
}
final View row = v;
TextView item = (TextView) row.findViewById(R.id.download_item);
TextView description = (TextView) row.findViewById(R.id.download_descr);
IndexItem e = (IndexItem) getChild(groupPosition, childPosition);
- OsmandApplication clctx = downloadActivity.getMyApplication();
+ OsmandApplication clctx = downloadFragment.getMyApplication();
String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx, osmandRegions);
item.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(clctx);
description.setText(d.trim());
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);
- ch.setChecked(downloadActivity.getEntriesToDownload().containsKey(e));
+ ch.setChecked(downloadFragment.getDownloadActivity().getEntriesToDownload().containsKey(e));
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
ch.setChecked(!ch.isChecked());
- downloadActivity.onChildClick(downloadActivity.getListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
+ downloadFragment.onChildClick(downloadFragment.getExpandableListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
}
});
@@ -278,22 +277,22 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} else if (e.getDate(format) != null) {
String sfName = e.getTargetFileName();
if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) {
- item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
+ item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
item.setTextColor(okColor); // GREEN
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else if (e.getDate(format).equals(indexFileNames.get(sfName))) {
- item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
+ item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
item.setTextColor(okColor);
item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else if (indexActivatedFileNames.containsKey(sfName)) {
- item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
+ item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
item.setTextColor(updateColor); // LIGHT_BLUE
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else {
- item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
+ item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
item.setTextColor(updateColor);
item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java
new file mode 100644
index 0000000000..ae7adc9adf
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java
@@ -0,0 +1,421 @@
+package net.osmand.plus.download;
+
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import android.widget.*;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.view.MenuInflater;
+import net.osmand.IndexConstants;
+import net.osmand.access.AccessibleAlertBuilder;
+import net.osmand.access.AccessibleToast;
+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;
+import net.osmand.plus.srtmplugin.SRTMPlugin;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+import android.os.AsyncTask.Status;
+import android.os.Build;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuItem;
+import com.actionbarsherlock.view.SubMenu;
+
+public class DownloadIndexFragment extends OsmandExpandableListFragment {
+
+ /** menus **/
+ private static final int MORE_ID = 10;
+ private static final int RELOAD_ID = 0;
+ private static final int SELECT_ALL_ID = 1;
+ private static final int DESELECT_ALL_ID = 2;
+ private static final int FILTER_EXISTING_REGIONS = 3;
+
+ private TextWatcher textWatcher ;
+ private EditText filterText;
+ private OsmandSettings settings;
+
+ DownloadIndexAdapter listAdapter;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+ View view = inflater.inflate(R.layout.download_index, container, false);
+ ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
+ List list = new ArrayList();
+ listAdapter = new DownloadIndexAdapter(this, list);
+ listView.setAdapter(listAdapter);
+ setListView(listView);
+
+ //getSupportActionBar().setTitle(R.string.local_index_download);
+ // recreation upon rotation is pgetaprevented in manifest file
+
+ filterText = (EditText) view.findViewById(R.id.search_box);
+ textWatcher = new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count,
+ int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before,
+ int count) {
+ if(listAdapter != null){
+ listAdapter.getFilter().filter(s);
+ }
+ }
+
+ };
+ filterText.addTextChangedListener(textWatcher);
+
+ return view;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setHasOptionsMenu(true);
+
+ DownloadActivity.downloadListIndexThread.setUiFragment(this);
+
+ settings = getMyApplication().getSettings();
+
+
+ if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
+ boolean showedDialog = false;
+ if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
+ SuggestExternalDirectoryDialog.showDialog(getActivity(), null, null);
+ }
+ if(!showedDialog) {
+ getDownloadActivity().showDialogOfFreeDownloadsIfNeeded();
+ }
+ } else {
+ getDownloadActivity().showDialogOfFreeDownloadsIfNeeded();
+ }
+
+
+ if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
+ final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
+ String primaryStorage = settings.getDefaultExternalStorageLocation();
+ if (!currentStorage.startsWith(primaryStorage)) {
+ // secondary storage
+ boolean currentDirectoryNotWritable = true;
+ for (String writeableDirectory : settings.getWritableSecondaryStorageDirectorys()) {
+ if (currentStorage.startsWith(writeableDirectory)) {
+ currentDirectoryNotWritable = false;
+ break;
+ }
+ }
+ if (currentDirectoryNotWritable) {
+ currentDirectoryNotWritable = !OsmandSettings.isWritable(settings.getExternalStorageDirectory());
+ }
+ if (currentDirectoryNotWritable) {
+ final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
+ if (newLoc != null && newLoc.length() != 0) {
+ 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() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ copyFilesForAndroid19(newLoc);
+ }
+ });
+ ab.setNegativeButton(R.string.default_buttons_cancel, null);
+ ab.show();
+ }
+ }
+ }
+ }
+ }
+
+ private void copyFilesForAndroid19(final String newLoc) {
+ MoveFilesToDifferentDirectory task =
+ new MoveFilesToDifferentDirectory(getDownloadActivity(),
+ new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
+ new File(newLoc, IndexConstants.APP_DIR)) {
+ protected Boolean doInBackground(Void[] params) {
+ Boolean result = super.doInBackground(params);
+ if(result) {
+ settings.setExternalStorageDirectory(newLoc);
+ getMyApplication().getResourceManager().resetStoreDirectory();
+ getMyApplication().getResourceManager().reloadIndexes(progress) ;
+ }
+ return result;
+ };
+ };
+ task.execute();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getMyApplication().setDownloadActivity(this);
+ getDownloadActivity().updateProgress(false);
+ BasicProgressAsyncTask, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
+ if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
+ View mainView = getView().findViewById(R.id.MainLayout);
+ if (mainView != null) {
+ mainView.setKeepScreenOn(true);
+ }
+ }
+ }
+
+ public void showDialogToDownloadMaps(Collection maps) {
+ int count = 0;
+ int sz = 0;
+ String s = "";
+ for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
+ for (String map : maps) {
+ if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) {
+ final List de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList(1));
+ for(DownloadEntry d : de ) {
+ count++;
+ sz += d.sizeMB;
+ }
+ if(s.length() > 0) {
+ s +=", ";
+ }
+ s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
+ getDownloadActivity().getEntriesToDownload().put(i, de);
+ }
+ }
+ }
+ if(count > 0){
+ 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
+ public void onClick(DialogInterface dialog, int which) {
+ getDownloadActivity().downloadFilesCheckInternet();
+ }
+ });
+ builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ getDownloadActivity().getEntriesToDownload().clear();
+ }
+ });
+ builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ getDownloadActivity().getEntriesToDownload().clear();
+ }
+ });
+ builder.show();
+
+ }
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == RELOAD_ID) {
+ // re-create the thread
+ DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
+ return true;
+ } else if (item.getItemId() == SELECT_ALL_ID) {
+ selectAll();
+ return true;
+ } else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
+ filterExisting();
+ return true;
+ } else if (item.getItemId() == DESELECT_ALL_ID) {
+ deselectAll();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ ActionBar actionBar = getDownloadActivity().getSupportActionBar();
+ final List downloadTypes = getDownloadActivity().getDownloadTypes();
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ ArrayAdapter spinnerAdapter = new ArrayAdapter(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
+ toString(downloadTypes));
+ spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
+ actionBar.setListNavigationCallbacks(spinnerAdapter, new ActionBar.OnNavigationListener() {
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ getDownloadActivity().changeType(downloadTypes.get(itemPosition));
+ return true;
+ }
+ });
+
+ if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
+ SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
+ s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
+ s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
+ s.add(0, SELECT_ALL_ID, 0, R.string.select_all);
+ s.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all);
+
+ s.setIcon(isLightActionBar() ? R.drawable.abs__ic_menu_moreoverflow_holo_light
+ : R.drawable.abs__ic_menu_moreoverflow_holo_dark);
+ }
+ }
+
+ public String getFilterText() {
+ return filterText.getText().toString();
+ }
+
+
+ public void deselectAll() {
+ DownloadActivity.downloadListIndexThread.getEntriesToDownload().clear();
+ listAdapter.notifyDataSetInvalidated();
+
+ getView().findViewById(R.id.DownloadButton).setVisibility(View.GONE);
+ }
+
+
+ private void filterExisting() {
+ final Map listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames();
+
+ final List filtered = new ArrayList();
+ for (IndexItem fileItem : listAdapter.getIndexFiles()) {
+ if(fileItem.isAlreadyDownloaded(listAlreadyDownloaded)){
+ filtered.add(fileItem);
+ }
+ }
+ listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getMyApplication(), filtered));
+ listAdapter.notifyDataSetChanged();
+ }
+
+
+ private void selectAll() {
+ int selected = 0;
+ for (int j = 0; j < listAdapter.getGroupCount(); j++) {
+ for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
+ IndexItem es = listAdapter.getChild(j, i);
+ if (!getDownloadActivity().getEntriesToDownload().containsKey(es)) {
+ selected++;
+ getDownloadActivity().getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(),
+ getDownloadActivity().getType(), new ArrayList(1)));
+ }
+ }
+ }
+ AccessibleToast.makeText(getDownloadActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
+ listAdapter.notifyDataSetInvalidated();
+ if(selected > 0){
+ getDownloadActivity().updateDownloadButton(true);
+ }
+ }
+
+
+
+ @Override
+ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
+ final IndexItem e = (IndexItem) listAdapter.getChild(groupPosition, childPosition);
+ final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
+
+ if(ch.isChecked()){
+ ch.setChecked(!ch.isChecked());
+ getDownloadActivity().getEntriesToDownload().remove(e);
+ getDownloadActivity().updateDownloadButton(true);
+ return true;
+ }
+
+ List download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList());
+ if (download.size() > 0) {
+ // if(!fileToUnzip.exists()){
+ // builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
+ getDownloadActivity().getEntriesToDownload().put(e, download);
+ getDownloadActivity().updateDownloadButton(true);
+ ch.setChecked(!ch.isChecked());
+ }
+ return true;
+ }
+
+
+ public static Map listWithAlternatives(final java.text.DateFormat dateFormat, File file, final String ext,
+ final Map files) {
+ if (file.isDirectory()) {
+ file.list(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String filename) {
+ if (filename.endsWith(ext)) {
+ String date = dateFormat.format(findFileInDir(new File(dir, filename)).lastModified());
+ files.put(filename, date);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ });
+
+ }
+ return files;
+ }
+
+ public static File findFileInDir(File file) {
+ if(file.isDirectory()) {
+ File[] lf = file.listFiles();
+ if(lf != null) {
+ for(File f : lf) {
+ if(f.isFile()) {
+ return f;
+ }
+ }
+ }
+ }
+ return file;
+ }
+
+
+
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (textWatcher != null && getView() != null) {
+ EditText filterText = (EditText) getView().findViewById(R.id.search_box);
+ filterText.removeTextChangedListener(textWatcher);
+ }
+ DownloadActivity.downloadListIndexThread.setUiFragment(null);
+ }
+
+ public List toString(List t) {
+ ArrayList items = new ArrayList();
+ for(DownloadActivityType ts : t) {
+ items.add(ts.getString(getMyApplication()));
+ }
+ return items;
+ }
+
+
+ public DownloadActivity getDownloadActivity(){ return (DownloadActivity)getActivity();}
+
+ public ExpandableListAdapter getExpandableListAdapter(){ return listAdapter;}
+
+ public View findViewById(int id){ return getView().findViewById(id);}
+
+ public void updateProgress(boolean b) {
+ getDownloadActivity().updateProgress(b);
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
index e2596278be..bd846a6a03 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
@@ -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.DownloadIndexActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.resources.ResourceManager;
@@ -47,7 +46,7 @@ import android.view.View;
import android.widget.Toast;
public class DownloadIndexesThread {
- private DownloadIndexActivity uiActivity = null;
+ private DownloadIndexFragment uiFragment = null;
private IndexFileList indexFiles = null;
private Map> entriesToDownload = new ConcurrentHashMap>();
private Set currentDownloads = new HashSet();
@@ -59,7 +58,8 @@ public class DownloadIndexesThread {
private Map indexFileNames = new LinkedHashMap();
private Map indexActivatedFileNames = new LinkedHashMap();
private java.text.DateFormat dateFormat;
-
+ private List itemsToUpdate = new ArrayList();
+
public DownloadIndexesThread(Context ctx) {
this.ctx = ctx;
@@ -72,8 +72,8 @@ public class DownloadIndexesThread {
indexFiles = null;
}
- public void setUiActivity(DownloadIndexActivity uiActivity) {
- this.uiActivity = uiActivity;
+ public void setUiFragment(DownloadIndexFragment uiFragment) {
+ this.uiFragment = uiFragment;
}
public List flattenDownloadEntries() {
@@ -92,13 +92,13 @@ public class DownloadIndexesThread {
public void updateLoadedFiles() {
Map indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
- DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
+ DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
indexActivatedFileNames);
Map indexFileNames = app.getResourceManager().getIndexFileNames();
- DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
+ DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
indexFileNames);
app.getAppCustomization().updatedLoadedFiles(indexFileNames, indexActivatedFileNames);
- DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR),
+ DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR),
IndexConstants.SQLITE_EXT, indexFileNames);
app.getResourceManager().getBackupIndexes(indexFileNames);
this.indexFileNames = indexFileNames;
@@ -112,6 +112,8 @@ public class DownloadIndexesThread {
public boolean isDownloadedFromInternet() {
return indexFiles != null && indexFiles.isDownloadedFromInternet();
}
+
+ public List getItemsToUpdate() { return itemsToUpdate;}
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask implements DownloadFileShowWarning {
@@ -134,15 +136,15 @@ public class DownloadIndexesThread {
protected void onProgressUpdate(Object... values) {
for (Object o : values) {
if (o instanceof DownloadEntry) {
- if (uiActivity != null) {
- ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated();
- uiActivity.updateDownloadButton(false);
+ if (uiFragment != null) {
+ ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
+ uiFragment.getDownloadActivity().updateDownloadButton(false);
}
} else if (o instanceof IndexItem) {
entriesToDownload.remove(o);
- if (uiActivity != null) {
- ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated();
- uiActivity.updateDownloadButton(false);
+ if (uiFragment != null) {
+ ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
+ uiFragment.getDownloadActivity().updateDownloadButton(false);
}
} else if (o instanceof String) {
AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
@@ -155,9 +157,9 @@ public class DownloadIndexesThread {
protected void onPreExecute() {
currentRunningTask.add( this);
super.onPreExecute();
- if (uiActivity != null) {
+ if (uiFragment != null) {
downloadFileHelper.setInterruptDownloading(false);
- View mainView = uiActivity.findViewById(R.id.MainLayout);
+ View mainView = uiFragment.findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(true);
}
@@ -171,19 +173,19 @@ public class DownloadIndexesThread {
AccessibleToast.makeText(ctx, result, Toast.LENGTH_LONG).show();
}
currentDownloads.clear();
- if (uiActivity != null) {
- View mainView = uiActivity.findViewById(R.id.MainLayout);
+ if (uiFragment != null) {
+ View mainView = uiFragment.findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(false);
}
- DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter());
+ DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter());
if (adapter != null) {
adapter.setLoadedFiles(indexActivatedFileNames, indexFileNames);
}
}
currentRunningTask.remove(this);
- if(uiActivity != null) {
- uiActivity.updateProgress(false);
+ if(uiFragment != null) {
+ uiFragment.updateProgress(false);
}
}
@@ -230,7 +232,7 @@ public class DownloadIndexesThread {
break downloadCycle;
}
if (exceedsFreelimit(entry)) {
- breakDownloadMessage = app.getString(R.string.free_version_message, DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
+ breakDownloadMessage = app.getString(R.string.free_version_message, DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
+ "");
break downloadCycle;
}
@@ -272,7 +274,7 @@ public class DownloadIndexesThread {
private boolean exceedsFreelimit(DownloadEntry entry) {
return Version.isFreeVersion(app) &&
- DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
+ DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
}
private String reindexFiles(List filesToReindex) {
@@ -322,8 +324,8 @@ public class DownloadIndexesThread {
boolean res = false;
if (de.isAsset) {
try {
- if (uiActivity != null) {
- ResourceManager.copyAssets(uiActivity.getAssets(), de.assetName, de.targetFile);
+ if (uiFragment != null) {
+ ResourceManager.copyAssets(uiFragment.getDownloadActivity().getAssets(), de.assetName, de.targetFile);
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
if(!changedDate) {
log.error("Set last timestamp is not supported");
@@ -344,8 +346,8 @@ public class DownloadIndexesThread {
@Override
protected void updateProgress(boolean updateOnlyProgress) {
- if(uiActivity != null) {
- uiActivity.updateProgress(updateOnlyProgress);
+ if(uiFragment != null) {
+ uiFragment.updateProgress(updateOnlyProgress);
}
}
}
@@ -376,19 +378,19 @@ public class DownloadIndexesThread {
protected void onPostExecute(IndexFileList result) {
indexFiles = result;
- if (indexFiles != null && uiActivity != null) {
- boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
+ if (indexFiles != null && uiFragment != null) {
+ boolean basemapExists = uiFragment.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap();
if (basemap != null ) {
- String dt = uiActivity.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
+ String dt = uiFragment.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate(dateFormat))) {
List downloadEntry = basemap
- .createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE,
+ .createDownloadEntry(uiFragment.getMyApplication(), DownloadActivityType.NORMAL_FILE,
new ArrayList());
- uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
- AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,
+ uiFragment.getDownloadActivity().getEntriesToDownload().put(basemap, downloadEntry);
+ AccessibleToast.makeText(uiFragment.getDownloadActivity(), R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show();
- uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
+ uiFragment.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
}
}
if (indexFiles.isIncreasedMapVersion()) {
@@ -398,9 +400,9 @@ public class DownloadIndexesThread {
AccessibleToast.makeText(ctx, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
}
currentRunningTask.remove(this);
- if (uiActivity != null) {
- uiActivity.updateProgress(false);
- runCategorization(uiActivity.getType());
+ if (uiFragment != null) {
+ uiFragment.updateProgress(false);
+ runCategorization(uiFragment.getDownloadActivity().getType());
}
}
@@ -429,8 +431,8 @@ public class DownloadIndexesThread {
@Override
protected void updateProgress(boolean updateOnlyProgress) {
- if (uiActivity != null) {
- uiActivity.updateProgress(updateOnlyProgress);
+ if (uiFragment != null) {
+ uiFragment.updateProgress(updateOnlyProgress);
}
};
@@ -469,8 +471,8 @@ public class DownloadIndexesThread {
super.onPreExecute();
currentRunningTask.add(this);
this.message = ctx.getString(R.string.downloading_list_indexes);
- if(uiActivity != null) {
- uiActivity.updateProgress(false);
+ if(uiFragment != null) {
+ uiFragment.updateProgress(false);
}
}
@@ -498,16 +500,17 @@ public class DownloadIndexesThread {
@Override
protected void onPostExecute(List filtered) {
- if (uiActivity != null) {
- DownloadIndexAdapter a = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter());
+ if (uiFragment != null) {
+ DownloadIndexAdapter a = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter());
a.setLoadedFiles(indexActivatedFileNames, indexFileNames);
a.setIndexFiles(filtered, cats);
+ prepareFilesToDownload(filtered);
a.notifyDataSetChanged();
- a.getFilter().filter(uiActivity.getFilterText());
+ a.getFilter().filter(uiFragment.getFilterText());
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);
+ Builder msg = new AlertDialog.Builder(uiFragment.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() {
@@ -525,15 +528,15 @@ public class DownloadIndexesThread {
}
}
currentRunningTask.remove(this);
- if(uiActivity != null) {
- uiActivity.updateProgress(false);
+ if(uiFragment != null) {
+ uiFragment.updateProgress(false);
}
}
@Override
protected void updateProgress(boolean updateOnlyProgress) {
- if(uiActivity != null) {
- uiActivity.updateProgress(updateOnlyProgress);
+ if(uiFragment != null) {
+ uiFragment.updateProgress(updateOnlyProgress);
}
};
@@ -542,7 +545,26 @@ public class DownloadIndexesThread {
execute(inst, new Void[0]);
}
-
+ private void prepareFilesToDownload(List filtered) {
+ itemsToUpdate.clear();
+ for (IndexItem item : filtered) {
+ String sfName = item.getTargetFileName();
+ java.text.DateFormat format = uiFragment.getDownloadActivity().getMyApplication().getResourceManager().getDateFormat();
+ String date = item.getDate(format);
+ String indexactivateddate = indexActivatedFileNames.get(sfName);
+ String indexfilesdate = indexFileNames.get(sfName);
+ if (date != null &&
+ !date.equals(indexactivateddate) &&
+ !date.equals(indexfilesdate) &&
+ indexActivatedFileNames.containsKey(sfName)) {
+ itemsToUpdate.add(item);
+ }
+ }
+ itemsToUpdate.size();
+ uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate);
+ }
+
+
public boolean isDownloadRunning() {
for (int i = 0; i < currentRunningTask.size(); i++) {
if (currentRunningTask.get(i) instanceof DownloadIndexesAsyncTask) {
diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java
similarity index 86%
rename from OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java
rename to OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java
index 350a77505a..8582e7f5cc 100644
--- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java
+++ b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java
@@ -1,4 +1,4 @@
-package net.osmand.plus.activities;
+package net.osmand.plus.download;
import java.io.File;
import java.text.MessageFormat;
@@ -10,6 +10,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.view.*;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
@@ -18,6 +20,7 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
+import net.osmand.plus.activities.*;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
@@ -30,12 +33,10 @@ import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.AsyncTask;
-import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.StatFs;
import android.text.SpannableString;
import android.text.TextPaint;
-import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -49,14 +50,9 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.TextView;
import android.widget.Toast;
-import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.ActionMode.Callback;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.view.SubMenu;
-import com.actionbarsherlock.view.Window;
-public class LocalIndexesActivity extends OsmandExpandableListActivity {
+public class LocalIndexesFragment extends OsmandExpandableListFragment {
private LoadLocalIndexTask asyncLoader;
private LocalIndexesAdapter listAdapter;
@@ -75,22 +71,48 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
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
- protected void onCreate(Bundle savedInstanceState) {
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+ public void onCreate(Bundle 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();
- listAdapter = new LocalIndexesAdapter(this);
-
+ updateDescriptionTextWithSize();
+ if (asyncLoader == null || asyncLoader.getResult() == null) {
+ // getLastNonConfigurationInstance method should be in onCreate() method
+ // (onResume() doesn't work)
+ Object indexes = getActivity().getLastNonConfigurationInstance();
+ asyncLoader = new LoadLocalIndexTask();
+ if (indexes instanceof List>) {
+ asyncLoader.setResult((List) indexes);
+ }
+ }
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (asyncLoader == null || asyncLoader.getResult() == null) {
+ asyncLoader = new LoadLocalIndexTask();
+ asyncLoader.execute(getActivity());
+ }
getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override
@@ -104,35 +126,14 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
}
}
});
-
- setListAdapter(listAdapter);
- updateDescriptionTextWithSize();
- if (asyncLoader == null || asyncLoader.getResult() == null) {
- // getLastNonConfigurationInstance method should be in onCreate() method
- // (onResume() doesn't work)
- Object indexes = getLastNonConfigurationInstance();
- asyncLoader = new LoadLocalIndexTask();
- if (indexes instanceof List>) {
- asyncLoader.setResult((List) indexes);
- }
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (asyncLoader == null || asyncLoader.getResult() == null) {
- asyncLoader = new LoadLocalIndexTask();
- asyncLoader.execute(this);
- }
}
private void showContextMenu(final LocalIndexInfo info) {
- Builder builder = new AlertDialog.Builder(this);
- final ContextMenuAdapter adapter = new ContextMenuAdapter(this);
+ Builder builder = new AlertDialog.Builder(getActivity());
+ final ContextMenuAdapter adapter = new ContextMenuAdapter(getActivity());
basicFileOperation(info, adapter);
- OsmandPlugin.onContextMenuActivity(this, null, info, adapter);
+ OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
String[] values = adapter.getItemNames();
builder.setItems(values, new DialogInterface.OnClickListener() {
@@ -158,7 +159,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} else if (resId == R.string.local_index_mi_restore) {
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
} else if (resId == R.string.local_index_mi_delete) {
- Builder confirm = new AlertDialog.Builder(LocalIndexesActivity.this);
+ Builder confirm = new AlertDialog.Builder(getActivity());
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@@ -187,9 +188,9 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
private void renameFile(LocalIndexInfo info) {
final File f = new File(info.getPathToData());
- Builder b = new AlertDialog.Builder(this);
+ Builder b = new AlertDialog.Builder(getActivity());
if(f.exists()){
- final EditText editText = new EditText(this);
+ final EditText editText = new EditText(getActivity());
editText.setText(f.getName());
b.setView(editText);
b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() {
@@ -199,7 +200,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
String newName = editText.getText().toString();
File dest = new File(f.getParentFile(), newName);
if (dest.exists()) {
- AccessibleToast.makeText(LocalIndexesActivity.this, 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();
@@ -207,7 +208,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
if(f.renameTo(dest)){
reloadIndexes();
} else {
- AccessibleToast.makeText(LocalIndexesActivity.this, 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();
}
}
@@ -234,9 +235,9 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
protected void onPreExecute() {
- setSupportProgressBarIndeterminateVisibility(true);
+ getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
}
-
+
@Override
protected void onProgressUpdate(LocalIndexInfo... values) {
for (LocalIndexInfo v : values) {
@@ -244,7 +245,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
}
listAdapter.notifyDataSetChanged();
}
-
+
public void setResult(List result) {
this.result = result;
if(result == null){
@@ -261,15 +262,15 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
protected void onPostExecute(List result) {
this.result = result;
- setSupportProgressBarIndeterminateVisibility(false);
+ getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
}
-
+
public List getResult() {
return result;
}
}
-
+
private File getFileToRestore(LocalIndexInfo i){
if(i.isBackupedData()){
File parent = new File(i.getPathToData()).getParentFile();
@@ -366,13 +367,13 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
protected void onPreExecute() {
- setProgressBarIndeterminateVisibility(true);
+ getDownloadActivity().setProgressBarIndeterminateVisibility(true);
}
@Override
protected void onPostExecute(String result) {
- setProgressBarIndeterminateVisibility(false);
- AccessibleToast.makeText(LocalIndexesActivity.this, result, Toast.LENGTH_LONG).show();
+ getDownloadActivity().setProgressBarIndeterminateVisibility(false);
+ AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
listAdapter.clear();
reloadIndexes();
@@ -431,7 +432,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
if(operationTask != null){
operationTask.cancel(true);
@@ -439,32 +440,32 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
}
@Override
- protected void onDestroy() {
+ public void onDestroy() {
super.onDestroy();
asyncLoader.cancel(true);
descriptionLoader.cancel(true);
}
- @Override
- public Object onRetainNonConfigurationInstance() {
- if(asyncLoader != null){
- return asyncLoader.getResult();
- }
- return super.onRetainNonConfigurationInstance();
- }
+// @Override
+// public Object onRetainNonConfigurationInstance() {
+// if(asyncLoader != null){
+// return asyncLoader.getResult();
+// }
+// return super.onRetainNonConfigurationInstance();
+// }
@Override
- public boolean onCreateOptionsMenu(Menu menu) {
- optionsMenuAdapter = new ContextMenuAdapter(this);
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ ActionBar actionBar = getDownloadActivity().getSupportActionBar();
+ //hide action bar from downloadindexfragment
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+ optionsMenuAdapter = new ContextMenuAdapter(getDownloadActivity());
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
localOptionsMenu(itemId);
}
};
- optionsMenuAdapter.item(R.string.local_index_download)
- .icons(R.drawable.ic_action_gdown_dark, R.drawable.ic_action_gdown_light)
- .listen(listener).position(0).reg();
optionsMenuAdapter.item(R.string.local_index_mi_reload)
.icons(R.drawable.ic_action_refresh_dark, R.drawable.ic_action_refresh_light)
.listen(listener).position(1).reg();
@@ -477,7 +478,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
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(this, null, optionsMenuAdapter);
+ OsmandPlugin.onOptionsMenuActivity(getDownloadActivity(), null, optionsMenuAdapter);
// doesn't work correctly
int max = getResources().getInteger(R.integer.abs__max_action_buttons);
SubMenu split = null;
@@ -502,18 +503,16 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
}
}
- return true;
}
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- if(operationTask == null || operationTask.getStatus() == Status.FINISHED){
- menu.setGroupVisible(0, true);
- } else {
- menu.setGroupVisible(0, false);
- }
- return true;
- }
+// @Override
+// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+// if(operationTask == null || operationTask.getStatus() == Status.FINISHED){
+// menu.setGroupVisible(0, true);
+// } else {
+// menu.setGroupVisible(0, false);
+// }
+// }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@@ -562,23 +561,23 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
final String actionButton = value;
if(listAdapter.getGroupCount() == 0){
listAdapter.cancelFilter();
- AccessibleToast.makeText(LocalIndexesActivity.this, 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 = 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 |
+ it.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@@ -591,12 +590,12 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (selectedItems.isEmpty()) {
- AccessibleToast.makeText(LocalIndexesActivity.this,
+ 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(LocalIndexesActivity.this);
+ 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);
@@ -607,15 +606,15 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
public void onDestroyActionMode(ActionMode mode) {
selectionMode = false;
- findViewById(R.id.DescriptionText).setVisibility(View.VISIBLE);
- updateDescriptionTextWithSize();
+ //findViewById(R.id.DescriptionText).setVisibility(View.VISIBLE);
+ //updateDescriptionTextWithSize();
listAdapter.cancelFilter();
collapseAllGroups();
listAdapter.notifyDataSetChanged();
}
-
+
});
- findViewById(R.id.DescriptionText).setVisibility(View.GONE);
+ //findViewById(R.id.DescriptionText).setVisibility(View.GONE);
listAdapter.notifyDataSetChanged();
}
@@ -626,7 +625,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
StatFs fs = new StatFs(dir.getAbsolutePath());
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
}
- TextView ds = (TextView) findViewById(R.id.DescriptionText);
+ //TextView ds = (TextView) findViewById(R.id.DescriptionText);
String text = getString(R.string.download_link_and_local_description, size);
int l = text.indexOf('.');
if(l == -1) {
@@ -637,7 +636,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
public void onClick(View widget) {
asyncLoader.setResult(null);
- startActivity(new Intent(LocalIndexesActivity.this, DownloadIndexActivity.class));
+ startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
}
@Override
@@ -646,8 +645,8 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
// ds.setColor(Color.GREEN);
}
}, 0, l, 0);
- ds.setText(content);
- ds.setMovementMethod(LinkMovementMethod.getInstance());
+ //ds.setText(content);
+ //ds.setMovementMethod(LinkMovementMethod.getInstance());
}
@@ -655,7 +654,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
public void localOptionsMenu(final int itemId) {
if (itemId == R.string.local_index_download) {
asyncLoader.setResult(null);
- startActivity(new Intent(LocalIndexesActivity.this, DownloadIndexActivity.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) {
@@ -708,7 +707,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override
protected void onPostExecute(List warnings) {
- setProgressBarIndeterminateVisibility(false);
+ getDownloadActivity().setProgressBarIndeterminateVisibility(false);
if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder();
boolean f = true;
@@ -720,17 +719,17 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
}
b.append(w);
}
- AccessibleToast.makeText(LocalIndexesActivity.this, b.toString(), Toast.LENGTH_LONG).show();
+ AccessibleToast.makeText(getDownloadActivity(), b.toString(), Toast.LENGTH_LONG).show();
}
if(asyncLoader.getStatus() == Status.PENDING) {
- asyncLoader.execute(LocalIndexesActivity.this);
+ asyncLoader.execute(getDownloadActivity());
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
- setProgressBarIndeterminateVisibility(true);
+ getDownloadActivity().setProgressBarIndeterminateVisibility(true);
}
@Override
protected List doInBackground(Void... params) {
@@ -878,12 +877,12 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
View v = convertView;
final LocalIndexInfo child = (LocalIndexInfo) getChild(groupPosition, childPosition);
if (v == null ) {
- LayoutInflater inflater = getLayoutInflater();
+ 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) 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);
@@ -952,10 +951,10 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
View v = convertView;
LocalIndexInfo group = getGroup(groupPosition);
if (v == null) {
- LayoutInflater inflater = getLayoutInflater();
+ 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(LocalIndexesActivity.this));
+ StringBuilder t = new StringBuilder(group.getType().getHumanString(getDownloadActivity()));
if(group.getSubfolder() != null) {
t.append(" ").append(group.getSubfolder());
}
@@ -1036,4 +1035,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
return "";
}
}
+
+ private DownloadActivity getDownloadActivity(){ return (DownloadActivity)getActivity();}
}
diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java
new file mode 100644
index 0000000000..8a0f0189d9
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java
@@ -0,0 +1,125 @@
+package net.osmand.plus.download;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.*;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockListFragment;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import net.osmand.map.OsmandRegions;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.OsmandExpandableListFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by Denis on 09.09.2014.
+ */
+public class UpdatesIndexFragment extends SherlockListFragment {
+
+ private OsmandRegions osmandRegions;
+ private java.text.DateFormat format;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ format = getMyApplication().getResourceManager().getDateFormat();
+ osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
+ setListAdapter(new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, DownloadActivity.downloadListIndexThread.getItemsToUpdate()));
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ Map> map = getDownloadActivity().getEntriesToDownload();
+
+ }
+
+ public void updateItemsList(List items){
+ UpdateIndexAdapter adapter = (UpdateIndexAdapter) getListAdapter();
+ if (adapter == null){
+ return;
+ }
+ adapter.clear();
+ for (IndexItem item : items){
+ adapter.add(item);
+ }
+ }
+
+ @Override
+ public void onListItemClick(ListView l, View v, int position, long id) {
+ super.onListItemClick(l, v, position, id);
+ }
+
+ public DownloadActivity getDownloadActivity() { return (DownloadActivity)getActivity(); }
+
+ private class UpdateIndexAdapter extends ArrayAdapter{
+ List items;
+
+ public UpdateIndexAdapter(Context context, int resource, List items) {
+ super(context, resource, items);
+ this.items = items;
+ }
+
+ @Override
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ View v = convertView;
+
+ if(v == null){
+ LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ v = inflater.inflate(R.layout.download_index_list_item, null);
+ }
+
+ TextView name = (TextView) v.findViewById(R.id.download_item);
+ TextView description = (TextView) v.findViewById(R.id.download_descr);
+ IndexItem e = items.get(position);
+ String eName = e.getVisibleDescription(getMyApplication()) + "\n" + e.getVisibleName(getMyApplication(), osmandRegions);
+ name.setText(eName.trim()); //$NON-NLS-1$
+ String d = e.getDate(format) + "\n" + e.getSizeDescription(getMyApplication());
+ description.setText(d);
+
+ final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
+ ch.setChecked(getDownloadActivity().getEntriesToDownload().containsKey(e));
+ ch.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ch.setChecked(!ch.isChecked());
+ final IndexItem e = (IndexItem) getListAdapter().getItem(position);
+ if(ch.isChecked()){
+ ch.setChecked(!ch.isChecked());
+ getDownloadActivity().getEntriesToDownload().remove(e);
+ getDownloadActivity().updateDownloadButton(true);
+ return;
+ }
+
+ List download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList());
+ if (download.size() > 0) {
+ getDownloadActivity().getEntriesToDownload().put(e, download);
+ getDownloadActivity().updateDownloadButton(true);
+ ch.setChecked(!ch.isChecked());
+ }
+
+ }
+ });
+
+ return v;
+ }
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ ActionBar actionBar = getDownloadActivity().getSupportActionBar();
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+ }
+
+ public OsmandApplication getMyApplication() { return getDownloadActivity().getMyApplication(); }
+}
diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java
index 6c34d01623..3bd0e573c3 100644
--- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java
+++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java
@@ -29,13 +29,14 @@ import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.Version;
-import net.osmand.plus.activities.DownloadIndexActivity;
+import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.SelectedGPXFragment;
import net.osmand.plus.activities.actions.ShareLocation;
import net.osmand.plus.api.FileSettingsAPIImpl;
import net.osmand.plus.api.SettingsAPI;
+import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.routing.RouteCalculationResult;
@@ -106,8 +107,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase();
- if(DownloadIndexActivity.downloadListIndexThread != null) {
- DownloadIndexActivity.downloadListIndexThread.clear();
+ if(DownloadActivity.downloadListIndexThread != null) {
+ DownloadActivity.downloadListIndexThread.clear();
}
if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode);
@@ -181,7 +182,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
public void updatedLoadedFiles(java.util.Map indexFileNames, java.util.Map indexActivatedFileNames) {
- DownloadIndexActivity.listWithAlternatives(app.getResourceManager().getDateFormat(),
+ DownloadIndexFragment.listWithAlternatives(app.getResourceManager().getDateFormat(),
toursFolder, "", indexFileNames);
}
@@ -197,7 +198,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
for(File tr : availableTours) {
if (tr.isDirectory()) {
String date = app.getResourceManager().getDateFormat()
- .format(new Date(DownloadIndexActivity.findFileInDir(tr).lastModified()));
+ .format(new Date(DownloadIndexFragment.findFileInDir(tr).lastModified()));
indexFileNames.put(tr.getName(), date);
final TourInformation tourInformation = new TourInformation(tr);
tourPresent.add(tourInformation);
@@ -228,7 +229,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
- final DownloadIndexActivity da = app.getDownloadActivity();
+ final DownloadIndexFragment da = app.getDownloadActivity();
if (da != null) {
app.runInUIThread(new Runnable() {
@@ -626,7 +627,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
return s;
}
- public void preDownloadActivity(final DownloadIndexActivity da, final List downloadTypes, ActionBar actionBar) {
+ public void preDownloadActivity(final DownloadActivity da, final List downloadTypes, ActionBar actionBar) {
actionBar.setTitle(TourDownloadType.TOUR.getString(da));
}
diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java
index 0b07c48322..04f1549bae 100644
--- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java
+++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java
@@ -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.DownloadIndexActivity;
+import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import android.content.Intent;
@@ -376,7 +376,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
public void startDownloadActivity() {
- final Intent download = new Intent(this, DownloadIndexActivity.class);
+ final Intent download = new Intent(this, DownloadIndexFragment.class);
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
refreshListAfterDownload = true;
startActivity(download);
diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java
index 5d091c475a..af24a3f559 100644
--- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java
@@ -12,7 +12,8 @@ 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.DownloadIndexActivity;
+import net.osmand.plus.download.DownloadActivity;
+import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@@ -87,7 +88,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
@Override
public void onClick(View v) {
final Intent intent = new Intent(view.getContext(), view.getApplication().getAppCustomization().getDownloadIndexActivity());
- intent.putExtra(DownloadIndexActivity.FILTER_KEY, filter.toString());
+ intent.putExtra(DownloadActivity.FILTER_KEY, filter.toString());
view.getContext().startActivity(intent);
}
});