Skip to content

Commit

Permalink
[Feat/#99] HomeView - getDummyDataDTO 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
boyeon0119 committed Jan 19, 2024
1 parent 265c637 commit 5519dcf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 48 deletions.
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 @@ -89,6 +89,7 @@
17CFA0042B545B60000DD09C /* TimeCalculate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17CFA0032B545B60000DD09C /* TimeCalculate.swift */; };
17CFA00A2B58687F000DD09C /* GetHomeChallengeResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17CFA0092B58687F000DD09C /* GetHomeChallengeResponseDTO.swift */; };
17E518CA2B5964C300F7B294 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 17E518C92B5964C300F7B294 /* Kingfisher */; };
17E518CC2B597F2400F7B294 /* GetDummyResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17E518CB2B597F2400F7B294 /* GetDummyResponseDTO.swift */; };
360D11022B5343C6008BE85A /* requestPermision.swift in Sources */ = {isa = PBXBuildFile; fileRef = 360D11012B5343C6008BE85A /* requestPermision.swift */; };
360D11082B536746008BE85A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 360D11072B536746008BE85A /* Assets.xcassets */; };
360D110E2B541DB4008BE85A /* UserDefault+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 360D110D2B541DB4008BE85A /* UserDefault+.swift */; };
Expand Down Expand Up @@ -330,6 +331,7 @@
17CFA0012B541F9C000DD09C /* HomeViewTotalDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewTotalDataModel.swift; sourceTree = "<group>"; };
17CFA0032B545B60000DD09C /* TimeCalculate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeCalculate.swift; sourceTree = "<group>"; };
17CFA0092B58687F000DD09C /* GetHomeChallengeResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetHomeChallengeResponseDTO.swift; sourceTree = "<group>"; };
17E518CB2B597F2400F7B294 /* GetDummyResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetDummyResponseDTO.swift; sourceTree = "<group>"; };
360D11012B5343C6008BE85A /* requestPermision.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = requestPermision.swift; sourceTree = "<group>"; };
360D11072B536746008BE85A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
360D110D2B541DB4008BE85A /* UserDefault+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefault+.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1065,6 +1067,7 @@
36F298472B55974200C1C903 /* HomeChallengeResponseDTO.swift */,
36F298492B55977900C1C903 /* AddAppResponseDTO.swift */,
36F2984D2B5599F500C1C903 /* EmptyResponseDTO.swift */,
17E518CB2B597F2400F7B294 /* GetDummyResponseDTO.swift */,
);
path = ChallengeModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -1508,6 +1511,7 @@
0B7817502B4BD9F10078E925 /* OnboardingButton.swift in Sources */,
36F2983E2B55766300C1C903 /* OnboardingGoalTimeViewController.swift in Sources */,
364923792B4FC8E800BF7ACA /* BaseModel.swift in Sources */,
17E518CC2B597F2400F7B294 /* GetDummyResponseDTO.swift in Sources */,
364923722B4F527200BF7ACA /* NetworkResult.swift in Sources */,
0B50F9CD2B369813000C5046 /* SceneDelegate.swift in Sources */,
36A3D9B42B3EBBED007EA272 /* UIStackView+.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import Then
final class AppUsingProgressViewCell: UICollectionViewCell {

static let identifier = "AppUsingProgressViewCell"
let provider = Providers.challengeProvider
var app: [App] = []

private let appStackView = UIStackView().then {
$0.axis = .horizontal
$0.spacing = 9
$0.alignment = .center
}

private let appIconImageView = UIImageView().then {
$0.backgroundColor = .whiteBtn
$0.makeCornerRound(radius: 6.adjusted)
}
private let appLabelStackView = UIStackView().then {
Expand Down Expand Up @@ -107,48 +109,17 @@ final class AppUsingProgressViewCell: UICollectionViewCell {
}
}

func bindData(data: AppUsingTimeModel) {
self.appGoalTimeLabel.text = "\(HourOrMinuteConvert(data: data))시간"
self.appRemainedTimeLabel.text = "\(finalTimeConvert(data: data))"
self.appNameLabel.text = data.usingAppName
self.appIconImageView.image = data.usingAppIcon
updateProgressBar(data: data)
HourOrMinuteConvert(data: data)
finalTimeConvert(data: data)

appProgressBar.setProgress(0, animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
let progress = Float(data.usedTime) / Float(data.appGoalTime)
self.appProgressBar.setProgress(progress, animated: true)
}
}

func updateProgressBar(data: AppUsingTimeModel) {
if data.appGoalTime != 0 {
let progress = Float(data.usedTime) / Float(data.appGoalTime)
appProgressBar.progress = progress
} else {
appProgressBar.progress = 0.0
}

if data.usedTime >= data.appGoalTime {
appProgressBar.progress = 1
}
}

func HourOrMinuteConvert(data: AppUsingTimeModel) {
let convertedGoalTime = convertMillisecondsToHoursAndMinutes(milliseconds: data.appGoalTime)
func bindData(data: App) {
let convertedGoalTime = convertMillisecondsToHoursAndMinutes(milliseconds: data.goalTime)
if convertedGoalTime.hours == 0 {
self.appGoalTimeLabel.text = "\(convertedGoalTime.minutes)"
} else if convertedGoalTime.minutes == 0 {
self.appGoalTimeLabel.text = "\(convertedGoalTime.hours)시간"
} else {
self.appGoalTimeLabel.text = "\(convertedGoalTime.hours)시간 \(convertedGoalTime.minutes)"
}
}

func finalTimeConvert(data: AppUsingTimeModel) {
let appRemainedTime = max(0, Int(data.appGoalTime) - Int(data.usedTime))

let appRemainedTime = max(0, Int(data.goalTime) - Int(data.usageTime))
let convertedTime = convertMillisecondsToHoursAndMinutes(milliseconds: appRemainedTime)

if convertedTime.hours == 0 {
Expand All @@ -159,8 +130,29 @@ final class AppUsingProgressViewCell: UICollectionViewCell {
appRemainedTimeLabel.text = "\(convertedTime.hours)시간 \(convertedTime.minutes)"
}

if data.usedTime >= data.appGoalTime {
if data.usageTime >= data.goalTime {
appRemainedTimeLabel.text = "0분"
}

self.appNameLabel.text = data.appName
self.appIconImageView.kfSetImage(url: data.appImageURL)
appProgressBar.setProgress(0, animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
let progress = Float(data.usageTime) / Float(data.goalTime)
self.appProgressBar.setProgress(progress, animated: true)
}
}

func updateProgressBar(data: AppUsingTimeModel) {
if data.appGoalTime != 0 {
let progress = Float(data.usedTime) / Float(data.appGoalTime)
appProgressBar.progress = progress
} else {
appProgressBar.progress = 0.0
}

if data.usedTime >= data.appGoalTime {
appProgressBar.progress = 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ final class HomeViewController: UIViewController {

private let homeView = HMHHomeView()
let provider = Providers.challengeProvider
var app: [App] = [] {
didSet{
homeView.homeCollectionView.reloadData()
}
}

var totalAppUsingTimeData: TotalAppUsingTimeDataModel = .init(
onboardingTotalGoalTime: 7200000,
totalAppRemainedTime: Float(TotalAppUsingTimeDataModel.calculateTotalUsageTime(data: appUsingTimeModel)),
onboardingTotalGoalTime: 0,
totalAppRemainedTime: 0,
isFailed: false) {
didSet {
homeView.homeCollectionView.reloadSections([1, 0])
Expand All @@ -25,18 +30,18 @@ final class HomeViewController: UIViewController {
super.viewWillAppear(animated)
requestPermision()
LoadTodayChallenge()
getDummyDataAPI()
}

override func viewDidLoad() {
super.viewDidLoad()
setUI()
configreCollectionView()

// // 영상 로딩을 위한 애니메이션 코드
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
// self.totalAppUsingTimeData.progressValue += 0.01
self.totalAppUsingTimeData.isFailed = true
}
//// // 영상 로딩을 위한 애니메이션 코드
// DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
//// self.totalAppUsingTimeData.progressValue += 0.01
// self.totalAppUsingTimeData.isFailed = true
// }
}


Expand Down Expand Up @@ -80,7 +85,7 @@ extension HomeViewController: UICollectionViewDataSource {
case 1:
return 1
case 2:
return appUsingTimeModel.count
return app.count
default:
return 1
}
Expand All @@ -91,7 +96,7 @@ extension HomeViewController: UICollectionViewDataSource {
guard let myGoalTimeCell = homeView.homeCollectionView.dequeueReusableCell(withReuseIdentifier: MyGoalTimeCell.identifier, for: indexPath) as? MyGoalTimeCell else { return UICollectionViewCell() }
guard let appUsingProgressViewCell = homeView.homeCollectionView.dequeueReusableCell(withReuseIdentifier: AppUsingProgressViewCell.identifier, for: indexPath) as? AppUsingProgressViewCell else { return UICollectionViewCell() }

myGoalTimeCell.bindData(data: totalAppUsingTimeData)
// myGoalTimeCell.bindData(data: App)

switch indexPath.section {
case 0:
Expand Down Expand Up @@ -132,14 +137,26 @@ extension HomeViewController: UICollectionViewDataSource {
return blackholeImageCell

case 1:
myGoalTimeCell.LoadTodayChallenge()
return myGoalTimeCell

case 2:
appUsingProgressViewCell.bindData(data: appUsingTimeModel[indexPath.row])
appUsingProgressViewCell.bindData(data: app[indexPath.item])
return appUsingProgressViewCell

default:
return UICollectionViewCell()
}
}
}

extension HomeViewController {
func getDummyDataAPI() {
provider.request(target: .getDummyData,
instance: BaseResponse<GetDummyResponseDTO>.self,
viewController: HomeViewController()) { data in
guard let data = data.data else { return }
self.app = data.apps
}
}
}

0 comments on commit 5519dcf

Please sign in to comment.