Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiaryEditViewController 구성 / Location 흐름 구축 #176

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Segno/Segno.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
7940FB33292E065F00276EFC /* DiaryDetailUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */; };
79767E64293E2A1200E489DD /* DiaryDeleteEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79767E63293E2A1200E489DD /* DiaryDeleteEndpoint.swift */; };
98003E0E293F20F6009FBC35 /* DarkModeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98003E0D293F20F6009FBC35 /* DarkModeManager.swift */; };
98138D292940B00900D2CEDF /* DeleteTapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98138D282940B00900D2CEDF /* DeleteTapGestureRecognizer.swift */; };
98138D2B2940EA0800D2CEDF /* LocationRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98138D2A2940EA0800D2CEDF /* LocationRepository.swift */; };
98138D4D2940F53F00D2CEDF /* LocationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98138D4C2940F53F00D2CEDF /* LocationUseCase.swift */; };
9825F41B29377875005F2163 /* ChangeNicknameUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41A29377875005F2163 /* ChangeNicknameUseCase.swift */; };
9825F41D29377ACF005F2163 /* SettingsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41C29377ACF005F2163 /* SettingsRepository.swift */; };
982A2A472924AE74006F6ACD /* UserDefaultsKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */; };
Expand Down Expand Up @@ -170,6 +173,9 @@
7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailUseCase.swift; sourceTree = "<group>"; };
79767E63293E2A1200E489DD /* DiaryDeleteEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDeleteEndpoint.swift; sourceTree = "<group>"; };
98003E0D293F20F6009FBC35 /* DarkModeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkModeManager.swift; sourceTree = "<group>"; };
98138D282940B00900D2CEDF /* DeleteTapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteTapGestureRecognizer.swift; sourceTree = "<group>"; };
98138D2A2940EA0800D2CEDF /* LocationRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationRepository.swift; sourceTree = "<group>"; };
98138D4C2940F53F00D2CEDF /* LocationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationUseCase.swift; sourceTree = "<group>"; };
9825F41A29377875005F2163 /* ChangeNicknameUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeNicknameUseCase.swift; sourceTree = "<group>"; };
9825F41C29377ACF005F2163 /* SettingsRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRepository.swift; sourceTree = "<group>"; };
982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsKey.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -333,6 +339,7 @@
988414DA2923606B007C9132 /* DiaryListUseCase.swift */,
7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */,
791529D72932F364005A8DDB /* DiaryEditUseCase.swift */,
98138D4C2940F53F00D2CEDF /* LocationUseCase.swift */,
66A8CF682937945300C17F84 /* UserDetailUseCase.swift */,
9894EAF429373385005F2B15 /* SettingsUseCase.swift */,
4F307A49293889C200FA36A0 /* SearchMusicUseCase.swift */,
Expand Down Expand Up @@ -474,6 +481,7 @@
4FCAC5C1292B5C9000BF9CDD /* LoginSession.swift */,
4F307A4529387C1100FA36A0 /* ShazamSession.swift */,
4F307A472938832900FA36A0 /* MusicSession.swift */,
98138D2A2940EA0800D2CEDF /* LocationRepository.swift */,
);
path = Session;
sourceTree = "<group>";
Expand Down Expand Up @@ -509,6 +517,7 @@
isa = PBXGroup;
children = (
9894EAF729375281005F2B15 /* DarkMode.swift */,
98138D282940B00900D2CEDF /* DeleteTapGestureRecognizer.swift */,
);
path = Utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -602,6 +611,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
98138D292940B00900D2CEDF /* DeleteTapGestureRecognizer.swift in Sources */,
98F5AD2A292DDDEB00E53E25 /* LocationContentView.swift in Sources */,
791529DE29333D40005A8DDB /* ImageEndpoint.swift in Sources */,
4F4E0D3E2924B925005ABA8F /* LoginRepository.swift in Sources */,
Expand All @@ -625,11 +635,13 @@
66A8CF692937945300C17F84 /* UserDetailUseCase.swift in Sources */,
988414AE2922235B007C9132 /* LocalUtilityRepository.swift in Sources */,
66A8CF612935F44100C17F84 /* MyPageViewModel.swift in Sources */,
98138D4D2940F53F00D2CEDF /* LocationUseCase.swift in Sources */,
988414D929235345007C9132 /* DiaryCollectionViewModel.swift in Sources */,
4F589DD6293FB9AB00DB39E5 /* ShazamSongDTO.swift in Sources */,
4FEBFAAF291CF9F300E78139 /* MusicInfo.swift in Sources */,
4FEBFAAB291CF30E00E78139 /* DiaryListItem.swift in Sources */,
7918380829233F7100BC6992 /* UIButton+.swift in Sources */,
98138D2B2940EA0800D2CEDF /* LocationRepository.swift in Sources */,
4F4E0D7B29252526005ABA8F /* TokenDTO.swift in Sources */,
666E6F81291CF49E00CECD4B /* LoginCoordinator.swift in Sources */,
7940FB31292E065100276EFC /* DiaryDetailEndpoint.swift in Sources */,
Expand Down Expand Up @@ -828,6 +840,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Segno/Resource/Info.plist;
INFOPLIST_KEY_NSAppleMusicUsageDescription = "";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "위치 정보를 받아오기 위해 권한이 필요합니다.";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "음악 검색 기능을 위해 마이크 사용 허가가 필요합니다.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
Expand Down Expand Up @@ -859,6 +872,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Segno/Resource/Info.plist;
INFOPLIST_KEY_NSAppleMusicUsageDescription = "";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "위치 정보를 받아오기 위해 권한이 필요합니다.";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "음악 검색 기능을 위해 마이크 사용 허가가 필요합니다.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
Expand Down
4 changes: 2 additions & 2 deletions Segno/Segno/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ final class AppCoordinator: Coordinator {

func start() {
// TODO: login이 안되어있으면 LoginCoordinator 실행
startLoginCoordinator()
// startLoginCoordinator()
// TODO: login이 되어있으면 TabBarCoordinator 실행
// startTabBarCoordinator()
startTabBarCoordinator()
}

func startLoginCoordinator() {
Expand Down
81 changes: 81 additions & 0 deletions Segno/Segno/Data/Session/LocationRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// LocationSession.swift
// Segno
//
// Created by YOONJONG on 2022/12/08.
//

import CoreLocation
import Foundation

import RxSwift

protocol LocationRepository {
var locationSubject: PublishSubject<Location> { get set }
var addressSubject: PublishSubject<String> { get set }
Comment on lines +14 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subject에 대한 고민이 정말.. 사람 미치게 하죠ㅎㅎㅋㅋ 이 주제에 대해서 오늘내일 이야기를 나눠 보고, 이번 주 칼럼에 실어 봅시다.

func getLocation()
func stopLocation()
}

final class LocationRepositoryImpl: NSObject, LocationRepository {
var locationSubject = PublishSubject<Location>()
var addressSubject = PublishSubject<String>()
private var locationManager = CLLocationManager()

override init() {

}

func getLocation() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
DispatchQueue.global().async {
if CLLocationManager.locationServicesEnabled() {
debugPrint("위치 서비스 on")
self.locationManager.startUpdatingLocation()
} else {
print("위치 서비스 off 상태")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 보다가 궁금해진건데, 다른 부분들은 debugPrint() 쓰시다 여기는 print()군요..?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋ.ㅋ 이런,,,,,

}
}
}

func stopLocation() {
DispatchQueue.global().async {
self.locationManager.stopUpdatingLocation()
}
}

func getAddress(location: CLLocation) {
let geocoder = CLGeocoder()
let locale = Locale(identifier: "Ko-kr")
geocoder.reverseGeocodeLocation(location, preferredLocale: locale) { placemarks, error in
guard let placemarks = placemarks,
let address = placemarks.last else { return }
// debugPrint("description : ", address.description)
let fullAddress = address.description.components(separatedBy: ", ")[1]
let array = Array(fullAddress.components(separatedBy: " ").dropFirst())
let refinedAddress = array.joined(separator: " ")
debugPrint("full : ", refinedAddress)

self.addressSubject.onNext(refinedAddress)
}
}
}

extension LocationRepositoryImpl: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
debugPrint("didUpdateLocations")
if let cllocation = locations.first {
print("위도 : \(cllocation.coordinate.latitude)")
print("경도 : \(cllocation.coordinate.longitude)")
let location = Location(latitude: cllocation.coordinate.latitude, longitude: cllocation.coordinate.longitude)
getAddress(location: cllocation)
locationSubject.onNext(location)
}
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
debugPrint("didFailWithError")
}
}
47 changes: 47 additions & 0 deletions Segno/Segno/Domain/UseCase/LocationUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// LocationUseCase.swift
// Segno
//
// Created by YOONJONG on 2022/12/08.
//

