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
38 changes: 27 additions & 11 deletions iBox/Sources/BoxList/BoxListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,6 @@ extension BoxListView: UITableViewDelegate {
}

private func makeContextMenu(for indexPath: IndexPath) -> UIMenu {
let deleteAction = UIAction(title: "삭제", image: UIImage(systemName: "trash"), attributes: .destructive) { [weak self] action in
self?.viewModel?.input.send(.deleteBookmark(indexPath: indexPath))
if UserDefaultsManager.isHaptics {
let generator = UIImpactFeedbackGenerator(style: .soft)
generator.prepare()
generator.impactOccurred()
}
}

let isFavorite = self.viewModel?.isFavoriteBookmark(at: indexPath) ?? false
let favoriteActionTitle = isFavorite ? "즐겨찾기 해제" : "즐겨찾기로 등록"
let favoriteActionImage = UIImage(systemName: isFavorite ? "heart.slash.fill" : "heart.fill")
Expand All @@ -382,7 +373,9 @@ extension BoxListView: UITableViewDelegate {
generator.impactOccurred()
}
}


favoriteAction.image?.withTintColor(.box2)

let shareAction = UIAction(title: "공유하기", image: UIImage(systemName: "square.and.arrow.up")) { [weak self] action in
guard let self = self, let url = self.viewModel?.boxList[indexPath.section].boxListCellViewModelsWithStatus[indexPath.row].url else { return }

Expand All @@ -397,8 +390,31 @@ extension BoxListView: UITableViewDelegate {
viewController.present(activityViewController, animated: true, completion: nil)
}
}

let editAction = UIAction(title: "북마크 편집", image: UIImage(systemName: "pencil")) { [weak self] action in
guard let self = self else { return }

return UIMenu(title: "", children: [favoriteAction, shareAction, deleteAction])
self.delegate?.presentEditBookmarkController(at: indexPath)

if UserDefaultsManager.isHaptics {
let generator = UIImpactFeedbackGenerator(style: .soft)
generator.prepare()
generator.impactOccurred()
}
}

let deleteAction = UIAction(title: "삭제", image: UIImage(systemName: "trash"), attributes: .destructive) { [weak self] action in
self?.viewModel?.input.send(.deleteBookmark(indexPath: indexPath))
if UserDefaultsManager.isHaptics {
let generator = UIImpactFeedbackGenerator(style: .soft)
generator.prepare()
generator.impactOccurred()
}
}



return UIMenu(title: "", children: [favoriteAction, shareAction, editAction, deleteAction])
}
}

Expand Down
10 changes: 9 additions & 1 deletion iBox/Sources/BoxList/BoxListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,20 @@ extension BoxListViewController: BoxListViewDelegate {
guard let newUrlString = controller.textFields?.last?.text,
let newUrl = URL(string: newUrlString) else { return }
guard let contentView = self?.contentView as? BoxListView else { return }

guard let bookmark = contentView.viewModel?.bookmark(at: indexPath) else { return }

contentView.viewModel?.editBookmark(at: indexPath, name: newName, url: newUrl)

WebCacheManager.shared.removeViewControllerForKey(bookmark.id)
}

controller.addAction(cancelAction)
controller.addAction(okAction)
okAction.isEnabled = true

controller.addTextField() { textField in
textField.clearButtonMode = .whileEditing

NotificationCenter.default.addObserver(forName: UITextField.textDidChangeNotification, object: textField, queue: OperationQueue.main, using:
{_ in
let textCount = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines).count ?? 0
Expand All @@ -169,6 +175,8 @@ extension BoxListViewController: BoxListViewDelegate {
})
}
controller.addTextField() { textField in
textField.clearButtonMode = .whileEditing

NotificationCenter.default.addObserver(forName: UITextField.textDidChangeNotification, object: textField, queue: OperationQueue.main, using:
{_ in
let textCount = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines).count ?? 0
Expand Down
38 changes: 21 additions & 17 deletions iBox/Sources/Shared/WebCacheManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@

import UIKit

class UUIDWrapper: NSObject {
let uuid: UUID

init(uuid: UUID) {
self.uuid = uuid
}

override func isEqual(_ object: Any?) -> Bool {
guard let other = object as? UUIDWrapper else { return false }
return uuid == other.uuid
}

override var hash: Int {
return uuid.hashValue
}
}

class WebCacheManager {

static let shared = WebCacheManager()
Expand All @@ -42,4 +25,25 @@ class WebCacheManager {
return cache.object(forKey: wrapper)
}

func removeViewControllerForKey(_ uuid: UUID) {
let wrapper = UUIDWrapper(uuid: uuid)
cache.removeObject(forKey: wrapper)
}
}

class UUIDWrapper: NSObject {
let uuid: UUID

init(uuid: UUID) {
self.uuid = uuid
}

override func isEqual(_ object: Any?) -> Bool {
guard let other = object as? UUIDWrapper else { return false }
return uuid == other.uuid
}

override var hash: Int {
return uuid.hashValue
}
}