Sha256: 6f0d7c3d0a416002ca7d30b36294bdd6b1b747c398df7134325fad9d5d898c66

Contents?: true

Size: 1.69 KB

Versions: 14

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require 'oily_png'

module Headdesk
  module Checks
    module Teak
      #
      # Check to make sure that an APK, which uses Teak, has an API 21+ icon.
      #
      class Api21Icon
        include Checks::Teak::APK

        check_name 'api21_icon'
        describe 'Check for API 21+ Teak icons'
        # :reek:NilCheck and :reek:UncommunicativeVariableName { accept: ['icon_v21'] }
        def call
          skip_check if: -> { apk.min_sdk 21 }

          icon = apk.resources
                    .values(v: 20)
                    .drawable.io_teak_small_notification_icon
          icon_v21 = apk.resources
                        .values(v: 21)
                        .drawable.io_teak_small_notification_icon
          export icon: icon, icon_v21: icon_v21

          describe "APK contains a drawable for 'io_teak_small_notification_icon'"
          fail_check if: -> { icon.nil? || icon_v21.nil? }

          describe "'io_teak_small_notification_icon' for v21 is different from < v21"
          fail_check unless: -> { icon != icon_v21 }

          resolutions = [['drawable-mdpi', 24], ['drawable-hdpi', 36], ['drawable-xhdpi', 48],
                         ['drawable-xxhdpi', 72], ['drawable-xxxhdpi', 96]]
          resolutions.each do |rname, size|
            resource_file = icon_v21.sub('@drawable', "res/#{rname}") + '.png'
            fail_check unless: -> { apk.resources.file?(resource_file) }

            describe "'#{resource_file}' is #{size}x#{size}"
            image = ChunkyPNG::Image.from_file(apk.resources.path_for(resource_file))
            fail_check unless: -> { size == image.width && size == image.height }
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
headdesk-0.17.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.16.2 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.16.1 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.16.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.15.1 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.15.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.14.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.13.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.12.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.11.3 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.11.2 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.11.1 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.11.0 lib/headdesk/checks/teak/api21_icon.rb
headdesk-0.10.0 lib/headdesk/checks/teak/api21_icon.rb