#!/bin/bash
# Come schermate-ios.sh, sull'emulatore: ./scripts/schermate-android.sh <seriale> <cartella>
# (APK installato con push + pm install, vedi docs/BUILD.md). L'orologio di
# Android esce «9:41» e il wifi col punto esclamativo: si incolla la striscia in
# alto (80 px telefono, 52 px tablet) di una schermata vecchia. Il tablet va
# messo in verticale: settings put system accelerometer_rotation 0 e user_rotation 1.
set -e
D=$1; OUT=$2; M="$(dirname "$0")/../maestro/schermate"
A="/opt/homebrew/share/android-commandlinetools/platform-tools/adb -s $D"
export JAVA_HOME=~/.jdks/jdk-17.0.20.1+1/Contents/Home
export PATH="/opt/homebrew/share/android-commandlinetools/platform-tools:$PATH"
$A shell settings put global sysui_demo_allowed 1
$A shell am broadcast -a com.android.systemui.demo -e command enter >/dev/null
$A shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 0941 >/dev/null
$A shell am broadcast -a com.android.systemui.demo -e command battery -e level 100 -e plugged false >/dev/null
$A shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false >/dev/null
# clearState di Maestro azzera anche la lingua dell'app: si pulisce prima, a mano
$A shell pm clear it.duebytes.spotthespy >/dev/null
$A shell cmd locale set-app-locales it.duebytes.spotthespy --user 0 --locales it-IT
~/.maestro/bin/maestro --device $D test "$M/vai-impostazioni-a.yaml"
sleep 1; $A exec-out screencap -p > "$OUT/02-impostazioni.png"
~/.maestro/bin/maestro --device $D test "$M/vai-luoghi-a.yaml"
sleep 2; $A exec-out screencap -p > "$OUT/06-luoghi.png"
