#!/bin/bash

# Quick Dev Script - Fast rebuild and install

echo "🔄 Quick rebuild and install..."

# Check if emulator is running
if ! adb devices | grep -q "emulator"; then
    echo "⚠️  Эмулятор не запущен. Запускаю..."
    $ANDROID_HOME/emulator/emulator -avd Pixel_9_Pro_API_35 &
    adb wait-for-device
    
    # Wait for boot complete
    while [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" != "1" ]; do
        sleep 2
    done
fi

echo "📱 Эмулятор готов!"

# Fast install (no clean)
./gradlew installDebug --no-daemon

if [ $? -eq 0 ]; then
    echo "✅ Установлено!"
    
    # Auto-launch
    adb shell am start -n com.rosetta.messenger/.MainActivity
    
    echo ""
    echo "🎉 Приложение запущено!"
    echo "📝 Для просмотра логов: adb logcat | grep rosetta"
else
    echo "❌ Ошибка установки"
fi
