<?xml version="1.0" encoding="utf-8"?>

<root xmlns:android="http://schemas.android.com/apk/res/android">
	<init>
		<!-- check if using Gradle -->
		<setBoolFromProperty result="bGradle" ini="Engine" section="/Script/AndroidRuntimeSettings.AndroidRuntimeSettings" property="bEnableGradle" default="false"/>
		<if condition="bGradle">
			<false>
				<log text="AntidoteSDK requires gradle integration!"/>
			</false>
		</if>
	</init>

	<resourceCopies>
		<copyFile src="$S(PluginDir)/../../Library/Android/antidote.aar" dst="$S(BuildDir)/libs/antidote.aar" />
	</resourceCopies>

	<buildGradleAdditions>
	<insert>
android {
	compileOptions {
		sourceCompatibility 1.8
		targetCompatibility 1.8
	}
}

task replaceImport {
	ant.replace(token:'import android.support.v13.app.FragmentCompat;', value:'import androidx.legacy.app.FragmentCompat;') {
		fileset(dir: '../permission_library/src/main/java/com/google/vr/sdk/samples/permission', includes: 'PermissionFragment.java')
	}
	ant.replace(token:'import android.support.v4.content.ContextCompat;', value:'import androidx.core.content.ContextCompat;') {
		fileset(dir: '../permission_library/src/main/java/com/google/vr/sdk/samples/permission', includes: 'PermissionHelper.java')
	}

	ant.replace(token:'import android.support.v4.app.NotificationCompat;', value:'import androidx.core.app.NotificationCompat;') {
		fileset(dir: 'src/main/java/com/google/android/vending/expansion/downloader/impl', includes: 'DownloadNotification.java')
	}

	ant.replace(token:'import android.support.v4.app.NotificationCompat;', value:'import androidx.core.app.NotificationCompat;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'LocalNotificationReceiver.java')
	}

	ant.replace(token:'import android.support.annotation.NonNull;', value:'import androidx.annotation.NonNull;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4/network', includes: 'NetworkChangedManager.java')
	}
	ant.replace(token:'import android.support.annotation.Nullable;', value:'import androidx.annotation.Nullable;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4/network', includes: 'NetworkChangedManager.java')
	}
	ant.replace(token:'import android.support.annotation.NonNull;', value:'import androidx.annotation.NonNull;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4/network', includes: 'NetworkConnectivityClient.java')
	}

	ant.replace(token:'import android.support.v4.app.NotificationManagerCompat;', value:'import androidx.core.app.NotificationManagerCompat;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'GameActivity.java')
	}

	ant.replace(token:'import android.support.v4.app.ActivityCompat;', value:'import androidx.core.app.ActivityCompat;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'SplashActivity.java')
	}
	ant.replace(token:'import android.support.v4.content.ContextCompat;', value:'import androidx.core.content.ContextCompat;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'SplashActivity.java')
	}

	ant.replace(token:'import android.support.v4.content.FileProvider;', value:'import androidx.core.content.FileProvider;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'GameActivity.java')
	}

	ant.replace(token:'import android.arch.lifecycle.Lifecycle;', value:'import androidx.lifecycle.Lifecycle;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'GameApplication.java')
	}
	ant.replace(token:'import android.arch.lifecycle.LifecycleObserver;', value:'import androidx.lifecycle.LifecycleObserver;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'GameApplication.java')
	}
	ant.replace(token:'import android.arch.lifecycle.OnLifecycleEvent;', value:'import androidx.lifecycle.OnLifecycleEvent;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'GameApplication.java')
	}
	ant.replace(token:'import android.arch.lifecycle.ProcessLifecycleOwner;', value:'import androidx.lifecycle.ProcessLifecycleOwner;') {
		fileset(dir: 'src/main/java/com/epicgames/ue4', includes: 'GameApplication.java')
	}
}

build.dependsOn replaceImport

dependencies {
	implementation files('src/main/libs/antidote.aar')
}
	</insert>
	</buildGradleAdditions>
	
	<gradleProperties>
		<insert>
			android.useAndroidX=true
			android.enableJetifier=true
		</insert>
	</gradleProperties>

	<gameActivityImportAdditions>
	<insert>
		import com.sekg.antidote.sdk.AntidoteSDK;
		import com.sekg.antidote.sdk.ValidationCallback;
	</insert>
	</gameActivityImportAdditions>
	
	<gameActivityClassAdditions>
	<insert>
		public void AndroidThunkJava_AntidoteSDK_showTouches() {
			AntidoteSDK.showTouches( this );
		}
		
		public void AndroidThunkJava_AntidoteSDK_validate() {
			AntidoteSDK.validate( this, isValid -> {
				AntidoteSDK_OnValidated( isValid );
			} );
		}
		
		public String AndroidThunkJava_AntidoteSDK_getUserId() {
			return AntidoteSDK.getUserId();
		}
		
		private static native void AntidoteSDK_OnValidated( boolean is_valid );
	</insert>
	</gameActivityClassAdditions>
</root>
