Module: BubbleWrap::NetworkIndicator

Defined in:
motion/network-indicator/network-indicator.rb

Constant Summary collapse

DELAY =
0.2

Class Method Summary collapse

Class Method Details

.counterObject



7
8
9
# File 'motion/network-indicator/network-indicator.rb', line 7

def counter
  @counter ||= 0
end

.hideObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'motion/network-indicator/network-indicator.rb', line 22

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

.reset!Object



61
62
63
64
# File 'motion/network-indicator/network-indicator.rb', line 61

def reset!
  @counter = 0
  self.update_spinner
end

.showObject



11
12
13
14
15
16
17
18
19
20
# File 'motion/network-indicator/network-indicator.rb', line 11

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

.update_spinnerObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'motion/network-indicator/network-indicator.rb', line 43

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

.update_spinner_timerObject



39
40
41
# File 'motion/network-indicator/network-indicator.rb', line 39

def update_spinner_timer
  update_spinner
end

.visible?Boolean



57
58
59
# File 'motion/network-indicator/network-indicator.rb', line 57

def visible?
  UIApplication.sharedApplication.networkActivityIndicatorVisible?
end