mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-09 13:50:57 +00:00
App: Changed course designer to cope with empty passing sides. The last published course is shown when the course from the server is empty
This commit is contained in:
1 parent
c73b152c64
commit
00800ccfdf
1 file changed
+48
-10
+48
-10
@@ -15,6 +15,7 @@ import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ListView;
|
||||
@@ -149,6 +150,16 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
}
|
||||
});
|
||||
|
||||
newCourseListView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
|
||||
CourseListDataElement courseElement = courseElementAdapter.getItem(position);
|
||||
createRoundingDirectionDialog(courseElement);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
dragSortController = buildDragSortController(newCourseListView);
|
||||
newCourseListView.setFloatViewManager(dragSortController);
|
||||
newCourseListView.setOnTouchListener(dragSortController);
|
||||
@@ -186,7 +197,12 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
CourseBase courseData = convertCourseElementsToACourseData();
|
||||
sendCourseDataAndDismiss(courseData);
|
||||
} catch (IllegalStateException ex) {
|
||||
Toast.makeText(getActivity(), "A right buoy is missing for a gate. Please select the right buoy.", Toast.LENGTH_LONG).show();
|
||||
if (ex.getMessage().equals("Gate has no right buoy")) {
|
||||
Toast.makeText(getActivity(), "A right buoy is missing for a gate. Please select the right buoy.", Toast.LENGTH_LONG).show();
|
||||
} else if (ex.getMessage().equals("Each waypoints needs a passing side")) {
|
||||
Toast.makeText(getActivity(), "A waypoint has no passing side. Please select the passing side by clicking long on the waypoint.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Toast.makeText(getActivity(), "The course design has to have at least one waypoint.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
@@ -233,19 +249,28 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception reason) {
|
||||
CourseBase lastPublishedCourseDesign = InMemoryDataStore.INSTANCE.getLastPublishedCourseDesign();
|
||||
if(lastPublishedCourseDesign != null) {
|
||||
fillPreviousCourseElementsInList(lastPublishedCourseDesign);
|
||||
}
|
||||
fillPreviousCourseElementsWithLastPublishedCourseDesign();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadSucceded(CourseBase data) {
|
||||
fillPreviousCourseElementsInList(data);
|
||||
if (Util.size(data.getWaypoints()) > 0) {
|
||||
fillPreviousCourseElementsInList(data);
|
||||
} else {
|
||||
fillPreviousCourseElementsWithLastPublishedCourseDesign();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void fillPreviousCourseElementsWithLastPublishedCourseDesign() {
|
||||
CourseBase lastPublishedCourseDesign = InMemoryDataStore.INSTANCE.getLastPublishedCourseDesign();
|
||||
if(lastPublishedCourseDesign != null) {
|
||||
fillPreviousCourseElementsInList(lastPublishedCourseDesign);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadMarks() {
|
||||
hostActivity.getDataManager().loadMarks(getRace(), new LoadClient<Collection<Mark>>() {
|
||||
@@ -337,6 +362,8 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
waypoints.add(waypoint);
|
||||
} else if (courseElement.getRoundingDirection().equals(RoundingDirection.Gate) && courseElement.getRightMark() == null) {
|
||||
throw new IllegalStateException("Gate has no right buoy");
|
||||
} else if (courseElement.getRoundingDirection().equals(RoundingDirection.None)) {
|
||||
throw new IllegalStateException("Each waypoints needs a passing side");
|
||||
} else {
|
||||
Waypoint waypoint = new WaypointImpl(courseElement.getLeftMark(), getNauticalSide(courseElement.getRoundingDirection()));
|
||||
|
||||
@@ -412,9 +439,9 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
if (courseElements.isEmpty()) {
|
||||
addNewCourseElementToList(mark);
|
||||
} else {
|
||||
CourseListDataElement lastCourseElement = courseElements.get(courseElements.size() - 1);
|
||||
if (lastCourseElement.getRoundingDirection().equals(RoundingDirection.Gate) && lastCourseElement.getRightMark() == null) {
|
||||
lastCourseElement.setRightMark(mark);
|
||||
CourseListDataElement gateCourseElement = getFirstGateCourseElementWithoutRightMark();
|
||||
if (gateCourseElement != null) {
|
||||
gateCourseElement.setRightMark(mark);
|
||||
courseElementAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
addNewCourseElementToList(mark);
|
||||
@@ -422,6 +449,15 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private CourseListDataElement getFirstGateCourseElementWithoutRightMark() {
|
||||
for (CourseListDataElement courseElement : courseElements) {
|
||||
if (courseElement.getRoundingDirection().equals(RoundingDirection.Gate) && courseElement.getRightMark() == null) {
|
||||
return courseElement;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addNewCourseElementToList(Mark mark) {
|
||||
CourseListDataElement courseElement = new CourseListDataElement();
|
||||
courseElement.setLeftMark(mark);
|
||||
@@ -448,7 +484,9 @@ public class CourseDesignDialogFragment extends RaceDialogFragment {
|
||||
|
||||
protected void onRoundingDirectionPicked(CourseListDataElement courseElement, RoundingDirection pickedDirection) {
|
||||
courseElement.setRoundingDirection(pickedDirection);
|
||||
courseElements.add(courseElement);
|
||||
if (!courseElements.contains(courseElement)) {
|
||||
courseElements.add(courseElement);
|
||||
}
|
||||
courseElementAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user