begin
  require 'rubygems'
  require 'irb/completion'
  require 'irb/ext/save-history'

  begin
    require 'awesome_print'
  rescue LoadError => e
    msg = ["Caught a LoadError: could not load 'awesome_print'",
          "#{e}",
          '',
          'Use bundler (recommended) or uninstall awesome_print.',
          '',
          '# Use bundler (recommended)',
          '$ bundle update',
          '$ bundle exec calabash-android console <path to apk>',
          '',
          '# Uninstall',
          '$ gem update --system',
          '$ gem uninstall -Vax --force --no-abort-on-dependent awesome_print']
    Kernel.puts msg
    exit(1)
  end

def reload!(print = true)
  Kernel.puts 'Reloading ...'
  # Main project directory.
  root_dir =  Dir.pwd
  Kernel.puts(root_dir)
  # Directories within the project that should be reloaded.
  reload_dirs = root_dir+'/features/android/pages'
  # Loop through and reload every file in all relevant project directories.
  Dir.glob(reload_dirs).each do |dir|
    Dir.glob(Dir.pwd+'/features/android/pages/*.rb').each { |f| load(f) }
    Kernel.puts(dir)
    init_android
  end
  # Return true when complete.
  true
end


  AwesomePrint.irb!

  ARGV.concat [ "--readline",
                "--prompt-mode",
                "simple" ]

  # 50 entries in the list
  IRB.conf[:SAVE_HISTORY] = 50

  # Store results in home directory with specified file name
  IRB.conf[:HISTORY_FILE] = ".irb-history"


  #These code loads all user's page description and step definitions for calabash-android 
  require 'calabash-android/defaults'
  require 'calabash-android/operations'
  ENV['PLATFORM'] = 'android'
  Kernel.puts(ENV['PLATFORM'])
  require 'require_all'
  require_all Dir.pwd+'/features/android/pages'
  init_android	
    #End of custom code 

rescue Exception => e
  Kernel.puts "Error loading Calabash irbrc: #{e}"
  exit(1)
end

module Calabash
  module Android
    module Operations
      def embed(*args)
        Kernel.puts "Embed is a Cucumber method and is not available in this console."
      end
    end
  end
end

module Cucumber
  class << self
    wants_to_quit = false
  end
end

extend Calabash::Android::Operations


def preferences
  Calabash::Android::Preferences.new
end

def disable_usage_tracking
  preferences.usage_tracking = "none"
  Kernel.puts "Calabash will not collect usage information."
  "none"
end

def enable_usage_tracking(level="system_info")
  preferences.usage_tracking = level
  Kernel.puts "Calabash will collect statistics using the '#{level}' rule."
  level
end

