Skip to content

Conversation

@Funital
Copy link
Collaborator

@Funital Funital commented Jun 30, 2025

#️⃣ 관련 이슈

Resolved #이슈번호

💡작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

  • 백그라운드에서 포그라운드로 전환 시, 마지막 활성화 날짜와 비교해 “새로운 날”이면 HomeViewController에 알림을 보내고, 마지막 활성화 시간을 갱신해서 앱을 메모리에서 해제하지 않고 다음날 혹은 며칠 이후 앱에 다시 접속할 때, 오늘 날짜로 갱신하도록 수정

💬리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

@Funital Funital requested review from CJiu01 and Hrepay June 30, 2025 05:17
@Funital Funital self-assigned this Jun 30, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a 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 SceneDelegate to 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, using UserDefaults to persist the last active date.
  • Inter-Component Communication: Established a NotificationCenter mechanism (didEnterNewDay) to inform relevant parts of the application (specifically HomeViewController) when a new day is detected. This decouples the detection logic from the UI update.
  • Calendar View Synchronization: Added functionality to HomeCalendarView and HomeViewController to programmatically select and display the current date when the didEnterNewDay notification 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +57 to +62
func setSelected(date: Date) {
// 날짜를 선택
calendar.select(date)
// 달력을 해당 날짜가 포함된 페이지로 이동
calendar.setCurrentPage(date, animated: true)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider updating this call to selectDate(_:) to match the renaming in HomeCalendarView for better API clarity and consistency.

Suggested change
self.homeCalendarView.setSelected(date: today)
self.homeCalendarView.selectDate(today)

Comment on lines 200 to 221
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")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)
        }
    }

Copy link
Collaborator

@CJiu01 CJiu01 left a 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 UserDefault에서 lastActiveDate 값을 저장하고 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set을 통해 UserDefault에 값을 저장하고 있습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재는 lastActiveDate값이 현재 시간으로 저장을 하고 있는데, 테스트 시 lastActiveDate값을 조정해 테스트 가능합니다

- checkAndNotifyNewDay() 메서드 리팩토링

#284
@Funital Funital merged commit 2a91ce9 into develop Jul 7, 2025
@Funital Funital deleted the refactor/#284 branch July 7, 2025 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants