Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 13:58:55 +01:00
parent 4af19165ec
commit 68073add76
12458 changed files with 12350765 additions and 2 deletions

View file

@ -0,0 +1,13 @@
#import "MWMTableViewCell.h"
@protocol MWMStreetEditorEditCellProtocol <NSObject>
- (void)editCellTextChanged:(NSString *)text;
@end
@interface MWMStreetEditorEditTableViewCell : MWMTableViewCell
- (void)configWithDelegate:(id<MWMStreetEditorEditCellProtocol>)delegate street:(NSString *)street;
@end

View file

@ -0,0 +1,33 @@
#import "MWMStreetEditorEditTableViewCell.h"
@interface MWMStreetEditorEditTableViewCell ()
@property (weak, nonatomic) IBOutlet UITextField * textField;
@property (weak, nonatomic) id<MWMStreetEditorEditCellProtocol> delegate;
@end
@implementation MWMStreetEditorEditTableViewCell
- (void)configWithDelegate:(id<MWMStreetEditorEditCellProtocol>)delegate street:(NSString *)street
{
self.delegate = delegate;
self.textField.text = street;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textDidChange:)
name:UITextFieldTextDidChangeNotification
object:self.textField];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)textDidChange:(NSNotification*)notification
{
UITextField * textField = (UITextField *)[notification object];
[self.delegate editCellTextChanged:textField.text];
}
@end

View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="KGk-i7-Jjw" customClass="MWMStreetEditorEditTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="8Pj-WT-J59">
<rect key="frame" x="16" y="12" width="288" height="20"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" priority="750" constant="44" id="bRV-YH-9xE"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular17:blackPrimaryText"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedPlaceholder" value="add_street"/>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="delegate" destination="KGk-i7-Jjw" id="r4r-Wy-T2m"/>
</connections>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="8Pj-WT-J59" secondAttribute="trailing" constant="16" id="R0z-r6-X9f"/>
<constraint firstAttribute="bottom" secondItem="8Pj-WT-J59" secondAttribute="bottom" constant="12" id="XDU-Xd-7Pl"/>
<constraint firstItem="8Pj-WT-J59" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="fWv-z1-q0b"/>
<constraint firstItem="8Pj-WT-J59" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="12" id="wRV-57-6CZ"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Background"/>
</userDefinedRuntimeAttributes>
</tableViewCellContentView>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Background"/>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="textField" destination="8Pj-WT-J59" id="lqN-IV-C5E"/>
</connections>
<point key="canvasLocation" x="139" y="154"/>
</tableViewCell>
</objects>
</document>

View file

@ -0,0 +1,19 @@
#import "MWMTableViewController.h"
#include "indexer/editable_map_object.hpp"
#include <vector>
@protocol MWMStreetEditorProtocol <NSObject>
- (osm::LocalizedStreet const &)currentStreet;
- (void)setNearbyStreet:(osm::LocalizedStreet const &)street;
- (std::vector<osm::LocalizedStreet> const &)nearbyStreets;
@end
@interface MWMStreetEditorViewController : MWMTableViewController
@property (weak, nonatomic) id<MWMStreetEditorProtocol> delegate;
@end

View file

