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

[Refactor] #237 - DetailClip, EditClip MVVM 리팩토링 #238

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions TOASTER-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
3FEA674D2CB51BFC00675805 /* PatchChangeCategoryResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FEA674C2CB51BFC00675805 /* PatchChangeCategoryResponseDTO.swift */; };
3FEA674E2CB51E6D00675805 /* PatchChangeCategoryRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FEA674A2CB51BBC00675805 /* PatchChangeCategoryRequestDTO.swift */; };
3FEA67502CB6522F00675805 /* ChangeClipBottomSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FEA674F2CB6522F00675805 /* ChangeClipBottomSheetView.swift */; };
3FEA67522CB663B100675805 /* ChangeClipViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FEA67512CB663B100675805 /* ChangeClipViewModel.swift */; };
3FEA67532CB677A400675805 /* PatchChangeCategoryResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FEA674C2CB51BFC00675805 /* PatchChangeCategoryResponseDTO.swift */; };
3FF02B302CAFE6600074332E /* ViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8334CF9F2CA6E2D200319922 /* ViewModelType.swift */; };
3FF2BF092BA17492001D7DC1 /* ToasterShareExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 3FF2BEFF2BA17492001D7DC1 /* ToasterShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -447,7 +446,6 @@
3FEA674A2CB51BBC00675805 /* PatchChangeCategoryRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchChangeCategoryRequestDTO.swift; sourceTree = "<group>"; };
3FEA674C2CB51BFC00675805 /* PatchChangeCategoryResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchChangeCategoryResponseDTO.swift; sourceTree = "<group>"; };
3FEA674F2CB6522F00675805 /* ChangeClipBottomSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeClipBottomSheetView.swift; sourceTree = "<group>"; };
3FEA67512CB663B100675805 /* ChangeClipViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeClipViewModel.swift; sourceTree = "<group>"; };
3FF2BEFF2BA17492001D7DC1 /* ToasterShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ToasterShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
3FF2BF062BA17492001D7DC1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6B0E85D82B564913001BC15F /* RemindTimerAddViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemindTimerAddViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -831,7 +829,6 @@
children = (
39A843C92B74512B007A4D75 /* DetailClipViewModel.swift */,
39A843CD2B745B3A007A4D75 /* DetailClipPropertyType.swift */,
3FEA67512CB663B100675805 /* ChangeClipViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -2191,7 +2188,6 @@
83D80DCC2CC1059000DD5410 /* RecentLinkModel.swift in Sources */,
3F82C3212CADA19300492EEE /* Publisher+UIButton.swift in Sources */,
6B6AE6AC2B3FF6F7000E2366 /* UIColor+.swift in Sources */,
3FEA67522CB663B100675805 /* ChangeClipViewModel.swift in Sources */,
6BC493682B45D7B100544249 /* ToasterNavigationController.swift in Sources */,
6BE6DA492B50ADC2008B06FA /* NetworkService.swift in Sources */,
6B6AE69C2B3FF5CC000E2366 /* HomeViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,22 @@ import UIKit
import SnapKit
import Then

protocol DetailClipSegmentedDelegate: AnyObject {
func setupAllLink()
func setupReadLink()
func setupNotReadLink()
}

final class DetailClipSegmentedControlView: UIView {

// MARK: - Properties

var detailClipSegmentedDelegate: DetailClipSegmentedDelegate?

// MARK: - UI Components

private let readSegmentedControl = UISegmentedControl()
lazy var readSegmentedControlValueChanged = readSegmentedControl
.publisher(for: .valueChanged)
.map { _ in self.readSegmentedControl.selectedSegmentIndex }

// MARK: - Life Cycles

override init(frame: CGRect) {
super.init(frame: frame)

setupStyle()
setupHierarchy()
setupLayout()
setupAddTarget()
}

@available(*, unavailable)
Expand Down Expand Up @@ -76,20 +67,4 @@ private extension DetailClipSegmentedControlView {
$0.leading.trailing.equalToSuperview().inset(20)
}
}

func setupAddTarget() {
readSegmentedControl.addTarget(self, action: #selector(didChangeValue(_:)), for: .valueChanged)
}

@objc
func didChangeValue(_ segment: UISegmentedControl) {
switch segment.selectedSegmentIndex {
case 0:
detailClipSegmentedDelegate?.setupAllLink()
case 1:
detailClipSegmentedDelegate?.setupReadLink()
default:
detailClipSegmentedDelegate?.setupNotReadLink()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,16 @@ import UIKit
import SnapKit
import Then

protocol EditLinkBottomSheetViewDelegate: AnyObject {
func dismissButtonTapped(title: String)
func addHeightBottom()
func minusHeightBottom()
func callCheckAPI(filter: DetailCategoryFilter)
}

final class EditLinkBottomSheetView: UIView {

// MARK: - Properties

weak var editLinkBottomSheetViewDelegate: EditLinkBottomSheetViewDelegate?
private var confirmBottomSheetViewButtonAction: (() -> Void)?

private var isButtonClicked: Bool = false {
didSet {
setupButtonColor()
}
}

private var isBorderColor: Bool = false {
didSet {
setupTextFieldBorder()
}
}

private var isError: Bool = false {
didSet {
setupErrorMessage()
}
}

private var isClearButtonShow: Bool = true {
didSet {
setupClearButton()
Expand All @@ -50,11 +28,13 @@ final class EditLinkBottomSheetView: UIView {

// MARK: - UI Components

let editClipTitleTextField = UITextField()
private(set) var editClipTitleTextField = UITextField()
private let editClipButton = UIButton()
private let errorMessage = UILabel()
private let clearButton = UIButton()

lazy var editClipButtonTap = editClipButton.publisher(for: .touchUpInside)

// MARK: - Life Cycles

override init(frame: CGRect) {
Expand Down Expand Up @@ -82,13 +62,11 @@ extension EditLinkBottomSheetView {
func resetTextField() {
editClipTitleTextField.text = nil
editClipTitleTextField.becomeFirstResponder()
isButtonClicked = true
isButtonClicked = false
}

func changeTextField(addButton: Bool, border: Bool, error: Bool, clearButton: Bool) {
func changeTextField(addButton: Bool, clearButton: Bool) {
isButtonClicked = addButton
isBorderColor = border
isError = error
isClearButtonShow = clearButton
}

Expand All @@ -100,10 +78,6 @@ extension EditLinkBottomSheetView {
editClipTitleTextField.text = message
editClipTitleTextField.placeholder = message
}

func setupConfirmBottomSheetButtonAction(_ action: (() -> Void)?) {
confirmBottomSheetViewButtonAction = action
}
}

// MARK: - Private Extensions
Expand All @@ -113,9 +87,13 @@ private extension EditLinkBottomSheetView {
backgroundColor = .toasterWhite

editClipTitleTextField.do {
$0.attributedPlaceholder = NSAttributedString(string: StringLiterals.Placeholder.addClip,
attributes: [.foregroundColor: UIColor.gray400,
.font: UIFont.suitRegular(size: 16)])
$0.attributedPlaceholder = NSAttributedString(
string: StringLiterals.Placeholder.addClip,
attributes: [
.foregroundColor: UIColor.gray400,
.font: UIFont.suitRegular(size: 16)
]
)
$0.addPadding(left: 14, right: 44)
$0.backgroundColor = .gray50
$0.textColor = .black900
Expand All @@ -130,7 +108,6 @@ private extension EditLinkBottomSheetView {
$0.setTitle(StringLiterals.Button.okay, for: .normal)
$0.setTitleColor(.toasterWhite, for: .normal)
$0.titleLabel?.font = .suitBold(size: 16)
$0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

errorMessage.do {
Expand Down Expand Up @@ -192,26 +169,6 @@ private extension EditLinkBottomSheetView {
}
}

func setupTextFieldBorder() {
if isBorderColor {
editClipTitleTextField.layer.borderColor = UIColor.toasterError.cgColor
editClipTitleTextField.layer.borderWidth = 1.0
} else {
editClipTitleTextField.layer.borderColor = UIColor.clear.cgColor
editClipTitleTextField.layer.borderWidth = 0.0
}
}

func setupErrorMessage() {
if isError {
editLinkBottomSheetViewDelegate?.addHeightBottom()
errorMessage.isHidden = false
} else {
editLinkBottomSheetViewDelegate?.minusHeightBottom()
errorMessage.isHidden = true
}
}

func setupClearButton() {
if isClearButtonShow {
clearButton.isHidden = false
Expand All @@ -220,12 +177,6 @@ private extension EditLinkBottomSheetView {
}
}

@objc
func buttonTapped() {
confirmBottomSheetViewButtonAction?()
editLinkBottomSheetViewDelegate?.dismissButtonTapped(title: editClipTitleTextField.text ?? "")
}

@objc
func clearButtonTapped() {
resetTextField()
Expand All @@ -238,9 +189,9 @@ extension EditLinkBottomSheetView: UITextFieldDelegate {
func textFieldDidChangeSelection(_ textField: UITextField) {
let currentText = textField.text ?? ""
if currentText.isEmpty {
changeTextField(addButton: false, border: false, error: false, clearButton: false)
changeTextField(addButton: false, clearButton: false)
} else {
changeTextField(addButton: true, border: false, error: false, clearButton: true)
changeTextField(addButton: true, clearButton: true)
}
}
}
Loading