Complete stage fragment

This commit is contained in:
Victor Shcherb 2014-08-15 09:41:18 +02:00
parent 657bf17d82
commit 998cbb6c28
5 changed files with 53 additions and 33 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <resources>
<string name="stage_is_completed">Stage is completed</string>
<string name="complete_stage">Complete Stage</string> <string name="complete_stage">Complete Stage</string>
<string name="show_waypoint_information">About waypoint</string> <string name="show_waypoint_information">About waypoint</string>
<string name="sherpafy_public_access">Public access</string> <string name="sherpafy_public_access">Public access</string>

View file

@ -19,7 +19,6 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;

View file

@ -36,7 +36,6 @@ public class WaypointDialogHelper {
private WaypointHelper waypointHelper; private WaypointHelper waypointHelper;
public static boolean OVERLAP_LAYOUT = true; public static boolean OVERLAP_LAYOUT = true;
private long uiModified;
private View closePointDialog; private View closePointDialog;
private static final String GPX_WAYPOINTS = "GPX waypoints"; private static final String GPX_WAYPOINTS = "GPX waypoints";
@ -53,25 +52,23 @@ public class WaypointDialogHelper {
public void updateDialog() { public void updateDialog() {
List<LocationPoint> vlp = waypointHelper.getAllVisibleLocationPoints(); List<LocationPoint> vlp = waypointHelper.getAllVisibleLocationPoints();
long locationPointsModified = waypointHelper.getLocationPointsModified(); if (vlp.isEmpty()) {
if (locationPointsModified != uiModified) { removeDialog();
uiModified = locationPointsModified; } else {
if (vlp.isEmpty()) { final LocationPoint point = vlp.get(0);
removeDialog(); boolean created = false;
} else { if (closePointDialog == null) {
final LocationPoint point = vlp.get(0); created = true;
boolean created = false; final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (closePointDialog == null) { closePointDialog = vi.inflate(R.layout.waypoint_reached, 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)); 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() { all.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -88,10 +85,8 @@ public class WaypointDialogHelper {
} }
}); });
if (created) { mainLayout.addView(closePointDialog, getDialogLayoutParams());
mainLayout.addView(closePointDialog, getDialogLayoutParams()); waitBeforeLayoutIsResized(closePointDialog);
waitBeforeLayoutIsResized(closePointDialog);
}
} }
} }
} }

View file

@ -22,7 +22,6 @@ public class WaypointHelper {
// every time we modify this collection, we change the reference (copy on write list) // every time we modify this collection, we change the reference (copy on write list)
private List<LocationPoint> visibleLocationPoints = new ArrayList<LocationPoint>(); private List<LocationPoint> visibleLocationPoints = new ArrayList<LocationPoint>();
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>(); private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
private long locationPointsModified;
private Location lastKnownLocation; private Location lastKnownLocation;
private static final int NOT_ANNOUNCED = 0; private static final int NOT_ANNOUNCED = 0;
@ -81,14 +80,9 @@ public class WaypointHelper {
} }
} }
public long getLocationPointsModified() {
return locationPointsModified;
}
public void removeVisibleLocationPoint(LocationPoint lp) { public void removeVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints = removeFromList(visibleLocationPoints, lp); this.visibleLocationPoints = removeFromList(visibleLocationPoints, lp);
this.locationPointsStates.remove(lp); this.locationPointsStates.remove(lp);
this.locationPointsModified = System.currentTimeMillis();
} }
public void announceVisibleLocations() { public void announceVisibleLocations() {
@ -103,12 +97,10 @@ public class WaypointHelper {
if (state <= ANNOUNCED_ONCE && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS)) { if (state <= ANNOUNCED_ONCE && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS)) {
nameToAnnounce = (nameToAnnounce == null ? "" : ", ") + point.getName(); nameToAnnounce = (nameToAnnounce == null ? "" : ", ") + point.getName();
locationPointsStates.remove(point); locationPointsStates.remove(point);
this.locationPointsModified = System.currentTimeMillis();
app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog();
announcePoints.add(point); announcePoints.add(point);
} else if (state == NOT_ANNOUNCED && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS)) { } else if (state == NOT_ANNOUNCED && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS)) {
locationPointsStates.put(point, state + 1); locationPointsStates.put(point, state + 1);
this.locationPointsModified = System.currentTimeMillis();
app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog();
approachPoints.add(point); approachPoints.add(point);
} }
@ -125,14 +117,12 @@ public class WaypointHelper {
public void addVisibleLocationPoint(LocationPoint lp) { public void addVisibleLocationPoint(LocationPoint lp) {
this.locationPointsStates.put(lp, NOT_ANNOUNCED); this.locationPointsStates.put(lp, NOT_ANNOUNCED);
this.locationPointsModified = System.currentTimeMillis();
sortVisibleWaypoints(); sortVisibleWaypoints();
} }
public void clearAllVisiblePoints() { public void clearAllVisiblePoints() {
this.locationPointsStates.clear(); this.locationPointsStates.clear();
this.visibleLocationPoints = new ArrayList<LocationPoint>(); this.visibleLocationPoints = new ArrayList<LocationPoint>();
this.locationPointsModified = System.currentTimeMillis();
} }
public void setVisibleLocationPoints(List<LocationPoint> points) { public void setVisibleLocationPoints(List<LocationPoint> points) {

View file

@ -37,6 +37,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.Window; import android.view.Window;
import android.widget.TextView; import android.widget.TextView;
@ -267,6 +268,33 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
selectNextAvailableStage(si.tour); 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() { public StageInformation getSelectedStage() {
return selectedStage; return selectedStage;
} }
@ -279,13 +307,17 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} else { } else {
selectedStagePref.set(stage.getOrder()); selectedStagePref.set(stage.getOrder());
selectedStage = stage; selectedStage = stage;
File fl = new File(stage.tour.getFolder(), "record" + stage.getOrder()); File fl = getStageGpxRec(stage);
fl.mkdirs(); fl.mkdirs();
saveGPXFolder.set(fl.getAbsolutePath()); saveGPXFolder.set(fl.getAbsolutePath());
} }
loadSelectedStage(); loadSelectedStage();
} }
protected File getStageGpxRec(StageInformation stage) {
return new File(stage.tour.getFolder(), "record" + stage.getOrder());
}
private void loadSelectedStage() { private void loadSelectedStage() {
final StageInformation st = selectedStage; final StageInformation st = selectedStage;
cachedFavorites = new ArrayList<StageFavorite>(); cachedFavorites = new ArrayList<StageFavorite>();
@ -389,6 +421,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
markStageAsCompleted(stage); markStageAsCompleted(stage);
showCompleteStageFragment(mapActivity, stage);
} }
}).reg(); }).reg();
} }
@ -403,6 +436,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}).reg(); }).reg();
} }
public void filter(ContextMenuAdapter a, Integer... ids) { public void filter(ContextMenuAdapter a, Integer... ids) {
if(isSettingsAvailable()) { if(isSettingsAvailable()) {
return; return;