motion-assets-library 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +45 -0
- data/lib/motion-assets-library.rb +8 -0
- data/lib/project/assets_library.rb +6 -0
- data/lib/project/assets_library/asset_wrapper.rb +35 -0
- data/lib/project/assets_library/loader.rb +84 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3633cf26f6c7037696ca2ec5601588fd14d94a80
|
4
|
+
data.tar.gz: 00b355138600626ccba4df0bbd200d4771b26ba6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2415865906e9841d62c0ad0425ea562a5cca6c5efd7e82f20cb36becd6eb449a8f43598ba2088b68004b8d2aec7eabb39175deb90c9e6b875d51b833284ba1f
|
7
|
+
data.tar.gz: 7adf72433abdbc6f84a0fc4c78561366b13f90f0b6c842c840b99842fe67ffb7b63ee1c57ea9674564d22e5f51abbf1ef363cdbc9421b6e1352b7c20bc05d33d
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# motion-assets-library
|
2
|
+
|
3
|
+
Access iOS media via ALAssetsLibrary
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Instantiate a loader and set a delegate:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
Motion::AssetsLibrary::Loader.new.tap do |loader|
|
11
|
+
loader.delegate = self
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
Implement the delegate method:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
def did_load_assets(assets)
|
19
|
+
self.assets = assets
|
20
|
+
|
21
|
+
colletion_view.reloadData
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
## Setup
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
gem 'motion-assets-library'
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install motion-assets-library
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
@@ -0,0 +1,8 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise 'This file must be required within a RubyMotion project Rakefile.'
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, 'project/**/*.rb')))
|
8
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Motion
|
2
|
+
class AssetsLibrary
|
3
|
+
class AssetWrapper
|
4
|
+
attr_accessor :asset
|
5
|
+
|
6
|
+
def initialize(asset)
|
7
|
+
self.asset = asset
|
8
|
+
end
|
9
|
+
|
10
|
+
def asset_url
|
11
|
+
asset.valueForProperty('ALAssetPropertyAssetURL')
|
12
|
+
end
|
13
|
+
|
14
|
+
def thumbnail
|
15
|
+
asset.thumbnail
|
16
|
+
end
|
17
|
+
|
18
|
+
def filename
|
19
|
+
default_representation.filename
|
20
|
+
end
|
21
|
+
|
22
|
+
def cgi_image
|
23
|
+
default_representation.CGImageWithOptions(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def type
|
27
|
+
asset.valueForProperty('ALAssetPropertyType')
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_representation
|
31
|
+
asset.defaultRepresentation
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class Motion
|
2
|
+
class AssetsLibrary
|
3
|
+
class Loader
|
4
|
+
attr_accessor :delegate, :observer
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
listen_to_asset_library
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_assets
|
11
|
+
assets_library.enumerateGroupsWithTypes(
|
12
|
+
ALAssetsGroupSavedPhotos,
|
13
|
+
usingBlock: album_block,
|
14
|
+
failureBlock: album_failure_block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset_assets
|
18
|
+
@_assets = []
|
19
|
+
|
20
|
+
load_assets
|
21
|
+
end
|
22
|
+
|
23
|
+
def assets
|
24
|
+
@_assets ||= []
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def listen_to_asset_library
|
30
|
+
self.observer = notification_center.addObserver(
|
31
|
+
WeakRef.new(self),
|
32
|
+
selector: 'asset_library_did_change:',
|
33
|
+
name: ALAssetsLibraryChangedNotification,
|
34
|
+
object: nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
def asset_library_did_change(notification)
|
38
|
+
reset_assets
|
39
|
+
end
|
40
|
+
|
41
|
+
def dealloc
|
42
|
+
notification_center.removeObserver(observer)
|
43
|
+
end
|
44
|
+
|
45
|
+
def album_block
|
46
|
+
lambda { |group, stop| group.enumerateAssetsUsingBlock(asset_block) if group }
|
47
|
+
end
|
48
|
+
|
49
|
+
def album_failure_block
|
50
|
+
lambda { |error| p "Error: #{error[0].description}" }
|
51
|
+
end
|
52
|
+
|
53
|
+
def asset_block
|
54
|
+
lambda do |asset, index, stop|
|
55
|
+
if asset
|
56
|
+
add_asset(asset)
|
57
|
+
else
|
58
|
+
notify_load
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def notify_load
|
64
|
+
unless delegate.respondsToSelector 'did_load_assets:'
|
65
|
+
raise DelegateMethodUnimplemented, 'did_load_assets: must be implemented'
|
66
|
+
end
|
67
|
+
|
68
|
+
delegate.did_load_assets(assets)
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_asset(asset)
|
72
|
+
assets << AssetsLibrary::AssetWrapper.new(asset)
|
73
|
+
end
|
74
|
+
|
75
|
+
def assets_library
|
76
|
+
@_assets_library ||= ALAssetsLibrary.alloc.init
|
77
|
+
end
|
78
|
+
|
79
|
+
def notification_center
|
80
|
+
NSNotificationCenter.defaultCenter
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-assets-library
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Devon Blandin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Easy access to iOS media assets via ALAssetsLibrary
|
28
|
+
email:
|
29
|
+
- dblandin@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/motion-assets-library.rb
|
36
|
+
- lib/project/assets_library/asset_wrapper.rb
|
37
|
+
- lib/project/assets_library/loader.rb
|
38
|
+
- lib/project/assets_library.rb
|
39
|
+
homepage: https://github.com/dblandin/motion-assets-library
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.0.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Easy access to iOS media assets via ALAssetsLibrary
|
63
|
+
test_files: []
|