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"?>
<resources>
<string name="stage_is_completed">Stage is completed</string>
<string name="complete_stage">Complete Stage</string>
<string name="show_waypoint_information">About waypoint</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.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;

View file

@ -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<LocationPoint> 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);
}
}
}

View file

@ -22,7 +22,6 @@ public class WaypointHelper {
// every time we modify this collection, we change the reference (copy on write list)
private List<LocationPoint> visibleLocationPoints = new ArrayList<LocationPoint>();
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
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<LocationPoint>();
this.locationPointsModified = System.currentTimeMillis();
}
public void setVisibleLocationPoints(List<LocationPoint> points) {

View file

@ -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<StageFavorite>();
@ -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;