apply plugin: 'com.android.application'

android {
    namespace 'nl.hnogames.domoticz'
    compileSdk 35

    def versionPropsFile = file('version.properties')
    if (versionPropsFile.canRead()) {
        Properties versionProps = new Properties()
        versionProps.load(new FileInputStream(versionPropsFile))
        def value = 0
        def runTasks = gradle.startParameter.taskNames

        println "****************************"
        println "runTasks: ${gradle.startParameter.taskNames}"
        if ('assembleRelease' in runTasks || 'aR' in runTasks || ':app:compilePaidReleaseSources' in runTasks || ':app:generatePaidReleaseSources' in runTasks || ':app:assemblePaidRelease' in runTasks || ':app:compileoottReleaseSources' in runTasks || ':app:generateoottReleaseSources' in runTasks || ':app:assembleoottRelease' in runTasks) {
            value = 1
            println "Build Version: +1"
        }
        if ('bundleRelease' in runTasks || 'aR' in runTasks || ':app:compilePaidReleaseSources' in runTasks || ':app:generatePaidReleaseSources' in runTasks || ':app:bundlePaidRelease' in runTasks || ':app:compileoottReleaseSources' in runTasks || ':app:generateoottReleaseSources' in runTasks || ':app:bundleoottRelease' in runTasks) {
            value = 1
            println "Build Version: +1"
        }

        println "****************************"
        def versionMajor = 0
        def versionMinor = 2

        def versionPatch = versionProps['VERSION_PATCH'].toInteger() + value
        def versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
        def version_Code = versionProps['VERSION_CODE'].toInteger() + value

        versionProps['VERSION_PATCH'] = versionPatch.toString()
        versionProps['VERSION_BUILD'] = versionBuild.toString()
        versionProps['VERSION_CODE'] = version_Code.toString()

        versionProps.store(versionPropsFile.newWriter(), null)

        defaultConfig {
            versionCode version_Code
            versionName "${versionMajor}.${versionMinor}.${versionPatch} (${versionBuild})"
            minSdkVersion 24
            targetSdkVersion 35
            multiDexEnabled true
            wearAppUnbundled true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        incremental = false
    }

    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = true
        }
        abi {
            enableSplit = true
        }
    }

    //noinspection GroovyAssignabilityCheck
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            lintOptions {
                disable 'MissingTranslation'
                checkReleaseBuilds false
                abortOnError false
            }
        }
    }

    flavorDimensions "tier"
    productFlavors {
        free {
            applicationId 'nl.hnogames.domoticz'
            resValue "string", "APK_VALIDATE_DEBUG", "$System.env.APK_VALIDATE_DEBUG"
            resValue "string", "APK_VALIDATE_PROD", "$System.env.APK_VALIDATE_PROD"
            resValue "string", "APK_LICENSE_PREMIUM", "$System.env.APK_LICENSE_PREMIUM"

            resValue "string", "ADMOB_COMP_KEY", "$System.env.ADMOB_COMP_KEY"
            resValue "string", "ADMOB_APP_KEY", "$System.env.ADMOBAPPKEY"
            resValue "string", "ADMOB_ADS_KEY", "$System.env.ADMOBADSKEY"

            resValue "string", "analiticsapikey", "$System.env.GOOGLE_ANALITICS_ID"
            resValue "string", "google_maps_key", "$System.env.GOOGLEAPIKEY"
            resValue "string", "revenuecat_apikey", "$System.env.REVENUECATKEY"
            resValue "string", "app_name_domoticz", 'Domoticz'
            buildConfigField "boolean", "NEW_VERSION", "true"
            buildConfigField "boolean", "PAID_OOTT", "false"
            dimension "tier"
        }
        paid {
            applicationId 'nl.hnogames.domoticz.premium'

            resValue "string", "APK_VALIDATE_DEBUG", "$System.env.APK_VALIDATE_DEBUG"
            resValue "string", "APK_VALIDATE_PROD", "$System.env.APK_VALIDATE_PROD"
            resValue "string", "APK_LICENSE_PREMIUM", "$System.env.APK_LICENSE_PREMIUM"

            resValue "string", "ADMOB_COMP_KEY", "$System.env.ADMOB_COMP_KEY"
            resValue "string", "ADMOB_APP_KEY", "$System.env.ADMOBAPPKEY"
            resValue "string", "ADMOB_ADS_KEY", "$System.env.ADMOBADSKEY"
            resValue "string", "revenuecat_apikey", "$System.env.REVENUECATKEY"

            resValue "string", "analiticsapikey", "$System.env.GOOGLE_ANALITICS_ID"
            resValue "string", "google_maps_key", "$System.env.GOOGLEAPIKEY"
            resValue "string", "app_name_domoticz", 'Domoticz Premium'
            buildConfigField "boolean", "NEW_VERSION", "false"
            buildConfigField "boolean", "PAID_OOTT", "false"
            dimension "tier"
        }
        oott {
            applicationId 'nl.hnogames.oott'

            resValue "string", "APK_VALIDATE_DEBUG", "$System.env.APK_VALIDATE_OOTT_DEBUG"
            resValue "string", "APK_VALIDATE_PROD", "$System.env.APK_VALIDATE_OOTT_PROD"
            resValue "string", "APK_LICENSE_PREMIUM", "$System.env.APK_LICENSE_OOTT"

            resValue "string", "ADMOB_COMP_KEY", "$System.env.ADMOB_COMP_KEY"
            resValue "string", "ADMOB_APP_KEY", "$System.env.ADMOBAPPKEY"
            resValue "string", "ADMOB_ADS_KEY", "$System.env.ADMOBADSKEY"
            resValue "string", "revenuecat_apikey", "$System.env.REVENUECATKEY"

            resValue "string", "analiticsapikey", "$System.env.GOOGLE_ANALITICS_ID"
            resValue "string", "google_maps_key", "$System.env.GOOGLEAPIKEY"

            resValue "string", "app_name_domoticz", 'OOTT'
            buildConfigField "boolean", "NEW_VERSION", "false"
            buildConfigField "boolean", "PAID_OOTT", "true"
            dimension "tier"
        }
    }

    afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }
    }


}

