Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #706 from edx/aleffert/badges-ui
Browse files Browse the repository at this point in the history
First part of badging UI changes
  • Loading branch information
aleffert committed Apr 12, 2016
2 parents 5c21b12 + a34a802 commit 7240e3a
Show file tree
Hide file tree
Showing 24 changed files with 454 additions and 234 deletions.
6 changes: 0 additions & 6 deletions Source/JSONFormBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ class JSONFormBuilder {

titleLabel.textAlignment = .Natural

let selectedAttributes = OEXTextStyle(weight: .Normal, size: .Small, color: OEXStyles.sharedStyles().neutralBlackT())
let unselectedAttributes = OEXTextStyle(weight: .Normal, size: .Small, color: OEXStyles.sharedStyles().neutralDark())
typeControl.setTitleTextAttributes(selectedAttributes.attributes, forState: .Selected)
typeControl.setTitleTextAttributes(unselectedAttributes.attributes, forState: .Normal)
typeControl.tintColor = OEXStyles.sharedStyles().primaryXLightColor()

descriptionLabel.textAlignment = .Natural
descriptionLabel.numberOfLines = 0
descriptionLabel.preferredMaxLayoutWidth = 200 //value doesn't seem to matter as long as it's small enough
Expand Down
15 changes: 9 additions & 6 deletions Source/LoadStateViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,20 @@ class LoadStateViewController : UIViewController {
self.messageView.attributedMessage = error.attributedDescriptionWithBaseStyle(self.messageStyle)
self.messageView.icon = info.icon ?? .UnknownError
}
else if let message = info.attributedMessage {
self.messageView.attributedMessage = message
self.messageView.icon = info.icon ?? .UnknownError
}
else if let message = info.message {
self.messageView.message = message
self.messageView.icon = info.icon ?? .UnknownError
}
else if let error = info.error where error.oex_isUnknownNetworkError {
self.messageView.message = Strings.courseContentUnknown
self.messageView.icon = info.icon ?? .UnknownError
}
else {
if let message = info.attributedMessage {
self.messageView.attributedMessage = message
}
else {
self.messageView.message = info.message ?? info.error?.localizedDescription
}
self.messageView.message = info.error?.localizedDescription
self.messageView.icon = info.icon ?? .UnknownError
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/OEXStyles+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension OEXStyles {
let styleAttributes = OEXTextStyle(weight: .Normal, size : .Small, color : self.neutralBlack()).attributes
UISegmentedControl.appearance().setTitleTextAttributes(styleAttributes, forState: UIControlState.Selected)
UISegmentedControl.appearance().setTitleTextAttributes(styleAttributes, forState: UIControlState.Normal)
UISegmentedControl.appearance().tintColor = self.neutralLight()
UISegmentedControl.appearance().tintColor = self.primaryXLightColor()

UINavigationBar.appearance().translucent = false

Expand Down
108 changes: 108 additions & 0 deletions Source/TabContainerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// TabContainerView.swift
// edX
//
// Created by Akiva Leffert on 4/5/16.
// Copyright © 2016 edX. All rights reserved.
//

import Foundation

// Simple tab view with a segmented control at the top
class TabContainerView : UIView {

struct Item {
let name : String
let view : UIView
let identifier : String
}

private let control = UISegmentedControl()

private let stackView = TZStackView()
private var activeTabBodyView : UIView? = nil

private var currentIdentifier : String?

override init(frame: CGRect) {
super.init(frame: frame)
stackView.insertArrangedSubview(control, atIndex: 0)
stackView.axis = .Vertical
stackView.alignment = .Fill
stackView.spacing = StandardVerticalMargin

addSubview(stackView)
stackView.snp_makeConstraints {make in
make.leading.equalTo(self.snp_leadingMargin)
make.trailing.equalTo(self.snp_trailingMargin)
make.top.equalTo(self.snp_topMargin)
make.bottom.equalTo(self.snp_bottomMargin)
}

control.oex_addAction({[weak self] control in
let index = (control as! UISegmentedControl).selectedSegmentIndex
self?.showTabAtIndex(index)
}, forEvents: .ValueChanged)
}

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

var items : [Item] = [] {
didSet {
control.removeAllSegments()

for (index, item) in items.enumerate() {
control.insertSegmentWithTitle(item.name, atIndex: control.numberOfSegments, animated: false)
if item.identifier == currentIdentifier {
showTabAtIndex(index)
}
}
if control.selectedSegmentIndex == UISegmentedControlNoSegment && items.count > 0 {
showTabAtIndex(0)
}
else {
currentIdentifier = nil
}

if items.count < 2 {
control.hidden = true
}
}
}

private func showTabAtIndex(index: Int) {
guard index != UISegmentedControlNoSegment else {
return
}

activeTabBodyView?.removeFromSuperview()

let item = items[index]
control.selectedSegmentIndex = index
currentIdentifier = item.identifier
stackView.addArrangedSubview(item.view)
activeTabBodyView = item.view
}

private func indexOfItemWithIdentifier(identifier : String) -> Int? {
return items.firstIndexMatching {$0.identifier == identifier }
}

func showTabWithIdentifier(identifier : String) {
if let index = indexOfItemWithIdentifier(identifier) {
showTabAtIndex(index)
}
}
}

// Only used for testing
extension TabContainerView {
func t_isShowingViewForItem(item : Item) -> Bool {
let viewsMatch = stackView.arrangedSubviews == [control, item.view]
let indexMatches = indexOfItemWithIdentifier(item.identifier) == control.selectedSegmentIndex
let identifierMatches = currentIdentifier == item.identifier
return viewsMatch && indexMatches && identifierMatches
}
}
Loading

0 comments on commit 7240e3a

Please sign in to comment.