Skip to content

Commit

Permalink
Count chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tnantoka committed Nov 6, 2018
1 parent 43fc575 commit 66542af
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Edhita.xcodeproj/project.pbxproj
Expand Up @@ -14,6 +14,7 @@
9B2E0A6119E76AE3002E9CA4 /* bootstrap in Resources */ = {isa = PBXBuildFile; fileRef = 9B2E0A6019E76AE3002E9CA4 /* bootstrap */; };
9B372B0F19EFF6BB00295862 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9B372B1119EFF6BB00295862 /* Localizable.strings */; };
9B372B1419EFFB1300295862 /* github-markdown.css in Resources */ = {isa = PBXBuildFile; fileRef = 9B372B1319EFFB1300295862 /* github-markdown.css */; };
9B4A580C2191DB2B00D780A0 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B4A580B2191DB2B00D780A0 /* Utility.swift */; };
9B6E1E9319E2EB2100C72D13 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B6E1E9219E2EB2100C72D13 /* AppDelegate.swift */; };
9B6E1E9C19E2EB2100C72D13 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9B6E1E9B19E2EB2100C72D13 /* Images.xcassets */; };
9B6E1E9F19E2EB2100C72D13 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9B6E1E9D19E2EB2100C72D13 /* LaunchScreen.xib */; };
Expand Down Expand Up @@ -43,6 +44,7 @@
9B372B1019EFF6BB00295862 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
9B372B1219EFF6C700295862 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
9B372B1319EFFB1300295862 /* github-markdown.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = "github-markdown.css"; sourceTree = "<group>"; };
9B4A580B2191DB2B00D780A0 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = "<group>"; };
9B6E1E8D19E2EB2100C72D13 /* Edhita.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Edhita.app; sourceTree = BUILT_PRODUCTS_DIR; };
9B6E1E9119E2EB2100C72D13 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9B6E1E9219E2EB2100C72D13 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -175,6 +177,7 @@
children = (
9B91999019E429B0003751FA /* AppSecret.swift */,
9B2E0A5519E683CC002E9CA4 /* SettingsForm.swift */,
9B4A580B2191DB2B00D780A0 /* Utility.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -378,6 +381,7 @@
9B6E1E9319E2EB2100C72D13 /* AppDelegate.swift in Sources */,
9B91999419E5185C003751FA /* EditorView.swift in Sources */,
9B6E1EBF19E423A100C72D13 /* FinderListViewController.swift in Sources */,
9B4A580C2191DB2B00D780A0 /* Utility.swift in Sources */,
9B6E1EBD19E35C2300C72D13 /* EditorViewController.swift in Sources */,
9B91999119E429B0003751FA /* AppSecret.swift in Sources */,
9B2E0A5819E6C876002E9CA4 /* SettingsViewController.swift in Sources */,
Expand Down
34 changes: 16 additions & 18 deletions Edhita/Controllers/EditorViewController.swift
Expand Up @@ -11,11 +11,12 @@ import MessageUI

