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 #731 from edx/aleffert/badges-cleanup
Browse files Browse the repository at this point in the history
Badges cleanup
  • Loading branch information
aleffert committed May 16, 2016
2 parents c89bc17 + 29dba72 commit 884e581
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 14 deletions.
33 changes: 23 additions & 10 deletions Source/AccomplishmentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ class AccomplishmentView : UIView {
private let shareButton = UIButton()
private let textStack = TZStackView()

init(accomplishment: Accomplishment, shareAction: () -> Void) {
init(accomplishment: Accomplishment, shareAction: (() -> Void)?) {
super.init(frame: CGRectZero)
textStack.axis = .Vertical

// horizontal: imageView - textStack(stretches) - shareButton
addSubview(imageView)
addSubview(textStack)
addSubview(shareButton)
let sharing = shareAction != nil

if(sharing) {
addSubview(shareButton)
}
// vertical stack in the center
textStack.addArrangedSubview(title)
textStack.addArrangedSubview(detail)
Expand All @@ -42,7 +46,7 @@ class AccomplishmentView : UIView {
shareButton.contentEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
shareButton.setContentHuggingPriority(UILayoutPriorityRequired, forAxis: .Horizontal)
shareButton.oex_addAction({ _ in
shareAction()
shareAction?()
}, forEvents: .TouchUpInside)

imageView.snp_makeConstraints {make in
Expand All @@ -58,10 +62,17 @@ class AccomplishmentView : UIView {
make.bottom.lessThanOrEqualTo(self)
}

shareButton.snp_makeConstraints {make in
make.leading.equalTo(textStack.snp_trailing).offset(StandardHorizontalMargin)
make.centerY.equalTo(imageView)
make.trailing.equalTo(self)
if sharing {
shareButton.snp_makeConstraints {make in
make.leading.equalTo(textStack.snp_trailing).offset(StandardHorizontalMargin)
make.centerY.equalTo(imageView)
make.trailing.equalTo(self)
}
}
else {
textStack.snp_makeConstraints {make in
make.trailing.equalTo(self)
}
}

title.numberOfLines = 0
Expand Down Expand Up @@ -102,12 +113,13 @@ class AccomplishmentView : UIView {
class AccomplishmentsView : UIView {

private let stack = TZStackView()
private let shareAction: Accomplishment -> Void
private let shareAction: (Accomplishment -> Void)?

private var accomplishments: [Accomplishment] = []
private let paginationController: PaginationController<Accomplishment>

init(paginator: AnyPaginator<Accomplishment>, containingScrollView scrollView: UIScrollView, shareAction: Accomplishment -> Void) {
// If shareAction is nil then don't show sharing buttons
init(paginator: AnyPaginator<Accomplishment>, containingScrollView scrollView: UIScrollView, shareAction: (Accomplishment -> Void)?) {
self.shareAction = shareAction
paginationController = PaginationController(paginator: paginator, stackView: stack, containingScrollView: scrollView)

Expand All @@ -133,7 +145,8 @@ class AccomplishmentsView : UIView {
let action = shareAction
for accomplishment in newAccomplishments {
stack.addArrangedSubview(
AccomplishmentView(accomplishment: accomplishment) { action(accomplishment) })
AccomplishmentView(accomplishment: accomplishment, shareAction: action.map {f in { f(accomplishment) }})
)
}
accomplishments.appendContentsOf(newAccomplishments)
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Code/OEXDateFormatting.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ + (NSString*)formatAsMonthDayYearString:(NSDate*)date {
return nil;
}
NSDateFormatter* formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@" MMMM dd, yyyy "];
[formater setDateFormat:@"MMMM dd, yyyy "];
return [formater stringFromDate:date];
}

Expand Down
9 changes: 7 additions & 2 deletions Source/UserProfilePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protocol UserProfilePresenter: class {
}

class UserProfileNetworkPresenter : NSObject, UserProfilePresenter {
typealias Environment = protocol<OEXConfigProvider, DataManagerProvider, NetworkManagerProvider>
typealias Environment = protocol<OEXConfigProvider, DataManagerProvider, NetworkManagerProvider, OEXSessionProvider>

static let AccomplishmentsTabIdentifier = "AccomplishmentsTab"
private let profileFeed: Feed<UserProfile>
Expand All @@ -58,6 +58,10 @@ class UserProfileNetworkPresenter : NSObject, UserProfilePresenter {
profileFeed.refresh()
}

private var canShareAccomplishments : Bool {
return self.username == self.environment.session.currentUser?.username
}

lazy var tabStream: Stream<[ProfileTabItem]> = {
if self.environment.config.badgesEnabled {
// turn badges into accomplishments
Expand Down Expand Up @@ -94,11 +98,12 @@ class UserProfileNetworkPresenter : NSObject, UserProfilePresenter {
// turn accomplishments into the accomplishments tab
if accomplishments.count > 0 {
return {scrollView -> TabItem in
let view = AccomplishmentsView(paginator: paginator, containingScrollView: scrollView) {[weak self] in
let shareAction : Accomplishment -> Void = {[weak self] in
if let owner = self {
owner.delegate?.presenter(owner, choseShareURL:$0.shareURL)
}
}
let view = AccomplishmentsView(paginator: paginator, containingScrollView: scrollView, shareAction: self.canShareAccomplishments ? shareAction: nil)
return TabItem(
name: Strings.Accomplishments.title,
view: view,
Expand Down
7 changes: 6 additions & 1 deletion Source/UserProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class UserProfileViewController: UIViewController, UserProfilePresenterDelegate

typealias Environment = protocol<
OEXAnalyticsProvider,
OEXConfigProvider,
NetworkManagerProvider,
OEXRouterProvider
>
Expand Down Expand Up @@ -94,7 +95,11 @@ class UserProfileViewController: UIViewController, UserProfilePresenterDelegate
}

func presenter(presenter: UserProfilePresenter, choseShareURL url: NSURL) {
let controller = UIActivityViewController(activityItems: [url], applicationActivities: nil)
let message = Strings.Accomplishments.shareText(platformName:self.environment.config.platformName())
let controller = UIActivityViewController(
activityItems: [message, url],
applicationActivities: nil
)
self.presentViewController(controller, animated: true, completion: nil)
}
}
Expand Down
2 changes: 2 additions & 0 deletions Source/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"ACCESSIBILITY_VIDEO" = "Video";
/* Title of user profile section for user accomplishments (like badges) */
"ACCOMPLISHMENTS.TITLE" = "Accomplishments";
/* Default text template when user shares an accomplishment */
"ACCOMPLISHMENTS.SHARE_TEXT" = "I earned a badge on {platform_name}! Check it out";
/* Add a comment button title and place holder used in discussion comment text view */
"ADD_A_COMMENT"="Add a comment";
/* Add a response button title used in discussion's responses screen */
Expand Down
Binary file modified ...rseCatalogDetailViewControllerTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...rseCatalogDetailViewControllerTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...ts/edXTests.UserProfileViewTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...ts/edXTests.UserProfileViewTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 884e581

Please sign in to comment.