Skip to content

Commit

Permalink
Merge pull request #20 from ApolloZhu/master
Browse files Browse the repository at this point in the history
Fix #7 and #14
  • Loading branch information
Nightonke committed May 2, 2017
2 parents 86fe080 + c136fc3 commit ec33016
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 39 deletions.
60 changes: 60 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots

#Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
4 changes: 4 additions & 0 deletions VHGithubNotifier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
37CB06001E1C0CC700E9B924 /* VHGithubNotifierManager+ChartDataProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 37CB05FF1E1C0CC700E9B924 /* VHGithubNotifierManager+ChartDataProvider.m */; };
37E7CCFB1E5C576D00BA8BA9 /* VHStateView.m in Sources */ = {isa = PBXBuildFile; fileRef = 37E7CCFA1E5C576D00BA8BA9 /* VHStateView.m */; };
37E7CD011E5C5D2D00BA8BA9 /* VHStateView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 37E7CD001E5C5D2D00BA8BA9 /* VHStateView.xib */; };
5269F87E1EB7D1BC00BAF757 /* VHPieChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5269F87D1EB7D1BC00BAF757 /* VHPieChartView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -674,6 +675,7 @@
37E7CCF91E5C576D00BA8BA9 /* VHStateView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VHStateView.h; sourceTree = "<group>"; };
37E7CCFA1E5C576D00BA8BA9 /* VHStateView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VHStateView.m; sourceTree = "<group>"; };
37E7CD001E5C5D2D00BA8BA9 /* VHStateView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VHStateView.xib; sourceTree = "<group>"; };
5269F87D1EB7D1BC00BAF757 /* VHPieChartView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VHPieChartView.swift; sourceTree = "<group>"; };
A9FD0823EF354958CE567028 /* libPods-VHGithubNotifier.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VHGithubNotifier.a"; sourceTree = BUILT_PRODUCTS_DIR; };
F12D56CE52FBE25F772313B8 /* Pods-VHGithubNotifier.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VHGithubNotifier.release.xcconfig"; path = "Pods/Target Support Files/Pods-VHGithubNotifier/Pods-VHGithubNotifier.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -1322,6 +1324,7 @@
373EAB2A1E7031A0005B5E86 /* VHContributionChartView.h */,
373EAB2B1E7031A0005B5E86 /* VHContributionChartView.m */,
373EAB181E6EFE69005B5E86 /* VHVisualEffectView.swift */,
5269F87D1EB7D1BC00BAF757 /* VHPieChartView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -1745,6 +1748,7 @@
373187771E61D95200926F4F /* PieChartRenderer.swift in Sources */,
373BA70F1E6ABD6F00653C92 /* VHGithubNotifierManager+Trend.m in Sources */,
373187841E61D95200926F4F /* XAxisRendererHorizontalBarChart.swift in Sources */,
5269F87E1EB7D1BC00BAF757 /* VHPieChartView.swift in Sources */,
373187751E61D95200926F4F /* LineRadarRenderer.swift in Sources */,
3731872E1E61D95200926F4F /* CandleChartDataSet.swift in Sources */,
3731871C1E61D95200926F4F /* IMarker.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions VHGithubNotifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ - (void)showMenu
else
{
NOTIFICATION_POST(kNotifyWindowWillAppear);
NSRect statusItemFrame = [[self.statusItem.view window] convertRectToScreen:self.statusItem.view.frame];
[self.menuWindow updateArrowWithStatusItemCenterX:statusItemFrame.origin.x + statusItemFrame.size.width / 2
withStatusItemFrame:statusItemFrame];


[self.menuWindow updateArrowWithStatusItem:self.statusItem];

[self.menuWindow setAlphaValue:0.0];
[self.menuWindow makeKeyAndOrderFront:self];
[self.menuWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
[[NSAnimationContext currentContext] setDuration:0.15];
[[self.menuWindow animator] setAlphaValue:1.0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "VHGithubNotifierManager.h"
#import "VHGithubNotifier-Bridging-Header.h"
#import "VHGithubNotifier-Swift.h"

@interface VHGithubNotifierManager (ChartDataProvider)

Expand Down
2 changes: 1 addition & 1 deletion VHGithubNotifier/Model/VHRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Realm/Realm.h>
#import "VHRecord.h"
#import "VHGithubNotifier-Bridging-Header.h"
#import "VHGithubNotifier-Swift.h"

@interface VHRepository : RLMObject

Expand Down
2 changes: 1 addition & 1 deletion VHGithubNotifier/Utils/VHDateValueFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017年 黄伟平. All rights reserved.
//

#import "VHGithubNotifier-Bridging-Header.h"
#import "VHGithubNotifier-Swift.h"

@interface VHDateValueFormatter : NSObject<IChartAxisValueFormatter>

Expand Down
2 changes: 1 addition & 1 deletion VHGithubNotifier/Utils/VHUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2016年 黄伟平. All rights reserved.
//

#import "VHGithubNotifier-Bridging-Header.h"
#import "VHGithubNotifier-Swift.h"

@interface VHUtils : NSObject

Expand Down
13 changes: 8 additions & 5 deletions VHGithubNotifier/VC/VHPieVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "VHPieVC.h"
#import "AFURLSessionManager.h"
#import "VHGithubNotifier-Bridging-Header.h"
#import "VHGithubNotifier-Swift.h"
#import "VHGithubNotifierManager+ChartDataProvider.h"
#import "VHGithubNotifierManager+UserDefault.h"
#import "VHUtils.h"
Expand All @@ -17,7 +17,7 @@

@interface VHPieVC ()<ChartViewDelegate>

@property (nonatomic, strong) PieChartView *pieChart;
@property (nonatomic, strong) VHPieChartView *pieChart;
@property (weak) IBOutlet VHCursorButton *openUrlButton;
@property (nonatomic, strong) NSString *highlightedRepositoryName;

Expand All @@ -30,7 +30,7 @@ @implementation VHPieVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.pieChart = [[PieChartView alloc] initWithFrame:self.view.bounds];
self.pieChart = [[VHPieChartView alloc] initWithFrame:self.view.bounds];
self.pieChart.extraLeftOffset = 30;
self.pieChart.extraRightOffset = 30;
self.pieChart.highlightPerTapEnabled = YES;
Expand Down Expand Up @@ -74,10 +74,10 @@ - (void)onNotifyRepositoriesLoadedSuccessfully:(NSNotification *)notification
[self.pieChart notifyDataSetChanged];
[self.pieChart highlightValue:nil];
self.openUrlButton.hidden = YES;

// update total star number
[self updateCenterText];

// update description text
[self updateDescriptionText];

Expand Down Expand Up @@ -107,6 +107,7 @@ - (void)onNotifyTabInTabViewControllerChanged:(NSNotification *)notification

- (void)onNotifyMinimumStarNumberInPieChanged:(NSNotification *)notification
{
[[VHGithubNotifierManager sharedManager] updateUserRepositoriesPieData];
[self onNotifyRepositoriesLoadedSuccessfully:nil];
}

Expand All @@ -116,6 +117,7 @@ - (void)chartValueSelected:(ChartViewBase * _Nonnull)chartView entry:(ChartDataE
{
NSString *name = ((PieChartDataEntry *)entry).label;
self.highlightedRepositoryName = name;
self.pieChart.descriptionTextAlign = NSTextAlignmentRight;
self.pieChart.chartDescription.text = [NSString stringWithFormat:@"Visit %@ ", name];
self.openUrlButton.hidden = NO;
}
Expand Down Expand Up @@ -163,6 +165,7 @@ - (void)updateCenterText
- (void)updateDescriptionText
{
[self.openUrlButton setTop:self.pieChart.legend.neededHeight + 20];
self.pieChart.descriptionTextAlign = NSTextAlignmentCenter;
NSUInteger repositoryNumber = [[self.pieChart.data.dataSets firstObject] entryCount];
if (repositoryNumber == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion VHGithubNotifier/VC/VHTrendVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "VHGithubNotifierManager.h"
#import "VHGithubNotifierManager+UserDefault.h"
#import "VHGithubNotifierManager+Trend.h"
#import "VHGithubNotifier-Bridging-Header.h"
#import "VHGithubNotifier-Swift.h"
#import "VHDateValueFormatter.h"
#import "VHUtils.h"
#import <WebKit/WebKit.h>
Expand Down
52 changes: 52 additions & 0 deletions VHGithubNotifier/View/VHPieChartView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Extensions.swift
// VHGithubNotifier
//
// Created by Apollo Zhu on 4/30/17.
// Copyright © 2017 黄伟平. All rights reserved.
//

extension Description {

fileprivate var fontSize: CGFloat {
get {
return font.pointSize
}
set {
font = NSUIFont(name: font.fontName, size: newValue) ?? font
}
}

fileprivate var width: CGFloat {
return text!.size(attributes: [NSFontAttributeName:font]).width
}

}

@objc class VHPieChartView: PieChartView {

override func draw(_ rect: CGRect) {
if chartDescription?.textAlign == .center {
let max = bounds.width - chartDescription!.xOffset * 2
let cur = chartDescription!.width
if cur > max {
chartDescription!.fontSize *= max / cur
}

chartDescription!.position =
CGPoint(x: bounds.midX,
y: bounds.maxY
- legend.yOffset
- legend.neededHeight
- chartDescription!.yOffset
- chartDescription!.font.lineHeight
- 20)
} else {
chartDescription?.position = nil
}

super.draw(rect)
}

}

25 changes: 9 additions & 16 deletions VHGithubNotifier/View/VHVisualEffectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,21 @@
import Cocoa

@objc class VHVisualEffectView: NSVisualEffectView {

override init(frame frameRect: NSRect) {
self.tintColor = NSColor.init(red: 0, green: 0, blue: 0, alpha: 0);
super.init(frame:frameRect);
tintColor = .clear
super.init(frame:frameRect)
}

required init?(coder: NSCoder) {
self.tintColor = NSColor.init(red: 0, green: 0, blue: 0, alpha: 0);
super.init(coder: coder);
tintColor = .clear
super.init(coder: coder)
}

var tintColor: NSColor {
willSet {

}
didSet {
for sublayer: CALayer in self.layer!.sublayers! {
if sublayer.name == "ClearCopyLayer" {
sublayer.backgroundColor = tintColor.cgColor
break
}
}
layer?.sublayers?.first(where: { $0.name == "ClearCopyLayer" })?.backgroundColor = tintColor.cgColor
}
}

}
2 changes: 1 addition & 1 deletion VHGithubNotifier/Window/VHWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

- (instancetype)initWithStatusItem:(NSStatusItem *)statusBarButton withDelegate:(id<VHWindowProtocol>)delegate;

- (void)updateArrowWithStatusItemCenterX:(CGFloat)centerX withStatusItemFrame:(CGRect)statusItemFrame;
- (void)updateArrowWithStatusItem:(NSStatusItem *) statusItem;

@end
22 changes: 14 additions & 8 deletions VHGithubNotifier/Window/VHWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,25 @@ - (instancetype)initWithStatusItem:(NSStatusItem *)statusBarButton withDelegate:
return self;
}

- (void)updateArrowWithStatusItemCenterX:(CGFloat)centerX withStatusItemFrame:(CGRect)statusItemFrame;
- (void)updateArrowWithStatusItem:(NSStatusItem *) statusItem;
{
NSRect frame = self.frame;
frame.origin.x = centerX - self.frame.size.width / 2;
frame.origin.y = statusItemFrame.origin.y - [self frame].size.height - MENU_WINDOW_TOP_MARGIN;

if (frame.origin.x + frame.size.width > [[self screen] frame].size.width)
NSRect statusItemFrame = [[statusItem.view window] convertRectToScreen:statusItem.view.frame];
CGFloat centerX = statusItemFrame.origin.x + statusItemFrame.size.width / 2;

frame.origin.x = centerX - frame.size.width / 2;
frame.origin.y = statusItemFrame.origin.y - frame.size.height - MENU_WINDOW_TOP_MARGIN;
[self setFrame: frame display:NO];

const CGFloat OFFSET = [[self screen] frame].origin.x;

if (frame.origin.x + frame.size.width > OFFSET + [[self screen] frame].size.width)
{
frame.origin.x = [[self screen] frame].size.width - frame.size.width - MENU_WINDOW_RIGHT_MARGIN;
frame.origin.x = OFFSET + [[self screen] frame].size.width - frame.size.width - MENU_WINDOW_RIGHT_MARGIN;
}
if (frame.origin.x < 0)
if (frame.origin.x < OFFSET)
{
frame.origin.x = MENU_WINDOW_LEFT_MARGIN;
frame.origin.x = OFFSET + MENU_WINDOW_LEFT_MARGIN;
}

[self setFrame:frame display:NO];
Expand Down

0 comments on commit ec33016

Please sign in to comment.