Skip to content
Permalink
Browse files

Fix emoticon theme

  • Loading branch information...
youknowone committed Jul 2, 2015
1 parent 2a9c1d5 commit 732533c4a1b75a8db607c3ac5db9e94e7410cfa2
@@ -22,6 +22,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
Fabric.with([Crashlytics()])
crashlyticsInitialized = true
sharedAppDelegate = self

if preferences.themeResources.count == 0 {
Theme.themeWithAddress(preferences.themePath).dump()
}
//store // force lazy loading
return true
@@ -14,7 +14,8 @@ class EmoticonKeyboardView: KeyboardView {
]

@IBOutlet var tableView: UITableView!
@IBOutlet var footerBlurView: UIVisualEffectView!
@IBOutlet var footerBlurView: UIView!
let dummyLabelButton = GRInputButton()

lazy var sectionButtons: [GRInputButton] = {
return map(enumerate(self.dynamicType.titleIcons), {
@@ -28,7 +29,7 @@ class EmoticonKeyboardView: KeyboardView {

override var visibleButtons: [GRInputButton] {
get {
return [self.nextKeyboardButton, self.deleteButton] + self.sectionButtons
return [self.nextKeyboardButton, self.deleteButton, self.dummyLabelButton] + self.sectionButtons
}
}

@@ -38,7 +39,7 @@ class EmoticonKeyboardView: KeyboardView {

override func awakeFromNib() {
super.awakeFromNib()

/*
let opaqueColor = UIColor(white: 0.0, alpha: 0.90).CGColor
let medianColor = UIColor(white: 0.0, alpha: 0.60).CGColor
let transparentColor = UIColor(white: 0.0, alpha: 0.0).CGColor
@@ -49,6 +50,7 @@ class EmoticonKeyboardView: KeyboardView {
gradientLayer.startPoint = CGPointMake(0.5, 0.0)
gradientLayer.endPoint = CGPointMake(0.5, 1.0)
self.footerBlurView.layer.mask = gradientLayer
*/
}

override init(frame: CGRect) {
@@ -120,7 +122,7 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
{ $0.row(row) },
{ $0.function },
{ $0.base },
], inGroups: [trait.tenkey, trait.common])
], inGroups: [trait.emoticon, trait.common])
})
}

@@ -131,14 +133,24 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
{ $0.row(row) },
{ $0.special },
{ $0.base },
], inGroups: [trait.tenkey, trait.common])
], inGroups: [trait.emoticon, trait.common])
})
}

return [
var themeMap = [
self.view.nextKeyboardButton!: functionCaption("globe", 4),
self.view.deleteButton!: functionCaption("delete", 4)
self.view.deleteButton!: functionCaption("delete", 4),
self.emoticonView.dummyLabelButton: trait.captionForIdentifier("emoticon-header", needsMargin: self.dynamicType.needsMargin, classes: {
trait.captionClassesForGetters([
{ $0.classByName("header") },
{ $0.base },
], inGroups: [trait.emoticon, trait.common])
})
]
for button in self.emoticonView.sectionButtons {
themeMap[button] = specialCaption("section", 4)
}
return themeMap
}

override class func loadContext() -> UnsafeMutablePointer<()> {
@@ -172,13 +184,18 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
let position = UITableViewScrollPosition.Top
self.emoticonView.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: position, animated: false)

let modelLabel = self.view.deleteButton.titleLabel!
for button in self.emoticonView.sectionButtons {
button.titleLabel?.textColor = modelLabel.textColor
button.addTarget(self, action: "selectSection:", forControlEvents: .TouchUpInside)
}
}

override func layoutDidLayoutForHelper(helper: GRKeyboardLayoutHelper, forRect rect: CGRect) {
super.layoutDidLayoutForHelper(helper, forRect: rect)

self.emoticonView.footerBlurView.backgroundColor = self.emoticonView.dummyLabelButton.backgroundColor
self.emoticonView.footerBlurView.alpha = 0.9
}

