forked from organicmaps/organicmaps-tmp
[MAPSME-5356] [ios] Fixed route manager.
This commit is contained in:
parent
d6a1769bba
commit
ced0a1e3ef
5 changed files with 59 additions and 14 deletions
|
@ -33,7 +33,9 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
|
|||
self.indexPath = indexPath
|
||||
addSubView(cell: cell, dragPoint: dragPoint)
|
||||
controller.tableView.heightUpdateStyle = .off
|
||||
controller.dimView.state = .visible
|
||||
if controller.canDeleteRow {
|
||||
controller.dimView.state = .visible
|
||||
}
|
||||
}
|
||||
|
||||
private func addSubView(cell: UITableViewCell, dragPoint: CGPoint) {
|
||||
|
@ -51,7 +53,9 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
|
|||
|
||||
func move(dragPoint: CGPoint, indexPath: IndexPath?, inManagerView: Bool) {
|
||||
snapshot.center = dragPoint
|
||||
controller.dimView.state = inManagerView ? .visible : .binOpenned
|
||||
if controller.canDeleteRow {
|
||||
controller.dimView.state = inManagerView ? .visible : .binOpenned
|
||||
}
|
||||
guard let newIP = indexPath else { return }
|
||||
let tv = controller.tableView!
|
||||
let cell = tv.cellForRow(at: newIP)
|
||||
|
@ -87,7 +91,7 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
|
|||
}
|
||||
let containerView = controller.containerView!
|
||||
let tv = controller.tableView!
|
||||
if inManagerView {
|
||||
if inManagerView || !controller.canDeleteRow {
|
||||
let dropCenter = tv.cellForRow(at: indexPath)?.center ?? snapshot.center
|
||||
UIView.animate(withDuration: kDefaultAnimationDuration,
|
||||
animations: { [snapshot] in
|
||||
|
@ -99,9 +103,11 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
|
|||
removeSnapshot()
|
||||
})
|
||||
} else {
|
||||
controller.viewModel.deletePoint(at: indexPath.row)
|
||||
tv.heightUpdateStyle = .animated
|
||||
tv.deleteRows(at: [indexPath], with: .automatic)
|
||||
tv.update {
|
||||
controller.viewModel.deletePoint(at: indexPath.row)
|
||||
tv.deleteRows(at: [indexPath], with: .automatic)
|
||||
}
|
||||
let dimView = controller.dimView!
|
||||
UIView.animate(withDuration: kDefaultAnimationDuration,
|
||||
animations: { [snapshot] in
|
||||
|
@ -147,6 +153,11 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
|
|||
}
|
||||
}
|
||||
viewModel.refreshControlsCallback()
|
||||
|
||||
viewModel.reloadCallback = { [tableView] in
|
||||
tableView?.reloadSections(IndexSet(integer: 0), with: .fade)
|
||||
}
|
||||
|
||||
viewModel.startTransaction()
|
||||
}
|
||||
|
||||
|
@ -201,8 +212,7 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource
|
|||
})
|
||||
}
|
||||
|
||||
@IBAction private func longPressGestureRecognized(_ longPress: UILongPressGestureRecognizer) {
|
||||
guard canDeleteRow else { return }
|
||||
@IBAction private func gestureRecognized(_ longPress: UIGestureRecognizer) {
|
||||
let locationInView = gestureLocation(longPress, in: containerView)
|
||||
let locationInTableView = gestureLocation(longPress, in: tableView)
|
||||
switch longPress.state {
|
||||
|
|
|
@ -197,7 +197,7 @@
|
|||
<outlet property="dataSource" destination="-1" id="RZu-Qk-qvN"/>
|
||||
<outlet property="delegate" destination="-1" id="QdP-tL-Afh"/>
|
||||
<outlet property="tableViewHeight" destination="69R-bB-eQ7" id="iLN-YX-m5u"/>
|
||||
<outletCollection property="gestureRecognizers" destination="0VI-xg-BIO" appends="YES" id="Cfs-BN-Jen"/>
|
||||
<outletCollection property="gestureRecognizers" destination="iVR-Au-pTp" appends="YES" id="abb-Ql-z0p"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</subviews>
|
||||
|
@ -229,16 +229,16 @@
|
|||
</constraints>
|
||||
<point key="canvasLocation" x="-239.5" y="-48.5"/>
|
||||
</view>
|
||||
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.5" id="0VI-xg-BIO">
|
||||
<connections>
|
||||
<action selector="longPressGestureRecognized:" destination="-1" id="Cmo-Jl-HLk"/>
|
||||
</connections>
|
||||
</pongPressGestureRecognizer>
|
||||
<tapGestureRecognizer id="deN-Z9-rbS">
|
||||
<tapGestureRecognizer id="deN-Z9-rbS" userLabel="Cancel Tap Gesture Recognizer">
|
||||
<connections>
|
||||
<action selector="onCancel" destination="-1" id="QyM-e1-7JM"/>
|
||||
</connections>
|
||||
</tapGestureRecognizer>
|
||||
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.10000000000000001" id="iVR-Au-pTp">
|
||||
<connections>
|
||||
<action selector="gestureRecognized:" destination="-1" id="osy-Ks-njV"/>
|
||||
</connections>
|
||||
</pongPressGestureRecognizer>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="ic_get_position" width="20" height="20"/>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
final class RouteManagerViewModel: NSObject, RouteManagerViewModelProtocol {
|
||||
var routePoints: [MWMRoutePoint] { return MWMRouter.points() }
|
||||
var refreshControlsCallback: (() -> Void)!
|
||||
var reloadCallback: (() -> Void)!
|
||||
|
||||
func startTransaction() { MWMRouter.openRouteManagerTransaction() }
|
||||
|
||||
|
@ -26,5 +27,6 @@ final class RouteManagerViewModel: NSObject, RouteManagerViewModelProtocol {
|
|||
MWMRouter.removePoint(routePoints[index])
|
||||
MWMRouter.updatePreviewMode()
|
||||
refreshControlsCallback()
|
||||
reloadCallback()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ protocol RouteManagerViewModelProtocol: class {
|
|||
var routePoints: [MWMRoutePoint] { get }
|
||||
|
||||
var refreshControlsCallback: (() -> Void)! { get set }
|
||||
var reloadCallback: (() -> Void)! { get set }
|
||||
|
||||
func startTransaction()
|
||||
func finishTransaction()
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
_isMyPosition = YES;
|
||||
_type = type;
|
||||
_intermediateIndex = intermediateIndex;
|
||||
|
||||
[self validatePoint];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -49,6 +51,8 @@
|
|||
_isMyPosition = NO;
|
||||
_type = type;
|
||||
_intermediateIndex = intermediateIndex;
|
||||
|
||||
[self validatePoint];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -69,6 +73,8 @@
|
|||
case RouteMarkType::Intermediate: _type = MWMRoutePointTypeIntermediate; break;
|
||||
case RouteMarkType::Finish: _type = MWMRoutePointTypeFinish; break;
|
||||
}
|
||||
|
||||
[self validatePoint];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -88,10 +94,17 @@
|
|||
_isMyPosition = NO;
|
||||
_type = type;
|
||||
_intermediateIndex = intermediateIndex;
|
||||
|
||||
[self validatePoint];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)validatePoint
|
||||
{
|
||||
NSAssert(_intermediateIndex >= 0 && _intermediateIndex <= 2, @"Invalid intermediateIndex");
|
||||
}
|
||||
|
||||
- (double)latitude { return MercatorBounds::YToLat(self.point.y); }
|
||||
- (double)longitude { return MercatorBounds::XToLon(self.point.x); }
|
||||
|
||||
|
@ -102,6 +115,8 @@
|
|||
|
||||
- (RouteMarkData)routeMarkData
|
||||
{
|
||||
[self validatePoint];
|
||||
|
||||
RouteMarkData pt;
|
||||
switch (self.type)
|
||||
{
|
||||
|
@ -117,4 +132,21 @@
|
|||
return pt;
|
||||
}
|
||||
|
||||
- (NSString *)debugDescription
|
||||
{
|
||||
NSString * type = nil;
|
||||
switch (_type)
|
||||
{
|
||||
case MWMRoutePointTypeStart: type = @"Start"; break;
|
||||
case MWMRoutePointTypeIntermediate: type = @"Intermediate"; break;
|
||||
case MWMRoutePointTypeFinish: type = @"Finish"; break;
|
||||
}
|
||||
|
||||
return [NSString stringWithFormat:@"<%@: %p> Position: [%@, %@] | IsMyPosition: %@ | Type: %@ | "
|
||||
@"IntermediateIndex: %@ | Title: %@ | Subtitle: %@",
|
||||
[self class], self, @(_point.x), @(_point.y),
|
||||
_isMyPosition ? @"true" : @"false", type, @(_intermediateIndex),
|
||||
_title, _subtitle];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Reference in a new issue