-
Notifications
You must be signed in to change notification settings - Fork 1
[#284] OS 메모리에서 해제하지 않고 오랜만에 앱에 들어왔을 때 오늘 날짜로 갱신 및 업데이트 최적화 #291
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Funital, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a mechanism to automatically update the application's displayed date, particularly within the home calendar view, when the app returns from the background after a day has passed. This ensures that users always see the current date reflected in the UI without needing to fully restart the application, improving the overall user experience and data freshness.
Highlights
- New Day Detection: Implemented logic in
SceneDelegateto detect if a new day has passed since the app was last active. This check occurs when the app transitions from the background to the foreground, usingUserDefaultsto persist the last active date. - Inter-Component Communication: Established a
NotificationCentermechanism (didEnterNewDay) to inform relevant parts of the application (specificallyHomeViewController) when a new day is detected. This decouples the detection logic from the UI update. - Calendar View Synchronization: Added functionality to
HomeCalendarViewandHomeViewControllerto programmatically select and display the current date when thedidEnterNewDaynotification is received, ensuring the calendar UI is always up-to-date.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request implements a feature to refresh the app's content to the current date when it returns from the background. The use of NotificationCenter and SceneDelegate lifecycle methods is appropriate. I've provided suggestions to improve code clarity and maintainability.
| func setSelected(date: Date) { | ||
| // 날짜를 선택 | ||
| calendar.select(date) | ||
| // 달력을 해당 날짜가 포함된 페이지로 이동 | ||
| calendar.setCurrentPage(date, animated: true) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name setSelected(date:) can be ambiguous, as it sounds like a setter for a property. A name like selectDate(_:) would be more descriptive of the action being performed (selecting a date and scrolling the calendar). This improves code clarity and aligns better with Swift conventions.
| func setSelected(date: Date) { | |
| // 날짜를 선택 | |
| calendar.select(date) | |
| // 달력을 해당 날짜가 포함된 페이지로 이동 | |
| calendar.setCurrentPage(date, animated: true) | |
| } | |
| func selectDate(_ date: Date) { | |
| // 날짜를 선택 | |
| calendar.select(date) | |
| // 달력을 해당 날짜가 포함된 페이지로 이동 | |
| calendar.setCurrentPage(date, animated: true) | |
| } |
| let today = Date() | ||
| self.currentDate = today | ||
| // 달력뷰에 오늘 날짜가 선택되도록 호출 | ||
| self.homeCalendarView.setSelected(date: today) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private func checkAndNotifyNewDay() { | ||
| let defaults = UserDefaults.standard | ||
| let calendar = Calendar.current | ||
| let today = calendar.startOfDay(for: Date()) | ||
|
|
||
| // 이전에 저장된 마지막 활성화 날짜가 있는지 확인 | ||
| if let lastActive = defaults.object(forKey: "lastActiveDate") as? Date { | ||
| // 저장된 날짜의 시점을 계산하여 비교 기준으로 사용 | ||
| let lastDay = calendar.startOfDay(for: lastActive) | ||
| // 오늘이 마지막 활성화 날짜보다 이후인지 검사 | ||
| if calendar.compare(today, to: lastDay, toGranularity: .day) == .orderedDescending { | ||
| // 새로운 날로 판단될 때, 알림을 보냄 | ||
| NotificationCenter.default.post(name: .didEnterNewDay, object: nil) | ||
| } | ||
| } else { | ||
| // 저장된 날짜가 없으면 첫 실행이므로 초기 업데이트를 위해 알림을 보냅니다. | ||
| NotificationCenter.default.post(name: .didEnterNewDay, object: nil) | ||
| } | ||
|
|
||
| // 마지막 활성화 날짜를 현재 시점으로 업데이트하여 다음 비교에 사용 | ||
| defaults.set(Date(), forKey: "lastActiveDate") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function's logic is correct, but it can be refactored to improve clarity and maintainability by reducing duplication and ensuring the UserDefaults update always occurs. Consider defining the lastActiveDate key as a static private constant to avoid magic strings.
private func checkAndNotifyNewDay() {
let defaults = UserDefaults.standard
let calendar = Calendar.current
let today = calendar.startOfDay(for: Date())
defer {
// 마지막 활성화 날짜를 현재 시점으로 업데이트하여 다음 비교에 사용
defaults.set(Date(), forKey: "lastActiveDate")
}
guard let lastActive = defaults.object(forKey: "lastActiveDate") as? Date else {
// 저장된 날짜가 없으면 첫 실행이므로 초기 업데이트를 위해 알림을 보냅니다.
NotificationCenter.default.post(name: .didEnterNewDay, object: nil)
return
}
// 저장된 날짜의 시점을 계산하여 비교 기준으로 사용
let lastDay = calendar.startOfDay(for: lastActive)
// 오늘이 마지막 활성화 날짜보다 이후인지 검사
if calendar.compare(today, to: lastDay, toGranularity: .day) == .orderedDescending {
// 새로운 날로 판단될 때, 알림을 보냄
NotificationCenter.default.post(name: .didEnterNewDay, object: nil)
}
}
CJiu01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다~!
해당 부분은 테스트할 때 lastActiveDate값을 조정해서 해야할까요?
| let today = calendar.startOfDay(for: Date()) | ||
|
|
||
| // 이전에 저장된 마지막 활성화 날짜가 있는지 확인 | ||
| if let lastActive = defaults.object(forKey: "lastActiveDate") as? Date { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 UserDefault에서 lastActiveDate 값을 저장하고 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set을 통해 UserDefault에 값을 저장하고 있습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 lastActiveDate값이 현재 시간으로 저장을 하고 있는데, 테스트 시 lastActiveDate값을 조정해 테스트 가능합니다
- checkAndNotifyNewDay() 메서드 리팩토링 #284
#️⃣ 관련 이슈
Resolved #이슈번호
💡작업 내용
💬리뷰 요구사항(선택)