Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from colinta/network_indicator
adds 'BW::NetworkIndicator'
- Loading branch information
Showing
9 changed files
with
330 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require File.expand_path('../loader', __FILE__) | ||
['core', 'http', 'reactor', 'rss_parser', 'ui', 'location', 'media', 'font', 'mail','sms'].each { |sub| | ||
['core', 'http', 'reactor', 'rss_parser', 'ui', 'location', 'media', 'font', 'mail','sms', 'network-indicator'].each { |sub| | ||
require File.expand_path("../#{sub}", __FILE__) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'bubble-wrap/loader' | ||
|
||
BubbleWrap.require_ios("network-indicator") do | ||
BubbleWrap.require('motion/core/app.rb') | ||
BubbleWrap.require('motion/network-indicator/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module BubbleWrap | ||
module NetworkIndicator | ||
DELAY = 0.2 | ||
|
||
module_function | ||
|
||
def counter | ||
@counter ||= 0 | ||
end | ||
|
||
def show | ||
if Dispatch::Queue.current.to_s == 'com.apple.main-thread' | ||
@counter = self.counter + 1 | ||
self.update_spinner | ||
else | ||
Dispatch::Queue.main.async do | ||
self.show | ||
end | ||
end | ||
end | ||
|
||
def hide | ||
if Dispatch::Queue.current.to_s == 'com.apple.main-thread' | ||
@counter = [self.counter - 1, 0].max | ||
if self.counter == 0 | ||
if @hide_indicator_timer | ||
@hide_indicator_timer.invalidate | ||
end | ||
@hide_indicator_timer = NSTimer.timerWithTimeInterval(DELAY - 0.01, target: self, selector: :update_spinner_timer, userInfo: nil, repeats: false) | ||
NSRunLoop.mainRunLoop.addTimer(@hide_indicator_timer, forMode:NSRunLoopCommonModes) | ||
end | ||
else | ||
Dispatch::Queue.main.async do | ||
self.hide | ||
end | ||
end | ||
end | ||
|
||
def update_spinner_timer | ||
update_spinner | ||
end | ||
|
||
def update_spinner | ||
if Dispatch::Queue.current.to_s == 'com.apple.main-thread' | ||
if @hide_indicator_timer | ||
@hide_indicator_timer.invalidate | ||
@hide_indicator_timer = nil | ||
end | ||
UIApplication.sharedApplication.networkActivityIndicatorVisible = (@counter > 0) | ||
else | ||
Dispatch::Queue.main.async do | ||
self.update_spinner | ||
end | ||
end | ||
end | ||
|
||
def visible? | ||
UIApplication.sharedApplication.networkActivityIndicatorVisible? | ||
end | ||
|
||
def reset! | ||
@counter = 0 | ||
self.update_spinner | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.