Skip to content

Commit 717cd36

Browse files
authored
Формат отображения дней и мелкие доработки (#13)
* Поднял версию до 1.6 * Добавил скролл на экран редактирования из списка Когда открываем экран редактирования события прямо из списка на главном экране, скролл нужно добавить вручную * Сделал переиспользуемую вьюху для пикера дат * Поправил доступность для смены темы * В процессе * Раскидал файлы по папкам * Тесты в процессе * Удалил хедеры с комментариями * Дорабатываю тесты и скриншоты
1 parent e1e0b87 commit 717cd36

File tree

58 files changed

+583
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+583
-440
lines changed

.swiftformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
--ifdef no-indent
2+
--header strip
23

34
--exclude SwiftUI-DaysUITests/SnapshotHelper.swift

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ make screenshots
4343
make upload_screenshots
4444
```
4545
### iPhone
46-
| Список записей | Создание новой записи | Сортировка на главном экране |
47-
| --- | --- | --- |
48-
| <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-1-demoList.png"> | <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-2-chooseDate.png"> | <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-3-sortByDate.png"> |
46+
| Список записей | Создание новой записи | Выбор опции отображения | Перед сохранением | Сортировка на главном экране |
47+
| --- | --- | --- | --- | --- |
48+
| <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-1-demoList.png"> | <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-2-chooseDate.png"> | <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-3-chooseDisplayOption.png"> | <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-4-beforeSave.png"> | <img src="./fastlane/screenshots/ru/iPhone 15 Pro Max-5-sortByDate.png"> |
4949

5050
### iPad
51-
| Список записей | Создание новой записи | Сортировка на главном экране |
52-
| --- | --- | --- |
53-
| <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-1-demoList.png"> | <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-2-chooseDate.png"> | <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-3-sortByDate.png"> |
51+
| Список записей | Создание новой записи | Выбор опции отображения | Перед сохранением | Сортировка на главном экране |
52+
| --- | --- | --- | --- | --- |
53+
| <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-1-demoList.png"> | <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-2-chooseDate.png"> | <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-3-chooseDisplayOption.png"> | <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-4-beforeSave.png"> | <img src="./fastlane/screenshots/ru/iPad Pro (12.9-inch) (6th generation)-5-sortByDate.png"> |

SwiftUI-Days.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
533533
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
534534
MACOSX_DEPLOYMENT_TARGET = 14.0;
535-
MARKETING_VERSION = 1.5;
535+
MARKETING_VERSION = 1.6;
536536
PRODUCT_BUNDLE_IDENTIFIER = "com.oleg991.SwiftUI-Days";
537537
PRODUCT_NAME = "$(TARGET_NAME)";
538538
SDKROOT = auto;
@@ -578,7 +578,7 @@
578578
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
579579
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
580580
MACOSX_DEPLOYMENT_TARGET = 14.0;
581-
MARKETING_VERSION = 1.5;
581+
MARKETING_VERSION = 1.6;
582582
PRODUCT_BUNDLE_IDENTIFIER = "com.oleg991.SwiftUI-Days";
583583
PRODUCT_NAME = "$(TARGET_NAME)";
584584
SDKROOT = auto;

SwiftUI-Days/EnvironmentKeys/CurrentDateEnvironmentKey.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// CurrentDateEnvironmentKey.swift
3-
// SwiftUI-Days
4-
//
5-
// Created by Олег Еременко on 27.04.2025.
6-
//
7-
81
import SwiftUI
92

103
private struct CurrentDateKey: EnvironmentKey {

SwiftUI-Days/Extensions/Binding+mappedToBool.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// Binding+mappedToBool.swift
3-
// SwiftUI-Days
4-
//
5-
// Created by Oleg991 on 06.04.2025.
6-
//
7-
81
import SwiftUI
92

103
extension Binding<Bool> {

SwiftUI-Days/Models/AppTheme.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// AppTheme.swift
3-
// SwiftUI-Days
4-
//
5-
// Created by Oleg991 on 26.03.2025.
6-
//
7-
81
import SwiftUI
92

103
enum AppTheme: Int, CaseIterable, Identifiable {

SwiftUI-Days/Models/BackupFileDocument.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// BackupFileDocument.swift
3-
// SwiftUI-Days
4-
//
5-
// Created by Oleg991 on 06.04.2025.
6-
//
7-
81
import SwiftUI
92
import UniformTypeIdentifiers
103

@@ -16,7 +9,8 @@ struct BackupFileDocument: FileDocument {
169
title: item.title,
1710
details: item.details,
1811
timestamp: item.timestamp,
19-
colorTag: item.colorTag
12+
colorTag: item.colorTag,
13+
displayOption: item.displayOption
2014
)
2115
}
2216

@@ -45,25 +39,34 @@ extension BackupFileDocument {
4539
let details: String
4640
let timestamp: Date
4741
let colorTag: Color?
42+
let displayOption: DisplayOption?
4843

4944
var realItem: Item {
5045
.init(
5146
title: title,
5247
details: details,
5348
timestamp: timestamp,
54-
colorTag: colorTag
49+
colorTag: colorTag,
50+
displayOption: displayOption
5551
)
5652
}
5753

5854
private enum CodingKeys: String, CodingKey {
59-
case title, details, timestamp, colorTag
55+
case title, details, timestamp, colorTag, displayOption
6056
}
6157

62-
init(title: String, details: String, timestamp: Date, colorTag: Color? = nil) {
58+
init(
59+
title: String,
60+
details: String,
61+
timestamp: Date,
62+
colorTag: Color? = nil,
63+
displayOption: DisplayOption? = .day
64+
) {
6365
self.title = title
6466
self.details = details
6567
self.timestamp = timestamp
6668
self.colorTag = colorTag
69+
self.displayOption = displayOption
6770
}
6871

6972
init(from decoder: Decoder) throws {
@@ -80,6 +83,7 @@ extension BackupFileDocument {
8083
} else {
8184
colorTag = nil
8285
}
86+
displayOption = try container.decodeIfPresent(DisplayOption.self, forKey: .displayOption) ?? .day
8387
}
8488

8589
func encode(to encoder: Encoder) throws {
@@ -95,6 +99,7 @@ extension BackupFileDocument {
9599
)
96100
try container.encode(colorData, forKey: .colorTag)
97101
}
102+
try container.encodeIfPresent(displayOption, forKey: .displayOption)
98103
}
99104
}
100105
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Foundation
2+
import SwiftUI
3+
4+
/// Вариант отображения количества дней до события
5+
enum DisplayOption: String, Codable, CaseIterable, Hashable {
6+
case day
7+
case monthDay
8+
case yearMonthDay
9+
10+
var allowedUnits: NSCalendar.Unit {
11+
switch self {
12+
case .day: [.day]
13+
case .monthDay: [.month, .day]
14+
case .yearMonthDay: [.year, .month, .day]
15+
}
16+
}
17+
18+
/// Локализованное название формата отображения
19+
var localizedTitle: LocalizedStringKey {
20+
switch self {
21+
case .day: "Days only"
22+
case .monthDay: "Months and days"
23+
case .yearMonthDay: "Years, months and days"
24+
}
25+
}
26+
}
27+
28+
extension DisplayOption {
29+
static func makeUnitsStyle(
30+
years: Int,
31+
months: Int,
32+
days: Int
33+
) -> DateComponentsFormatter.UnitsStyle {
34+
let hasYears = years != 0
35+
let hasMonths = months != 0
36+
let hasDays = days != 0
37+
return switch (hasYears, hasMonths, hasDays) {
38+
case (true, true, true): .abbreviated
39+
case (true, true, false), (true, false, true), (false, true, true): .short
40+
default: .full
41+
}
42+
}
43+
}

SwiftUI-Days/Models/Item.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// Item.swift
3-
// SwiftUI-Days
4-
//
5-
// Created by Oleg991 on 19.03.2024.
6-
//
7-
81
import Foundation
92
import SwiftData
103
import SwiftUI
@@ -16,11 +9,19 @@ final class Item {
169
var details = ""
1710
var timestamp = Date.now
1811
var colorTagData: Data?
12+
var displayOption: DisplayOption?
1913

20-
init(title: String, details: String = "", timestamp: Date, colorTag: Color? = nil) {
14+
init(
15+
title: String,
16+
details: String = "",
17+
timestamp: Date,
18+
colorTag: Color? = nil,
19+
displayOption: DisplayOption? = .day
20+
) {
2121
self.title = title
2222
self.details = details
2323
self.timestamp = timestamp
24+
self.displayOption = displayOption
2425
colorTagData = colorTag.flatMap { color in
2526
try? NSKeyedArchiver.archivedData(
2627
withRootObject: UIColor(color),
@@ -30,11 +31,26 @@ final class Item {
3031
}
3132

3233
/// Количество дней с момента события
33-
func makeDaysCount(to date: Date) -> Int {
34+
func makeDaysCount(to date: Date) -> String {
3435
let startDate = Self.calendar.startOfDay(for: timestamp)
3536
let endDate = Self.calendar.startOfDay(for: date)
36-
let daysCount = Self.calendar.dateComponents([.day], from: startDate, to: endDate).day
37-
return daysCount ?? 0
37+
let components = Self.calendar.dateComponents([.year, .month, .day], from: startDate, to: endDate)
38+
let yearsCount = components.year ?? 0
39+
let monthsCount = components.month ?? 0
40+
let daysCount = components.day ?? 0
41+
let todayString = NSLocalizedString("Today", comment: "Today")
42+
guard yearsCount != 0 || monthsCount != 0 || daysCount != 0 else {
43+
return todayString
44+
}
45+
let formatter = DateComponentsFormatter()
46+
let option = displayOption ?? .day
47+
formatter.allowedUnits = option.allowedUnits
48+
formatter.unitsStyle = DisplayOption.makeUnitsStyle(
49+
years: yearsCount,
50+
months: monthsCount,
51+
days: daysCount
52+
)
53+
return formatter.string(from: startDate, to: endDate) ?? todayString
3854
}
3955

4056
var colorTag: Color? {
@@ -62,7 +78,8 @@ final class Item {
6278
title: title,
6379
details: details,
6480
timestamp: timestamp,
65-
colorTag: colorTag
81+
colorTag: colorTag,
82+
displayOption: displayOption
6683
)
6784
}
6885
}

SwiftUI-Days/Models/SortOrder+.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// SortOrder+.swift
3-
// SwiftUI-Days
4-
//
5-
// Created by Oleg991 on 03.04.2025.
6-
//
7-
81
import SwiftUI
92

103
extension SortOrder {

0 commit comments

Comments
 (0)