repositories {
    maven {
        url "https://jitpack.io"
    }
}

allprojects {
    repositories {
        google()
        maven {
            url "https://maven.google.com"
        }
        maven { url "https://jitpack.io" }
    }
}

//noinspection GroovyAssignabilityCheck
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    wearApp project(':wear')

    implementation "com.android.billingclient:billing:8.0.0"

    implementation 'androidx.core:core:1.16.0'
    implementation "androidx.work:work-runtime:2.10.2"
    implementation 'androidx.preference:preference:1.2.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.7.1'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.4.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.biometric:biometric:1.1.0'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
    implementation 'androidx.annotation:annotation:1.9.1'
    implementation "androidx.car.app:app:1.4.0"
    implementation 'org.reactivestreams:reactive-streams:1.0.4'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
    implementation 'com.revenuecat.purchases:purchases:8.20.0'

    implementation 'androidx.room:room-runtime:2.7.2'
    annotationProcessor 'androidx.room:room-compiler:2.7.2'

    implementation 'com.google.firebase:firebase-core:21.1.1'
    implementation 'com.google.firebase:firebase-iid:21.1.0'
    implementation 'com.google.firebase:firebase-analytics:22.2.0'
    implementation 'com.google.firebase:firebase-crashlytics:19.4.0'
    implementation "com.google.firebase:firebase-messaging:24.1.0"
    implementation "com.google.firebase:firebase-ads:23.6.0"

    implementation 'com.google.android.ads.consent:consent-library:1.0.8'
    implementation "com.google.android.gms:play-services-analytics:18.1.1"
    implementation "com.google.android.gms:play-services-wearable:19.0.0"
    implementation "com.google.android.gms:play-services-maps:19.0.0"
    implementation "com.google.android.gms:play-services-gcm:17.0.0"
    implementation "com.google.android.gms:play-services-location:21.3.0"
    implementation "com.google.android.gms:play-services-places:17.1.0"
    implementation "com.google.android.gms:play-services-ads:23.6.0"
    implementation 'com.google.android.ads.consent:consent-library:1.0.8'
    implementation "com.github.nisrulz:recyclerviewhelper:27.1.1"
    implementation "org.altbeacon:android-beacon-library:2.21.1"

    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
    implementation('com.github.ihsanbal:LoggingInterceptor:3.0.0') {
        exclude group: 'org.json', module: 'json'
    }

    implementation 'com.google.guava:guava:33.4.8-android'
    implementation 'com.github.alxrm:animated-clock-icon:1.0.2'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.google.code.gson:gson:2.13.1'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'

    implementation 'com.github.zurche:plain-pie:v0.2.9'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

    implementation 'com.github.hotchemi:android-rate:1.0.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar'
    implementation 'me.dm7.barcodescanner:zxing:1.9.8'
    implementation 'com.github.jd-alexander:LikeButton:0.2.3'
    implementation 'com.github.javiersantos:PiracyChecker:1.1'
    implementation 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar'
    implementation 'com.alexvasilkov:gesture-views:2.8.3'

    implementation 'com.github.rubengees:easy-header-footer-adapter:3.0.0@aar'

    implementation("com.mikepenz:materialdrawer:6.1.3@aar") {
        transitive = true
    }

    implementation 'com.github.stfalcon:chatkit:0.3.3'
    implementation ('com.adevinta.android:leku:12.0.0') {
        exclude group: 'com.google.android.gms'
        exclude group: 'androidx.appcompat'
    }
    implementation 'com.github.k0shk0sh:PermissionHelper:1.1.1'
    implementation 'com.github.zagum:SpeechRecognitionView:1.2.2'
    implementation "com.github.skydoves:colorpickerview:2.3.0"
    implementation 'com.github.paolorotolo:appintro:v5.1.0'
    implementation 'com.52inc:scoops:1.0.0'
    implementation 'com.isupatches:wisefy:4.0.0'

    implementation project(':libs:MemorizingTrustManager')
    implementation project(path: ':SeekArc_library')
    implementation project(path: ':domoticzapi')
    implementation project(path: ':materialList')

    constraints {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
            because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
        }
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
            because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
        }
    }
}

buildscript {
    repositories {
        mavenCentral()
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
