-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Feat [#12] 이용시간 통계뷰 구현 #20
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c58b467
[Add/#12] String 값 추가
Zoe0929 6b74878
[Feat/#12] 홈 뷰
Zoe0929 57be461
[Fix/#12] 폴더링 변경
Zoe0929 ba3e154
[Feat/#12] HomeViewModel 구현
Zoe0929 b007345
[Feat/#12] 리스트 뷰 요소 구현
Zoe0929 76b141a
[Feat/#12] HomeView 구현
Zoe0929 203f35d
[Feat/#12] DeviceActivity 타겟 추가
Zoe0929 ea52a53
[Feat/#12] 앱그룹
Zoe0929 fbf0cab
[Feat/#12] HomeView 총 스크린타임
Zoe0929 c23fb99
[Add/#12] 앱 사용시간 뷰 추가
Zoe0929 fd467e6
[Feat/#12] 더미 데이터
Zoe0929 e386fa2
[Fix/#12] 코드리뷰 반영 - 포맷팅
Zoe0929 cc7d477
지희 / feat / 폴더링 변경
Zoe0929 0351535
[Fix/#12] 로직 ViewModel로 이동
Zoe0929 57b9eaa
[Fix/#12] 네이밍 변경 및 로직 이동
Zoe0929 06761fe
[Fix/#12] 충돌 해결
Zoe0929 9afc735
[Fix/#12] 네비게이션바 적용
Zoe0929 7d68574
Merge branch 'develop' into feat/#12/usageTimeView
Zoe0929 166fd41
Merge branch 'develop' into feat/#12/usageTimeView
Zoe0929 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// AppActivityView.swift | ||
// HMHDeviceActivityReport | ||
// | ||
// Created by 이지희 on 4/27/24. | ||
// | ||
|
||
import SwiftUI | ||
import FamilyControls | ||
|
||
struct AppActivityView: View { | ||
let totalActivity: String | ||
|
||
var body: some View { | ||
if let timeString = convertStringToTime(totalActivity) { | ||
Text("\(timeString) 사용") | ||
.font(.title2_semibold_24) | ||
.foregroundStyle(.whiteText) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
} | ||
} | ||
} | ||
|
||
extension AppActivityView { | ||
func convertStringToTime(_ string: String) -> String? { | ||
let components = string.components(separatedBy: " ") | ||
guard components.count == 3, | ||
let hours = Int(components[0].replacingOccurrences(of: "h", with: "")), | ||
let minutes = Int(components[1].replacingOccurrences(of: "m", with: "")), | ||
let seconds = Int(components[2].replacingOccurrences(of: "s", with: "")) else { | ||
return nil | ||
} | ||
|
||
let hoursText = String(format: "%02d", hours) | ||
let minutesText = String(format: "%02d", minutes) | ||
|
||
return "\(hoursText)시간 \(minutesText)분" | ||
} | ||
} | ||
|
||
// In order to support previews for your extension's custom views, make sure its source files are | ||
// members of your app's Xcode target as well as members of your extension's target. You can use | ||
// Xcode's File Inspector to modify a file's Target Membership. | ||
#Preview { | ||
AppActivityView(totalActivity: "1h 23m") | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMHDeviceActivityReport/HMHDeviceActivityReport.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.family-controls</key> | ||
<true/> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>group.HMH</string> | ||
</array> | ||
</dict> | ||
</plist> |
20 changes: 20 additions & 0 deletions
20
HMH_iOS/HMHDeviceActivityReport/HMHDeviceActivityReport.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// HMHDeviceActivityReport.swift | ||
// HMHDeviceActivityReport | ||
// | ||
// Created by 이지희 on 4/15/24. | ||
// | ||
|
||
import DeviceActivity | ||
import SwiftUI | ||
|
||
@main | ||
struct HMHDeviceActivityReport: DeviceActivityReportExtension { | ||
var body: some DeviceActivityReportScene { | ||
// Create a report for each DeviceActivityReport.Context that your app supports. | ||
TotalActivityReport { totalActivity in | ||
TotalActivityView(totalActivity: totalActivity) | ||
} | ||
// Add more reports here... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>EXAppExtensionAttributes</key> | ||
<dict> | ||
<key>EXExtensionPointIdentifier</key> | ||
<string>com.apple.deviceactivityui.report-extension</string> | ||
</dict> | ||
<key>UIAppFonts</key> | ||
<array> | ||
<string>Pretendard-Regular.otf</string> | ||
<string>Pretendard-SemiBold.otf</string> | ||
<string>Pretendard-Medium.otf</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// TotalActivityReport.swift | ||
// HMHDeviceActivityReport | ||
// | ||
// Created by 이지희 on 4/15/24. | ||
// | ||
|
||
import DeviceActivity | ||
import SwiftUI | ||
|
||
extension DeviceActivityReport.Context { | ||
// If your app initializes a DeviceActivityReport with this context, then the system will use | ||
// your extension's corresponding DeviceActivityReportScene to render the contents of the | ||
// report. | ||
static let totalActivity = Self("Total Activity") | ||
} | ||
|
||
struct TotalActivityReport: DeviceActivityReportScene { | ||
// Define which context your scene will represent. | ||
let context: DeviceActivityReport.Context = .totalActivity | ||
|
||
// Define the custom configuration and the resulting view for this report. | ||
let content: (String) -> TotalActivityView | ||
|
||
func makeConfiguration(representing data: DeviceActivityResults<DeviceActivityData>) async -> String { | ||
// Reformat the data into a configuration that can be used to create | ||
// the report's view. | ||
|
||
let formatter = DateComponentsFormatter() | ||
formatter.allowedUnits = [.day, .hour, .minute, .second] | ||
formatter.unitsStyle = .abbreviated | ||
formatter.zeroFormattingBehavior = .dropAll | ||
|
||
let totalActivityDuration = await data.flatMap { $0.activitySegments }.reduce(0, { | ||
$0 + $1.totalActivityDuration | ||
}) | ||
return formatter.string(from: totalActivityDuration) ?? "No activity data" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// TotalActivityView.swift | ||
// HMHDeviceActivityReport | ||
// | ||
// Created by 이지희 on 4/15/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct TotalActivityView: View { | ||
let totalActivity: String | ||
|
||
var body: some View { | ||
if let timeString = convertStringToTime(totalActivity) { | ||
Text("\(timeString) 사용") | ||
.font(.title2_semibold_24) | ||
.foregroundStyle(.whiteText) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
} | ||
} | ||
} | ||
|
||
extension TotalActivityView { | ||
func convertStringToTime(_ string: String) -> String? { | ||
let components = string.components(separatedBy: " ") | ||
guard components.count == 3, | ||
let hours = Int(components[0].replacingOccurrences(of: "h", with: "")), | ||
let minutes = Int(components[1].replacingOccurrences(of: "m", with: "")), | ||
let seconds = Int(components[2].replacingOccurrences(of: "s", with: "")) else { | ||
return nil | ||
} | ||
|
||
let hoursText = String(format: "%d", hours) | ||
let minutesText = String(format: "%d", minutes) | ||
|
||
return "\(hoursText)시간 \(minutesText)분" | ||
} | ||
} | ||
|
||
// In order to support previews for your extension's custom views, make sure its source files are | ||
// members of your app's Xcode target as well as members of your extension's target. You can use | ||
// Xcode's File Inspector to modify a file's Target Membership. | ||
#Preview { | ||
TotalActivityView(totalActivity: "1h 23m") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💊 코드 포멧팅을 변경하여, 3시간 3분 이런 타입으로 가는 것 제안드립니다!
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.
넵 이 부분 놓쳤네요 꼼꼼한 피드백 감사합니다~