From 998cbb6c28e5153aa436fc61df381dee1ef5da27 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 15 Aug 2014 09:41:18 +0200 Subject: [PATCH] Complete stage fragment --- OsmAnd/res/values/sherpafy.xml | 1 + .../plus/activities/SelectedGPXFragment.java | 1 - .../plus/helpers/WaypointDialogHelper.java | 37 ++++++++----------- .../osmand/plus/helpers/WaypointHelper.java | 10 ----- .../plus/sherpafy/SherpafyCustomization.java | 37 ++++++++++++++++++- 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/OsmAnd/res/values/sherpafy.xml b/OsmAnd/res/values/sherpafy.xml index 8e361e80a3..d9d6fafaf0 100644 --- a/OsmAnd/res/values/sherpafy.xml +++ b/OsmAnd/res/values/sherpafy.xml @@ -1,5 +1,6 @@ + Stage is completed Complete Stage About waypoint Public access diff --git a/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java index 92d69871bc..f1ec0cb4f0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java @@ -19,7 +19,6 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.R; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.util.Algorithms; diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 171df1ba8f..081433a3ec 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -36,7 +36,6 @@ public class WaypointDialogHelper { private WaypointHelper waypointHelper; public static boolean OVERLAP_LAYOUT = true; - private long uiModified; private View closePointDialog; private static final String GPX_WAYPOINTS = "GPX waypoints"; @@ -53,25 +52,23 @@ public class WaypointDialogHelper { public void updateDialog() { List vlp = waypointHelper.getAllVisibleLocationPoints(); - long locationPointsModified = waypointHelper.getLocationPointsModified(); - if (locationPointsModified != uiModified) { - uiModified = locationPointsModified; - if (vlp.isEmpty()) { - removeDialog(); - } else { - final LocationPoint point = vlp.get(0); - boolean created = false; - if (closePointDialog == null) { - created = true; - final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - closePointDialog = vi.inflate(R.layout.waypoint_reached, null); - } + if (vlp.isEmpty()) { + removeDialog(); + } else { + final LocationPoint point = vlp.get(0); + boolean created = false; + if (closePointDialog == null) { + created = true; + final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + closePointDialog = vi.inflate(R.layout.waypoint_reached, null); + } - updatePointInfoView(closePointDialog, point); + updatePointInfoView(closePointDialog, point); + View all = closePointDialog.findViewById(R.id.all_points); + all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE); + if (created) { closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black)); ((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() { @Override public void onClick(View view) { @@ -88,10 +85,8 @@ public class WaypointDialogHelper { } }); - if (created) { - mainLayout.addView(closePointDialog, getDialogLayoutParams()); - waitBeforeLayoutIsResized(closePointDialog); - } + mainLayout.addView(closePointDialog, getDialogLayoutParams()); + waitBeforeLayoutIsResized(closePointDialog); } } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 9085e227f7..7f73e32c5f 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -22,7 +22,6 @@ public class WaypointHelper { // every time we modify this collection, we change the reference (copy on write list) private List visibleLocationPoints = new ArrayList(); private ConcurrentHashMap locationPointsStates = new ConcurrentHashMap(); - private long locationPointsModified; private Location lastKnownLocation; private static final int NOT_ANNOUNCED = 0; @@ -81,14 +80,9 @@ public class WaypointHelper { } } - public long getLocationPointsModified() { - return locationPointsModified; - } - public void removeVisibleLocationPoint(LocationPoint lp) { this.visibleLocationPoints = removeFromList(visibleLocationPoints, lp); this.locationPointsStates.remove(lp); - this.locationPointsModified = System.currentTimeMillis(); } public void announceVisibleLocations() { @@ -103,12 +97,10 @@ public class WaypointHelper { if (state <= ANNOUNCED_ONCE && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS)) { nameToAnnounce = (nameToAnnounce == null ? "" : ", ") + point.getName(); locationPointsStates.remove(point); - this.locationPointsModified = System.currentTimeMillis(); app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); announcePoints.add(point); } else if (state == NOT_ANNOUNCED && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS)) { locationPointsStates.put(point, state + 1); - this.locationPointsModified = System.currentTimeMillis(); app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); approachPoints.add(point); } @@ -125,14 +117,12 @@ public class WaypointHelper { public void addVisibleLocationPoint(LocationPoint lp) { this.locationPointsStates.put(lp, NOT_ANNOUNCED); - this.locationPointsModified = System.currentTimeMillis(); sortVisibleWaypoints(); } public void clearAllVisiblePoints() { this.locationPointsStates.clear(); this.visibleLocationPoints = new ArrayList(); - this.locationPointsModified = System.currentTimeMillis(); } public void setVisibleLocationPoints(List points) { diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java index c24f65ae51..3624f9df5e 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java @@ -37,6 +37,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.view.Window; import android.widget.TextView; @@ -267,6 +268,33 @@ public class SherpafyCustomization extends OsmAndAppCustomization { selectNextAvailableStage(si.tour); } + public static class CompleteStageFragment extends DialogFragment { + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { +// Bundle args = getArguments(); +// SherpafyFavoriteFragment ssf = new SherpafyFavoriteFragment(); +// ssf.setArguments(args); +// ssf.onAttach(getActivity()); + AlertDialog dlg = new AlertDialog.Builder(getActivity()) +// .setView(ssf.onCreateView(getActivity().getLayoutInflater(), null, savedInstanceState)) + .setMessage("Stage is completed TODO") + .setPositiveButton(R.string.default_buttons_ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + } + } + ) + .create(); + return dlg; + } + } + + protected void showCompleteStageFragment(FragmentActivity activity, StageInformation stage) { + // TODO Auto-generated method stub + + } + public StageInformation getSelectedStage() { return selectedStage; } @@ -279,13 +307,17 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } else { selectedStagePref.set(stage.getOrder()); selectedStage = stage; - File fl = new File(stage.tour.getFolder(), "record" + stage.getOrder()); + File fl = getStageGpxRec(stage); fl.mkdirs(); saveGPXFolder.set(fl.getAbsolutePath()); } loadSelectedStage(); } + protected File getStageGpxRec(StageInformation stage) { + return new File(stage.tour.getFolder(), "record" + stage.getOrder()); + } + private void loadSelectedStage() { final StageInformation st = selectedStage; cachedFavorites = new ArrayList(); @@ -389,6 +421,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { @Override public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { markStageAsCompleted(stage); + showCompleteStageFragment(mapActivity, stage); } }).reg(); } @@ -403,6 +436,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization { }).reg(); } + + public void filter(ContextMenuAdapter a, Integer... ids) { if(isSettingsAvailable()) { return;