/
SettingsViewController.m
1648 lines (1475 loc) · 78.9 KB
/
SettingsViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// SettingsViewController.m
// piwigo
//
// Created by Spencer Baker on 1/20/15.
// Copyright (c) 2015 bakercrew. All rights reserved.
//
#import "SettingsViewController.h"
#import "SessionService.h"
#import "AppDelegate.h"
#import "Model.h"
#import "SelectPrivacyViewController.h"
#import "TextFieldTableViewCell.h"
#import "ButtonTableViewCell.h"
#import "LabelTableViewCell.h"
#import "AboutViewController.h"
#import "ClearCache.h"
#import "SliderTableViewCell.h"
#import "SwitchTableViewCell.h"
#import "AlbumService.h"
#import "CategorySortViewController.h"
#import "PiwigoImageData.h"
#import "DefaultImageSizeViewController.h"
#import "DefaultThumbnailSizeViewController.h"
#import "ReleaseNotesViewController.h"
#import "ImagesCollection.h"
typedef enum {
SettingsSectionServer,
SettingsSectionLogout,
SettingsSectionThumbnails,
SettingsSectionImages,
SettingsSectionImageUpload,
SettingsSectionCache,
SettingsSectionColor,
SettingsSectionAbout,
SettingsSectionCount
} SettingsSection;
typedef enum {
kImageUploadSettingAuthor
} kImageUploadSetting;
@interface SettingsViewController () <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, SelectPrivacyDelegate, CategorySortDelegate>
@property (nonatomic, strong) UITableView *settingsTableView;
@property (nonatomic, strong) NSLayoutConstraint *topConstraint;
@property (nonatomic, strong) NSLayoutConstraint *tableViewBottomConstraint;
@property (nonatomic, strong) UIBarButtonItem *doneBarButton;
@property (nonatomic, assign) CGFloat previousContentYOffset;
@property (nonatomic, assign) CGFloat minContentYOffset;
@end
@implementation SettingsViewController
-(instancetype)init
{
self = [super init];
if(self)
{
// Table view
self.settingsTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
self.settingsTableView.translatesAutoresizingMaskIntoConstraints = NO;
self.settingsTableView.backgroundColor = [UIColor clearColor];
self.settingsTableView.delegate = self;
self.settingsTableView.dataSource = self;
[self.view addSubview:self.settingsTableView];
[self.view addConstraints:[NSLayoutConstraint constraintFillWidth:self.settingsTableView]];
[self.view addConstraint:[NSLayoutConstraint constraintViewFromTop:self.settingsTableView amount:0]];
self.tableViewBottomConstraint = [NSLayoutConstraint constraintViewFromBottom:self.settingsTableView amount:0];
[self.view addConstraint:self.tableViewBottomConstraint];
// Button for returning to albums/images
self.doneBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(quitSettings)];
// Keyboard management
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDismiss:) name:UIKeyboardWillHideNotification object:nil];
// Before starting scrolling
self.previousContentYOffset = -INFINITY;
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Background color of the view
self.view.backgroundColor = [UIColor piwigoBackgroundColor];
self.settingsTableView.indicatorStyle = [Model sharedInstance].isDarkPaletteActive ?UIScrollViewIndicatorStyleWhite : UIScrollViewIndicatorStyleBlack;
// Navigation bar appearence
NSDictionary *attributes = @{
NSForegroundColorAttributeName: [UIColor piwigoWhiteCream],
NSFontAttributeName: [UIFont piwigoFontNormal],
};
self.navigationController.navigationBar.titleTextAttributes = attributes;
[self.navigationController.navigationBar setTintColor:[UIColor piwigoOrange]];
[self.navigationController.navigationBar setBarTintColor:[UIColor piwigoBackgroundColor]];
self.navigationController.navigationBar.barStyle = [Model sharedInstance].isDarkPaletteActive ? UIBarStyleBlack : UIBarStyleDefault;
[self.navigationItem setRightBarButtonItems:@[self.doneBarButton] animated:YES];
// Tab bar appearance
self.tabBarController.tabBar.barTintColor = [UIColor piwigoBackgroundColor];
self.tabBarController.tabBar.tintColor = [UIColor piwigoOrange];
if (@available(iOS 10, *)) {
self.tabBarController.tabBar.unselectedItemTintColor = [UIColor piwigoTextColor];
}
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor piwigoTextColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor piwigoOrange]} forState:UIControlStateSelected];
// Table view
self.settingsTableView.separatorColor = [UIColor piwigoSeparatorColor];
[self.settingsTableView reloadData];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
//Reload the tableview on orientation change, to match the new width of the table.
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.settingsTableView reloadData];
} completion:nil];
}
-(void)quitSettings
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UITableView - headers
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
// Header strings
NSString *titleString, *textString = @"";
switch(section)
{
case SettingsSectionServer:
if ([[Model sharedInstance].serverProtocol isEqualToString:@"https://"]) {
titleString = NSLocalizedString(@"settingsHeader_server", @"Piwigo Server");
} else {
titleString = [NSString stringWithFormat:@"%@\n", NSLocalizedString(@"settingsHeader_server", @"Piwigo Server")];
textString = NSLocalizedString(@"settingsHeader_notSecure", @"Website Not Secure!");
}
break;
case SettingsSectionLogout:
return 14;
case SettingsSectionThumbnails:
titleString = NSLocalizedString(@"settingsHeader_thumbnails", @"Thumbnails");
break;
case SettingsSectionImages:
titleString = NSLocalizedString(@"settingsHeader_images", @"Images");
break;
case SettingsSectionImageUpload:
titleString = NSLocalizedString(@"settingsHeader_upload", @"Default Upload Settings");
break;
case SettingsSectionCache:
titleString = NSLocalizedString(@"settingsHeader_cache", @"Cache Settings (Used/Total)");
break;
case SettingsSectionColor:
titleString = NSLocalizedString(@"settingsHeader_colors", @"Colors");
break;
case SettingsSectionAbout:
titleString = NSLocalizedString(@"settingsHeader_about", @"Information");
break;
}
// Header height
NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
context.minimumScaleFactor = 1.0;
NSDictionary *titleAttributes = @{NSFontAttributeName: [UIFont piwigoFontBold]};
CGRect titleRect = [titleString boundingRectWithSize:CGSizeMake(tableView.frame.size.width - 30.0, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:titleAttributes
context:context];
// Header height
NSInteger headerHeight;
if ([textString length] > 0) {
NSDictionary *textAttributes = @{NSFontAttributeName: [UIFont piwigoFontSmall]};
CGRect textRect = [textString boundingRectWithSize:CGSizeMake(tableView.frame.size.width - 30.0, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:textAttributes
context:context];
headerHeight = fmax(44.0, ceil(titleRect.size.height + textRect.size.height));
} else {
headerHeight = fmax(44.0, ceil(titleRect.size.height));
}
return headerHeight;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// Header strings
NSString *titleString, *textString = @"";
switch(section)
{
case SettingsSectionServer:
if ([[Model sharedInstance].serverProtocol isEqualToString:@"https://"]) {
titleString = NSLocalizedString(@"settingsHeader_server", @"Piwigo Server");
} else {
titleString = [NSString stringWithFormat:@"%@\n", NSLocalizedString(@"settingsHeader_server", @"Piwigo Server")];
textString = NSLocalizedString(@"settingsHeader_notSecure", @"Website Not Secure!");
}
break;
case SettingsSectionLogout:
return nil;
case SettingsSectionThumbnails:
titleString = NSLocalizedString(@"settingsHeader_thumbnails", @"Thumbnails");
break;
case SettingsSectionImages:
titleString = NSLocalizedString(@"settingsHeader_images", @"Images");
break;
case SettingsSectionImageUpload:
titleString = NSLocalizedString(@"settingsHeader_upload", @"Default Upload Settings");
break;
case SettingsSectionCache:
titleString = NSLocalizedString(@"settingsHeader_cache", @"Cache Settings (Used/Total)");
break;
case SettingsSectionColor:
titleString = NSLocalizedString(@"settingsHeader_colors", @"Colors");
break;
case SettingsSectionAbout:
titleString = NSLocalizedString(@"settingsHeader_about", @"Information");
break;
}
NSMutableAttributedString *headerAttributedString = [[NSMutableAttributedString alloc] initWithString:@""];
// Title
NSMutableAttributedString *titleAttributedString = [[NSMutableAttributedString alloc] initWithString:titleString];
[titleAttributedString addAttribute:NSFontAttributeName value:[UIFont piwigoFontBold]
range:NSMakeRange(0, [titleString length])];
[headerAttributedString appendAttributedString:titleAttributedString];
// Text
if ([textString length] > 0) {
NSMutableAttributedString *textAttributedString = [[NSMutableAttributedString alloc] initWithString:textString];
[textAttributedString addAttribute:NSFontAttributeName value:[UIFont piwigoFontSmall]
range:NSMakeRange(0, [textString length])];
[headerAttributedString appendAttributedString:textAttributedString];
}
// Header label
UILabel *headerLabel = [UILabel new];
headerLabel.translatesAutoresizingMaskIntoConstraints = NO;
headerLabel.textColor = [UIColor piwigoHeaderColor];
headerLabel.numberOfLines = 0;
headerLabel.adjustsFontSizeToFitWidth = NO;
headerLabel.lineBreakMode = NSLineBreakByWordWrapping;
headerLabel.attributedText = headerAttributedString;
// Header view
UIView *header = [[UIView alloc] init];
header.backgroundColor = [UIColor clearColor];
[header addSubview:headerLabel];
[header addConstraint:[NSLayoutConstraint constraintViewFromBottom:headerLabel amount:4]];
if (@available(iOS 11, *)) {
[header addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[header]-|"
options:kNilOptions
metrics:nil
views:@{@"header" : headerLabel}]];
} else {
[header addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-15-[header]-15-|"
options:kNilOptions
metrics:nil
views:@{@"header" : headerLabel}]];
}
return header;
}
#pragma mark - UITableView - rows
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return SettingsSectionCount;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger nberOfRows = 0;
switch(section)
{
case SettingsSectionServer:
nberOfRows = 2;
break;
case SettingsSectionLogout:
nberOfRows = 1;
break;
case SettingsSectionThumbnails:
nberOfRows = 4;
break;
case SettingsSectionImages:
nberOfRows = 1;
break;
case SettingsSectionImageUpload:
nberOfRows = 6 + ([Model sharedInstance].resizeImageOnUpload ? 1 : 0) +
([Model sharedInstance].compressImageOnUpload ? 1 : 0);
break;
case SettingsSectionCache:
nberOfRows = 3;
break;
case SettingsSectionColor:
nberOfRows = 1 + ([Model sharedInstance].isDarkPaletteModeActive ? 1 + ([Model sharedInstance].switchPaletteAutomatically ? 1 : 0) : 0);
break;
case SettingsSectionAbout:
nberOfRows = 5;
break;
}
return nberOfRows;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44.0;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *tableViewCell = [UITableViewCell new];
switch(indexPath.section)
{
case SettingsSectionServer: // Piwigo Server
{
LabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"server"];
if(!cell)
{
cell = [LabelTableViewCell new];
}
switch(indexPath.row)
{
case 0:
cell.leftText = NSLocalizedString(@"settings_server", @"Address");
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6, 7 screen width
cell.rightText = [NSString stringWithFormat:@"%@%@", [Model sharedInstance].serverProtocol, [Model sharedInstance].serverName];
} else {
cell.rightText = [Model sharedInstance].serverName;
}
break;
case 1:
cell.leftText = NSLocalizedString(@"settings_username", @"Username");
if([Model sharedInstance].username.length > 0)
{
cell.rightText = [Model sharedInstance].username;
}
else
{
cell.rightText = NSLocalizedString(@"settings_notLoggedIn", @" - Not Logged In - ");
}
break;
}
tableViewCell = cell;
break;
}
case SettingsSectionLogout: // Logout Button
{
ButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"button"];
if(!cell)
{
cell = [ButtonTableViewCell new];
}
if([Model sharedInstance].username.length > 0)
{
cell.buttonText = NSLocalizedString(@"settings_logout", @"Logout");
}
else
{
cell.buttonText = NSLocalizedString(@"login", @"Login");
}
tableViewCell = cell;
break;
}
#pragma mark Thumbnails
case SettingsSectionThumbnails: // Thumbnails
{
switch(indexPath.row)
{
case 0: // Default Sort
{
LabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"defaultSort"];
if(!cell)
{
cell = [LabelTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6,7 Plus screen width
cell.leftText = NSLocalizedString(@"defaultImageSort>414px", @"Default Sort of Images");
} else if(self.view.bounds.size.width > 320) { // i.e. larger than iPhone 5 screen width
cell.leftText = NSLocalizedString(@"defaultImageSort>320px", @"Default Sort");
} else {
cell.leftText = NSLocalizedString(@"defaultImageSort", @"Sort");
}
cell.rightText = [CategorySortViewController getNameForCategorySortType:[Model sharedInstance].defaultSort];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableViewCell = cell;
break;
}
case 1: // Default Thumbnail File
{
LabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"defaultThumbnailFile"];
if(!cell) {
cell = [LabelTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.leftText = NSLocalizedString(@"defaultThumbnailFile>414px", @"Thumbnail Image File");
} else if(self.view.bounds.size.width > 320) { // i.e. larger than iPhone 5 screen width
cell.leftText = NSLocalizedString(@"defaultThumbnailFile>320px", @"Thumbnail File");
} else {
cell.leftText = NSLocalizedString(@"defaultThumbnailFile", @"File");
}
cell.rightText = [PiwigoImageData nameForThumbnailSizeType:(kPiwigoImageSize)[Model sharedInstance].defaultThumbnailSize];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableViewCell = cell;
break;
}
case 2: // Default Thumbnail Size
{
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"defaultThumbnailSize"];
if(!cell)
{
cell = [SliderTableViewCell new];
}
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.sliderName.text = NSLocalizedString(@"defaultThumbnailSize>414px", @"Default Size of Thumbnails");
} else if(self.view.bounds.size.width > 320) { // i.e. larger than iPhone 5 screen width
cell.sliderName.text = NSLocalizedString(@"defaultThumbnailSize>320px", @"Thumbnails Size");
} else {
cell.sliderName.text = NSLocalizedString(@"defaultThumbnailSize", @"Size");
}
NSInteger minNberOfImages = [ImagesCollection numberOfImagesPerRowForViewInPortrait:self.view withMaxWidth:kThumbnailFileSize];
cell.slider.minimumValue = 1;
cell.slider.maximumValue = 1 + minNberOfImages; // Allows to double the number of thumbnails
cell.incrementSliderBy = 1;
cell.sliderCountPrefix = @"";
cell.sliderCountSuffix = [NSString stringWithFormat:@"/%d", (int)cell.slider.maximumValue];
cell.sliderValue = 2 * minNberOfImages - [Model sharedInstance].thumbnailsPerRowInPortrait + 1;
[cell.slider addTarget:self action:@selector(updateThumbnailSize:) forControlEvents:UIControlEventValueChanged];
tableViewCell = cell;
break;
}
case 3: // Display titles on thumbnails
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"titles"];
if(!cell)
{
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 320) {
cell.leftLabel.text = NSLocalizedString(@"settings_displayTitles>320px", @"Display Titles on Thumbnails");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_displayTitles", @"Titles on Thumbnails");
}
[cell.cellSwitch setOn:[Model sharedInstance].displayImageTitles];
cell.cellSwitchBlock = ^(BOOL switchState) {
[Model sharedInstance].displayImageTitles = switchState;
[[Model sharedInstance] saveToDisk];
};
tableViewCell = cell;
break;
}
}
break;
}
#pragma mark Images
case SettingsSectionImages: // Images
{
switch(indexPath.row)
{
case 0: // Default Size of Previewed Images
{
LabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"defaultPreviewFile"];
if(!cell) {
cell = [LabelTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.leftText = NSLocalizedString(@"defaultPreviewFile>414px", @"Preview Image File");
} else if(self.view.bounds.size.width > 320) { // i.e. larger than iPhone 5 screen width
cell.leftText = NSLocalizedString(@"defaultPreviewFile>320px", @"Preview File");
} else {
cell.leftText = NSLocalizedString(@"defaultPreviewFile", @"Preview");
}
cell.rightText = [PiwigoImageData nameForImageSizeType:(kPiwigoImageSize)[Model sharedInstance].defaultImagePreviewSize withAdvice:NO];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableViewCell = cell;
break;
}
}
break;
}
#pragma mark Default Upload Settings
case SettingsSectionImageUpload: // Default Upload Settings
{
switch(indexPath.row)
{
case 0: // Author Name
{
TextFieldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"uploadSettingsField"];
if(!cell)
{
cell = [TextFieldTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 320) { // i.e. larger than iPhone 5 screen width
cell.labelText = NSLocalizedString(@"settings_defaultAuthor>320px", @"Author Name");
} else {
cell.labelText = NSLocalizedString(@"settings_defaultAuthor", @"Author");
}
cell.rightTextField.text = [Model sharedInstance].defaultAuthor;
cell.rightTextField.placeholder = NSLocalizedString(@"settings_defaultAuthorPlaceholder", @"Author Name");
cell.rightTextField.delegate = self;
cell.rightTextField.tag = kImageUploadSettingAuthor;
tableViewCell = cell;
break;
}
case 1: // Privacy Level
{
LabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"privacy"];
if(!cell)
{
cell = [LabelTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6,7 Plus screen width
cell.leftText = NSLocalizedString(@"settings_defaultPrivacy>414px", @"Who Can See the Media?");
} else {
cell.leftText = NSLocalizedString(@"settings_defaultPrivacy", @"Privacy");
}
cell.rightText = [[Model sharedInstance] getNameForPrivacyLevel:[Model sharedInstance].defaultPrivacyLevel];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableViewCell = cell;
break;
}
case 2: // Strip private Metadata
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"gps"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_stripGPSdata>375px", @"Strip Private Metadata Before Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_stripGPSdata", @"Strip Private Metadata");
}
[cell.cellSwitch setOn:[Model sharedInstance].stripGPSdataOnUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
[Model sharedInstance].stripGPSdataOnUpload = switchState;
[[Model sharedInstance] saveToDisk];
};
tableViewCell = cell;
break;
}
case 3: // Resize Before Upload
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"resize"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_photoResize>375px", @"Resize Image Before Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_photoResize", @"Resize Before Upload");
}
[cell.cellSwitch setOn:[Model sharedInstance].resizeImageOnUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
// Number of rows will change accordingly
[Model sharedInstance].resizeImageOnUpload = switchState;
// Store modified setting
[[Model sharedInstance] saveToDisk];
// Position of the row that should be added/removed
NSIndexPath *rowAtIndexPath = [NSIndexPath indexPathForRow:4
inSection:SettingsSectionImageUpload];
if(switchState) {
// Insert row in existing table
[self.settingsTableView insertRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
// Remove row in existing table
[self.settingsTableView deleteRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
};
tableViewCell = cell;
break;
}
case 4: // Image Size slider or Compress Before Upload switch
{
if ([Model sharedInstance].resizeImageOnUpload) {
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"photoSize"];
if(!cell)
{
cell = [SliderTableViewCell new];
}
cell.sliderName.text = NSLocalizedString(@"settings_photoSize", @"> Size");
cell.slider.minimumValue = 5;
cell.slider.maximumValue = 100;
cell.sliderCountPrefix = @"";
cell.sliderCountSuffix = @"%";
cell.incrementSliderBy = 5;
cell.sliderValue = [Model sharedInstance].photoResize;
[cell.slider addTarget:self action:@selector(updateImageSize:) forControlEvents:UIControlEventValueChanged];
tableViewCell = cell;
} else {
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"compress"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_photoCompress>375px", @"Compress Image Before Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_photoCompress", @"Compress Before Upload");
}
[cell.cellSwitch setOn:[Model sharedInstance].compressImageOnUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
// Number of rows will change accordingly
[Model sharedInstance].compressImageOnUpload = switchState;
// Store modified setting
[[Model sharedInstance] saveToDisk];
// Position of the row that should be added/removed (depends on resize option)
NSIndexPath *rowAtIndexPath = [NSIndexPath indexPathForRow:(5 + ([Model sharedInstance].resizeImageOnUpload ? 1 : 0))
inSection:SettingsSectionImageUpload];
if(switchState) {
// Insert row in existing table
[self.settingsTableView insertRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
// Remove row in existing table
[self.settingsTableView deleteRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
};
tableViewCell = cell;
}
break;
}
case 5: // Compress Before Upload switch or Image Quality slider or Delete Image switch
{
if ([Model sharedInstance].resizeImageOnUpload) {
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"compress"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_photoCompress>375px", @"Compress Image Before Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_photoCompress", @"Compress Before Upload");
}
[cell.cellSwitch setOn:[Model sharedInstance].compressImageOnUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
// Number of rows will change accordingly
[Model sharedInstance].compressImageOnUpload = switchState;
// Store modified setting
[[Model sharedInstance] saveToDisk];
// Position of the row that should be added/removed
NSIndexPath *rowAtIndexPath = [NSIndexPath indexPathForRow:(5 + ([Model sharedInstance].resizeImageOnUpload ? 1 : 0))
inSection:SettingsSectionImageUpload];
if(switchState) {
// Insert row in existing table
[self.settingsTableView insertRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
// Remove row in existing table
[self.settingsTableView deleteRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
};
tableViewCell = cell;
} else if ([Model sharedInstance].compressImageOnUpload) {
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"photoQuality"];
if(!cell)
{
cell = [SliderTableViewCell new];
}
cell.sliderName.text = NSLocalizedString(@"settings_photoQuality", @"> Quality");
cell.slider.minimumValue = 50;
cell.slider.maximumValue = 98;
cell.sliderCountPrefix = @"";
cell.sliderCountSuffix = @"%";
cell.incrementSliderBy = 2;
cell.sliderValue = [Model sharedInstance].photoQuality;
[cell.slider addTarget:self action:@selector(updateImageQuality:) forControlEvents:UIControlEventValueChanged];
tableViewCell = cell;
} else {
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"delete"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_deleteImage>375px", @"Delete Image After Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_deleteImage", @"Delete After Upload");
}
[cell.cellSwitch setOn:[Model sharedInstance].deleteImageAfterUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
[Model sharedInstance].deleteImageAfterUpload = switchState;
[[Model sharedInstance] saveToDisk];
};
tableViewCell = cell;
}
break;
}
case 6: // Image Quality slider or Delete Image switch
{
if ([Model sharedInstance].resizeImageOnUpload && [Model sharedInstance].compressImageOnUpload) {
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"photoQuality"];
if(!cell)
{
cell = [SliderTableViewCell new];
}
cell.sliderName.text = NSLocalizedString(@"settings_photoQuality", @"> Quality");
cell.slider.minimumValue = 50;
cell.slider.maximumValue = 98;
cell.sliderCountPrefix = @"";
cell.sliderCountSuffix = @"%";
cell.incrementSliderBy = 2;
cell.sliderValue = [Model sharedInstance].photoQuality;
[cell.slider addTarget:self action:@selector(updateImageQuality:) forControlEvents:UIControlEventValueChanged];
tableViewCell = cell;
} else {
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"delete"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_deleteImage>375px", @"Delete Image After Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_deleteImage", @"Delete After Upload");
}
[cell.cellSwitch setOn:[Model sharedInstance].deleteImageAfterUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
[Model sharedInstance].deleteImageAfterUpload = switchState;
[[Model sharedInstance] saveToDisk];
};
tableViewCell = cell;
}
break;
}
case 7: // Delete image after upload
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"delete"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6,7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_deleteImage>375px", @"Delete Image After Upload");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_deleteImage", @"Delete After Upload");
}
[cell.cellSwitch setOn:[Model sharedInstance].deleteImageAfterUpload];
cell.cellSwitchBlock = ^(BOOL switchState) {
[Model sharedInstance].deleteImageAfterUpload = switchState;
[[Model sharedInstance] saveToDisk];
};
tableViewCell = cell;
break;
}
}
break;
}
#pragma mark Cache Settings
case SettingsSectionCache: // Cache Settings
{
switch(indexPath.row)
{
case 0: // Download all Albums at Start
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"switchCell"];
if(!cell)
{
cell = [SwitchTableViewCell new];
}
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 414) { // i.e. larger than iPhones 6, 7 screen width
cell.leftLabel.text = NSLocalizedString(@"settings_loadAllCategories>320px", @"Download all Albums at Start (uncheck if troubles)");
} else {
cell.leftLabel.text = NSLocalizedString(@"settings_loadAllCategories", @"Download all Albums at Start");
}
[cell.cellSwitch setOn:[Model sharedInstance].loadAllCategoryInfo];
cell.cellSwitchBlock = ^(BOOL switchState) {
if(![Model sharedInstance].loadAllCategoryInfo && switchState)
{
[AlbumService getAlbumListForCategory:0 usingCacheIfPossible:NO inRecursiveMode:YES OnCompletion:nil onFailure:nil];
}
[Model sharedInstance].loadAllCategoryInfo = switchState;
[[Model sharedInstance] saveToDisk];
};
tableViewCell = cell;
break;
}
case 1: // Disk
{
NSInteger currentDiskSize = [[NSURLCache sharedURLCache] currentDiskUsage];
float currentDiskSizeInMB = currentDiskSize / (1024.0f * 1024.0f);
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sliderSettingsDisk"];
if(!cell)
{
cell = [SliderTableViewCell new];
}
cell.sliderName.text = NSLocalizedString(@"settings_cacheDisk", @"Disk");
cell.slider.minimumValue = 10;
cell.slider.maximumValue = 500;
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhones 6,7 screen width
cell.sliderCountPrefix = [NSString stringWithFormat:@"%.1f/", currentDiskSizeInMB];
} else {
cell.sliderCountPrefix = [NSString stringWithFormat:@"%ld/", lroundf(currentDiskSizeInMB)];
}
cell.sliderCountSuffix = NSLocalizedString(@"settings_cacheMegabytes", @"MB");
cell.incrementSliderBy = 10;
cell.sliderValue = [Model sharedInstance].diskCache;
[cell.slider addTarget:self action:@selector(updateDiskCacheSize:) forControlEvents:UIControlEventValueChanged];
tableViewCell = cell;
break;
}
case 2: // Memory
{
NSInteger currentMemSize = [[NSURLCache sharedURLCache] currentMemoryUsage];
float currentMemSizeInMB = currentMemSize / (1024.0f * 1024.0f);
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sliderSettingsMem"];
if(!cell)
{
cell = [SliderTableViewCell new];
}
cell.sliderName.text = NSLocalizedString(@"settings_cacheMemory", @"Memory");
cell.slider.minimumValue = 10;
cell.slider.maximumValue = 200;
// See https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
if(self.view.bounds.size.width > 375) { // i.e. larger than iPhone 6,7 screen width
cell.sliderCountPrefix = [NSString stringWithFormat:@"%.1f/", currentMemSizeInMB];
} else {
cell.sliderCountPrefix = [NSString stringWithFormat:@"%ld/", lroundf(currentMemSizeInMB)];
}
cell.sliderCountSuffix = NSLocalizedString(@"settings_cacheMegabytes", @"MB");
cell.incrementSliderBy = 10;
cell.sliderValue = [Model sharedInstance].memoryCache;
[cell.slider addTarget:self action:@selector(updateMemoryCacheSize:) forControlEvents:UIControlEventValueChanged];
tableViewCell = cell;
break;
}
}
break;
}
#pragma mark Colors
case SettingsSectionColor: // Colors
{
switch (indexPath.row)
{
case 0: // Dark Palette Mode
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"darkPalette"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
cell.leftLabel.text = NSLocalizedString(@"settings_darkPalette", @"Dark Palette");
[cell.cellSwitch setOn:[Model sharedInstance].isDarkPaletteModeActive];
cell.cellSwitchBlock = ^(BOOL switchState) {
// Number of rows will change accordingly
[Model sharedInstance].isDarkPaletteModeActive = switchState;
// Position of the row(s) that should be added/removed
NSIndexPath *rowAtIndexPath = [NSIndexPath indexPathForRow:1
inSection:SettingsSectionColor];
NSIndexPath *row2AtIndexPath = [NSIndexPath indexPathForRow:2
inSection:SettingsSectionColor];
if(switchState) {
// Insert row in existing table
if ([Model sharedInstance].switchPaletteAutomatically)
[self.settingsTableView insertRowsAtIndexPaths:@[rowAtIndexPath,row2AtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
else
[self.settingsTableView insertRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
// Remove row in existing table
if ([Model sharedInstance].switchPaletteAutomatically)
[self.settingsTableView deleteRowsAtIndexPaths:@[rowAtIndexPath,row2AtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
else
[self.settingsTableView deleteRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
// Switch off auto mode if dark palette mode disabled
if (!switchState) [Model sharedInstance].switchPaletteAutomatically = NO;
// Store modified setting
[[Model sharedInstance] saveToDisk];
// Refresh table
[self.settingsTableView reloadData];
// Redraw views in windows
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate screenBrightnessChanged:nil];
// Background color of the view
self.view.backgroundColor = [UIColor piwigoBackgroundColor];
self.settingsTableView.indicatorStyle = [Model sharedInstance].isDarkPaletteActive ?UIScrollViewIndicatorStyleWhite : UIScrollViewIndicatorStyleBlack;
// Navigation bar appearence
NSDictionary *attributes = @{
NSForegroundColorAttributeName: [UIColor piwigoWhiteCream],
NSFontAttributeName: [UIFont piwigoFontNormal],
};
self.navigationController.navigationBar.titleTextAttributes = attributes;
[self.navigationController.navigationBar setTintColor:[UIColor piwigoOrange]];
[self.navigationController.navigationBar setBarTintColor:[UIColor piwigoBackgroundColor]];
self.navigationController.navigationBar.barStyle = [Model sharedInstance].isDarkPaletteActive ? UIBarStyleBlack : UIBarStyleDefault;
[self.navigationItem setRightBarButtonItems:@[self.doneBarButton] animated:YES];
// Tab bar appearance
self.tabBarController.tabBar.barTintColor = [UIColor piwigoBackgroundColor];
self.tabBarController.tabBar.tintColor = [UIColor piwigoOrange];
if (@available(iOS 10, *)) {
self.tabBarController.tabBar.unselectedItemTintColor = [UIColor piwigoTextColor];
}
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor piwigoTextColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor piwigoOrange]} forState:UIControlStateSelected];
// Table view
self.settingsTableView.separatorColor = [UIColor piwigoSeparatorColor];
};
tableViewCell = cell;
break;
}
case 1: // Switch automatically ?
{
SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"switchPalette"];
if(!cell) {
cell = [SwitchTableViewCell new];
}
cell.leftLabel.text = NSLocalizedString(@"settings_switchPalette", @"Switch Automatically");
[cell.cellSwitch setOn:[Model sharedInstance].switchPaletteAutomatically];
cell.cellSwitchBlock = ^(BOOL switchState) {
// Number of rows will change accordingly
[Model sharedInstance].switchPaletteAutomatically = switchState;
// Store modified setting
[[Model sharedInstance] saveToDisk];
// Position of the row that should be added/removed
NSIndexPath *rowAtIndexPath = [NSIndexPath indexPathForRow:2
inSection:SettingsSectionColor];
if(switchState) {
// Insert row in existing table
[self.settingsTableView insertRowsAtIndexPaths:@[rowAtIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} else {