plugins {
	id "com.android.application"
	id "kotlin-android"
	id "kotlin-parcelize"

	id "com.mikepenz.aboutlibraries.plugin"
}

def isFullVariant = getGradle().getStartParameter().getTaskRequests().any { request ->
	request.args.any { it.contains("Full") }
}
if(isFullVariant) {
	apply plugin: "com.google.gms.google-services"
	apply plugin: "com.google.firebase.crashlytics"
	
	apply plugin: "com.google.android.libraries.mapsplatform.secrets-gradle-plugin"
	
	secrets {
		propertiesFileName "secrets.properties"
		defaultPropertiesFileName = "secrets.default.properties"
	}
}

//Load shared keystore
def sharedKeystoreFile = rootProject.file("signingshared/shared.keystore")

//Load keystore
def keystorePropertiesFile = rootProject.file(".signing/keystore.properties")
def keystoreProperties = null
if(keystorePropertiesFile.exists()) {
	keystoreProperties = new Properties()
	keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
	signingConfigs {
		if(sharedKeystoreFile.exists()) {
			shared {
				storeFile sharedKeystoreFile
				storePassword "android"
				keyAlias "androiddebugkey"
				keyPassword "android"
			}
		}

		if(keystoreProperties) {
			release {
				storeFile new File(keystorePropertiesFile.parentFile, keystoreProperties["storeFile"])
				storePassword keystoreProperties["storePassword"]
				keyAlias keystoreProperties["keyAlias"]
				keyPassword keystoreProperties["keyPassword"]
			}
		}
	}
	compileSdkVersion 31
	defaultConfig {
		applicationId "me.tagavari.airmessage"
		minSdkVersion 23
		targetSdkVersion 31
		versionName "3.5.2"
		versionCode 140
		
		resConfigs "en", "fr", "ja"
		
		testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
	}
	buildTypes {
		debug {
			ext.enableCrashlytics = false

			applicationIdSuffix ".debug"
			versionNameSuffix "-DEBUG"

			resValue "string", "applicationId", "me.tagavari.airmessage.debug"

			//Use shared, or default to debug if unavailable
			if(sharedKeystoreFile.exists()) {
				signingConfig signingConfigs.shared
			}
		}
		release {
			//minifyEnabled true
			//shrinkResources true

			//proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"

			resValue "string", "applicationId", "me.tagavari.airmessage"

			if(keystoreProperties) {
				signingConfig signingConfigs.release
			}
		}
	}
	lintOptions {
		abortOnError false
	}

	flavorDimensions "distribution"
	productFlavors {
		full {
			dimension "distribution"
		}

		foss {
			dimension "distribution"
			versionNameSuffix "-fdroid"
		}
	}

	packagingOptions {
		resources {
			excludes += ["META-INF/DEPENDENCIES", "META-INF/LICENSE"]
		}
	}
	testOptions {
		unitTests.includeAndroidResources = true

	}
	compileOptions {
		coreLibraryDesugaringEnabled true
		sourceCompatibility JavaVersion.VERSION_11
		targetCompatibility JavaVersion.VERSION_11
	}
	kotlinOptions {
		jvmTarget = JavaVersion.VERSION_11.toString()
	}
	androidResources {
		noCompress 'tflite'
	}
}

dependencies {
	coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"

	//implementation fileTree(include: ["*.jar"], dir: "libs")
	testImplementation "junit:junit:4.13.2"
	testImplementation "com.google.truth:truth:1.1.2"
	testImplementation "com.google.truth.extensions:truth-java8-extension:1.1.2"
	testImplementation "androidx.test:core:1.4.0"
	testImplementation "org.mockito:mockito-core:3.6.28"

	androidTestImplementation "androidx.test.ext:truth:1.4.0"
	androidTestImplementation "androidx.test:runner:1.4.0"
	androidTestImplementation "androidx.test:rules:1.4.0"

	//Android extensions
	implementation "androidx.core:core-ktx:1.8.0"
	implementation "androidx.activity:activity-ktx:1.4.0"
	implementation "androidx.fragment:fragment-ktx:1.4.1"
	implementation "androidx.preference:preference-ktx:1.2.0"
	implementation "androidx.browser:browser:1.4.0"
	implementation "androidx.exifinterface:exifinterface:1.3.3"
	implementation "androidx.security:security-crypto:1.0.0"

	//Material components
	implementation "com.google.android.material:material:1.6.1"

	//Android architecture components
	def lifecycle_version = "2.4.1"

	// ViewModel
	implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
	// LiveData
	implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
	// Lifecycles only (without ViewModel or LiveData)
	implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

	//WorkManager
	def work_version = "2.7.1"
	implementation "androidx.work:work-runtime-ktx:$work_version"
	implementation "androidx.work:work-rxjava3:$work_version"

	//ReactiveX
	implementation "io.reactivex.rxjava3:rxandroid:3.0.0"
	implementation "io.reactivex.rxjava3:rxjava:3.1.3"
	implementation "io.reactivex.rxjava3:rxkotlin:3.0.1"

	//Layouts and views
	implementation "androidx.constraintlayout:constraintlayout:2.1.4"
	implementation "androidx.viewpager2:viewpager2:1.0.0"
	implementation "com.google.android.flexbox:flexbox:3.0.0"
	
	implementation "nl.dionsegijn:konfetti-xml:2.0.2"
	implementation "com.github.chrisbanes:PhotoView:2.3.0"

	//ML Kit
	fullImplementation "com.google.mlkit:smart-reply:17.0.1"

	//Firebase
	fullImplementation platform("com.google.firebase:firebase-bom:30.2.0")

	fullImplementation "com.google.firebase:firebase-core"
	fullImplementation "com.google.firebase:firebase-messaging-ktx"
	fullImplementation "com.google.firebase:firebase-auth-ktx"
	fullImplementation "com.google.firebase:firebase-analytics-ktx"
	fullImplementation "com.google.firebase:firebase-crashlytics-ktx"

	//GMS
	fullImplementation "com.google.android.gms:play-services-maps:18.0.2"
	fullImplementation "com.google.android.gms:play-services-location:20.0.0"
	fullImplementation "com.google.android.gms:play-services-auth:20.2.0"

	//CameraX
	def camerax_version = "1.1.0-rc02"
	implementation "androidx.camera:camera-camera2:$camerax_version"
	implementation "androidx.camera:camera-lifecycle:$camerax_version"
	implementation "androidx.camera:camera-view:$camerax_version"

	//About libraries
	implementation "com.mikepenz:aboutlibraries-core:$aboutlibs_version"
	implementation "com.mikepenz:aboutlibraries:$aboutlibs_version"

	//Tools
	implementation "com.googlecode.ez-vcard:ez-vcard:0.11.3"
	implementation "org.commonmark:commonmark:0.18.1"

	//Backend
	implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
	implementation "org.bouncycastle:bcprov-jdk15to18:1.69"

	implementation "com.github.bumptech.glide:glide:4.12.0"
	implementation "jp.wasabeef:glide-transformations:4.3.0"

	implementation "com.google.android.exoplayer:exoplayer-core:2.18.0"
	implementation "com.google.android.exoplayer:exoplayer-ui:2.18.0"

	implementation "org.jsoup:jsoup:1.15.1"

	implementation project(":android-smsmms")

	implementation "org.java-websocket:Java-WebSocket:1.5.3"
	implementation "com.otaliastudios:transcoder:0.10.4"
}

repositories {
	maven {
		url "https://maven.google.com"
		// Alternative URL is "https://dl.google.com/dl/android/maven2/"
	}
	maven {
		url "https://jitpack.io"
	}
}
