[fix] Fixed routing manager points movement.

This commit is contained in:
Ilya Grechuhin 2017-08-14 10:13:51 +03:00 committed by Roman Kuznetsov
parent a1ede167f7
commit 571021074a
7 changed files with 91 additions and 81 deletions

View file

@ -84,13 +84,16 @@ final class RouteManagerCell: MWMTableViewCell {
}
private func setupLabels() {
let subtitle: String?
if model.isMyPosition && index != 0 {
titleLabel.text = model.latLonString
subtitle = model.title
} else {
titleLabel.text = model.title
subtitle = model.subtitle
}
var subtitleConstraintsActive = false
if let subtitle = model.subtitle, !subtitle.isEmpty {
if let subtitle = subtitle, !subtitle.isEmpty {
subtitleLabel.text = subtitle
subtitleConstraintsActive = true
}

View file

@ -50,9 +50,9 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
func move(dragPoint: CGPoint, indexPath: IndexPath?, inManagerView: Bool) {
snapshot.center = dragPoint
controller.dimView.state = inManagerView ? .visible : .binOpenned
guard let indexPath = indexPath else { return }
guard let newIP = indexPath else { return }
let tv = controller.tableView!
let cell = tv.cellForRow(at: indexPath)
let cell = tv.cellForRow(at: newIP)
let canMoveCell: Bool
if let cell = cell {
let (centerX, centerY) = (snapshot.width / 2, snapshot.height / 2)
@ -62,15 +62,17 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
canMoveCell = true
}
guard canMoveCell else { return }
let selfIndexPath = self.indexPath
if indexPath != selfIndexPath {
controller.viewModel.movePoint(at: selfIndexPath.row, to: indexPath.row)
let currentIP = self.indexPath
if newIP != currentIP {
let (currentRow, newRow) = (currentIP.row, newIP.row)
controller.viewModel.movePoint(at: currentRow, to: newRow)
tv.moveRow(at: selfIndexPath, to: indexPath)
tv.reloadRows(at: [selfIndexPath, indexPath], with: .fade)
tv.cellForRow(at: indexPath)?.isHidden = true
tv.moveRow(at: currentIP, to: newIP)
let reloadRows = (min(currentRow, newRow)...max(currentRow, newRow)).map { IndexPath(row: $0, section: 0) }
tv.reloadRows(at: reloadRows, with: .fade)
tv.cellForRow(at: newIP)?.isHidden = true
self.indexPath = indexPath
self.indexPath = newIP
}
}

View file

@ -40,39 +40,7 @@
+ (void)movePointAtIndex:(NSInteger)index toIndex:(NSInteger)newIndex
{
NSAssert(index != newIndex, @"Route manager moves point to its' current position.");
NSMutableArray<MWMRoutePoint *> * points = [[MWMRouter points] mutableCopy];
auto removeIndex = index;
auto insertIndex = newIndex;
if (index < newIndex)
insertIndex += 1;
else
removeIndex += 1;
[points insertObject:points[index] atIndex:insertIndex];
[points removeObjectAtIndex:removeIndex];
[MWMRouter removePoints];
[points enumerateObjectsUsingBlock:^(MWMRoutePoint * point, NSUInteger idx, BOOL * stop) {
if (idx == 0)
{
point.type = MWMRoutePointTypeStart;
point.intermediateIndex = 0;
}
else if (idx == points.count - 1)
{
point.type = MWMRoutePointTypeFinish;
point.intermediateIndex = 0;
}
else
{
point.type = MWMRoutePointTypeIntermediate;
point.intermediateIndex = idx - 1;
}
[MWMRouter addPoint:point];
}];
GetFramework().GetRoutingManager().MoveRoutePoint(index, newIndex);
}
@end

View file

@ -621,6 +621,39 @@ void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentInt
routePoints.NotifyChanges();
}
void RoutingManager::MoveRoutePoint(int8_t currentIndex, int8_t targetIndex)
{
ASSERT(m_bmManager != nullptr, ());
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
size_t const sz = routePoints.GetRoutePointsCount();
auto const convertIndex = [sz](RouteMarkType & type, int8_t & index) {
if (index == 0)
{
type = RouteMarkType::Start;
index = 0;
}
else if (index == sz - 1)
{
type = RouteMarkType::Finish;
index = 0;
}
else
{
type = RouteMarkType::Intermediate;
--index;
}
};
RouteMarkType currentType;
RouteMarkType targetType;
convertIndex(currentType, currentIndex);
convertIndex(targetType, targetIndex);
routePoints.MoveRoutePoint(currentType, currentIndex, targetType, targetIndex);
routePoints.NotifyChanges();
}
void RoutingManager::SetPointsFollowingMode(bool enabled)
{
ASSERT(m_bmManager != nullptr, ());

View file

@ -173,6 +173,7 @@ public:
void RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
void RemoveRoutePoints();
void RemoveIntermediateRoutePoints();
void MoveRoutePoint(int8_t currentIndex, int8_t targetIndex);
void MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
RouteMarkType targetType, int8_t targetIntermediateIndex);
void HideRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);

View file

@ -177,7 +177,10 @@ bool RoutePointsLayout::RemoveRoutePoint(RouteMarkType type, int8_t intermediate
auto userMark = m_routeMarks.GetUserMarkForEdit(index);
ASSERT(dynamic_cast<RouteMarkPoint *>(userMark) != nullptr, ());
RouteMarkPoint * mark = static_cast<RouteMarkPoint *>(userMark);
if (mark->GetRoutePointType() == type && mark->GetIntermediateIndex() == intermediateIndex)
auto const markPointType = mark->GetRoutePointType();
if (markPointType == type && (markPointType == RouteMarkType::Intermediate
? mark->GetIntermediateIndex() == intermediateIndex
: true))
{
point = mark;
break;

View file

@ -435,47 +435,21 @@
675345BD1A4054AD00A0A8C3 /* map */ = {
isa = PBXGroup;
children = (
454649EF1F2728CE00EF4064 /* local_ads_mark.cpp */,
454649F01F2728CE00EF4064 /* local_ads_mark.hpp */,
3D47B2C51F20EF06000828D2 /* displayed_categories_modifiers.cpp */,
3D47B2C61F20EF06000828D2 /* displayed_categories_modifiers.hpp */,
3D47B2901F054BC5000828D2 /* taxi_delegate.cpp */,
3D47B2911F054BC5000828D2 /* taxi_delegate.hpp */,
3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */,
45580ABD1E2CBD5E00CD535D /* benchmark_tools.hpp */,
45580ABC1E2CBD5E00CD535D /* benchmark_tools.cpp */,
F63421F61DF9BF9100A96868 /* reachable_by_taxi_checker.cpp */,
F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */,
F6D2CE7C1EDEB7F500636DFD /* routing_manager.cpp */,
F6D2CE7D1EDEB7F500636DFD /* routing_manager.hpp */,
BBD9E2C41EE9D01900DF189A /* routing_mark.cpp */,
BBD9E2C51EE9D01900DF189A /* routing_mark.hpp */,
347B60741DD9926D0050FA24 /* traffic_manager.cpp */,
347B60751DD9926D0050FA24 /* traffic_manager.hpp */,
348AB57A1D7EE0C6009F8301 /* chart_generator.cpp */,
348AB57B1D7EE0C6009F8301 /* chart_generator.hpp */,
342D83381D5233E8000D8AEA /* displacement_mode_manager.cpp */,
342D83391D5233E8000D8AEA /* displacement_mode_manager.hpp */,
34583BCD1C88556800F94664 /* place_page_info.cpp */,
34583BCE1C88556800F94664 /* place_page_info.hpp */,
670E393E1C46C5C700E9C0A6 /* gps_tracker.cpp */,
670E393F1C46C5C700E9C0A6 /* gps_tracker.hpp */,
F6B282FB1C1B03320081957A /* gps_track_collection.cpp */,
F6B282FC1C1B03320081957A /* gps_track_collection.hpp */,
F6B282FD1C1B03320081957A /* gps_track_filter.cpp */,
F6B282FE1C1B03320081957A /* gps_track_filter.hpp */,
F6B282FF1C1B03320081957A /* gps_track_storage.cpp */,
F6B283001C1B03320081957A /* gps_track_storage.hpp */,
F6B283011C1B03320081957A /* gps_track.cpp */,
F6B283021C1B03320081957A /* gps_track.hpp */,
674C385F1BFF3095000D603B /* user_mark.cpp */,
34921F611BFA0A6900737D6E /* api_mark_point.hpp */,
45201E921CE4AC90008A4842 /* api_mark_point.cpp */,
675345CB1A4054E800A0A8C3 /* address_finder.cpp */,
45201E921CE4AC90008A4842 /* api_mark_point.cpp */,
34921F611BFA0A6900737D6E /* api_mark_point.hpp */,
45580ABC1E2CBD5E00CD535D /* benchmark_tools.cpp */,
45580ABD1E2CBD5E00CD535D /* benchmark_tools.hpp */,
675345D91A4054E800A0A8C3 /* bookmark_manager.cpp */,
675345DA1A4054E800A0A8C3 /* bookmark_manager.hpp */,
675345DB1A4054E800A0A8C3 /* bookmark.cpp */,
675345DC1A4054E800A0A8C3 /* bookmark.hpp */,
348AB57A1D7EE0C6009F8301 /* chart_generator.cpp */,
348AB57B1D7EE0C6009F8301 /* chart_generator.hpp */,
342D83381D5233E8000D8AEA /* displacement_mode_manager.cpp */,
342D83391D5233E8000D8AEA /* displacement_mode_manager.hpp */,
3D47B2C51F20EF06000828D2 /* displayed_categories_modifiers.cpp */,
3D47B2C61F20EF06000828D2 /* displayed_categories_modifiers.hpp */,
675345F31A4054E800A0A8C3 /* feature_vec_model.cpp */,
675345F41A4054E800A0A8C3 /* feature_vec_model.hpp */,
675345F51A4054E800A0A8C3 /* framework.cpp */,
@ -484,18 +458,44 @@
675345F81A4054E800A0A8C3 /* ge0_parser.hpp */,
675345FB1A4054E800A0A8C3 /* geourl_process.cpp */,
675345FC1A4054E800A0A8C3 /* geourl_process.hpp */,
F6B282FB1C1B03320081957A /* gps_track_collection.cpp */,
F6B282FC1C1B03320081957A /* gps_track_collection.hpp */,
F6B282FD1C1B03320081957A /* gps_track_filter.cpp */,
F6B282FE1C1B03320081957A /* gps_track_filter.hpp */,
F6B282FF1C1B03320081957A /* gps_track_storage.cpp */,
F6B283001C1B03320081957A /* gps_track_storage.hpp */,
F6B283011C1B03320081957A /* gps_track.cpp */,
F6B283021C1B03320081957A /* gps_track.hpp */,
670E393E1C46C5C700E9C0A6 /* gps_tracker.cpp */,
670E393F1C46C5C700E9C0A6 /* gps_tracker.hpp */,
0C2B73DC1E92AB9900530BB8 /* local_ads_manager.cpp */,
0C2B73DD1E92AB9900530BB8 /* local_ads_manager.hpp */,
454649EF1F2728CE00EF4064 /* local_ads_mark.cpp */,
454649F01F2728CE00EF4064 /* local_ads_mark.hpp */,
3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */,
675346051A4054E800A0A8C3 /* mwm_url.cpp */,
675346061A4054E800A0A8C3 /* mwm_url.hpp */,
674A2A371B2715FB001A525C /* osm_opening_hours.hpp */,
34583BCD1C88556800F94664 /* place_page_info.cpp */,
34583BCE1C88556800F94664 /* place_page_info.hpp */,
F63421F61DF9BF9100A96868 /* reachable_by_taxi_checker.cpp */,
F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */,
0CD3BA401ECDF30C0029AA81 /* routing_helpers.cpp */,
0CD3BA411ECDF30C0029AA81 /* routing_helpers.hpp */,
F6D2CE7C1EDEB7F500636DFD /* routing_manager.cpp */,
F6D2CE7D1EDEB7F500636DFD /* routing_manager.hpp */,
BBD9E2C41EE9D01900DF189A /* routing_mark.cpp */,
BBD9E2C51EE9D01900DF189A /* routing_mark.hpp */,
3D47B2901F054BC5000828D2 /* taxi_delegate.cpp */,
3D47B2911F054BC5000828D2 /* taxi_delegate.hpp */,
6753462C1A4054E800A0A8C3 /* track.cpp */,
6753462D1A4054E800A0A8C3 /* track.hpp */,
347B60741DD9926D0050FA24 /* traffic_manager.cpp */,
347B60751DD9926D0050FA24 /* traffic_manager.hpp */,
6753462E1A4054E800A0A8C3 /* user_mark_container.cpp */,
6753462F1A4054E800A0A8C3 /* user_mark_container.hpp */,
674C385F1BFF3095000D603B /* user_mark.cpp */,
675346331A4054E800A0A8C3 /* user_mark.hpp */,
674A2A371B2715FB001A525C /* osm_opening_hours.hpp */,
);
name = map;
path = ../../map;