@ -0,0 +1,198 @@
#import "MWMStreetEditorViewController.h"
#import "MWMStreetEditorEditTableViewCell.h"
#import "SwiftBridge.h"
@interface MWMStreetEditorViewController () <MWMStreetEditorEditCellProtocol>
{
std::vector<osm::LocalizedStreet> m_streets;
std::string m_editedStreetName;
}
@property (nonatomic) NSUInteger selectedStreet;
@property (nonatomic) NSUInteger lastSelectedStreet;
@end
@implementation MWMStreetEditorViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self configNavBar];
[self configData];
[self configTable];
}
#pragma mark - Configuration
- (void)configNavBar
{
self.title = L(@"choose_street");
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(onCancel)];
self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(onDone)];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
}
- (void)configData
{
id<MWMStreetEditorProtocol> delegate = self.delegate;
m_streets = delegate.nearbyStreets;
auto const & currentStreet = delegate.currentStreet;
BOOL const haveCurrentStreet = !currentStreet.m_defaultName.empty();
if (haveCurrentStreet)
{
auto const it = find(m_streets.begin(), m_streets.end(), currentStreet);
if (it == m_streets.end())
{
m_streets.insert(m_streets.begin(), currentStreet);
self.selectedStreet = 0;
}
else
{
self.selectedStreet = distance(m_streets.begin(), it);
}
}
else
{
self.selectedStreet = NSNotFound;
}
self.navigationItem.rightBarButtonItem.enabled = haveCurrentStreet;
self.lastSelectedStreet = NSNotFound;
m_editedStreetName = "";
}
- (void)configTable
{
UITableView * tv = self.tableView;
[tv registerNibWithCellClass:[MWMStreetEditorEditTableViewCell class]];
}
#pragma mark - Actions
- (void)onCancel
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)onDone
{
id<MWMStreetEditorProtocol> delegate = self.delegate;
if (self.selectedStreet == NSNotFound)
[delegate setNearbyStreet:{m_editedStreetName, ""}];
else
[delegate setNearbyStreet:m_streets[self.selectedStreet]];
[self onCancel];
}
- (void)fillCell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath
{
if ([cell isKindOfClass:[MWMStreetEditorEditTableViewCell class]])
{
MWMStreetEditorEditTableViewCell * tCell = (MWMStreetEditorEditTableViewCell *)cell;
[tCell configWithDelegate:self street:@(m_editedStreetName.c_str())];
}
else
{
NSUInteger const index = indexPath.row;
auto const & localizedStreet = m_streets[index];
NSString * street = @(localizedStreet.m_defaultName.c_str());
BOOL const selected = (self.selectedStreet == index);
cell.textLabel.text = street;
cell.detailTextLabel.text = @(localizedStreet.m_localizedName.c_str());
cell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
}
}
#pragma mark - MWMStreetEditorEditCellProtocol
- (void)editCellTextChanged:(NSString *)text
{
if (text && text.length != 0)
{
self.navigationItem.rightBarButtonItem.enabled = YES;
m_editedStreetName = text.UTF8String;
if (self.selectedStreet != NSNotFound)
{
self.lastSelectedStreet = self.selectedStreet;
self.selectedStreet = NSNotFound;
}
}
else
{
self.selectedStreet = self.lastSelectedStreet;
self.navigationItem.rightBarButtonItem.enabled = (self.selectedStreet != NSNotFound);
}
for (UITableViewCell * cell in self.tableView.visibleCells)
{
if ([cell isKindOfClass:[MWMStreetEditorEditTableViewCell class]])
continue;
NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];
[self fillCell:cell indexPath:indexPath];
}
}
#pragma mark - UITableViewDataSource
- (UITableViewCell * _Nonnull)tableView:(UITableView * _Nonnull)tableView cellForRowAtIndexPath:(NSIndexPath * _Nonnull)indexPath
{
UITableViewCell * cell = nil;
if (m_streets.empty())
{
cell = [tableView dequeueReusableCellWithCellClass:[MWMStreetEditorEditTableViewCell class]
indexPath:indexPath];
}
else
{
if (indexPath.section == 0)
{
Class cls = m_streets[indexPath.row].m_localizedName.empty()
? [UITableViewCell class]
: [MWMTableViewSubtitleCell class];
cell = [tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath];
}
else
{
cell = [tableView dequeueReusableCellWithCellClass:[MWMStreetEditorEditTableViewCell class]
indexPath:indexPath];
}
}
[self fillCell:cell indexPath:indexPath];
return cell;
}
- (NSInteger)tableView:(UITableView * _Nonnull)tableView numberOfRowsInSection:(NSInteger)section
{
auto const count = m_streets.size();
if ((section == 0 && count == 0) || section != 0)
return 1;
return count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return m_streets.empty()? 1 : 2;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[MWMStreetEditorEditTableViewCell class]])
return;
self.selectedStreet = indexPath.row;
[self onDone];
}
@end