Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

위젯 Small 사이즈 로직 구현 #41

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PlantingMind/PlantingMind.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
7B0A76CE2B904A1200ADC039 /* MoodRecords.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A76CC2B904A1200ADC039 /* MoodRecords.xcdatamodeld */; };
7B0A76D12B906FE100ADC039 /* CoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A76D02B906FE100ADC039 /* CoreDataStack.swift */; };
7B0A77112B93196D00ADC039 /* MoodRecordViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A77102B93196D00ADC039 /* MoodRecordViewModel.swift */; };
7B0E1BCE2BAD57940060458D /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 7B95D1792BA1645C00484F9D /* Localizable.xcstrings */; };
7B0E1BCF2BAD57A70060458D /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B95D17B2BA166AC00484F9D /* StringExtension.swift */; };
7B0E1BD32BAD6C240060458D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B11F82B2B4549E000346A41 /* Assets.xcassets */; };
7B11F8282B4549DF00346A41 /* PlantingMindApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B11F8272B4549DF00346A41 /* PlantingMindApp.swift */; };
7B11F82A2B4549DF00346A41 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B11F8292B4549DF00346A41 /* ContentView.swift */; };
7B11F82C2B4549E000346A41 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B11F82B2B4549E000346A41 /* Assets.xcassets */; };
Expand Down Expand Up @@ -480,6 +483,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7B0E1BCE2BAD57940060458D /* Localizable.xcstrings in Resources */,
7B0E1BD32BAD6C240060458D /* Assets.xcassets in Resources */,
7B63CAA72BA9CB4700943DED /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -546,6 +551,7 @@
7B63CAA52BA9CB4600943DED /* PlantingWidget.swift in Sources */,
7BA079972BAAD87A009B5E46 /* ColorExtension.swift in Sources */,
7BA079962BAAD834009B5E46 /* Mood.swift in Sources */,
7B0E1BCF2BAD57A70060458D /* StringExtension.swift in Sources */,
7BA079952BAAD669009B5E46 /* MoodRecords.xcdatamodeld in Sources */,
7B63CAA32BA9CB4600943DED /* PlantingWidgetBundle.swift in Sources */,
7BA079932BAAD662009B5E46 /* MoodRecord+CoreDataClass.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xF9",
"green" : "0xF9",
"red" : "0xF9"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "extended-srgb",
"components" : {
"alpha" : "0.240",
"blue" : "0x63",
"green" : "0x63",
"red" : "0x63"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
2 changes: 2 additions & 0 deletions PlantingMind/PlantingMind/ColorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

private enum CustomColor: String {
case background
case widgetBackground
case line
case general
case point
Expand All @@ -24,6 +25,7 @@ extension Color {
struct Custom {
// Basic Color
static let background = Color(CustomColor.background.rawValue)
static let widgetBackground = Color(CustomColor.widgetBackground.rawValue)
static let line = Color(CustomColor.line.rawValue)
static let general = Color(CustomColor.general.rawValue)
static let point = Color(CustomColor.point.rawValue)
Expand Down
8 changes: 8 additions & 0 deletions PlantingMind/PlantingMind/CoreData/CoreDataStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ enum StorageType {

final class CoreDataStack: ObservableObject {
let persistentContainer: NSPersistentContainer
private let datebaseName = "PlantingMind.sqlite"

var sharedStoreURL: URL? {
let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.eunjoo.planting-mind.PlantingMind")
return container?.appendingPathComponent(datebaseName)
}

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

self.persistentContainer.loadPersistentStores { _, error in
Expand Down
9 changes: 2 additions & 7 deletions PlantingMind/PlantingMind/DateExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ import Foundation

extension Date {
var startOfMonth: Date? {
Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: self))
Calendar.current.dateInterval(of: .month, for: self)?.start
}

var endOfMonth: Date? {
guard let nextMonth = Calendar.current.date(byAdding: .month, value: 1, to: self),
let startOfNextMonth = Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: nextMonth)) else {
return nil
}

return Calendar.current.date(byAdding: .second, value: -1, to: startOfNextMonth)
Calendar.current.dateInterval(of: .month, for: self)?.end
}
}
153 changes: 153 additions & 0 deletions PlantingMind/PlantingMind/Localization/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"sourceLanguage" : "en",
"strings" : {
"app_title" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Planting Mind"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "마음심기"
}
}
}
},
"cancel" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -68,6 +85,40 @@
}
}
},
"friday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "F"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㄱ"
}
}
}
},
"monday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "M"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㅇ"
}
}
}
},
"mood_reason" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -102,6 +153,23 @@
}
}
},
"saturday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "S"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㅌ"
}
}
}
},
"save" : {
"extractionState" : "manual",
"localizations" : {
Expand All @@ -119,6 +187,23 @@
}
}
},
"sunday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "S"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㅇ"
}
}
}
},
"text_limit" : {
"extractionState" : "manual",
"localizations" : {
Expand All @@ -135,6 +220,74 @@
}
}
}
},
"thursday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "T"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㅁ"
}
}
}
},
"tuesday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "T"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㅎ"
}
}
}
},
"wednesday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "W"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "ㅅ"
}
}
}
},
"widget_desc" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Check the widget to see how you feel."
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "기록한 기분을 위젯으로 확인하세요."
}
}
}
}
},
"version" : "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import CoreData
import WidgetKit

class MoodRecordViewModel: ObservableObject {
private let context: NSManagedObjectContext
Expand Down Expand Up @@ -46,6 +47,7 @@ class MoodRecordViewModel: ObservableObject {
record.reason = self.reason
}
try context.save()
WidgetCenter.shared.reloadAllTimelines()
} catch {
print("Failed to save the mood record", error.localizedDescription)
}
Expand Down
Loading
Loading