tgios 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTY2MzY1YTFkNzVlNDMxOTIzN2I5Y2JmMWNlYTQ2MmQ1ZTI5NmZjMw==
4
+ NDgwMjVjYThlM2M3YzExYTRjNGE0NTMxMDVmNDBkNjRlNjcxMmY3Nw==
5
5
  data.tar.gz: !binary |-
6
- NzU2NzBiYTZjYjc4ZDc3OGU3MjE4ZjJhYTEyNjUzMTM1NTliYmU2ZQ==
6
+ NDliZjc4NTNiYWFjM2VkMWQ5YWZiNTBhMjJlNzE3OGI5MDcwMTg0Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzBiYTgzN2Y5ZTcwOGNhYmFhMDQzZTU4NGE5OTVlN2QzYTg3M2QyMjlhMDkw
10
- ZDVmMmJlNTAyNDJjNDlmMzIxN2FkZDE2ODA4NmVmOGE1ZDNkMjk1ZDBmOWU4
11
- NGFjOTliYzA3ZmVjMjE0NDNmZTEzNDYzMWU1NmRlNTllN2U0NTQ=
9
+ ZTk3ODVmNTZjZDg4NDYzMTdiOTZhYjJlMTUxMTkzOTA2NjIxM2M4NDFjYjc0
10
+ ODdkYTE2YmY1ZWMwMjkyODViYzYyYzBmYjRkYzU4ZmE2ZWEyZjg1NTQzM2Ex
11
+ M2QzZWJjYTQ4ZjA4MjE5OTVlMjg0NjY0YTlkZTg0NjNiOGU1NzQ=
12
12
  data.tar.gz: !binary |-
