Skip to content

Commit 3a07bc6

Browse files
authored
Merge pull request #5 from easydev991/develop
Доработки 1.3
2 parents b596f68 + f6364d3 commit 3a07bc6

File tree

13 files changed

+104
-32
lines changed

13 files changed

+104
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
SwiftUI-Days.xcodeproj/xcuserdata/oleg991.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
33
fastlane/screenshots/screenshots.html
44
fastlane/report.xml
5+
SwiftUI-Days.xcodeproj/project.xcworkspace/xcuserdata/oleg991.xcuserdatad/UserInterfaceState.xcuserstate

SwiftUI-Days.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@
515515
GENERATE_INFOPLIST_FILE = YES;
516516
INFOPLIST_FILE = "SwiftUI-Days/SupportingFiles/Info.plist";
517517
INFOPLIST_KEY_CFBundleDisplayName = Days;
518+
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
518519
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
519520
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
520521
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
@@ -531,7 +532,7 @@
531532
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
532533
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
533534
MACOSX_DEPLOYMENT_TARGET = 14.0;
534-
MARKETING_VERSION = 1.2;
535+
MARKETING_VERSION = 1.3;
535536
PRODUCT_BUNDLE_IDENTIFIER = "com.oleg991.SwiftUI-Days";
536537
PRODUCT_NAME = "$(TARGET_NAME)";
537538
SDKROOT = auto;
@@ -560,6 +561,7 @@
560561
GENERATE_INFOPLIST_FILE = YES;
561562
INFOPLIST_FILE = "SwiftUI-Days/SupportingFiles/Info.plist";
562563
INFOPLIST_KEY_CFBundleDisplayName = Days;
564+
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
563565
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
564566
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
565567
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
@@ -576,7 +578,7 @@
576578
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
577579
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
578580
MACOSX_DEPLOYMENT_TARGET = 14.0;
579-
MARKETING_VERSION = 1.2;
581+
MARKETING_VERSION = 1.3;
580582
PRODUCT_BUNDLE_IDENTIFIER = "com.oleg991.SwiftUI-Days";
581583
PRODUCT_NAME = "$(TARGET_NAME)";
582584
SDKROOT = auto;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// CurrentDateEnvironmentKey.swift
3+
// SwiftUI-Days
4+
//
5+
// Created by Олег Еременко on 27.04.2025.
6+
//
7+
8+
import SwiftUI
9+
10+
private struct CurrentDateKey: EnvironmentKey {
11+
static let defaultValue = Date.now
12+
}
13+
14+
extension EnvironmentValues {
15+
/// Текущая дата, нужна для вычисления количества дней
16+
/// при переходе приложения в активное состояние
17+
///
18+
/// Например, если свернуть приложение и открыть через пару дней,
19+
/// то количество дней в списке не обновится по умолчанию, а если
20+
/// считать дни по отношению к этой дате, то все будет обновляться
21+
var currentDate: Date {
22+
get { self[CurrentDateKey.self] }
23+
set { self[CurrentDateKey.self] = newValue }
24+
}
25+
}

SwiftUI-Days/Models/Item.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ import SwiftData
1010

