Skip to content

Commit b4c3fb1

Browse files
authored
Merge pull request #41 from eunjooChoi/small-widget
위젯 Small 사이즈 로직 구현
2 parents 44560d4 + c0e9446 commit b4c3fb1

File tree

8 files changed

+301
-42
lines changed

8 files changed

+301
-42
lines changed

PlantingMind/PlantingMind.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
7B0A76CE2B904A1200ADC039 /* MoodRecords.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A76CC2B904A1200ADC039 /* MoodRecords.xcdatamodeld */; };
1212
7B0A76D12B906FE100ADC039 /* CoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A76D02B906FE100ADC039 /* CoreDataStack.swift */; };
1313
7B0A77112B93196D00ADC039 /* MoodRecordViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A77102B93196D00ADC039 /* MoodRecordViewModel.swift */; };
14+
7B0E1BCE2BAD57940060458D /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 7B95D1792BA1645C00484F9D /* Localizable.xcstrings */; };
15+
7B0E1BCF2BAD57A70060458D /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B95D17B2BA166AC00484F9D /* StringExtension.swift */; };
16+
7B0E1BD32BAD6C240060458D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B11F82B2B4549E000346A41 /* Assets.xcassets */; };
1417
7B11F8282B4549DF00346A41 /* PlantingMindApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B11F8272B4549DF00346A41 /* PlantingMindApp.swift */; };
1518
7B11F82A2B4549DF00346A41 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B11F8292B4549DF00346A41 /* ContentView.swift */; };
1619
7B11F82C2B4549E000346A41 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B11F82B2B4549E000346A41 /* Assets.xcassets */; };
@@ -480,6 +483,8 @@
480483
isa = PBXResourcesBuildPhase;
481484
buildActionMask = 2147483647;
482485
files = (
486+
7B0E1BCE2BAD57940060458D /* Localizable.xcstrings in Resources */,
487+
7B0E1BD32BAD6C240060458D /* Assets.xcassets in Resources */,
483488
7B63CAA72BA9CB4700943DED /* Assets.xcassets in Resources */,
484489
);
485490
runOnlyForDeploymentPostprocessing = 0;
@@ -546,6 +551,7 @@
546551
7B63CAA52BA9CB4600943DED /* PlantingWidget.swift in Sources */,
547552
7BA079972BAAD87A009B5E46 /* ColorExtension.swift in Sources */,
548553
7BA079962BAAD834009B5E46 /* Mood.swift in Sources */,
554+
7B0E1BCF2BAD57A70060458D /* StringExtension.swift in Sources */,
549555
7BA079952BAAD669009B5E46 /* MoodRecords.xcdatamodeld in Sources */,
550556
7B63CAA32BA9CB4600943DED /* PlantingWidgetBundle.swift in Sources */,
551557
7BA079932BAAD662009B5E46 /* MoodRecord+CoreDataClass.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0xF9",
9+
"green" : "0xF9",
10+
"red" : "0xF9"
11+
}
12+
},
13+
"idiom" : "universal"
14+
},
15+
{
16+
"appearances" : [
17+
{
18+
"appearance" : "luminosity",
19+
"value" : "dark"
20+
}
21+
],
22+
"color" : {
23+
"color-space" : "extended-srgb",
24+
"components" : {
25+
"alpha" : "0.240",
26+
"blue" : "0x63",
27+
"green" : "0x63",
28+
"red" : "0x63"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}

PlantingMind/PlantingMind/ColorExtension.swift

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwiftUI
1010

1111
private enum CustomColor: String {
1212
case background
13+
case widgetBackground
1314
case line
1415
case general
1516
case point
@@ -24,6 +25,7 @@ extension Color {
2425
struct Custom {
2526
// Basic Color
2627
static let background = Color(CustomColor.background.rawValue)
28+
static let widgetBackground = Color(CustomColor.widgetBackground.rawValue)
2729
static let line = Color(CustomColor.line.rawValue)
2830
static let general = Color(CustomColor.general.rawValue)
2931
static let point = Color(CustomColor.point.rawValue)

PlantingMind/PlantingMind/CoreData/CoreDataStack.swift

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ enum StorageType {
1515

1616
final class CoreDataStack: ObservableObject {
1717
let persistentContainer: NSPersistentContainer
18+
private let datebaseName = "PlantingMind.sqlite"
19+
20+
var sharedStoreURL: URL? {
21+
let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.eunjoo.planting-mind.PlantingMind")
22+
return container?.appendingPathComponent(datebaseName)
23+
}
1824

1925
init(_ storageType: StorageType = .persistent) {
2026
self.persistentContainer = NSPersistentContainer(name: "MoodRecords")
@@ -23,6 +29,8 @@ final class CoreDataStack: ObservableObject {
2329
if storageType == .inMemory {
2430
let description = NSPersistentStoreDescription(url: URL(filePath: "dev/null"))
2531
self.persistentContainer.persistentStoreDescriptions = [description]
32+
} else {
33+
self.persistentContainer.persistentStoreDescriptions.first?.url = self.sharedStoreURL
2634
}
2735

2836
self.persistentContainer.loadPersistentStores { _, error in

PlantingMind/PlantingMind/DateExtension.swift

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ import Foundation
99

1010
extension Date {
1111
var startOfMonth: Date? {
12-
Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: self))
12+
Calendar.current.dateInterval(of: .month, for: self)?.start
1313
}
1414

1515
var endOfMonth: Date? {
16-
guard let nextMonth = Calendar.current.date(byAdding: .month, value: 1, to: self),
17-
let startOfNextMonth = Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: nextMonth)) else {
18-
return nil
19-
}
20-
21-
return Calendar.current.date(byAdding: .second, value: -1, to: startOfNextMonth)
16+
Calendar.current.dateInterval(of: .month, for: self)?.end
2217
}
2318
}

PlantingMind/PlantingMind/Localization/Localizable.xcstrings

+153
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
{
22
"sourceLanguage" : "en",
33
"strings" : {
4+
"app_title" : {
5+
"extractionState" : "manual",
6+
"localizations" : {
7+
"en" : {
8+
"stringUnit" : {
9+
"state" : "translated",
10+
"value" : "Planting Mind"
11+
}
12+
},
13+
"ko" : {
14+
"stringUnit" : {
15+
"state" : "translated",
16+
"value" : "마음심기"
17+
}
18+
}
19+
}
20+
},
421
"cancel" : {
522
"extractionState" : "manual",
623
"localizations" : {
@@ -68,6 +85,40 @@
6885
}
6986
}
7087
},
88+
"friday" : {
89+
"extractionState" : "manual",
90+
"localizations" : {
91+
"en" : {
92+
"stringUnit" : {
93+
"state" : "translated",
94+
"value" : "F"
95+
}
96+
},
97+
"ko" : {
98+
"stringUnit" : {
99+
"state" : "translated",
100+
"value" : "ㄱ"
101+
}
102+
}
103+
}
104+
},
105+
"monday" : {
106+
"extractionState" : "manual",
107+
"localizations" : {
108+
"en" : {
109+
"stringUnit" : {
110+
"state" : "translated",
111+
"value" : "M"
112+
}
113+
},
114+
"ko" : {
115+
"stringUnit" : {
116+
"state" : "translated",
117+
"value" : "ㅇ"
118+
}
119+
}
120+
}
121+
},
71122
"mood_reason" : {
72123
"extractionState" : "manual",
73124
"localizations" : {
@@ -102,6 +153,23 @@
102153
}
103154
}
104155
},
156+
"saturday" : {
157+
"extractionState" : "manual",
158+
"localizations" : {
159+
"en" : {
160+
"stringUnit" : {
161+
"state" : "translated",
162+
"value" : "S"
163+
}
164+
},
165+
"ko" : {
166+
"stringUnit" : {
167+
"state" : "translated",
168+
"value" : "ㅌ"
169+
}
170+
}
171+
}
172+
},
105173
"save" : {
106174
"extractionState" : "manual",
107175
"localizations" : {
@@ -119,6 +187,23 @@
119187
}
120188
}
121189
},
190+
"sunday" : {
191+
"extractionState" : "manual",
192+
"localizations" : {
193+
"en" : {
194+
"stringUnit" : {
195+
"state" : "translated",
196+
"value" : "S"
197+
}
198+
},
199+
"ko" : {
200+
"stringUnit" : {
201+
"state" : "translated",
202+
"value" : "ㅇ"
203+
}
204+
}
205+
}
206+
},
122207
"text_limit" : {
123208
"extractionState" : "manual",
124209
"localizations" : {
@@ -135,6 +220,74 @@
135220
}
136221
}
137222
}
223+
},
224+
"thursday" : {
225+
"extractionState" : "manual",
226+
"localizations" : {
227+
"en" : {
228+
"stringUnit" : {
229+
"state" : "translated",
230+
"value" : "T"
231+
}
232+
},
233+
"ko" : {
234+
"stringUnit" : {
235+
"state" : "translated",
236+
"value" : "ㅁ"
237+
}
238+
}
239+
}
240+
},
241+
"tuesday" : {
242+
"extractionState" : "manual",
243+
"localizations" : {
244+
"en" : {
245+
"stringUnit" : {
246+
"state" : "translated",
247+
"value" : "T"
248+
}
249+
},
250+
"ko" : {
251+
"stringUnit" : {
252+
"state" : "translated",
253+
"value" : "ㅎ"
254+
}
255+
}
256+
}
257+
},
258+
"wednesday" : {
259+
"extractionState" : "manual",
260+
"localizations" : {
261+
"en" : {
262+
"stringUnit" : {
263+
"state" : "translated",
264+
"value" : "W"
265+
}
266+
},
267+
"ko" : {
268+
"stringUnit" : {
269+
"state" : "translated",
270+
"value" : "ㅅ"
271+
}
272+
}
273+
}
274+
},
275+
"widget_desc" : {
276+
"extractionState" : "manual",
277+
"localizations" : {
278+
"en" : {
279+
"stringUnit" : {
280+
"state" : "translated",
281+
"value" : "Check the widget to see how you feel."
282+
}
283+
},
284+
"ko" : {
285+
"stringUnit" : {
286+
"state" : "translated",
287+
"value" : "기록한 기분을 위젯으로 확인하세요."
288+
}
289+
}
290+
}
138291
}
139292
},
140293
"version" : "1.0"

PlantingMind/PlantingMind/MoodRecord/MoodRecordViewModel.swift

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import CoreData
10+
import WidgetKit
1011

1112
class MoodRecordViewModel: ObservableObject {
1213
private let context: NSManagedObjectContext
@@ -46,6 +47,7 @@ class MoodRecordViewModel: ObservableObject {
4647
record.reason = self.reason
4748
}
4849
try context.save()
50+
WidgetCenter.shared.reloadAllTimelines()
4951
} catch {
5052
print("Failed to save the mood record", error.localizedDescription)
5153
}

0 commit comments

Comments
 (0)