Browse files

adds 'BW::NetworkIndicator'

  • Loading branch information...
1 parent 841ddaa commit 07b49ee7f8abaacad86a8ff5ccca6751cf4aa351 @colinta colinta committed Mar 6, 2014
View
2 Rakefile
@@ -28,7 +28,7 @@ Motion::Project::App.setup do |app|
app.spec_files
if Motion::Project::App.osx?
app.spec_files -= Dir.glob("./spec/motion/**/ios/**.rb")
- ["font", "location", "media", "ui", "mail", "sms"].each do |package|
+ ["font", "location", "media", "ui", "mail", "sms", "network-indicator"].each do |package|
app.spec_files -= Dir.glob("./spec/motion/#{package}/**/*.rb")
end
else
View
2 lib/bubble-wrap/all.rb
@@ -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__)
}
View
8 lib/bubble-wrap/network-indicator.rb
@@ -0,0 +1,8 @@
+require 'bubble-wrap/loader'
+
+BubbleWrap.require_ios("network-indicator") do
+ BubbleWrap.require('motion/core/app.rb')
+ BubbleWrap.require('motion/network-indicator/**/*.rb') do
+ # file('motion/network-indicator/network-indicator.rb').depends_on('motion/network-indicator/result.rb')
+ end
+end
View
10 motion/http/query.rb
@@ -171,7 +171,15 @@ def did_receive_response(response)
def show_status_indicator(show)
if App.ios?
- UIApplication.sharedApplication.networkActivityIndicatorVisible = show
+ if defined?(BW::NetworkIndicator)
+ if show
+ BW::NetworkIndicator.show
+ else
+ BW::NetworkIndicator.hide
+ end
+ else
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = show
+ end
end
end
View
36 motion/network-indicator/network-indicator.rb
@@ -0,0 +1,36 @@
+module BubbleWrap
+ module NetworkIndicator
+
+ module_function
+
+ def show
+ self.counter += 1
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = true
+ end
+
+ def hide
+ self.counter = [self.counter - 1, 0].max
+ if self.counter == 0
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = false
+ end
+ end
+
+ def visible?
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?
+ end
+
+ def reset!
+ @counter = 0
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = false
+ end
+
+ def counter
+ @counter ||= 0
+ end
+
+ def counter=(value)
+ @counter = value
+ end
+
+ end
+end
View
58 spec/motion/network-indicator/network_indicator_spec.rb
@@ -0,0 +1,58 @@
+describe BW::NetworkIndicator do
+
+ after do
+ BW::NetworkIndicator.instance_variable_set(:@counter, 0)
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = false
+ end
+
+ it 'should show the indicator' do
+ BW::NetworkIndicator.show
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == true
+ end
+
+ it 'should hide the indicator' do
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.hide
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == false
+ end
+
+ it 'should keep track of how many times `show` was called' do
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.show
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == true
+ BW::NetworkIndicator.hide
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == true
+ BW::NetworkIndicator.hide
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == false
+ end
+
+ it 'should allow `hide` to be called too many times' do
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.hide
+ BW::NetworkIndicator.hide
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == false
+
+ BW::NetworkIndicator.hide
+ BW::NetworkIndicator.hide
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == false
+
+ BW::NetworkIndicator.show
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == true
+ end
+
+ it 'should reset the counter when `reset!` is called' do
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.reset!
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?.should == false
+ end
+
+ it 'should have `visible?` method' do
+ BW::NetworkIndicator.show
+ BW::NetworkIndicator.visible?.should == true
+ BW::NetworkIndicator.hide
+ BW::NetworkIndicator.visible?.should == false
+ end
+
+end

0 comments on commit 07b49ee

Please sign in to comment.