13
- Yjc4NWRmZTYyYzU1NzY1N2Q0YWJkNjQ3YjhiMWVjZDhiNGU5YjU3MjQ1NWRl
14
- YjNiYWZlMjRmNGRjMjNmNGQ0ZWUxMTUzZDEwMjQxN2UyMzJmYjA0ZDcxZmE1
15
- ZTE4YmE2NWYxZGIzNmEyZTI0MTAxOGU4ZmY2YzJlNjZjMWQ2MmE=
13
+ MTg5OWFjZDIyNGQ4NzgwYTQzZjRkOTUxM2E1ZWZmYmE4ODE5OWJiODQyMGRm
14
+ MDU2ZTJkMzJjYzRhZDgxZjI4ODE3NmMwYjRmNDY5NjdmOTJiMzZlNGRiMmVl
15
+ OTcwZjgxNWNkNTViOTkzNTI3ZTYwMzljYmQwYmMyOTk0ZDcwNzI=
@@ -0,0 +1,163 @@
1
+ module Tgios
2
+ class FakeBeacon
3
+ attr_accessor :proximityUUID, :major, :minor
4
+
5
+ def initialize(attributes)
6
+ attributes.each do |k, v|
7
+ k = :proximityUUID if k.to_s == 'uuid'
8
+ instance_variable_set("@#{k}", v)
9
+ end
10
+ end
11
+ end
12
+
13
+ class BeaconManager < BindingBase
14
+ attr_accessor :rssi
15
+
16
+ def self.default=(val)
17
+ @default = val
18
+ end
19
+
20
+ def self.default
21
+ @default
22
+ end
23
+
24
+ def initialize(uuid, rssi=-70)
25
+ @events = {}
26
+ @previous_beacons = []
27
+
28
+ @uuid = NSUUID.alloc.initWithUUIDString(uuid)
29
+ @rssi = rssi
30
+
31
+ @region = CLBeaconRegion.alloc.initWithProximityUUID(@uuid, identifier: uuid.split('-').first)
32
+ @region.notifyOnEntry = true
33
+ @region.notifyOnExit = true
34
+ @region.notifyEntryStateOnDisplay = true
35
+
36
+ start_monitor
37
+
38
+ UIApplicationWillEnterForegroundNotification.add_observer(self, 'on_enter_foreground:')
39
+ UIApplicationDidEnterBackgroundNotification.add_observer(self, 'on_enter_background:')
40
+ end
41
+
42
+ def on(event_key,&block)
43
+ @events[event_key] = block.weak!
44
+ self
45
+ end
46
+
47
+ def locationManager(manager, didDetermineState: state, forRegion: region)
48
+ NSLog "didDetermineState #{state}"
49
+ if state == CLRegionStateInside
50
+ location_manager.startRangingBeaconsInRegion(region)
51
+ end
52
+ end
53
+
54
+ def locationManager(manager, didEnterRegion: region)
55
+ NSLog 'didEnterRegion'
56
+ if region.isKindOfClass(CLBeaconRegion)
57
+ location_manager.startRangingBeaconsInRegion(region)
58
+ end
59
+ end
60
+
61
+ def locationManager(manager, didExitRegion: region)
62
+ NSLog 'didExitRegion'
63
+ if region.isKindOfClass(CLBeaconRegion)
64
+ location_manager.stopRangingBeaconsInRegion(region)
65
+ end
66
+ end
67
+
68
+ def locationManager(manager, didRangeBeacons: beacons, inRegion: region)
69
+ if has_event(:beacons_found)
70
+ @events[:beacons_found].call(beacons.select{|b| b.proximity != CLProximityUnknown && b.rssi >= @rssi})
71
+ end
72
+ if has_event(:beacon_found)
73
+ known_beacons = beacons.select{|b| b.proximity != CLProximityUnknown}.sort_by{|b| b.rssi}
74
+ if known_beacons.present?
75
+ beacon = known_beacons.last if known_beacons.last.rssi >= @rssi
76
+ beacon ||= known_beacons.last if known_beacons.length == 1 && known_beacons.last.rssi >= @rssi - 1
77
+ end
78
+
79
+ push_beacon(beacon)
80
+ @events[:beacon_found].call(@current_beacon)
81
+ end
82
+ end
83
+
84
+ def location_manager
85
+ @location_manager ||=
86
+ begin
87
+ manager = CLLocationManager.alloc.init
88
+ manager.delegate = self
89
+ manager
90
+ end
91
+ end
92
+
93
+ def start_monitor
94
+ location_manager.startMonitoringForRegion(@region)
95
+ location_manager.requestStateForRegion(@region)
96
+ end
97
+
98
+ def stop_monitor
99
+ location_manager.stopRangingBeaconsInRegion(@region)
100
+ location_manager.stopMonitoringForRegion(@region)
101
+ end
102
+
103
+ def on_enter_foreground(noti)
104
+ NSLog 'on_enter_foreground'
105
+ self.performSelector('start_monitor', withObject: nil, afterDelay:1)
106
+ end
107
+
108
+ def on_enter_background(noti)
109
+ NSLog 'on_enter_background'
110
+ stop_monitor
111
+ end
112
+
113
+ def has_event(event)
114
+ @events.has_key?(event)
115
+ end
116
+
117
+ def push_beacon(beacon)
118
+ if beacon_eqs(beacon, @current_beacon)
119
+ @current_beacon = beacon
120
+ else
121
+ if @previous_beacons.find { |b| !beacon_eqs(beacon, b) }.blank?
122
+ @current_beacon = beacon
123
+ else
124
+ @current_beacon = nil if @previous_beacons.find{ |b| beacon_eqs(@current_beacon, b)}.blank?
125
+ end
126
+ end
127
+ @previous_beacons << beacon
128
+ @previous_beacons.delete_at(0) if @previous_beacons.length > 3
129
+ end
130
+
131
+ def beacon_eqs(beacon1, beacon2)
132
+ self.class.beacon_eqs(beacon1, beacon2)
133
+ end
134
+
135
+ def self.beacon_eqs(beacon1, beacon2)
136
+ return beacon1 == beacon2 if beacon1.nil? || beacon2.nil?
137
+ beacon1.minor == beacon2.minor && beacon1.major == beacon2.major && beacon1.proximityUUID == beacon2.proximityUUID
138
+ end
139
+
140
+ def new_fake_beacon(options)
141
+ FakeBeacon.new({uuid: @uuid}.merge(options))
142
+ end
143
+
144
+ def self.supported
145
+ CLLocationManager.isRangingAvailable
146
+ end
147
+
148
+ def onPrepareForRelease
149
+ UIApplicationWillEnterForegroundNotification.remove_observer(self)
150
+ UIApplicationDidEnterBackgroundNotification.remove_observer(self)
151
+ stop_monitor
152
+ @location_manager = nil
153
+ @events = nil
154
+ @current_beacon = nil
155
+ @previous_beacons = nil
156
+ end
157
+
158
+ def dealloc
159
+ onPrepareForRelease
160
+ super
161
+ end
162
+ end
163
+ end
@@ -8,7 +8,7 @@ module Tgios
8
8
  end
