Skip to content

Commit

Permalink
[Feat/#12] 더미 데이터
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe0929 committed May 1, 2024
1 parent c23fb99 commit fd467e6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
32 changes: 30 additions & 2 deletions HMH_iOS/HMHDeviceActivityReport/AppActivityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,41 @@
//

import SwiftUI
import FamilyControls

struct AppActivityView: View {
let totalActivity: String

var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
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()
AppActivityView(totalActivity: "1h 23m")
}

This file was deleted.

4 changes: 4 additions & 0 deletions HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
368C5D992BCC41990035A1AC /* TotalActivityReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 368C5D982BCC41990035A1AC /* TotalActivityReport.swift */; };
368C5D9B2BCC41990035A1AC /* TotalActivityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 368C5D9A2BCC41990035A1AC /* TotalActivityView.swift */; };
368C5DA02BCC41990035A1AC /* HMHDeviceActivityReport.appex in Embed ExtensionKit Extensions */ = {isa = PBXBuildFile; fileRef = 368C5D942BCC41990035A1AC /* HMHDeviceActivityReport.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
36EB6EC02BDCC65600E8C939 /* AppActivityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36EB6EBF2BDCC65600E8C939 /* AppActivityView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -142,6 +143,7 @@
368CAA942BB9617A00FA83B3 /* DeviceActivity.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DeviceActivity.framework; path = System/Library/Frameworks/DeviceActivity.framework; sourceTree = SDKROOT; };
368CAABC2BB961D900FA83B3 /* ManagedSettings.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ManagedSettings.framework; path = System/Library/Frameworks/ManagedSettings.framework; sourceTree = SDKROOT; };
368CAADD2BB97FE000FA83B3 /* HMH_iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HMH_iOS.entitlements; sourceTree = "<group>"; };
36EB6EBF2BDCC65600E8C939 /* AppActivityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppActivityView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -400,6 +402,7 @@
368C5D9A2BCC41990035A1AC /* TotalActivityView.swift */,
368C5D9C2BCC41990035A1AC /* Info.plist */,
368C5D9D2BCC41990035A1AC /* HMHDeviceActivityReport.entitlements */,
36EB6EBF2BDCC65600E8C939 /* AppActivityView.swift */,
);
path = HMHDeviceActivityReport;
sourceTree = "<group>";
Expand Down Expand Up @@ -578,6 +581,7 @@
files = (
361C61EA2BD6B7F200EF0D8B /* Font.swift in Sources */,
368C5D9B2BCC41990035A1AC /* TotalActivityView.swift in Sources */,
36EB6EC02BDCC65600E8C939 /* AppActivityView.swift in Sources */,
368C5D972BCC41990035A1AC /* HMHDeviceActivityReport.swift in Sources */,
368C5D992BCC41990035A1AC /* TotalActivityReport.swift in Sources */,
);
Expand Down
23 changes: 13 additions & 10 deletions HMH_iOS/HMH_iOS/Presentation/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@
// Created by 이지희 on 4/11/24.
//

import Foundation
import SwiftUI

import FamilyControls
import DeviceActivity
import Combine
import _DeviceActivity_SwiftUI

class HomeViewModel: ObservableObject {
@Published var totalGoalTime: TimeInterval
@Published var currentTotalUsage: TimeInterval
@Published var appsUsage: [AppUsage] = []

init(totalGoalTime: TimeInterval = 3600, currentTotalUsage: TimeInterval = 0, appsUsage: [AppUsage] = []) {
self.totalGoalTime = totalGoalTime
self.currentTotalUsage = currentTotalUsage
self.appsUsage = appsUsage
}

func remainingTimeForApp(appId: String) -> TimeInterval {
if let appUsage = appsUsage.first(where: { $0.appId == appId }) {
return max(appUsage.goalTime - appUsage.usedTime, 0)
}
return 0
}

func updateUsage(forApp appId: String, time: TimeInterval) {
if let index = appsUsage.firstIndex(where: { $0.appId == appId }) {
appsUsage[index].usedTime += time
Expand All @@ -35,12 +38,12 @@ class HomeViewModel: ObservableObject {
}

func generateDummyData() {
appsUsage = [
AppUsage(appId: "1", appName: "Instagram", goalTime: 60, usedTime: 45),
AppUsage(appId: "2", appName: "YouTube", goalTime: 45, usedTime: 30),
AppUsage(appId: "3", appName: "Twitter", goalTime: 30, usedTime: 15)
]
}
appsUsage = [
AppUsage(appId: "1", appName: "Instagram", goalTime: 60, usedTime: 45),
AppUsage(appId: "2", appName: "YouTube", goalTime: 45, usedTime: 30),
AppUsage(appId: "3", appName: "Twitter", goalTime: 30, usedTime: 15)
]
}
}

struct AppUsage: Identifiable {
Expand Down

0 comments on commit fd467e6

Please sign in to comment.