From 605d4c3e9e449b7cdf10cb5cb00f1c8901e4b11d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 13 Aug 2014 02:11:32 +0200 Subject: [PATCH] Add special download for sherpafy --- OsmAnd/res/layout/waypoint_reached.xml | 2 ++ OsmAnd/res/values/sherpafy.xml | 1 + OsmAnd/res/values/strings.xml | 2 ++ .../net/osmand/plus/OsmAndAppCustomization.java | 6 +++++- .../download/DownloadOsmandIndexesHelper.java | 13 ++++--------- .../plus/sherpafy/SherpafyCustomization.java | 17 ++++++++++++++++- .../sherpafy/SherpafySelectToursFragment.java | 8 +++++++- .../osmand/plus/sherpafy/TourDownloadType.java | 7 ++++++- .../osmand/plus/sherpafy/TourViewActivity.java | 10 ++++++---- .../plus/sherpafy/WaypointDialogHelper.java | 2 +- 10 files changed, 50 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/layout/waypoint_reached.xml b/OsmAnd/res/layout/waypoint_reached.xml index 0613ff603e..3844a6cc51 100644 --- a/OsmAnd/res/layout/waypoint_reached.xml +++ b/OsmAnd/res/layout/waypoint_reached.xml @@ -26,6 +26,7 @@ + Public access Do you want to interrupt current stage and start new ? Enter access code to see if you are entitled for a specific tour (optional) Fav diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c32a65f305..fee7b7d286 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Less... + More... Colored buildings Invite... Do you want to leave group %1$s? diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index 411839b89f..7dfb263dc8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import net.osmand.IProgress; +import net.osmand.IndexConstants; import net.osmand.data.FavouritePoint; import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.FavouritesActivity; @@ -16,7 +17,6 @@ import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.download.DownloadActivityType; -import net.osmand.plus.views.OsmandMapTileView; import android.app.Activity; import android.view.Window; @@ -107,4 +107,8 @@ public class OsmAndAppCustomization { return null; } + public String getIndexesUrl() { + return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$; + } + } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 1cef1a6fcf..e4e61fb1bd 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -4,8 +4,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,8 +14,6 @@ import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.Version; -import net.osmand.plus.sherpafy.TourDownloadType; import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; @@ -29,7 +25,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; -import android.text.format.DateFormat; public class DownloadOsmandIndexesHelper { private final static Log log = PlatformUtil.getLog(DownloadOsmandIndexesHelper.class); @@ -38,8 +33,7 @@ public class DownloadOsmandIndexesHelper { public static IndexFileList getIndexesList(Context ctx) { PackageManager pm =ctx.getPackageManager(); AssetManager amanager = ctx.getAssets(); - String versionUrlParam = Version.getVersionAsURLParam(((OsmandApplication) ctx.getApplicationContext())); - IndexFileList result = downloadIndexesListFromInternet(ctx, versionUrlParam); + IndexFileList result = downloadIndexesListFromInternet((OsmandApplication) ctx.getApplicationContext()); if (result == null) { result = new IndexFileList(); } else { @@ -115,12 +109,13 @@ public class DownloadOsmandIndexesHelper { } - private static IndexFileList downloadIndexesListFromInternet(Context ctx, String versionAsUrl){ + private static IndexFileList downloadIndexesListFromInternet(OsmandApplication ctx){ try { IndexFileList result = new IndexFileList(); log.debug("Start loading list of index files"); //$NON-NLS-1$ try { - String strUrl = "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + versionAsUrl; //$NON-NLS-1$ + String strUrl = ctx.getAppCustomization().getIndexesUrl(); + log.info(strUrl); URL url = new URL(strUrl ); XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java index d41b1ed94c..1448ec02ed 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.TreeSet; import net.osmand.IProgress; +import net.osmand.IndexConstants; import net.osmand.data.FavouritePoint; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.GPXUtilities; @@ -18,6 +19,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; +import net.osmand.plus.Version; import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; @@ -25,6 +27,7 @@ import net.osmand.plus.api.FileSettingsAPIImpl; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageInformation; +import net.osmand.util.Algorithms; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -37,9 +40,11 @@ public class SherpafyCustomization extends OsmAndAppCustomization { private static final String SELECTED_TOUR = "selected_tour"; private static final String ACCESS_CODE = "access_code"; private static final String SELECTED_STAGE = "selected_stage"; + private static final String VISITED_STAGES = "visited_STAGES"; private OsmandSettings originalSettings; private CommonPreference selectedTourPref; private CommonPreference selectedStagePref; + private CommonPreference visitedStagesPref; private List tourPresent = new ArrayList(); private StageInformation selectedStage = null; private TourInformation selectedTour = null; @@ -58,7 +63,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { public boolean setAccessCode(String acCode) { acCode = acCode.toUpperCase(); - if(validate(acCode)) { + if(validate(acCode) || Algorithms.isEmpty(acCode)) { accessCodePref.set(acCode); return true; } @@ -193,6 +198,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { app.showToastMessage(R.string.settings_file_create_error); } selectedStagePref = app.getSettings().registerStringPreference(SELECTED_STAGE, null).makeGlobal(); + visitedStagesPref = app.getSettings().registerStringPreference(VISITED_STAGES, null).makeGlobal(); selectedTour = tourInformation; } @@ -309,4 +315,13 @@ public class SherpafyCustomization extends OsmAndAppCustomization { public List getFavorites() { return cachedFavorites; } + + @Override + public String getIndexesUrl() { + String s = "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/tours.php?gzip&" + Version.getVersionAsURLParam(app); + if(!Algorithms.isEmpty(accessCodePref.get())) { + s += "&code="+accessCodePref.get(); + } + return s; + } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java index 70b6b93c31..a19f6471a8 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java @@ -96,7 +96,13 @@ public class SherpafySelectToursFragment extends SherlockListFragment { ll.setPadding(5, 3, 5, 0); ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); builder.setView(ll); - builder.setNegativeButton(R.string.default_buttons_cancel, null); + builder.setNegativeButton(R.string.sherpafy_public_access, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + custom.setAccessCode(""); + ((TourViewActivity) getActivity()).startDownloadActivity(); + } + }); builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourDownloadType.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourDownloadType.java index e28fc654cd..a225b8cc7d 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourDownloadType.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourDownloadType.java @@ -8,6 +8,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.IndexItem; +import net.osmand.util.Algorithms; import android.content.Context; public class TourDownloadType extends DownloadActivityType { @@ -43,7 +44,11 @@ public class TourDownloadType extends DownloadActivityType { } public String getUrlSuffix(OsmandApplication ctx) { - return "&tour=yes"; + String accessCode = ""; + if (ctx.getAppCustomization() instanceof SherpafyCustomization) { + accessCode = ((SherpafyCustomization) ctx.getAppCustomization()).getAccessCode(); + } + return "&tour=yes" + (Algorithms.isEmpty(accessCode) ? "" : "&code=" + accessCode); } public String getVisibleDescription(IndexItem indexItem, Context ctx) { diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 17c7d3b81b..a9daf40e9d 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -3,8 +3,6 @@ package net.osmand.plus.sherpafy; import java.util.List; import java.util.WeakHashMap; -import android.view.KeyEvent; -import android.widget.*; import net.osmand.IProgress; import net.osmand.data.LatLon; import net.osmand.plus.GPXUtilities.GPXFile; @@ -32,7 +30,12 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; @@ -55,7 +58,6 @@ public class TourViewActivity extends SherlockFragmentActivity { private SherpafyCustomization customization; - private Point displaySize; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; private ListView mDrawerList; @@ -106,7 +108,6 @@ public class TourViewActivity extends SherlockFragmentActivity { } }); - displaySize = new Point(getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getHeight()); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer_light, R.string.default_buttons_other_actions, R.string.close); if (getMyApplication().isApplicationInitializing()) { @@ -420,6 +421,7 @@ public class TourViewActivity extends SherlockFragmentActivity { WptPt point = null; GPXFile gpx = null; customization.selectTour(tour, IProgress.EMPTY_PROGRESS); + customization.selectStage(stage, IProgress.EMPTY_PROGRESS); if (customization.getSelectedStage() != null) { gpx = customization.getSelectedStage().getGpx(); diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java index eb8ead13fa..80fa2f0a4d 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java @@ -64,7 +64,7 @@ public class WaypointDialogHelper { updatePointInfoView(closePointDialog, point); closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black)); - ((TextView)closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE); + ((TextView) closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE); View all = closePointDialog.findViewById(R.id.all_points); all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE); all.setOnClickListener(new View.OnClickListener() {