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
2 changes: 1 addition & 1 deletion iBox/Resources/Version
Submodule Version updated 1 files
+63 −3 db.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CustomLaunchScreenViewController: UIViewController {
switch result {
case .success, .maxRetryReached, .later:
self?.transitionToNextScreen()
print("App 정상 실행")
case .urlError:
print("URL 에러가 발생했습니다.")
case .networkError:
Expand All @@ -64,13 +65,17 @@ class CustomLaunchScreenViewController: UIViewController {
print("scene error 수집")
case .internalInfoError:
print("info error 수집")
case .Initial:
print("초기값")
case .initial:
self?.startupFlow()
print("init")
}
}
.store(in: &cancellables)
}

private func startupFlow() {
DefaultData.insertDefaultDataIfNeeded()
}

private func transitionToNextScreen() {
guard let window = self.view.window else { return }
Expand Down
2 changes: 1 addition & 1 deletion iBox/Sources/Extension/UIColor+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ extension UIColor {
static let webIconColor = color(light: .black, dark: .systemGray)
static let dimmedViewColor = UIColor.black.withAlphaComponent(0.75)
static let backgroundColor = color(light: .white, dark: UIColor(hex: 0x242424))

static let invertBackgroundColor = color(light: UIColor(hex: 0x242424), dark: .white)
}
50 changes: 50 additions & 0 deletions iBox/Sources/Initializer/DefaultData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// DefaultData.swift
// iBox
//
// Created by Chan on 4/17/24.
//

import Foundation


class DefaultData {

static func insertDefaultDataIfNeeded(_ isReset: Bool = false, completion: (() -> Void)? = nil) {
let isDefaultDataInserted = UserDefaultsManager.isDefaultDataInserted
if !isDefaultDataInserted || isReset {
fetchDefaultData { defaultFolders in
DispatchQueue.main.async {
CoreDataManager.shared.deleteAllFolders()
CoreDataManager.shared.addInitialFolders(defaultFolders)
UserDefaultsManager.isDefaultDataInserted = true
completion?()
}
}
}
}

static func fetchDefaultData(completion: @escaping ([Folder]) -> Void) {
let localDic: [String : String] = ["Seoul" : "default-kr", "default" : "default"]
let cityName = "Seoul" // 추후 global 예정
let local = localDic[cityName] ?? "default"

let url = URL(string: "https://raw.githubusercontent.com/42Box/versioning/main/\(local).json")!
URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, error == nil else {
print("Error fetching default data: \(String(describing: error))")
completion(DefaultDataLoader.defaultData)
return
}

do {
let folderData = try JSONDecoder().decode(FolderData.self, from: data)
let folders = [Folder(id: UUID(), name: "42 \(cityName)", bookmarks: folderData.list.map { Bookmark(id: UUID(), name: $0.name, url: URL(string: $0.url)!) })]
completion(folders)
} catch {
print("Error decoding JSON: \(error)")
completion(DefaultDataLoader.defaultData)
}
}.resume()
}
}
31 changes: 31 additions & 0 deletions iBox/Sources/Initializer/DefaultDataModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// DefaultDataModel.swift
// iBox
//
// Created by Chan on 4/17/24.
//

import Foundation


struct FolderData: Codable {
var list: [BookmarkData]
}

struct BookmarkData: Codable {
var name: String
var url: String
}

