Skip to content

Commit

Permalink
Merge pull request #627 from hyun99999/feature/#626
Browse files Browse the repository at this point in the history
[Refactor] #626 - DispatchQueue 무분별한 사용 정리
  • Loading branch information
hyun99999 authored May 18, 2022
2 parents 64a13b6 + 7660196 commit 4bfdb67
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,9 @@ extension AuthUploadVC {
// 업로드
@objc
func touchUploadButton() {
DispatchQueue.main.async {
self.setLoading()
}

DispatchQueue.main.async {
self.authUploadWithAPI()
self.uploadTracking()
}
setLoading()
authUploadWithAPI()
uploadTracking()
}

// MARK: - Screen Change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,17 @@ extension HabitRoomVC {

@objc
private func updateHabitRoom() {
DispatchQueue.main.async {
// 로딩
self.setLoading()
}
DispatchQueue.main.async {
self.fetchHabitRoomDetailWithAPI(roomID: self.roomID ?? 0) {
self.mainCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
self.setHabitRoomGuide()
}
setLoading()
fetchHabitRoomDetailWithAPI(roomID: self.roomID ?? 0) {
self.mainCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
self.setHabitRoomGuide()
}
}

@objc
private func updateWithRefreshControl() {
DispatchQueue.main.async {
self.fetchHabitRoomDetailWithAPI(roomID: self.roomID ?? 0) {
self.refreshControl.endRefreshing()
}
fetchHabitRoomDetailWithAPI(roomID: self.roomID ?? 0) {
self.refreshControl.endRefreshing()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class StorageMoreVC: UIViewController {
setLayout()

DispatchQueue.main.async { [self] in
if self.isChangingImageView {
self.getMyRoomCertiChangeWithAPI(lastID: myRoomCertificationLastID, size: myRoomCountSize) { [self] in
if isChangingImageView {
getMyRoomCertiChangeWithAPI(lastID: myRoomCertificationLastID, size: myRoomCountSize) { [self] in
storageMoreCV.reloadData()
}
} else {
self.getMyRoomCertiWithAPI(lastID: myRoomCertificationLastID, size: myRoomCountSize) { [self] in
getMyRoomCertiWithAPI(lastID: myRoomCertificationLastID, size: myRoomCountSize) { [self] in
storageMoreCV.reloadData()
}
}
Expand Down
92 changes: 44 additions & 48 deletions Spark-iOS/Spark-iOS/Source/ViewControllers/TabBar/FeedVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,38 @@ class FeedVC: UIViewController {
setNotification()
initRefreshControl()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

setTabBar()
setFloatingButton()

navigationController?.isNavigationBarHidden = true

setLoading()

DispatchQueue.main.async {
self.getFeedListFetchWithAPI(lastID: self.feedInitID) {
self.feeds = self.newFeeds
if self.feeds.count >= self.feedCountSize {
self.isFirstScroll = false
}

self.dateList.removeAll()
self.dayList.removeAll()

self.firstList.removeAll()
self.secondList.removeAll()
self.thirdList.removeAll()
self.fourthList.removeAll()
self.fifthList.removeAll()
self.sixthList.removeAll()
self.seventhList.removeAll()

self.setData(datalist: self.newFeeds)
if !self.feeds.isEmpty {
self.collectionView.reloadData()
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .bottom, animated: false)
}
getFeedListFetchWithAPI(lastID: self.feedInitID) {
self.feeds = self.newFeeds
if self.feeds.count >= self.feedCountSize {
self.isFirstScroll = false
}

self.dateList.removeAll()
self.dayList.removeAll()

self.firstList.removeAll()
self.secondList.removeAll()
self.thirdList.removeAll()
self.fourthList.removeAll()
self.fifthList.removeAll()
self.sixthList.removeAll()
self.seventhList.removeAll()

self.setData(datalist: self.newFeeds)
if !self.feeds.isEmpty {
self.collectionView.reloadData()
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .bottom, animated: false)
}
}
}
Expand Down Expand Up @@ -237,30 +235,28 @@ class FeedVC: UIViewController {

@objc
private func refreshCollectionView() {
DispatchQueue.main.async {
self.getFeedListFetchWithAPI(lastID: self.feedInitID) {
self.feeds = self.newFeeds
if self.feeds.count >= self.feedCountSize {
self.isFirstScroll = false
}

self.dateList.removeAll()
self.dayList.removeAll()

self.firstList.removeAll()
self.secondList.removeAll()
self.thirdList.removeAll()
self.fourthList.removeAll()
self.fifthList.removeAll()
self.sixthList.removeAll()
self.seventhList.removeAll()

self.setData(datalist: self.newFeeds)
if !self.feeds.isEmpty {
self.collectionView.reloadData()
}
self.refreshControl.endRefreshing()
getFeedListFetchWithAPI(lastID: self.feedInitID) {
self.feeds = self.newFeeds
if self.feeds.count >= self.feedCountSize {
self.isFirstScroll = false
}

self.dateList.removeAll()
self.dayList.removeAll()

self.firstList.removeAll()
self.secondList.removeAll()
self.thirdList.removeAll()
self.fourthList.removeAll()
self.fifthList.removeAll()
self.sixthList.removeAll()
self.seventhList.removeAll()

self.setData(datalist: self.newFeeds)
if !self.feeds.isEmpty {
self.collectionView.reloadData()
}
self.refreshControl.endRefreshing()
}
}

Expand Down
111 changes: 52 additions & 59 deletions Spark-iOS/Spark-iOS/Source/ViewControllers/TabBar/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,22 @@ class HomeVC: UIViewController {
setFloatingButton()
setLoading()

DispatchQueue.main.async {
self.newNoticeFetchWithAPI {
self.habitRoomFetchWithAPI(lastID: self.habitRoomInitID) {
self.habitRooms = self.newHabitRooms
self.mainCollectionView.reloadData()

if self.habitRooms.count != 0 {
self.updateHiddenCollectionView()
self.mainCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .bottom, animated: false)
} else {
self.setEmptyView()
}

if self.isNewNotice {
self.customNavigationBar.buttonsImage("icProfile", "icNoticeNew")
} else {
self.customNavigationBar.buttonsImage("icProfile", "icNotice")
}
self.newNoticeFetchWithAPI {
self.habitRoomFetchWithAPI(lastID: self.habitRoomInitID) {
self.habitRooms = self.newHabitRooms
self.mainCollectionView.reloadData()

if self.habitRooms.count != 0 {
self.updateHiddenCollectionView()
self.mainCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .bottom, animated: false)
} else {
self.setEmptyView()
}

if self.isNewNotice {
self.customNavigationBar.buttonsImage("icProfile", "icNoticeNew")
} else {
self.customNavigationBar.buttonsImage("icProfile", "icNotice")
}
}
}
Expand Down Expand Up @@ -245,7 +243,7 @@ extension HomeVC {

navigationController?.pushViewController(nextVC, animated: true)
}

private func pushToNoticeVC() {
guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.notice, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.notice) as? NoticeVC else { return }

Expand All @@ -256,26 +254,24 @@ extension HomeVC {

@objc
private func refreshCollectionView() {
DispatchQueue.main.async {
self.newNoticeFetchWithAPI {
self.habitRoomFetchWithAPI(lastID: self.habitRoomInitID) {
self.habitRooms = self.newHabitRooms
self.mainCollectionView.reloadData()

if self.habitRooms.count != 0 {
self.updateHiddenCollectionView()
} else {
self.setEmptyView()
}

if self.isNewNotice {
self.customNavigationBar.buttonsImage("icProfile", "icNoticeNew")
} else {
self.customNavigationBar.buttonsImage("icProfile", "icNotice")
}

self.refreshControl.endRefreshing()
newNoticeFetchWithAPI {
self.habitRoomFetchWithAPI(lastID: self.habitRoomInitID) {
self.habitRooms = self.newHabitRooms
self.mainCollectionView.reloadData()

if self.habitRooms.count != 0 {
self.updateHiddenCollectionView()
} else {
self.setEmptyView()
}

if self.isNewNotice {
self.customNavigationBar.buttonsImage("icProfile", "icNoticeNew")
} else {
self.customNavigationBar.buttonsImage("icProfile", "icNotice")
}

self.refreshControl.endRefreshing()
}
}
}
Expand All @@ -288,7 +284,7 @@ extension HomeVC {
guard let isHost: Bool = notification.userInfo?["isHost"] as? Bool else { return }

let message: String

if roomName.count > 8 {
let index = roomName.index(roomName.startIndex, offsetBy: 8)
roomName = roomName[..<index] + "..."
Expand All @@ -307,25 +303,22 @@ extension HomeVC {
private func updateHome() {
setNavigationBar()
setLoading()

DispatchQueue.main.async {
self.newNoticeFetchWithAPI {
self.habitRoomFetchWithAPI(lastID: self.habitRoomInitID) {
self.habitRooms = self.newHabitRooms
self.mainCollectionView.reloadData()

if self.habitRooms.count != 0 {
self.updateHiddenCollectionView()
self.mainCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
} else {
self.setEmptyView()
}

if self.isNewNotice {
self.customNavigationBar.buttonsImage("icProfile", "icNoticeNew")
} else {
self.customNavigationBar.buttonsImage("icProfile", "icNotice")
}
newNoticeFetchWithAPI {
self.habitRoomFetchWithAPI(lastID: self.habitRoomInitID) {
self.habitRooms = self.newHabitRooms
self.mainCollectionView.reloadData()

if self.habitRooms.count != 0 {
self.updateHiddenCollectionView()
self.mainCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
} else {
self.setEmptyView()
}

if self.isNewNotice {
self.customNavigationBar.buttonsImage("icProfile", "icNoticeNew")
} else {
self.customNavigationBar.buttonsImage("icProfile", "icNotice")
}
}
}
Expand Down Expand Up @@ -363,7 +356,7 @@ extension HomeVC: UICollectionViewDelegate {
if habitRooms.count != 0 {
if habitRooms[indexPath.item].isStarted == true {
// 습관방

guard let roomStatus = RoomStatus(rawValue: habitRooms[indexPath.item].myStatus ?? "NONE") else { return }
switch roomStatus {
case .none, .rest, .done:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class StorageVC: UIViewController {
failRoomList?.removeAll()

DispatchQueue.main.async { [self] in
self.setLoading()
setLoading()
}

let group = DispatchGroup.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,9 @@ class WaitingVC: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

DispatchQueue.main.async {
self.setLoading()
}

DispatchQueue.main.async {
self.getWaitingRoomWithAPI(roomID: self.roomId ?? 0)
}

setLoading()
getWaitingRoomWithAPI(roomID: self.roomId ?? 0)
setTabBar()
setFloatingButton()
}
Expand Down

0 comments on commit 4bfdb67

Please sign in to comment.