Skip to content
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
12 changes: 12 additions & 0 deletions iBox/Sources/BoxList/BoxListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ protocol BoxListViewDelegate: AnyObject {
func pushViewController(type: EditType)
func pushViewController(url: URL?)
func presentEditBookmarkController(at indexPath: IndexPath)
func deleteFolderinBoxList(at section: Int)
func editFolderNameinBoxList(at section: Int, currentName: String)
}

class BoxListView: UIView {
Expand Down Expand Up @@ -187,6 +189,16 @@ extension BoxListView: UITableViewDelegate {

button.addTarget(self, action: #selector(handleOpenClose), for: .touchUpInside)

let edit = UIAction(title: "ํด๋” ํŽธ์ง‘", image: UIImage(systemName: "pencil")) { [weak self] _ in
guard let folderName = self?.viewModel?.boxList[section].name else { return }
self?.delegate?.editFolderNameinBoxList(at: section, currentName: folderName)
}
let delete = UIAction(title: "ํด๋” ์‚ญ์ œ", image: UIImage(systemName: "trash"), attributes: .destructive) { [weak self] _ in
self?.delegate?.deleteFolderinBoxList(at: section)
}

button.menu = UIMenu(options: .displayInline, children: [edit, delete])

return button
}

Expand Down
46 changes: 46 additions & 0 deletions iBox/Sources/BoxList/BoxListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,52 @@ extension BoxListViewController: AddBookmarkViewControllerProtocol {
}

extension BoxListViewController: BoxListViewDelegate {
func deleteFolderinBoxList(at section: Int) {
recheckDeleteFolder(at: section)
}

private func recheckDeleteFolder(at section: Int) {
let actionSheetController = UIAlertController(title: nil, message: "๋ชจ๋“  ๋ถ๋งˆํฌ๊ฐ€ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.", preferredStyle: .actionSheet)
let firstAction = UIAlertAction(title: "ํด๋” ์‚ญ์ œ", style: .destructive) {[weak self] _ in
guard let contentView = self?.contentView as? BoxListView else { return }
contentView.viewModel?.deleteFolderDirect(section)
}
let cancelAction = UIAlertAction(title: "์ทจ์†Œ", style: .cancel)
actionSheetController.addAction(firstAction)
actionSheetController.addAction(cancelAction)
present(actionSheetController, animated: true)
}

func editFolderNameinBoxList(at section: Int, currentName: String) {
let controller = UIAlertController(title: "ํด๋” ์ด๋ฆ„ ๋ณ€๊ฒฝ", message: nil, preferredStyle: .alert)

let cancelAction = UIAlertAction(title: "์ทจ์†Œ", style: .default) { _ in return }
let okAction = UIAlertAction(title: "ํ™•์ธ", style: .default) { [weak self] action in
guard let newName = controller.textFields?.first?.text else { return }
guard let contentView = self?.contentView as? BoxListView else { return }
contentView.viewModel?.editFolderDirect(section, name: newName)
}
controller.addAction(cancelAction)
controller.addAction(okAction)
okAction.isEnabled = true

controller.addTextField() { textField in
NotificationCenter.default.addObserver(forName: UITextField.textDidChangeNotification, object: textField, queue: OperationQueue.main, using:
{_ in
let textCount = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines).count ?? 0
let textIsNotEmpty = textCount > 0

okAction.isEnabled = textIsNotEmpty

})
}
controller.textFields?.first?.text = currentName
controller.textFields?.first?.autocorrectionType = .no
controller.textFields?.first?.spellCheckingType = .no

self.present(controller, animated: true)
}

func presentEditBookmarkController(at indexPath: IndexPath) {
guard let contentView = contentView as? BoxListView else { return }

Expand Down
21 changes: 21 additions & 0 deletions iBox/Sources/BoxList/BoxListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,25 @@ class BoxListViewModel {
output.send(.sendBoxList(boxList: boxList))
}

func deleteFolderDirect(_ section: Int) {
let folderId = boxList[section].id
CoreDataManager.shared.deleteFolder(id: folderId)
boxList.remove(at: section)
for box in boxList {
sectionsToReload.update(with: box.id)
}
output.send(.sendBoxList(boxList: boxList))
output.send(.reloadSections(idArray: Array(sectionsToReload)))
sectionsToReload.removeAll()
}

func editFolderDirect(_ section: Int, name: String) {
let folderId = boxList[section].id
CoreDataManager.shared.updateFolder(id: folderId, name: name)
boxList[section].name = name
sectionsToReload.update(with: boxList[section].id)
output.send(.reloadSections(idArray: Array(sectionsToReload)))
sectionsToReload.removeAll()
}

}
3 changes: 3 additions & 0 deletions iBox/Sources/BoxList/FolderButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class FolderButton: UIButton {
private func setupProperty() {
backgroundColor = .tableViewBackgroundColor
openCloseImageView.image = UIImage(systemName: "chevron.right")
if isOpen {
openCloseImageView.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2)
}
}

private func setupHierarchy() {
Expand Down