Skip to content

Commit

Permalink
- Fixes iOS build
Browse files Browse the repository at this point in the history
- Adds checks on external projects removing #1183
  • Loading branch information
glushchenko committed Oct 24, 2021
1 parent f2716f3 commit f05a53f
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 172 deletions.
27 changes: 25 additions & 2 deletions FSNotes iOS/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
navigationController?.navigationBar.mixedBarTintColor = Colors.Header
navigationController?.navigationBar.mixedBackgroundColor = Colors.Header

if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
navigationController?.navigationBar.standardAppearance = appearance

updateNavigationBarBackground()
}

NotificationCenter.default.addObserver(self, selector: #selector(updateNavigationBarBackground), name: NSNotification.Name(rawValue: NightNightThemeChangeNotification), object: nil)

self.navigationItem.rightBarButtonItems = [getMoreButton(), self.getPreviewButton()]
self.navigationItem.leftBarButtonItem = Buttons.getBack(target: self, selector: #selector(cancel))

Expand All @@ -67,14 +77,26 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick
self.addToolBar(textField: editArea, toolbar: self.getMarkdownToolbar())

NotificationCenter.default.addObserver(self, selector: #selector(preferredContentSizeChanged), name: UIContentSizeCategory.didChangeNotification, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(refill), name: NSNotification.Name(rawValue: "es.fsnot.external.file.changed"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(updateNavigationBarBackground), name: NSNotification.Name(rawValue: NightNightThemeChangeNotification), object: nil)

editArea.keyboardDismissMode = .interactive
}

@objc func updateNavigationBarBackground() {
if #available(iOS 13.0, *) {
var color = UIColor(red: 0.15, green: 0.28, blue: 0.42, alpha: 1.00)
if NightNight.theme == .night {
color = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.00)
}

guard let navController = navigationController else { return }
navController.navigationBar.standardAppearance.backgroundColor = color
navController.navigationBar.scrollEdgeAppearance = navController.navigationBar.standardAppearance
}
}

@objc func rotated() {
guard isLandscape != nil else {
isLandscape = UIDevice.current.orientation.isLandscape
Expand Down Expand Up @@ -1689,6 +1711,7 @@ class EditorViewController: UIViewController, UITextViewDelegate, UIDocumentPick

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.checkDarkMode()
self.updateNavigationBarBackground()
}
}

Expand Down
29 changes: 29 additions & 0 deletions FSNotes iOS/Extensions/UITableViewController+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// UITableViewController+.swift
// FSNotes iOS
//
// Created by Александр on 24.10.2021.
// Copyright © 2021 Oleksandr Glushchenko. All rights reserved.
//

import Foundation
import UIKit
import NightNight

extension UITableViewController {
@objc func updateNavigationBarBackground() {
if #available(iOS 13.0, *) {
var color = UIColor(red: 0.15, green: 0.28, blue: 0.42, alpha: 1.00)

if NightNight.theme == .night {
color = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.00)
}

guard let navController = navigationController else { return }

navController.navigationBar.standardAppearance.backgroundColor = color
navController.navigationBar.standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navController.navigationBar.scrollEdgeAppearance = navController.navigationBar.standardAppearance
}
}
}
6 changes: 5 additions & 1 deletion FSNotes iOS/FolderPopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ class FolderPopoverViewControler : UITableViewController, UIDocumentPickerDelega
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in

mvc.sidebarTableView.removeRows(projects: [selectedProject])
try? FileManager.default.removeItem(at: selectedProject.url)

if !selectedProject.isExternal {
try? FileManager.default.removeItem(at: selectedProject.url)
}

Storage.shared().remove(project: selectedProject)
}))

Expand Down
27 changes: 26 additions & 1 deletion FSNotes iOS/PreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class PreviewViewController: UIViewController, UIGestureRecognizerDelegate {
super.viewDidLoad()

NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIContentSizeCategory.didChangeNotification, object: nil)

let tapGR = UITapGestureRecognizer(target: self, action: #selector(editMode))
Expand All @@ -39,6 +38,16 @@ class PreviewViewController: UIViewController, UIGestureRecognizerDelegate {
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(returnBack))
swipeRight.direction = UISwipeGestureRecognizer.Direction.right
self.view.addGestureRecognizer(swipeRight)

if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
navigationController?.navigationBar.standardAppearance = appearance

updateNavigationBarBackground()
}