import Foundation

import RxSwift

protocol LocationUseCase {
var locationSubject: PublishSubject<Location> { get set }
var addressSubject: PublishSubject<String> { get set }
func getLocation()
func stopLocation()
}

final class LocationUseCaseImpl: LocationUseCase {
var locationSubject = PublishSubject<Location>()
var addressSubject = PublishSubject<String>()
let repository: LocationRepository
private let disposeBag = DisposeBag()

init(repository: LocationRepository = LocationRepositoryImpl()) {
self.repository = repository
subscribeResults()
}

func getLocation() {
repository.getLocation()
}

func stopLocation() {
repository.stopLocation()
}

private func subscribeResults() {
repository.addressSubject
.bind(to: addressSubject)
.disposed(by: disposeBag)

repository.locationSubject
.bind(to: locationSubject)
.disposed(by: disposeBag)
}
}
13 changes: 13 additions & 0 deletions Segno/Segno/Presentation/Utility/DeleteTapGestureRecognizer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DeleteTapGestureRecognizer.swift
// Segno
//
// Created by YOONJONG on 2022/12/07.
//

import UIKit

class DeleteGestureRecognizer: UITapGestureRecognizer {
var title: String?
}

4 changes: 2 additions & 2 deletions Segno/Segno/Presentation/View/TagView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class TagView: UIView {
static let cornerRadius: CGFloat = 15
}

private lazy var tagLabel: UILabel = {
lazy var tagLabel: UILabel = {
let label = UILabel()
label.font = .appFont(.surround, size: Metric.tagFontSize)
label.textColor = .appColor(.white)
Expand All @@ -34,7 +34,7 @@ final class TagView: UIView {

private func setupLayout(tagTitle: String) {
addSubview(tagLabel)
backgroundColor = .appColor(.color3)
backgroundColor = .appColor(.color4)
layer.cornerRadius = Metric.cornerRadius

tagLabel.text = tagTitle
Expand Down
Loading