Skip to content

Commit

Permalink
[Feat/#21] 홈뷰 앱 사용시간 뷰 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe0929 committed May 13, 2024
1 parent 3f0c030 commit b87f78a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
10 changes: 0 additions & 10 deletions HMH_iOS/HMH_iOS/Presentation/Home/ViewModels/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ class HomeViewModel: ObservableObject {
AppUsage(appId: "3", appName: "Twitter", goalTime: 30, usedTime: 15)
]
}

func requestAuthorization() {
Task {
do {
try await AuthorizationCenter.shared.requestAuthorization(for: FamilyControlsMember.individual)
} catch {
print("스크린타임 권한 설정이 실패: \(error.localizedDescription)")
}
}
}
}

struct AppUsage: Identifiable {
Expand Down
33 changes: 26 additions & 7 deletions HMH_iOS/HMH_iOS/Presentation/Home/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ struct HomeView: View {
users: .all,
devices: .init([.iPhone, .iPad])
)

@State var appContext: DeviceActivityReport.Context = .init(rawValue: "App Activity")
@State var appFilter = DeviceActivityFilter(
segment: .daily(
during: Calendar.current.dateInterval(
of: .day, for: .now
)!
),
users: .all,
devices: .init([.iPhone, .iPad]),
applications: ScreenTimeViewModel.shared.selectionToDiscourage.applicationTokens,
categories: ScreenTimeViewModel.shared.selectionToDiscourage.categoryTokens
)

var body: some View {
ScrollView {
Expand Down Expand Up @@ -72,19 +83,27 @@ struct HomeView: View {
}
}
.padding(.bottom, 60)
ForEach(homeViewModel.appsUsage) { appUsage in
UsageTimeListItemView(appName: appUsage.appName,
usageTime: Int(appUsage.usedTime), remainingTime: "\(appUsage.goalTime - appUsage.usedTime)")
}
DeviceActivityReport(appContext, filter: appFilter)
}
.background(.blackground)
.customNavigationBar(title: StringLiteral.NavigationBar.home,
showBackButton: false,
showPointButton: false)
}
.onAppear {
homeViewModel.requestAuthorization()
homeViewModel.generateDummyData()
ScreenTimeViewModel.shared.requestAuthorization()

appFilter = DeviceActivityFilter(
segment: .daily(
during: Calendar.current.dateInterval(
of: .day, for: .now
) ?? DateInterval()
),
users: .all,
devices: .init([.iPhone]),
applications: ScreenTimeViewModel.shared.selectionToDiscourage.applicationTokens,
categories: ScreenTimeViewModel.shared.selectionToDiscourage.categoryTokens
)
}
.background(.blackground)
}
Expand Down

0 comments on commit b87f78a

Please # to comment.