9
9
 
10
10
  def on(event_name, &block)
11
- @events[event_name]=block
11
+ @events[event_name]=block.weak!
12
12
  end
13
13
 
14
14
  def off(*event_names)
@@ -8,7 +8,7 @@ module Tgios
8
8
  end
9
9
 
10
10
  def on(event, &block)
11
- @events[event]=block
11
+ @events[event]=block.weak!
12
12
  end
13
13
 
14
14
  def load
@@ -0,0 +1,44 @@
1
+ module Tgios
2
+ class ImagesCollectionViewBinding < UICollectionViewBinding
3
+ include PlasticCup
4
+ attr_accessor :image_collection_view, :image_views
5
+ def initialize(list, collection_view=nil, image_view_options={})
6
+ super
7
+ @image_collection_view = collection_view.nil? ? self.class.new_horizontal_collection_view : WeakRef.new(collection_view)
8
+ @image_views = self.class.new_image_views(list, image_view_options)
9
+
10
+ bind(@image_collection_view, @image_views)
11
+ end
12
+
13
+ def self.new_image_views(list, options={})
14
+ image_views = []
15
+ list.each do |item|
16
+ image_view = Base.style(UIImageView.new, {frame: [[0,0], [50, 50]],
17
+ contentMode: UIViewContentModeScaleAspectFill,
18
+ layer: {
19
+ borderWidth: 1,
20
+ borderColor: :gray.uicolor.CGColor
21
+ },
22
+ clipsToBounds: true}.merge(options))
23
+ CommonUIUtility.get_image(item) do |image|
24
+ image_view.image = image
25
+ end
26
+ image_views << image_view
27
+ end
28
+ image_views
29
+ end
30
+
31
+ def list=(new_list)
32
+ if new_list.is_a?(Array)
33
+ @image_views = self.class.new_image_views(new_list)
34
+ reload(@image_views)
35
+ end
36
+ end
37
+
38
+ def onPrepareForRelease
39
+ @image_collection_view = nil
40
+ @image_views = nil
41
+ end
42
+
43
+ end
44
+ end
@@ -1,22 +1,25 @@
1
1
  module Tgios
2
2
  class NSDateHelper
3
3
  def self.to_nsdate(date_string)
