Class: Fastlane::Helper::AppiconHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/appicon/helper/appicon_helper.rb

Class Method Summary collapse

Class Method Details

.check_input_image_size(image, size) ⇒ Object



4
5
6
7
8
# File 'lib/fastlane/plugin/appicon/helper/appicon_helper.rb', line 4

def self.check_input_image_size(image, size)
  UI.user_error!("Minimum width of input image should be #{size}") if image.width < size
  UI.user_error!("Minimum height of input image should be #{size}") if image.height < size
  UI.user_error!("Input image should be square") if image.width != image.height
end

.get_needed_icons(devices, needed_icons, is_android = false, custom_sizes = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/appicon/helper/appicon_helper.rb', line 10

def self.get_needed_icons(devices, needed_icons, is_android = false, custom_sizes = {})
  icons = []
  devices.each do |device|
    needed_icons[device].each do |scale, sizes|
      sizes.each do |size|
        if size.kind_of?(Array)
          size, role, subtype = size
        end

        if is_android
          width, height = size.split('x').map { |v| v.to_f }
        else
          width, height = size.split('x').map { |v| v.to_f * scale.to_i }
        end

        icons << {
          'width' => width,
          'height' => height,
          'size' => size,
          'device' => device.to_s.gsub('_', '-'),
          'scale' => scale,
          'role' => role,
          'subtype' => subtype
        }
        
      end
    end
  end
  
  # Add custom icon sizes (probably for notifications) 
  custom_sizes.each do |path, size|
    path = path.to_s
    width, height = size.split('x').map { |v| v.to_f }

    icons << {
      'width' => width,
      'height' => height,
      'size' => size,
      'basepath' => File.dirname(path),
      'filename' => File.basename(path)
    }
  end
  
  # Sort from the largest to the smallest needed icon
  icons = icons.sort_by {|value| value['width']} .reverse
end