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
1 change: 1 addition & 0 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class iBoxFactory: ProjectFactory {
let dependencies: [TargetDependency] = [
.external(name: "SnapKit"),
.external(name: "SwiftSoup"),
.external(name: "SkeletonView"),
.target(name: "iBoxShareExtension")
]

Expand Down
3 changes: 2 additions & 1 deletion Tuist/Dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import ProjectDescription
let spm = SwiftPackageManagerDependencies([
.remote(url: "https://github.com/SnapKit/SnapKit.git", requirement: .upToNextMinor(from: "5.0.1")),
.remote(url: "https://github.com/scinfu/SwiftSoup.git", requirement: .upToNextMajor(from: "2.7.1")),
], productTypes: ["SnapKit": .framework, "SwiftSoup": .framework]
.remote(url: "https://github.com/Juanpe/SkeletonView.git", requirement: .upToNextMajor(from: "1.0.0"))
], productTypes: ["SnapKit": .framework, "SwiftSoup": .framework, "SkeletonView": .framework]
)

let dependencies = Dependencies(
Expand Down
16 changes: 16 additions & 0 deletions iBox/Sources/AddBookmark/AddBookmarkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit
import Combine

import SkeletonView
import SnapKit

class AddBookmarkView: UIView {
Expand Down Expand Up @@ -35,6 +36,8 @@ class AddBookmarkView: UIView {
$0.text = "๋ถ๋งˆํฌ ์ด๋ฆ„"
$0.font = .cellTitleFont
$0.textColor = .systemGray3
$0.isSkeletonable = true
$0.isHiddenWhenSkeletonIsActive = true
}

let nameTextView = UITextView().then {
Expand All @@ -46,6 +49,9 @@ class AddBookmarkView: UIView {
$0.isScrollEnabled = true
$0.keyboardType = .default
$0.autocorrectionType = .no
$0.isSkeletonable = true
$0.skeletonTextLineHeight = .fixed(20)
$0.skeletonPaddingInsets = .init(top: 5, left: 0, bottom: 5, right: 0)
}

private let clearButton = UIButton().then {
Expand All @@ -62,6 +68,8 @@ class AddBookmarkView: UIView {
$0.text = "URL"
$0.font = .cellTitleFont
$0.textColor = .systemGray3
$0.isSkeletonable = true
$0.isHiddenWhenSkeletonIsActive = true
}

let urlTextView = UITextView().then {
Expand All @@ -73,6 +81,10 @@ class AddBookmarkView: UIView {
$0.isScrollEnabled = true
$0.keyboardType = .URL
$0.autocorrectionType = .no
$0.isSkeletonable = true
$0.skeletonTextLineHeight = .fixed(20)
$0.skeletonTextNumberOfLines = 2
$0.skeletonPaddingInsets = .init(top: 5, left: 0, bottom: 5, right: 0)
}

private let button = UIButton(type: .custom).then {
Expand Down Expand Up @@ -120,6 +132,8 @@ class AddBookmarkView: UIView {
deinit {
AddBookmarkManager.shared.incomingTitle = nil
AddBookmarkManager.shared.incomingData = nil
AddBookmarkManager.shared.incomingFaviconUrl = nil
AddBookmarkManager.shared.incomingError = nil
}

// MARK: - Setup Methods
Expand All @@ -130,6 +144,8 @@ class AddBookmarkView: UIView {
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
nameTextView.delegate = self
urlTextView.delegate = self

isSkeletonable = true
}

private func setupHierarchy() {
Expand Down
35 changes: 35 additions & 0 deletions iBox/Sources/AddBookmark/AddBookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
// Created by jiyeon on 1/5/24.
//

import Combine
import UIKit

import SkeletonView

protocol AddBookmarkViewControllerProtocol: AnyObject {
func addFolderDirect(_ folder: Folder)
func addBookmarkDirect(_ bookmark: Bookmark, at folderIndex: Int)
Expand All @@ -15,6 +18,8 @@ protocol AddBookmarkViewControllerProtocol: AnyObject {
final class AddBookmarkViewController: UIViewController {
weak var delegate: AddBookmarkViewControllerProtocol?

var cancellables = Set<AnyCancellable>()

var haveValidInput = false
var selectedFolder: Folder?
var selectedFolderIndex: Int?
Expand All @@ -38,6 +43,9 @@ final class AddBookmarkViewController: UIViewController {
setupNavigationBar()
updateSelectedFolder()
addBookmarkView.nameTextView.becomeFirstResponder()
setupBindings()

view.isSkeletonable = true
}

private func setupNavigationBar() {
Expand Down Expand Up @@ -105,6 +113,33 @@ final class AddBookmarkViewController: UIViewController {
}
}

private func setupBindings() {
AddBookmarkManager.shared.$isFetching
.receive(on: DispatchQueue.main)
.sink { [weak self] isFetching in
if isFetching {
self?.view.hideSkeleton()
self?.view.showAnimatedGradientSkeleton()
} else {
self?.view.hideSkeleton()
}
}
.store(in: &cancellables)

AddBookmarkManager.shared.$incomingError
.receive(on: DispatchQueue.main)
.sink { [weak self] error in
guard error != nil else { return }
let alert = UIAlertController(title: "์˜ค๋ฅ˜", message: "ํ•ด๋‹น URL์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค", preferredStyle: .alert)
let okAction = UIAlertAction(title: "ํ™•์ธ", style: .default) { _ in
AddBookmarkManager.shared.isFetching = false
}
alert.addAction(okAction)
self?.present(alert, animated: true)
}
.store(in: &cancellables)
}

@objc private func cancelButtonTapped() {

let isTextFieldsEmpty = addBookmarkView.nameTextView.text?.isEmpty ?? true && addBookmarkView.urlTextView.text?.isEmpty ?? true
Expand Down
8 changes: 7 additions & 1 deletion iBox/Sources/BoxList/BoxListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

import UIKit

import SkeletonView

class BoxListViewController: BaseViewController<BoxListView>, BaseViewControllerProtocol {

var shouldPresentModalAutomatically: Bool = false {
didSet {
if shouldPresentModalAutomatically {
if findAddBookmarkViewController() == false {
if let vc = findAddBookmarkViewController() {
if vc.presentedViewController is UIAlertController {
vc.dismiss(animated: false)
}
} else {
dismiss(animated: false)
self.addButtonTapped()
}
Expand Down
8 changes: 4 additions & 4 deletions iBox/Sources/Extension/UIViewController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ extension UIViewController {
return nil
}

func findAddBookmarkViewController() -> Bool {
func findAddBookmarkViewController() -> AddBookmarkViewController? {
if let navigationController = presentedViewController as? UINavigationController,
let _ = navigationController.topViewController as? AddBookmarkViewController {
return true
let vc = navigationController.topViewController as? AddBookmarkViewController {
return vc
}
return false
return nil
}
}
14 changes: 14 additions & 0 deletions iBox/Sources/Model/BookmarkError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// BookmarkError.swift
// iBox
//
// Created by ์ด์ง€ํ˜„ on 4/21/24.
//

import Foundation

enum BookmarkError {
case htmlError
case decodeError
case parseError
}
19 changes: 11 additions & 8 deletions iBox/Sources/Shared/AddBookmarkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import SwiftSoup
class AddBookmarkManager {
static let shared = AddBookmarkManager()

@Published var isFetching: Bool = false
@Published var incomingTitle: String?
@Published var incomingData: String?
@Published var incomingFaviconUrl: String?
@Published var incomingError: BookmarkError?

private init() {}

private func update(with data: (title: String?, data: String?, faviconUrl: String?)) {
DispatchQueue.main.async {
self.isFetching = false
self.incomingTitle = data.title?.removingPercentEncoding
self.incomingData = data.data?.removingPercentEncoding
self.incomingFaviconUrl = data.faviconUrl?.removingPercentEncoding
Expand All @@ -33,9 +36,8 @@ class AddBookmarkManager {
let faviconLink = try doc.select("link[rel='icon']").first()?.attr("href")

self.update(with: (title: title, data: url.absoluteString, faviconUrl: faviconLink))

} catch {
print("Error parsing HTML: \(error)")
self.incomingError = .parseError
}
}

Expand All @@ -53,15 +55,15 @@ class AddBookmarkManager {
private func fetchWebsiteDetails(from url: URL) {
let task = URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
guard let data = data, error == nil else {
print("Error downloading HTML: \(String(describing: error))")
self?.incomingError = .htmlError
return
}

let encodingName = (response as? HTTPURLResponse)?.textEncodingName ?? "utf-8"
let encoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding(encodingName as CFString)))

guard let html = String(data: data, encoding: encoding) else {
print("Failed to decode data with encoding: \(encodingName)")
self?.incomingError = .decodeError
return
}

Expand All @@ -72,11 +74,12 @@ class AddBookmarkManager {

func navigateToAddBookmarkView(from url: URL, in tabBarController: UITabBarController) {
guard url.scheme == "iBox", let urlString = extractDataParameter(from: url) else { return }
guard let url = URL(string: urlString) else {
print("Invalid URL \(urlString)")
return
}
guard let url = URL(string: urlString) else { return }

incomingTitle = nil
incomingData = nil
incomingFaviconUrl = nil
isFetching = true
fetchWebsiteDetails(from: url)

tabBarController.selectedIndex = 0
Expand Down