struct DefaultDataLoader {
static let defaultData = [
Folder(id: UUID(), name: "42 폴더", bookmarks: [
Bookmark(id: UUID(), name: "42 Intra", url: URL(string: "https://profile.intra.42.fr/")!),
Bookmark(id: UUID(), name: "42Where", url: URL(string: "https://www.where42.kr/")! ),
Bookmark(id: UUID(), name: "42Stat", url: URL(string: "https://stat.42seoul.kr/")!),
Bookmark(id: UUID(), name: "집현전", url: URL(string: "https://42library.kr/")!),
Bookmark(id: UUID(), name: "42gg", url: URL(string: "https://gg.42seoul.kr/")!),
Bookmark(id: UUID(), name: "24HANE", url: URL(string: "https://24hoursarenotenough.42seoul.kr/")!)
])
]
}
6 changes: 1 addition & 5 deletions iBox/Sources/Model/VersionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ struct VersionInfo: Codable {

// MARK: - URLClass
struct URLClass: Codable {
let updateURL: String?

enum CodingKeys: String, CodingKey {
case updateURL = "updateUrl"
}
let storeUrl: String
}

// MARK: - Version
Expand Down
23 changes: 1 addition & 22 deletions iBox/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene

// 앱 테마 정보
window?.overrideUserInterfaceStyle = window?.toUserInterfaceStyle(UserDefaultsManager.theme) ?? .unspecified

insertDefaultDataIfNeeded()

window?.rootViewController = CustomLaunchScreenViewController(urlContext: connectionOptions.urlContexts.first)
window?.makeKeyAndVisible()
}

private func insertDefaultDataIfNeeded() {
let isDefaultDataInserted = UserDefaultsManager.isDefaultDataInserted
if !isDefaultDataInserted {
let defaultData = [
Folder(id: UUID(), name: "42 폴더", bookmarks: [
Bookmark(id: UUID(), name: "42 Intra", url: URL(string: "https://profile.intra.42.fr/")!),
Bookmark(id: UUID(), name: "42Where", url: URL(string: "https://www.where42.kr/")! ),
Bookmark(id: UUID(), name: "42Stat", url: URL(string: "https://stat.42seoul.kr/")!),
Bookmark(id: UUID(), name: "집현전", url: URL(string: "https://42library.kr/")!),
Bookmark(id: UUID(), name: "Cabi", url: URL(string: "https://cabi.42seoul.io/")!),
Bookmark(id: UUID(), name: "24HANE", url: URL(string: "https://24hoursarenotenough.42seoul.kr/")!)
])
]
CoreDataManager.shared.deleteAllFolders()
CoreDataManager.shared.addInitialFolders(defaultData)
UserDefaultsManager.isDefaultDataInserted = true
}

}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
Expand Down
98 changes: 98 additions & 0 deletions iBox/Sources/Settings/Reset/ResetSuccessView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// ResetSuccessView.swift
// iBox
//
// Created by Chan on 4/17/24.
//

import UIKit

import SnapKit

protocol ResetSuccessViewDelegate: AnyObject {
func didCompleteReset()
}

class ResetSuccessView: UIView {

weak var delegate: ResetSuccessViewDelegate?

private let checkMarkImageView = UIImageView().then {
$0.image = UIImage(systemName: "checkmark")
$0.contentMode = .scaleAspectFit
$0.tintColor = .box2
}

private let label = UILabel().then {
$0.text = "초기화 성공"
$0.textColor = .invertBackgroundColor
$0.textAlignment = .center
$0.font = UIFont.systemFont(ofSize: 16)
}

private let stackView = UIStackView().then {
$0.axis = .vertical
$0.spacing = 10
$0.alignment = .center
$0.distribution = .equalSpacing
}

private let backPannelView = UIView().then {
$0.backgroundColor = .backgroundColor
$0.layer.cornerRadius = 20
$0.clipsToBounds = true
}

override init(frame: CGRect) {
super.init(frame: frame)
setupView()
animateView()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupView() {
self.alpha = 0
self.backgroundColor = UIColor.invertBackgroundColor.withAlphaComponent(0.35)
self.addSubview(backPannelView)
backPannelView.addSubview(stackView)

stackView.addArrangedSubview(checkMarkImageView)
stackView.addArrangedSubview(label)

backPannelView.snp.makeConstraints { make in
make.width.height.equalTo(200)
make.center.equalToSuperview()
}

stackView.snp.makeConstraints { make in
make.center.equalToSuperview()
}

checkMarkImageView.snp.makeConstraints { make in
make.width.height.equalTo(50)
}
}
private func animateView() {
UIView.animate(withDuration: 0.5, animations: {
self.alpha = 1.0
}) { _ in
UIView.animate(withDuration: 0.5) {
self.backPannelView.alpha = 1.0
}

UIView.animate(withDuration: 0.5, delay: 2, options: []) {
self.backPannelView.alpha = 0.0
} completion: { _ in
UIView.animate(withDuration: 0.5, animations: {
self.alpha = 0.0
}) { _ in
self.removeFromSuperview()
self.delegate?.didCompleteReset()
}
}
}
}
}
58 changes: 33 additions & 25 deletions iBox/Sources/Settings/Reset/ResetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,55 @@ extension ResetViewController: ResetViewDelegate {
alertController.addAction(cancelAction)

let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self] _ in
guard let self = self else { return }
if let textField = alertController.textFields?.first, let text = textField.text, text == "iBox" {
self?.resetData()
self?.navigationController?.popViewController(animated: true)
self.resetData()
} else {
self?.showAlert()
self.showAlert()
}
}