4
- @formatter ||= (
5
- @formatter = NSDateFormatter.new
6
- @formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
7
- @formatter.timeZone = NSTimeZone.timeZoneForSecondsFromGMT(0)
8
- @formatter
9
- )
10
- date = @formatter.dateFromString(date_string)
11
- if date.nil?
12
- @formatter2 ||= (
13
- @formatter2 = NSDateFormatter.new
14
- @formatter2.dateFormat = "yyyy-MM-dd HH:mm:ss"
15
- @formatter2.timeZone = NSTimeZone.timeZoneForSecondsFromGMT(0)
16
- @formatter2
4
+ if date_string.is_a?(String)
5
+ date_string = date_string.gsub(/\.\d*/, '') # remove mini-seconds
6
+ @formatter ||= (
7
+ @formatter = NSDateFormatter.new
8
+ @formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
9
+ @formatter.timeZone = NSTimeZone.timeZoneForSecondsFromGMT(0)
10
+ @formatter
17
11
  )
18
- date = @formatter2.dateFromString(date_string).utc
19
-
12
+ date = @formatter.dateFromString(date_string)
13
+ if date.nil?
14
+ @formatter2 ||= (
15
+ @formatter2 = NSDateFormatter.new
16
+ @formatter2.dateFormat = "yyyy-MM-dd HH:mm:ss"
17
+ @formatter2.timeZone = NSTimeZone.timeZoneForSecondsFromGMT(0)
18
+ @formatter2
19
+ )
20
+ date = @formatter2.dateFromString(date_string).utc
21
+ end
22
+ date
20
23
  else
21
24
  date.utc
22
25
  end
@@ -6,7 +6,7 @@ module Tgios
6
6
 
7
7
  def on(event_name, &block)
8
8
  raise ArgumentError.new("Event not found, valid events are: [#{Events.join(', ')}]") unless Events.include?(event_name)
9
- @events[event_name]=block
9
+ @events[event_name]=block.weak!
10
10
  self
11
11
  end
12
12
 
@@ -5,7 +5,7 @@ module Tgios
5
5
  end
6
6
 
7
7
  def on(event_name, &block)
8
- @events[event_name]= block
8
+ @events[event_name]= block.weak!
9
9
  self
10
10
  end
11
11
 
@@ -0,0 +1,78 @@
1
+ module Tgios
2
+ class UICollectionViewBinding < BindingBase
3
+ include PlasticCup
4
+
5
+ def initialize(*args)
6
+ super
7
+ @events={}
8
+ @events[:setup_cell]=->(cell, subview, index_path) { setup_cell(cell, subview, index_path) }
9
+ end
10
+
11
+ def on(event_name, &block)
12
+ @events[event_name]=block.weak!
13
+ self
14
+ end
15
+
16
+ def bind(collection_view, views=nil)
17
+ @collection_view = WeakRef.new(collection_view)
18
+ @collection_view.registerClass(UICollectionViewCell, forCellWithReuseIdentifier:'UICollectionViewCell')
19
+ @views = WeakRef.new(views) unless views.nil?
20
+ @collection_view.delegate = self
21
+ @collection_view.dataSource = self
22
+ self
23
+ end
24
+
25
+ def reload(views=nil)
26
+ @views = WeakRef.new(views) unless views.nil?
27
+ @collection_view.reloadData if @collection_view.weakref_alive?
28
+ end
29
+
30
+ def collectionView(collectionView, numberOfItemsInSection: section)
31
+ @views.count
32
+ end
33
+
34
+ def collectionView(collectionView, cellForItemAtIndexPath: indexPath)
35
+ cell = collectionView.dequeueReusableCellWithReuseIdentifier('UICollectionViewCell', forIndexPath:indexPath)
36
+ @events[:setup_cell].call(cell, view_at(indexPath), indexPath)
37
+ cell
38
+ end
39
+
40
+ def collectionView(collectionView, didSelectItemAtIndexPath: indexPath)
41
+ @events[:item_tapped].call(view_at(indexPath), indexPath.row) unless @events[:item_tapped].nil?
42
+ end
43
+
44
+ def scrollViewDidEndDecelerating(scrollView)
45
+ page = (scrollView.contentOffset.x / scrollView.frame.size.width).round
46
+ if page != @page
47
+ @page = page
48
+ @events[:page_changed].call(page) unless @events[:page_changed].nil?
49
+ end
50
+ end
51
+
52
+ def view_at(index_path)
53
+ @views[index_path.row]
54
+ end
55
+
56
+ def setup_cell(cell, subview, index_path)
57
+ cell.contentView.subviews.makeObjectsPerformSelector('removeFromSuperview')
58
+ cell.contentView.addSubview(subview)
59
+ end
60
+
61
+ def self.new_horizontal_collection_view(options={})
62
+ layout = Base.style(UICollectionViewFlowLayout.new,
63
+ {scrollDirection: UICollectionViewScrollDirectionHorizontal,
64
+ sectionInset:UIEdgeInsetsMake(0, 15, 0, 10)}.merge(options[:layout] || {}))
65
+ Base.style(UICollectionView.alloc.initWithFrame(CGRectZero, collectionViewLayout: layout),
66
+ {backgroundColor: :white.uicolor}.merge(options[:view] || {})
67
+ )
68
+ end
69
+
70
+ def onPrepareForRelease
71
+ @events=nil
72
+ @collection_view.delegate = nil
73
+ @collection_view.dataSource = nil
74
+ @collection_view = nil
75
+ @views = nil
76
+ end
77
+ end
78
+ end
@@ -5,7 +5,7 @@ module Tgios
5
5
  end
6
6
 
7
7
  def on(event_name, &block)
8
- @events[event_name]=block
8
+ @events[event_name]=block.weak!
9
9
  end
10
10
 
11
11
  def bind(picker_view, list: list, display_field: display_field)
@@ -17,7 +17,7 @@ module Tgios
17
17
  end
18
18
 
19
19
  def on(event_name, &block)
20
- @events[event_name]=block
20
+ @events[event_name]=block.weak!
21
21
  self
22
22
  end
23
23
 
@@ -62,7 +62,7 @@ module Tgios
62
62
  end
63
63
 
64
64
  def on(event_name, &block)
65
- @events[event_name]=block
65
+ @events[event_name]=block.weak!
66
66
  self
67
67
  end
68
68
 
@@ -27,7 +27,7 @@ module Tgios
27
27
  end
28
28
 
29
29
  def on(event_name, &block)
30
- @events[event_name]=block
30
+ @events[event_name]=block.weak!
31
31
  self
32
32
  end
33
33
 
@@ -70,7 +70,7 @@ module Tgios
70
70
  end
71
71
 
72
72
  def on(event, &block)
73
- @events[event]=block
73
+ @events[event]=block.weak!
74
74
  self
75
75
  end
76
76
 
@@ -48,7 +48,7 @@ module Tgios
48
48
  end
49
49
 
50
50
  def on(event, &block)
51
- @events[event]=block
51
+ @events[event]=block.weak!
52
52
  end
53
53
 
54
54
  #### options
data/lib/tgios/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tgios
2
- VERSION = '0.0.28'
2
+ VERSION = '0.0.29'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tgios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - April Tsang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-23 00:00:00.000000000 Z
12
+ date: 2014-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sugarcube
@@ -86,12 +86,14 @@ files:
86
86
  - app/app_delegate.rb
87
87
  - lib/tgios.rb
88
88
  - lib/tgios/animatable_view.rb
89
+ - lib/tgios/beacon_manager.rb
89
90
  - lib/tgios/binding_base.rb
90
91
  - lib/tgios/common_ui_utility.rb
91
92
  - lib/tgios/custom_method.rb
92
93
  - lib/tgios/extended_ui_table_view.rb
93
94
  - lib/tgios/extended_ui_view_controller.rb
94
95
  - lib/tgios/image_loader.rb
96
+ - lib/tgios/images_collection_view_binding.rb
95
97
  - lib/tgios/loading_indicator.rb
96
98
  - lib/tgios/model_errors_helper.rb
97
99
  - lib/tgios/ns_date_helper.rb
@@ -100,6 +102,7 @@ files:
100
102
  - lib/tgios/photo_upload.rb
101
103
  - lib/tgios/search_controller.rb
102
104
  - lib/tgios/ui_button_binding.rb
105
+ - lib/tgios/ui_collection_view_binding.rb
103
106
  - lib/tgios/ui_picker_view_list_binding.rb
104
107
  - lib/tgios/ui_table_view_list_binding.rb
105
108
  - lib/tgios/ui_table_view_model_binding.rb