#!/bin/bash

# Android代码迁移脚本：将android2的代码迁移到android

SOURCE_DIR="android2/app/src/main/java/com/xindazhou/app"
TARGET_DIR="android/app/src/main/java/com/narutohuo/xindazhou"

echo "开始迁移Android代码..."
echo "源目录: $SOURCE_DIR"
echo "目标目录: $TARGET_DIR"
echo ""
echo "⚠️  注意：包名将从 com.xindazhou.app 改为 com.narutohuo.xindazhou"
echo ""

# 1. 复制所有代码目录（排除MainActivity，需要特殊处理）
echo "1. 复制代码目录..."
rsync -av --exclude='MainActivity.kt' "$SOURCE_DIR/base" "$TARGET_DIR/"
rsync -av "$SOURCE_DIR/capability" "$TARGET_DIR/"
rsync -av "$SOURCE_DIR/common" "$TARGET_DIR/"
rsync -av "$SOURCE_DIR/community" "$TARGET_DIR/"
rsync -av "$SOURCE_DIR/service" "$TARGET_DIR/"
rsync -av "$SOURCE_DIR/user" "$TARGET_DIR/"
rsync -av "$SOURCE_DIR/vehicle" "$TARGET_DIR/"

# 2. 复制assets目录（如果有）
echo "2. 复制assets目录..."
if [ -d "android2/app/src/main/assets" ]; then
    mkdir -p "android/app/src/main/assets"
    rsync -av "android2/app/src/main/assets/" "android/app/src/main/assets/"
fi

# 3. 复制MainActivity（需要修改包名）
echo "3. 处理MainActivity..."
if [ -f "$SOURCE_DIR/MainActivity.kt" ]; then
    cp "$SOURCE_DIR/MainActivity.kt" "$TARGET_DIR/MainActivity.kt"
    # 修改包名
    sed -i '' 's/package com.xindazhou.app/package com.narutohuo.xindazhou/g' "$TARGET_DIR/MainActivity.kt"
fi

echo ""
echo "✅ 代码迁移完成！"
echo ""
echo "⚠️  接下来需要："
echo "   1. 批量修改所有文件的包名（从 com.xindazhou.app 改为 com.narutohuo.xindazhou）"
echo "   2. 更新build.gradle配置（依赖、权限等）"
echo "   3. 更新AndroidManifest.xml"
echo "   4. 在Android Studio中Sync Project"
