#!/bin/bash
LOCATION=$(dirname "$0")
source "$LOCATION"/../common_tools

set_animation_speed(){
  adb -s "$SELECTED_DEVICE" shell settings put global animator_duration_scale "$1"
  adb -s "$SELECTED_DEVICE" shell settings put global transition_animation_scale "$1"
  adb -s "$SELECTED_DEVICE" shell settings put global window_animation_scale "$1"
}

restore_animation_speed(){
  set_animation_speed 1
  echo "🔄 Animation speed restored to default \"1\""
}

android_choose_device
if [ -n "$1" ] 2> /dev/null ;then
  echo "🎬 Setting animation speed to \"$1\" (bigger is slower)..."
  set_animation_speed "$1"
else
  if [ "$(adb -s "$SELECTED_DEVICE" shell settings get global animator_duration_scale)" != "1" ] || [ "$(adb -s "$SELECTED_DEVICE" shell settings get global transition_animation_scale)" != "1" ] || [ "$(adb -s "$SELECTED_DEVICE" shell settings get global window_animation_scale)" != "1" ] ; then
    restore_animation_speed
  else
    echo "🎬 Setting animation speed to \"5\" (bigger is slower)..."
    set_animation_speed 5
  fi
fi
