##!/usr/bin/env bash
## @author juntao
## @2021.11.30
#
## 不同的 hosted_url 似乎会造成 pubspec.lock 文件变更，https://github.com/dart-lang/pub/issues/2226
#export PUB_HOSTED_URL=https://pub.flutter-io.cn
#export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
#
#version=$(awk -v FS="versionName = " 'NF>1{print $2}' dependencies.gradle | sed "s/\"//g")
#versionCode=$(awk -v FS="versionCode = " 'NF>1{print $2}' dependencies.gradle | sed "s/\"//g")
#build_time=$(TZ=Asia/Shanghai date +'%Y-%m%d-%H%M')
#build_time_without_divider=$(TZ=Asia/Shanghai date +'%Y%m%d%H%M')L
#
#git checkout module_common/build.gradle
#git checkout gradle.properties
#
#if [[ "$OSTYPE" == "darwin"* ]]; then
#  sed -i '' '10 a setBinding(new Binding([gradle: this]))' settings.gradle
#  sed -i '' '11 a evaluate(new File(settingsDir, "assistant_flutter/.android/include_flutter.groovy"))' settings.gradle
#else
#  sed -i '10 a setBinding(new Binding([gradle: this]))' settings.gradle
#  sed -i '11 a evaluate(new File(settingsDir, "assistant_flutter/.android/include_flutter.groovy"))' settings.gradle
#fi
#
## 添加 -n 代表全局禁用深色模式
#while getopts "n" arg
#do
#	case ${arg} in
#		n)
#		  # 移除夜间颜色资源
#      rm -r app/src/main/res/values-night
#      rm -r app/src/main/res/drawable-night-xxxhdpi
#      rm -r app/src/main/res/drawable-night
#      rm -r app/src/main/res/drawable-night-nodpi
#      rm -r module_core/src/main/res/drawable-night-xxxhdpi
#      rm -r module_core/src/main/res/values-night
#      rm -r module_common/src/main/res/values-night
#      rm -r module_common/src/main/res/drawable-night-xxxhdpi
#      rm -r module_common/src/main/res/drawable-night-nodpi
#      rm -r module_common/src/main/res/drawable-night
#      sed -i 's/buildConfigField "boolean", "IS_DARK_MODE_ON", "true"/buildConfigField "boolean", "IS_DARK_MODE_ON", "false"/g' module_common/build.gradle
#		;;
#	esac
#done
#
#cd assistant_flutter
#
#flutter pub get
#
#cd ..
#
#./gradlew --stop
#./gradlew clean
#
#sed -i 's/buildConfigField "long", "BUILD_TIME", "0"/buildConfigField "long", "BUILD_TIME", '"\"${build_time_without_divider}\""'/g' module_common/build.gradle
#
#./gradlew rIR -I init.flutter.gradle
#if [ ! -f app/build/outputs/apk/internal/release/app-internal-release.apk ]; then
#    ./gradlew rIR -I init.gradle
#fi
#mv app/build/outputs/apk/internal/release/app-internal-release.apk app/build/tmp/${version}-${versionCode}-internal-${build_time}.apk
#
#git checkout module_common/build.gradle
#git checkout gradle.properties
#git checkout settings.gradle
#
#cd assistant_flutter
#git checkout pubspec.lock