#!/bin/bash

TITLE="$1"

echo "Setting the application title  to $TITLE"

sed -i "s/android:label=\"[^\"]\+\"/android:label=\"$TITLE\"/"  android/app/src/main/AndroidManifest.xml

NAME_LENGTH="${#TITLE}"
LONG_NAME="$(( $NAME_LENGTH > 15))" # 1 if long name
BUNDLE_NAME="$(echo $TITLE | cut -c -15)"

perl -0777 -i -pe "s#\t<key>CFBundleName</key>\n[^\n]+#\t<key>CFBundleName</key>\n\t<string>$BUNDLE_NAME</string>#igs" ios/Runner/Info.plist

 if [ "$LONG_NAME" = "1" ] ; then
# todo : set bundleDisplayName
echo "Warning: name truncated to $BUNDLE_NAME"
fi

