Skip to content

Commit

Permalink
Merge pull request #124 from Team-HMH/feat/#123/demo
Browse files Browse the repository at this point in the history
Feat [#123] 데모데이용 앱
  • Loading branch information
Zoe0929 authored Jan 19, 2024
2 parents 4c8f888 + 4d2eb98 commit 5ccb593
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,3 @@ struct App: Codable {
case goalTime, usageTime
}
}
//
//var getDummyResponseDTO: [GetDummyResponseDTO] = [
// .init(apps: [App(appName: "Netflix",
// appImageURL: "https://github.com/Team-HMH/HMH-Server/assets/69035864/dd068b83-641a-4bff-b4f5-381ea6e04d44",
// goalTime: 2400000,
// usageTime: 1320000)]),
//
// .init(apps: [App(appName: "Instagram",
// appImageURL: "https://github.com/Team-HMH/HMH-Server/assets/69035864/bd572377-9dd9-47e7-a9f4-9efbbe66cd2e",
// goalTime: 5400000,
// usageTime: 2880000)]),
//
// .init(apps: [App(appName: "YouTube",
// appImageURL: "https://github.com/Team-HMH/HMH-Server/assets/69035864/8afa60c0-bf1d-4ff0-9b50-4d1558a71f0a",
// goalTime: 3300000,
// usageTime: 900000)]),
//]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class AppListCollectionViewCell: UICollectionViewCell {
}
}

private let appImageView = UIImageView().then {
var appImageView = UIImageView().then {
$0.backgroundColor = .blue
$0.makeCornerRound(radius: 8.adjusted)
}
Expand Down Expand Up @@ -92,9 +92,8 @@ final class AppListCollectionViewCell: UICollectionViewCell {
contentView.makeCornerRound(radius: 6.adjusted)
}

func configureCell(appName: String, appIconImage: UIImage = UIImage(), appTime: String){
func configureCell(appName: String, appTime: String){
self.appNameLabel.text = appName
self.appImageView.image = appIconImage
self.timeLabel.text = appTime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ final class ChallengeManager {
static let shared = ChallengeManager()
private init() {
self.type = .completed
loadChallenge()
}
var type: ChallengeType

func updateType(_ type: ChallengeType) {
self.type = type
}

func loadChallenge() {
let provider = Providers.challengeProvider
provider.request(target: .getChallenge, instance: BaseResponse<GetChallengeResponseDTO>.self) { result in
if let data = result.data {
if data.todayIndex == -1 {
self.type = .completed
} else if data.period == 7 {
self.type = .sevenDays
} else if data.period == 14 {
self.type = .fourteenDays
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ final class ChallengeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
loadChallenge()
loadDummyData()
challengeView.configreCollectionView()
setUI()
setDelegate()
Expand Down Expand Up @@ -113,7 +114,6 @@ final class ChallengeViewController: UIViewController {

self.challengeView.days = data.period
self.challengeView.goalTimeHour = data.goalTime
self.challengeView.appList = data.apps
self.challengeView.dailyStatus = data.statuses
if data.todayIndex == -1 {
self.challengeView.challengeType = .completed
Expand All @@ -125,8 +125,15 @@ final class ChallengeViewController: UIViewController {
}
self.challengeView.challengeCollectionView.reloadData()
}


}

func loadDummyData() {
let provider = Providers.challengeProvider
provider.request(target: .getDummyData, instance: BaseResponse<GetDummyResponseDTO>.self) { result in
if let data = result.data {
self.challengeView.appList = data.apps
}
}
}
}

Expand Down
16 changes: 11 additions & 5 deletions HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ final class ChallengeView: UIView {

var goalTimeHour: Int = 3
var days: Int = 0
var appList: [Apps] = []
var appList: [App] = [] {
didSet {
challengeCollectionView.reloadData()
}
}
var dailyStatus: [String] = []
var todayIndex = 0
var isCompleted = false
Expand Down Expand Up @@ -127,7 +131,7 @@ extension ChallengeView: UICollectionViewDataSource {
if ChallengeManager.shared.type == .completed { return 0 }
return days
case 1:
return token.count
return appList.count
default:
return 0
}
Expand Down Expand Up @@ -173,10 +177,12 @@ extension ChallengeView: UICollectionViewDataSource {
} else {
cell.isSelectedCell = false
}
let appGoalHour = convertMillisecondsToHoursAndMinutes(milliseconds: appList[indexPath.item].goalTime).hours
let appGoalMin = convertMillisecondsToHoursAndMinutes(milliseconds: appList[indexPath.item].goalTime).minutes
let appGoalHour = convertMillisecondsToHoursAndMinutes(milliseconds: appList[indexPath.item].usageTime).hours
let appGoalMin = convertMillisecondsToHoursAndMinutes(milliseconds: appList[indexPath.item].usageTime).minutes
let appTimeString = appGoalHour<=0 ? "\(appGoalMin)" : "\(appGoalHour)시간 \(appGoalMin)"
cell.configureCell(appName: "인스타그램", appTime: appTimeString)
print(appTimeString)
cell.configureCell(appName: appList[indexPath.item].appName, appTime: appTimeString)
cell.appImageView.kfSetImage(url: appList[indexPath.item].appImageURL)
return cell
default:
return UICollectionViewCell()
Expand Down

0 comments on commit 5ccb593

Please sign in to comment.