confirmAction.isEnabled = false
confirmAction.setValue(UIColor.red, forKey: "titleTextColor")

alertController.addAction(confirmAction)

alertController.addTextField() { textField in
NotificationCenter.default.addObserver(forName: UITextField.textDidChangeNotification, object: textField, queue: OperationQueue.main, using:
{_ in
let isTextMatch = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "iBox"
confirmAction.isEnabled = isTextMatch
})
{_ in
let isTextMatch = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "iBox"

confirmAction.isEnabled = isTextMatch
})

}

self.present(alertController, animated: true, completion: nil)
}

private func resetData() {
let defaultData = [
Folder(id: UUID(), name: "42 폴더", bookmarks: [
Bookmark(id: UUID(), name: "42 Intra", url: URL(string: "https://profile.intra.42.fr/")!),
Bookmark(id: UUID(), name: "42Where", url: URL(string: "https://www.where42.kr/")! ),
Bookmark(id: UUID(), name: "42Stat", url: URL(string: "https://stat.42seoul.kr/")!),
Bookmark(id: UUID(), name: "집현전", url: URL(string: "https://42library.kr/")!),
Bookmark(id: UUID(), name: "Cabi", url: URL(string: "https://cabi.42seoul.io/")!),
Bookmark(id: UUID(), name: "24HANE", url: URL(string: "https://24hoursarenotenough.42seoul.kr/")!)
])
]
CoreDataManager.shared.deleteAllFolders()
CoreDataManager.shared.addInitialFolders(defaultData)
UserDefaultsManager.isDefaultDataInserted = true

UserDefaultsManager.favoriteId = nil
WebViewPreloader.shared.setFavoriteUrl(url: nil)
NotificationCenter.default.post(name: .didResetData, object: nil)
DefaultData.insertDefaultDataIfNeeded(true) {
UserDefaultsManager.favoriteId = nil
WebViewPreloader.shared.setFavoriteUrl(url: nil)
NotificationCenter.default.post(name: .didResetData, object: nil)
DispatchQueue.main.async {
let successView = ResetSuccessView(frame: self.view.bounds)
successView.delegate = self
self.view.addSubview(successView)
successView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
}
}
}

// MARK: - ResetSuccessView

extension ResetViewController: ResetSuccessViewDelegate {

func didCompleteReset() {
self.navigationController?.popViewController(animated: true)
}

}
5 changes: 1 addition & 4 deletions iBox/Sources/Shared/AppStateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import Combine
class AppStateManager {
static let shared = AppStateManager()

@Published var isVersionCheckCompleted: VersionCheckCode = .Initial
@Published var isVersionCheckCompleted: VersionCheckCode = .initial

func shouldTransitionToNextScreen(completion: @escaping (VersionCheckCode) -> Void) {
completion(isVersionCheckCompleted)
}
}
Loading