1111
@Model
1212
final class Item {
13-
var title: String
14-
var details: String
15-
var timestamp: Date
16-
17-
init(title: String, details: String = "", timestamp: Date = .now) {
13+
var title = ""
14+
var details = ""
15+
var timestamp = Date.now
16+
17+
init(title: String, details: String = "", timestamp: Date) {
1818
self.title = title
1919
self.details = details
2020
self.timestamp = timestamp
2121
}
22-
22+
2323
/// Количество дней с момента события
24-
var daysCount: Int {
24+
func makeDaysCount(to date: Date) -> Int {
2525
Calendar.current.dateComponents(
2626
[.day],
2727
from: timestamp,
28-
to: .now
28+
to: date
2929
).day ?? 0
3030
}
3131

SwiftUI-Days/Screens/Main/Detail/ItemScreen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99

1010
struct ItemScreen: View {
11+
@Environment(\.currentDate) private var currentDate
1112
@State private var isEditing = false
1213
let item: Item
1314

@@ -53,7 +54,7 @@ struct ItemScreen: View {
5354
Spacer()
5455
}
5556
.padding()
56-
.navigationTitle("\(item.daysCount) days")
57+
.navigationTitle("\(item.makeDaysCount(to: currentDate)) days")
5758
.toolbar {
5859
ToolbarItem(placement: .topBarTrailing) {
5960
DaysEditButton { isEditing.toggle() }

SwiftUI-Days/Screens/Main/MainScreen+ListView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwiftData
1010

1111
extension MainScreen {
1212
struct ListView: View {
13+
@Environment(\.currentDate) private var currentDate
1314
@Environment(\.modelContext) private var modelContext
1415
@Binding private var editItem: Item?
1516
@Query private var items: [Item]
@@ -51,7 +52,8 @@ extension MainScreen {
5152
Text(item.title)
5253
.lineLimit(2)
5354
.frame(maxWidth: .infinity, alignment: .leading)
54-
Text("\(item.daysCount) days")
55+
Text("\(item.makeDaysCount(to: currentDate)) days")
56+
.contentTransition(.numericText())
5557
.containerRelativeFrame(.horizontal, alignment: .trailing) { length, _ in
5658
length * 0.3
5759
}

SwiftUI-Days/Screens/More/MoreScreen.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import SwiftUI
1010
struct MoreScreen: View {
1111
@Environment(\.locale) private var locale
1212
@Environment(AppSettings.self) private var appSettings
13-
13+
private let appId = "id6744068216"
14+
1415
var body: some View {
1516
NavigationStack {
1617
ScrollView {
@@ -21,6 +22,7 @@ struct MoreScreen: View {
2122
appThemePicker
2223
appDataButton
2324
feedbackButton
25+
rateAppButton
2426
shareAppButton
2527
githubButton
2628
}
@@ -55,20 +57,27 @@ struct MoreScreen: View {
5557
}
5658

5759
private var appDataButton: some View {
58-
NavigationLink(destination: AppDataScreen()) {
59-
Text("App data")
60-
}
60+
NavigationLink("App data", destination: AppDataScreen())
61+
.accessibilityIdentifier("appDataButton")
6162
}
6263

6364
private var feedbackButton: some View {
6465
Button("Send feedback", action: FeedbackSender.sendFeedback)
6566
.accessibilityIdentifier("sendFeedbackButton")
6667
}
67-
68+
69+
@ViewBuilder
70+
private var rateAppButton: some View {
71+
if let appReviewLink = URL(string: "https://apps.apple.com/app/\(appId)?action=write-review") {
72+
Link("Rate the app", destination: appReviewLink)
73+
.accessibilityIdentifier("rateAppButton")
74+
}
75+
}
76+
6877
@ViewBuilder
6978
private var shareAppButton: some View {
7079
let languageCode = locale.identifier.split(separator: "_").first == "ru" ? "ru" : "us"
71-
if let appStoreLink = URL(string: "https://apps.apple.com/\(languageCode)/app/id6744068216") {
80+
if let appStoreLink = URL(string: "https://apps.apple.com/\(languageCode)/app/\(appId)") {
7281
ShareLink(item: appStoreLink) {
7382
Text("Share the app")
7483
}
@@ -79,10 +88,8 @@ struct MoreScreen: View {
7988
@ViewBuilder
8089
private var githubButton: some View {
8190
if let githubLink = URL(string: "https://github.com/easydev991/SwiftUI-Days") {
82-
Link(destination: githubLink) {
83-
Text("GitHub page")
84-
}
85-
.accessibilityIdentifier("linkToGitHubPage")
91+
Link("GitHub page", destination: githubLink)
92+
.accessibilityIdentifier("linkToGitHubPage")
8693
}
8794
}
8895

SwiftUI-Days/Screens/RootScreen.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import SwiftUI
99

1010
struct RootScreen: View {
11+
@Environment(\.scenePhase) private var scenePhase
1112
@State private var tab = Tab.list
12-
13+
@State private var currentDate = Date.now
14+
1315
var body: some View {
1416
TabView(selection: $tab) {
1517
ForEach(Tab.allCases, id: \.self) { tab in
@@ -18,6 +20,13 @@ struct RootScreen: View {
1820
.tag(tab)
1921
}
2022
}
23+
.environment(\.currentDate, currentDate)
24+
.animation(.default, value: currentDate)
25+
.onChange(of: scenePhase) { _, newPhase in
26+
if newPhase == .active {
27+
currentDate = .now
28+
}
29+
}
2130
}
2231
}
2332

-230 KB
Loading

SwiftUI-Days/SupportingFiles/Info.plist

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>ITSAppUsesNonExemptEncryption</key>
6-
<false/>
75
<key>LSApplicationQueriesSchemes</key>
86
<array>
97
<string>mailto</string>
108
</array>
9+
<key>UIBackgroundModes</key>
10+
<array>
11+
<string>remote-notification</string>
12+
</array>
1113
</dict>
1214
</plist>

0 commit comments

Comments
 (0)