plugins {
	id 'com.android.application'
	id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
	androidResources {
		generateLocaleConfig = true
	}

	compileSdk 35
	defaultConfig {
		manifestPlaceholders = [oAuthScheme:"moshidon-android-auth"]
		archivesBaseName = "moshidon"
		applicationId "org.joinmastodon.android.moshinda"
		minSdk 23
		targetSdk 35
		versionCode 110
		versionName "2.11.9+fork.110.moshinda"
		testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
		testBuildType "screenshotsUiTest"
	}

	signingConfigs {
		nightly{
			storeFile = file("keystore/nightly_keystore.jks")
			storePassword System.getenv("SIGNING_STORE_PASSWORD")
			if (storePassword == null) {
				Properties properties = new Properties()
				properties.load(project.rootProject.file('local.properties').newDataInputStream())
				storePassword = properties.getProperty('SIGNING_STORE_PASSWORD')
			}
			keyAlias System.getenv("SIGNING_KEY_ALIAS")
			if (keyAlias == null) {
				Properties properties = new Properties()
				properties.load(project.rootProject.file('local.properties').newDataInputStream())
				keyAlias = properties.getProperty('SIGNING_KEY_ALIAS')
			}
			keyPassword System.getenv("SIGNING_KEY_PASSWORD")
			if (keyPassword == null) {
				Properties properties = new Properties()
				properties.load(project.rootProject.file('local.properties').newDataInputStream())
				keyPassword = properties.getProperty('SIGNING_KEY_PASSWORD')
			}
		}
	}

	buildTypes {
		release {
			minifyEnabled true
			shrinkResources true
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
		}
		debug{
			debuggable true
			versionNameSuffix '-debug'
			applicationIdSuffix '.debug'
			manifestPlaceholders = [oAuthScheme:"moshidon-android-debug-auth"]
		}
//		appcenterPrivateBeta{
//			initWith release
//			minifyEnabled false
//			shrinkResources false
//			versionNameSuffix "-priv-beta"
//		}
//		appcenterPublicBeta{
//			initWith release
//			versionNameSuffix "-beta"
//		}
		githubRelease{
			initWith release
			versionNameSuffix '-github'
		}
		nightly{
			if(System.getenv("CURRENT_DATE") != null){
				versionNameSuffix '-nightly+@' + System.getenv("CURRENT_DATE")
			} else {
				Properties properties = new Properties()
				properties.load(project.rootProject.file('local.properties').newDataInputStream())
				versionNameSuffix '-nightly+@' + properties.getProperty('CURRENT_DATE')
			}
			applicationIdSuffix '.nightly'

			signingConfig signingConfigs.nightly
			manifestPlaceholders = [oAuthScheme:"moshidon-android-nightly-auth"]
		}
		githubDebug{
			initWith debug
		}
		screenshotsUiTest{
			// Note: if Android Studio complains that "module not specified", select "screenshotsUiTest" in the "build variants" panel
			// None of this makes sense, I know. Google enjoys making developers suffer for no good reason.
			initWith debug
			debuggable false
		}
		fdroidRelease {
			initWith release
			// TODO: readd vcsinfo
			// vcsInfo.include true
			// The F-droid build system doesn't like this at all for some reason.
//			versionNameSuffix '-fdroid'
//			signingConfig signingConfigs.release
		}
	}
	compileOptions {
		sourceCompatibility JavaVersion.VERSION_17
		targetCompatibility JavaVersion.VERSION_17
		coreLibraryDesugaringEnabled true
	}
	sourceSets{
//		appcenterPrivateBeta{
//			setRoot "src/appcenter"
//		}
//		appcenterPublicBeta{
//			setRoot "src/appcenter"
//		}
		githubRelease{
			setRoot "src/github"
		}
		githubDebug{
			setRoot "src/github"
		}
	}
	lintOptions{
		checkReleaseBuilds false
		abortOnError false
	}
	buildFeatures{
		aidl true
		buildConfig true
	}
	dependenciesInfo{
		// Disables dependency metadata when building APKs.
		includeInApk false
		// Disables dependency metadata when building Android App Bundles.
		includeInBundle false
	}
	namespace 'org.joinmastodon.android'
}

dependencies {
	api 'androidx.annotation:annotation:1.3.0'
	implementation 'com.squareup.okhttp3:okhttp:3.14.9'
	implementation 'me.grishka.litex:recyclerview:1.2.1.1'
	implementation 'me.grishka.litex:swiperefreshlayout:1.2.0-beta01'
	implementation 'me.grishka.litex:browser:1.4.0'
	implementation 'me.grishka.litex:dynamicanimation:1.1.0-alpha03'
	implementation 'me.grishka.litex:viewpager:1.0.0'
	implementation 'me.grishka.litex:viewpager2:1.0.0'
	implementation 'me.grishka.litex:palette:1.0.0'
	implementation 'me.grishka.appkit:appkit:1.4.8'
	implementation 'com.google.code.gson:gson:2.8.9'
	implementation 'org.jsoup:jsoup:1.14.3'
	implementation 'com.squareup:otto:1.3.8'
	implementation 'de.psdev:async-otto:1.0.3'
	implementation 'com.google.zxing:core:3.5.3'
	implementation 'org.microg:safe-parcel:1.5.0'
	implementation 'org.parceler:parceler-api:1.1.12'
	annotationProcessor 'org.parceler:parceler:1.1.12'
	coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'

	// MOSHIDON: we don't do that here
//	def appCenterSdkVersion = "5.0.4"
//	appcenterPrivateBetaImplementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
//	appcenterPrivateBetaImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
//	appcenterPublicBetaImplementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
//	appcenterPublicBetaImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"

	androidTestImplementation 'androidx.test:core:1.5.0'
	androidTestImplementation 'androidx.test.ext:junit:1.1.5'
	androidTestImplementation 'androidx.test:runner:1.5.2'
	androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
