139 lines
5.4 KiB
Objective-C
139 lines
5.4 KiB
Objective-C
//
|
|
// SegnalazioniUtentiTableViewController.m
|
|
// Earthquake Network
|
|
//
|
|
// Refactored by Andrea Busi 25/08/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
#import "SegnalazioniUtentiTableViewController.h"
|
|
#import "EQNNotificheSegnalazioniUtente.h"
|
|
#import "EQNUtility.h"
|
|
|
|
@interface SegnalazioniUtentiTableViewController ()
|
|
|
|
@property (nonatomic, strong) NSArray<SettingItem *> *settings;
|
|
@property (nonatomic, assign) BOOL notificationsEnabled;
|
|
@property (nonatomic, strong) NSString *currentRadius;
|
|
@end
|
|
|
|
@implementation SegnalazioniUtentiTableViewController
|
|
|
|
#pragma mark - View Lifecycle
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
|
|
self.tableView.estimatedRowHeight = 100.0;
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
[self.tableView registerClass:[SettingSectionHeaderView class] forHeaderFooterViewReuseIdentifier:SettingSectionHeaderView.Identifier];
|
|
[self.tableView registerClass:[SettingEnableTableViewCell class] forCellReuseIdentifier:SettingEnableTableViewCell.Identifier];
|
|
[self.tableView registerClass:[SettingSliderTableViewCell class] forCellReuseIdentifier:SettingSliderTableViewCell.Identifier];
|
|
|
|
self.settings = @[
|
|
[[SettingItem alloc] initWithType:SettingTypeEnable title:NSLocalizedString(@"Abilitato", @"voce menu") subtitle:NSLocalizedString(@"Ricevi le notifiche dei suoni segnalati manualmente dagli utenti", @"") icon:nil segue:nil],
|
|
[[SettingItem alloc] initWithType:SettingTypeSlider title:NSLocalizedString(@"Raggio dalla tua posizione", @"voce menu") subtitle:nil icon:nil segue:nil]
|
|
];
|
|
|
|
if (![EQNNotificheSegnalazioniUtente center].distanzaPosizione)
|
|
[EQNNotificheSegnalazioniUtente center].distanzaPosizione = @"100000"; //NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi");
|
|
[[EQNNotificheSegnalazioniUtente center] saveUserInfo];
|
|
|
|
[self updateUI];
|
|
}
|
|
|
|
#pragma mark - Private
|
|
|
|
- (void)updateUI
|
|
{
|
|
self.notificationsEnabled = [EQNNotificheSegnalazioniUtente center].isAbilitato;
|
|
|
|
if ([[EQNNotificheSegnalazioniUtente center].distanzaPosizione isEqualToString:@"100000"]) {
|
|
self.currentRadius = NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi");
|
|
} else {
|
|
self.currentRadius = [EQNNotificheSegnalazioniUtente center].distanzaPosizione;
|
|
}
|
|
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)updateRadius:(NSString *)radius
|
|
{
|
|
if ([radius isEqualToString:NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi")]) {
|
|
radius = @"100000";
|
|
}
|
|
|
|
[EQNNotificheSegnalazioniUtente center].distanzaPosizione = radius;
|
|
[[EQNNotificheSegnalazioniUtente center] saveUserInfo];
|
|
|
|
[self updateUI];
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
|
{
|
|
SettingSectionHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SettingSectionHeaderView.Identifier];
|
|
if (section == 0) {
|
|
headerView.titleLabel.text = NSLocalizedString(@"Notifiche segnalazioni utente", @"titolo impostazioni notifiche");
|
|
} else {
|
|
headerView.titleLabel.text = NSLocalizedString(@"Vibrazioni e suono", @"titolo impostazioni notifiche");
|
|
}
|
|
return headerView;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
{
|
|
return SettingSectionHeaderView.Height;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
return self.settings.count;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
SettingItem *setting = self.settings[indexPath.row];
|
|
|
|
if (setting.type == SettingTypeEnable) {
|
|
SettingEnableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingEnableTableViewCell.Identifier forIndexPath:indexPath];
|
|
cell.toggleSwitch.on = self.notificationsEnabled;
|
|
cell.isDisabled = !self.notificationsEnabled;
|
|
cell.titleLabel.text = setting.displayTitle;
|
|
cell.descriptionLabel.text = setting.subtitle;
|
|
|
|
__weak SettingEnableTableViewCell *weakCell = cell;
|
|
cell.valueChanged = ^(void) {
|
|
self.notificationsEnabled = weakCell.toggleSwitch.isOn;
|
|
weakCell.isDisabled = !self.notificationsEnabled;
|
|
[EQNNotificheSegnalazioniUtente center].isAbilitato = self.notificationsEnabled;
|
|
[[EQNNotificheSegnalazioniUtente center] saveUserInfo];
|
|
[self.tableView reloadData];
|
|
};
|
|
|
|
return cell;
|
|
} else if (setting.type == SettingTypeSlider) {
|
|
SettingSliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingSliderTableViewCell.Identifier forIndexPath:indexPath];
|
|
cell.isDisabled = !self.notificationsEnabled;
|
|
cell.titleLabel.text = setting.displayTitle;
|
|
if ([self.currentRadius isEqualToString:NSLocalizedString(@"Qualsiasi distanza", nil)]) {
|
|
cell.valueLabel.text = self.currentRadius;
|
|
} else {
|
|
cell.valueLabel.text = [NSString stringWithFormat:@"%@ km", self.currentRadius];
|
|
}
|
|
[cell configureSliderWith:[EQNUtility arrayRaggioSismi] current:self.currentRadius];
|
|
|
|
cell.valueChanged = ^(NSString *item) {
|
|
[self updateRadius:item];
|
|
};
|
|
|
|
return cell;
|
|
}
|
|
|
|
return nil;
|
|
}
|
|
|
|
@end
|