class EditorViewController: UIViewController, EDHFinderListViewControllerDelegate, MFMailComposeViewControllerDelegate {

let kToolbarIconSize: CGFloat = 30.0
let toolbarIconSize: CGFloat = 30.0

var fullscreenItem: UIBarButtonItem!
var reloadItem: UIBarButtonItem!
var shareItem: UIBarButtonItem!
var countItem: UIBarButtonItem!
var modeControl: UISegmentedControl!
var editorView: EditorView!

Expand All @@ -31,17 +32,19 @@ class EditorViewController: UIViewController, EDHFinderListViewControllerDelegat
self.edgesForExtendedLayout = UIRectEdge()

self.editorView = EditorView(frame: self.view.bounds)
editorView.onChangeText = updateCountItem
self.view.addSubview(self.editorView)

// Toolbar
self.fullscreenItem = UIBarButtonItem(image: nil, style: .plain, target: self,
action: #selector(fullscreenItemDidTap))
self.reloadItem = self.barButtonItem(icon: FAKIonIcons.refreshIcon(withSize: self.kToolbarIconSize),
action: #selector(reloadItemDidTap))
self.shareItem = self.barButtonItem(icon: FAKIonIcons.shareIcon(withSize: self.kToolbarIconSize),
action: #selector(shareItemDidTap))
let settingsItem = self.barButtonItem(icon: FAKIonIcons.gearAIcon(withSize: self.kToolbarIconSize),
action: #selector(settingsItemDidTap))
self.reloadItem = Utility.barButtonItem(target: self,
icon: FAKIonIcons.refreshIcon(withSize: self.toolbarIconSize),
action: #selector(reloadItemDidTap))
self.shareItem = Utility.barButtonItem(target: self,
icon: FAKIonIcons.shareIcon(withSize: self.toolbarIconSize),
action: #selector(shareItemDidTap))
self.countItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
let flexibleItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

self.toolbarItems = [
Expand All @@ -51,7 +54,7 @@ class EditorViewController: UIViewController, EDHFinderListViewControllerDelegat
flexibleItem,
shareItem,
flexibleItem,
settingsItem
countItem
]

// Right
Expand Down Expand Up @@ -292,17 +295,18 @@ class EditorViewController: UIViewController, EDHFinderListViewControllerDelegat
}
self.editorView.finderItem = self.finderItem
self.modeControlDidChange(self.modeControl)
updateCountItem()
}

func updateFullscreenItem() {
var icon: FAKIcon
if self.splitViewController?.displayMode == UISplitViewControllerDisplayMode.allVisible {
// FIXME: Does not show back button label after rotation to portrait
self.navigationItem.leftBarButtonItem = nil // Don't show default exapnd item on portrail
icon = FAKIonIcons.arrowExpandIcon(withSize: self.kToolbarIconSize)
icon = FAKIonIcons.arrowExpandIcon(withSize: toolbarIconSize)
} else {
self.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem
icon = FAKIonIcons.arrowShrinkIcon(withSize: self.kToolbarIconSize)
icon = FAKIonIcons.arrowShrinkIcon(withSize: toolbarIconSize)
}
self.fullscreenItem.image = icon.image(with: CGSize(width: icon.iconFontSize, height: icon.iconFontSize))

Expand All @@ -311,13 +315,7 @@ class EditorViewController: UIViewController, EDHFinderListViewControllerDelegat
}
}

func barButtonItem(icon: FAKIcon, action: Selector) -> UIBarButtonItem {
let image = self.iconImage(icon)
let item = UIBarButtonItem(image: image, style: .plain, target: self, action: action)
return item
}

func iconImage(_ icon: FAKIcon) -> UIImage {
return icon.image(with: CGSize(width: icon.iconFontSize, height: icon.iconFontSize))
func updateCountItem() {
countItem.title = String(format: NSLocalizedString("Chars: %d", comment: ""), editorView.count)
}
}
15 changes: 15 additions & 0 deletions Edhita/Controllers/FinderListViewController.swift
Expand Up @@ -10,12 +10,19 @@ import UIKit

class FinderListViewController: EDHFinderListViewController {

let kToolbarIconSize: CGFloat = 26.0

var bannerView: GADBannerView!

override func viewDidLoad() {
super.viewDidLoad()

self.initAd()

let settingsItem = Utility.barButtonItem(target: self,
icon: FAKIonIcons.gearAIcon(withSize: self.kToolbarIconSize),
action: #selector(settingsItemDidTap))
navigationItem.leftBarButtonItem = settingsItem
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -51,4 +58,12 @@ class FinderListViewController: EDHFinderListViewController {
self.tableView.tableFooterView = self.bannerView
}

// MARK: - Actions

@objc func settingsItemDidTap(_ sender: AnyObject) {
let formController = SettingsViewController()
let navController = UINavigationController(rootViewController: formController)
navController.modalPresentationStyle = .formSheet
self.present(navController, animated: true, completion: nil)
}
}
21 changes: 21 additions & 0 deletions Edhita/Models/Utility.swift
@@ -0,0 +1,21 @@
//
// Utility.swift
// Edhita
//
// Created by Tatsuya Tobioka on 2018/11/06.
// Copyright © 2018 tnantoka. All rights reserved.
//

import Foundation

struct Utility {
static func barButtonItem(target: UIViewController, icon: FAKIcon, action: Selector) -> UIBarButtonItem {
let image = self.iconImage(icon)
let item = UIBarButtonItem(image: image, style: .plain, target: target, action: action)
return item
}

static func iconImage(_ icon: FAKIcon) -> UIImage {
return icon.image(with: CGSize(width: icon.iconFontSize, height: icon.iconFontSize))
}
}
5 changes: 5 additions & 0 deletions Edhita/Views/EditorView.swift
Expand Up @@ -18,6 +18,7 @@ class EditorView: UIView, UITextViewDelegate {

var textView: UITextView!
var webView: UIWebView! // TODO: Use WKWebView
var onChangeText: () -> Void = {}
var finderItem: EDHFinderItem? {
didSet {
self.configureView()
Expand All @@ -30,6 +31,9 @@ class EditorView: UIView, UITextViewDelegate {
}
}
}
var count: Int {
return textView.text.count
}

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -121,6 +125,7 @@ class EditorView: UIView, UITextViewDelegate {
func textViewDidChange(_ textView: UITextView) {
self.finderItem?.updateContent(textView.text)
self.preview()
onChangeText()
}

// MARK: - Utilities
Expand Down
Binary file modified Edhita/en.lproj/Localizable.strings
Binary file not shown.
Binary file modified Edhita/ja.lproj/Localizable.strings
Binary file not shown.

0 comments on commit 66542af

Please sign in to comment.