# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:android)

platform :android do
  desc "Runs all the tests"
  lane :test do
    gradle(task: "test")
  end

  desc "Submit a new Beta Build to Crashlytics Beta"
  lane :beta do
    gradle(task: "clean assembleRelease")
    crashlytics
  
    # sh "your_script.sh"
    # You can also use other beta testing services here
  end

  desc "Deploy a new version to the Google Play"
  lane :deploy do
    gradle(task: "clean assembleRelease")
    upload_to_play_store
  end

  lane :screenshots do
      # To run from terminal: fastlane screenshots
      # Build the debug and AndroidTest packages so they are available for screenshots
      gradle(
          task: "assembleDebug assembleDebugAndroidTest"
      )

      # Dynamically locate APKs
      app_apk = Dir.glob(File.expand_path("../app/build/outputs/apk/debug/com.aisleron-*-debug.apk")).first
      tests_apk = Dir.glob(File.expand_path("../app/build/outputs/apk/androidTest/debug/com.aisleron-*-debug-androidTest.apk")).first

      # Take light mode screenshots
      screengrab(
          output_directory: "fastlane/screenshots/light-mode",
          device_type: "phone",
          locales: ["en-US"],
          app_package_name: "com.aisleron.debug",
          use_tests_in_packages: ["com.aisleron.screenshots"],
          test_instrumentation_runner: "com.aisleron.di.KoinInstrumentationTestRunner",
          use_timestamp_suffix: false,
          app_apk_path: app_apk,
          tests_apk_path: tests_apk,
          skip_open_summary: true
      )

      # Take dark mode screenshots
      screengrab(
          output_directory: "fastlane/screenshots/dark-mode",
          device_type: "phone",
          locales: ["en-US"],
          app_package_name: "com.aisleron.debug",
          use_tests_in_packages: ["com.aisleron.screenshots"],
          test_instrumentation_runner: "com.aisleron.di.KoinInstrumentationTestRunner",
          use_timestamp_suffix: false,
          app_apk_path: app_apk,
          tests_apk_path: tests_apk,
          skip_open_summary: true,
          launch_arguments: ["uiMode dark"]
      )
  end
end