override func numberOfRowsForHelper(helper: GRKeyboardLayoutHelper) -> Int {
return 2
}
@@ -238,15 +255,33 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
return self.dynamicType.table.count
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == 0 || indexPath.row == self.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1 {
return 10
} else {
return tableView.rowHeight
}
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let emoticons = section == 0 ? self.favorites : self.dynamicType.table[section]
let length = count(emoticons)
let numberOfRow = (length - 1) / self.dynamicType.numbersOfColumns[section] + 1
return numberOfRow
return numberOfRow + 2
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let section = indexPath.section
if indexPath.row == 0 || indexPath.row == self.tableView(tableView, numberOfRowsInSection: section) - 1 {
let identifier = "margin"
let cell = (tableView.dequeueReusableCellWithIdentifier(identifier) as! UITableViewCell?) ?? {
let cell = UITableViewCell(style: .Default, reuseIdentifier: identifier)
cell.backgroundColor = UIColor.clearColor()
return cell
}()
return cell
}

let identifier = "cell_\(section)"
let numberOfColumns = self.dynamicType.numbersOfColumns[indexPath.section]
let cell = (tableView.dequeueReusableCellWithIdentifier(identifier) as! UITableViewCell?) ?? {
@@ -272,8 +307,9 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
let margin: CGFloat = 8.0
let buttonWidth = (tableView.frame.size.width - 2 * margin) / CGFloat(numberOfColumns)

let row = indexPath.row - 1
for column in 0..<numberOfColumns {
let position = indexPath.row * numberOfColumns + column
let position = row * numberOfColumns + column
if position >= length {
break
}
@@ -300,6 +336,11 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
let headerView = view as! UITableViewHeaderFooterView

let backgroundView = self.headerBackgroundViews[section] ?? {
let blurView = UIView()
blurView.backgroundColor = self.emoticonView.dummyLabelButton.backgroundColor
blurView.alpha = 0.9
return blurView
/*
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
let opaqueColor = UIColor(white: 0.0, alpha: 0.90).CGColor
let medianColor = UIColor(white: 0.0, alpha: 0.60).CGColor
@@ -313,11 +354,13 @@ class EmoticonKeyboardLayout: KeyboardLayout, UITableViewDataSource, UITableView
blurView.layer.mask = gradientLayer
self.headerBackgroundViews[section] = blurView
return blurView
*/
}()

headerView.backgroundView = backgroundView
headerView.textLabel.font = self.view.deleteButton.captionLabel.font
headerView.textLabel.textColor = self.view.deleteButton.captionLabel.textColor
let modelLabel = self.emoticonView.sectionButtons[0].captionLabel
headerView.textLabel.font = modelLabel.font
headerView.textLabel.textColor = modelLabel.textColor
}

func input(sender: GRInputButton) {
@@ -14,7 +14,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="216"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="30" sectionHeaderHeight="28" sectionFooterHeight="1" id="BYD-6b-ClK">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="30" sectionHeaderHeight="40" sectionFooterHeight="1" id="BYD-6b-ClK">
<rect key="frame" x="0.0" y="0.0" width="320" height="216"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
@@ -65,21 +65,17 @@
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
<visualEffectView opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" id="nfM-X5-gfi">
<rect key="frame" x="0.0" y="170" width="320" height="46"/>
<view alpha="0.80000000000000004" contentMode="scaleToFill" id="EwU-fh-3JE">
<rect key="frame" x="0.0" y="176" width="320" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="nsA-Wd-CyC">
<rect key="frame" x="0.0" y="0.0" width="320" height="46"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<blurEffect style="light"/>
</visualEffectView>
<color key="backgroundColor" white="0.8002525845864662" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" red="0.93290389521089212" green="1" blue="0.30695314822234521" alpha="0.0" colorSpace="calibratedRGB"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="deleteButton" destination="ZYd-Nn-XeZ" id="0RR-YL-jc4"/>
<outlet property="footerBlurView" destination="nfM-X5-gfi" id="qG9-b4-6ga"/>
<outlet property="footerBlurView" destination="EwU-fh-3JE" id="XLc-61-zeu"/>
<outlet property="nextKeyboardButton" destination="0pk-7q-hxg" id="oNt-db-nBa"/>
<outlet property="spaceButton" destination="IRp-Ff-sUq" id="RiC-OE-UI0"/>
<outlet property="tableView" destination="BYD-6b-ClK" id="kNV-2P-Jar"/>
@@ -14,6 +14,7 @@ class InputMethodView: UIView, UIGestureRecognizerDelegate, UIScrollViewDelegate
var theme: Theme = {
var theme: Theme = preferences.theme
if theme.dataForFilename("config.json") == nil {
assert(false)
theme = BuiltInTheme()
}
return CachedTheme(theme: theme)
@@ -223,25 +223,21 @@ public class ThemeCaptionClass {
self.configuration = full
}

func _imageNames() -> [String] {
if let sub: AnyObject = self.configuration["image"] {
func _backgroundImageNames() -> [String] {
if let sub: AnyObject = self.backgroundConfiguration["image"] {
return (sub is String ? [sub] : sub) as! [String]
} else {
return []
}
}

lazy var labelConfiguration: Dictionary<String, AnyObject> = {
return self.configuration["label"] as? Dictionary<String, AnyObject> ?? [:]
}()
lazy var backgroundConfiguration: Dictionary<String, AnyObject> = self.configuration["background"] as? Dictionary<String, AnyObject> ?? [:]

lazy var fontConfiguration: Dictionary<String, AnyObject> = {
return self.labelConfiguration["font"] as? Dictionary<String, AnyObject> ?? [:]
}()
lazy var labelConfiguration: Dictionary<String, AnyObject> = self.configuration["label"] as? Dictionary<String, AnyObject> ?? [:]

lazy var effectConfiguration: Dictionary<String, AnyObject> = {
return self.configuration["effect"] as? Dictionary<String, AnyObject> ?? [:]
}()
lazy var fontConfiguration: Dictionary<String, AnyObject> = self.labelConfiguration["font"] as? Dictionary<String, AnyObject> ?? [:]

lazy var effectConfiguration: Dictionary<String, AnyObject> = self.configuration["effect"] as? Dictionary<String, AnyObject> ?? [:]
}

public class ThemeCaptionGroup {
@@ -289,13 +285,16 @@ public class ThemeCaption {
}

func appealButton(button: GRInputButton) {
let (image1, image2, image3) = self.images
let (image1, image2, image3) = self.backgroundImages
//assert(image1 != nil)
button.tintColor = UIColor.clearColor()
button.setBackgroundImage(image1, forState: .Normal)
button.setBackgroundImage(image2, forState: .Highlighted)
button.setBackgroundImage(image3, forState: .Selected)

let color = self.backgroundColor
button.backgroundColor = color

if let glyph = self.glyph {
assert(button.glyphView.superview == button)
button.glyphView.image = glyph
@@ -389,8 +388,8 @@ public class ThemeCaption {
return nil
}

func _images() -> (UIImage?, UIImage?, UIImage?) {
if let imageNames = self.attributeByGetter({ $0._imageNames() }, until: { $0!.count > 0 }) as? [String] {
func _backgroundImages() -> (UIImage?, UIImage?, UIImage?) {
if let imageNames = self.attributeByGetter({ $0._backgroundImageNames() }, until: { $0!.count > 0 }) as? [String] {
var images: [UIImage?] = []
for imageName in imageNames {
let image = self.trait.owner.imageForFilename(imageName, withTopMargin: self.topMargin)
@@ -408,7 +407,15 @@ public class ThemeCaption {
}
}

public lazy var images: (UIImage?, UIImage?, UIImage?) = self._images()
public lazy var backgroundImages: (UIImage?, UIImage?, UIImage?) = self._backgroundImages()

public lazy var backgroundColor: UIColor? = {
if let colorExpression = self.attributeByGetter({ $0.backgroundConfiguration["color"] }) as? String {
return UIColor(HTMLExpression: colorExpression)
} else {
return nil
}
}()

public lazy var text: String? = {
if let text = self.attributeByGetter({ $0.labelConfiguration["text"] }) as? String {
@@ -517,6 +524,8 @@ class CachedTheme: Theme {

class BuiltInTheme: Theme {
override func dataForFilename(name: String) -> NSData? {
return nil
/*
if let dataString: String = {
switch name {
case "landscape.json": return "ewogICAgIm5hbWUiOiAiYmx1ZXB1cnBsZSIsCgogICAgImJsdXIiOiBmYWxzZSwKICAgICJiYWNrZ3JvdW5kIjogImJnLnBuZyIsCiAgICAiZm9yZWdyb3VuZCI6ICJmb3JlZ3JvdW5kLnBuZyIsCgogICAgInF3ZXJ0eSI6IHsKICAgICAgICAiaW1hZ2UiOiBbInF3ZXJ0eS85cGF0Y2gucG5nOjoxMCAxMCAxMCAxMCIsICJxd2VydHkvc2VsZWN0ZWQucG5nOjoxMCAxMCAxMCAxMCJdLAogICAgICAgICJsYWJlbCI6IHsKICAgICAgICAgICAgImZvbnQiOiB7CiAgICAgICAgICAgICAgICAibmFtZSI6ICJBdmVuaXIgTGlnaHQiLAogICAgICAgICAgICAgICAgInNpemUiOiAxNSwKICAgICAgICAgICAgICAgICJjb2xvciI6ICIjZmZmIiwKICAgICAgICAgICAgfSwKICAgICAgICAgICAgInRleHQiOiBudWxsLAogICAgICAgICAgICAicG9zaXRpb24iOiBbMCwgMl0KICAgICAgICB9LAogICAgfSwKICAgICJxd2VydHktc2hpZnQiOiB7CiAgICAgICJsYWJlbCI6eyJnbHlwaCI6InF3ZXJ0eS1nbHlwaC80OHB4LXNoaWZ0LnBuZyIsfSx9LAogICAgInF3ZXJ0eS1nbG9iZSI6IHsKICAgICAgImxhYmVsIjp7ImdseXBoIjoicXdlcnR5LWdseXBoLzQwcHgtZ2xvYmUucG5nIix9LH0sCiAgICAicXdlcnR5LWRlbGV0ZSI6IHsKICAgICAgImxhYmVsIjp7ImdseXBoIjoicXdlcnR5LWdseXBoLzQ4cHgtZGVsZXRlLnBuZyIsfSx9LAoKICAgICJ0ZW5rZXkiOiB7CiAgICAgICAgImltYWdlIjogWyJxd2VydHkvOXBhdGNoLnBuZzo6MTAgMTAgMTAgMTAiLCAicXdlcnR5L3NlbGVjdGVkLnBuZzo6MTAgMTAgMTAgMTAiXSwKICAgICAgICAibGFiZWwiOiB7CiAgICAgICAgICAgICJmb250IjogewogICAgICAgICAgICAgICAgIm5hbWUiOiAiQXZlbmlyIExpZ2h0IiwKICAgICAgICAgICAgICAgICJzaXplIjogMTYsCiAgICAgICAgICAgICAgICAiY29sb3IiOiAiI2ZmZiIsCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgICJ0ZXh0IjogbnVsbCwKICAgICAgICAgICAgInBvc2l0aW9uIjogWzAsIDBdLAogICAgICAgIH0sCiAgICB9LAogICAgInRlbmtleS1zaGlmdCI6IHsKICAgICAgImxhYmVsIjp7ImdseXBoIjoicXdlcnR5LWdseXBoLzQ4cHgtc2hpZnQucG5nIix9LH0sCiAgICAidGVua2V5LWdsb2JlIjogewogICAgICAibGFiZWwiOnsiZ2x5cGgiOiJxd2VydHktZ2x5cGgvNDBweC1nbG9iZS5wbmciLH0sfSwKICAgICJ0ZW5rZXktZGVsZXRlIjogewogICAgICAibGFiZWwiOnsiZ2x5cGgiOiJxd2VydHktZ2x5cGgvNDhweC1kZWxldGUucG5nIix9LH0KfQ=="
@@ -550,6 +559,7 @@ class BuiltInTheme: Theme {
} else {
return nil
}
*/
}
}

0 comments on commit 732533c

Please sign in to comment.
You can’t perform that action at this time.