NotificationCenter.default.addObserver(self, selector: #selector(updateNavigationBarBackground), name: NSNotification.Name(rawValue: NightNightThemeChangeNotification), object: nil)
}

public func getEditButton() -> UIBarButtonItem {
Expand Down Expand Up @@ -227,4 +236,20 @@ class PreviewViewController: UIViewController, UIGestureRecognizerDelegate {
}
}
}

@objc func updateNavigationBarBackground() {
if #available(iOS 13.0, *) {
var color = UIColor(red: 0.15, green: 0.28, blue: 0.42, alpha: 1.00)

if NightNight.theme == .night {
color = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.00)
}

guard let navController = navigationController else { return }

navController.navigationBar.standardAppearance.backgroundColor = color
navController.navigationBar.standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navController.navigationBar.scrollEdgeAppearance = navController.navigationBar.standardAppearance
}
}
}
10 changes: 10 additions & 0 deletions FSNotes iOS/Settings/ProjectSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class ProjectSettingsViewController: UITableViewController {

self.title = NSLocalizedString("Project", comment: "Settings") + " \"\(project.getFullLabel())\""

if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
navigationController?.navigationBar.standardAppearance = appearance

updateNavigationBarBackground()
}

NotificationCenter.default.addObserver(self, selector: #selector(updateNavigationBarBackground), name: NSNotification.Name(rawValue: NightNightThemeChangeNotification), object: nil)

super.viewDidLoad()
}

Expand Down
12 changes: 12 additions & 0 deletions FSNotes iOS/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ class SettingsViewController: UITableViewController, UIGestureRecognizerDelegate
version.textAlignment = .center

tableView.tableFooterView = version

if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
navigationController?.navigationBar.standardAppearance = appearance

updateNavigationBarBackground()
}

NotificationCenter.default.addObserver(self, selector: #selector(updateNavigationBarBackground), name: NSNotification.Name(rawValue: NightNightThemeChangeNotification), object: nil)
}

override func numberOfSections(in tableView: UITableView) -> Int {
Expand Down Expand Up @@ -358,5 +368,7 @@ class SettingsViewController: UITableViewController, UIGestureRecognizerDelegate
}
}
}

updateNavigationBarBackground()
}
}
7 changes: 6 additions & 1 deletion FSNotes iOS/View/NoteCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ class NoteCellView: SwipeTableViewCell {
if ["firstImageTop", "secondImageTop", "thirdImageTop"].contains(constraint.identifier) {
let ident = constraint.identifier

let height = position != nil ? tableView.cellHeights[IndexPath(row: position!, section: 0)]! : self.frame.height
var height = CGFloat(0)
if let position = position, let heightUnwrapped = tableView.cellHeights[IndexPath(row: position, section: 0)] {
height = heightUnwrapped
} else {
height = self.frame.height
}

self.contentView.removeConstraint(constraint)
var con = CGFloat(0)
Expand Down
6 changes: 5 additions & 1 deletion FSNotes iOS/ViewController+More.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ extension ViewController: UIDocumentPickerDelegate {
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in

mvc.sidebarTableView.removeRows(projects: [selectedProject])
try? FileManager.default.removeItem(at: selectedProject.url)

if !selectedProject.isExternal {
try? FileManager.default.removeItem(at: selectedProject.url)
}

Storage.shared().remove(project: selectedProject)
}))

Expand Down
21 changes: 5 additions & 16 deletions FSNotes iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -949,31 +949,20 @@ class ViewController: UIViewController, UISearchBarDelegate, UIGestureRecognizer

func createNote(content: String? = nil, pasteboard: Bool? = nil) {
var currentProject: Project
var tag: String?

if let project = storage.getProjects().first {
currentProject = project
} else {
return
}

if let item = self.sidebarTableView.getSidebarItem() {
if item.type == .Tag {
tag = item.name
}

if let project = item.project,
!project.isTrash,
!project.isVirtual {
currentProject = project
}
if let item = self.sidebarTableView.getSidebarItem(),
let project = item.project,
!project.isTrash,
!project.isVirtual {
currentProject = project
}

let note = Note(name: "", project: currentProject)
if let tag = tag {
note.tagNames.append(tag)
}

if let content = content {
note.content = NSMutableAttributedString(string: content)
}
Expand Down
Loading

0 comments on commit f05a53f

Please sign in to comment.