import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    id 'com.google.devtools.ksp'
}

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

android {
    namespace "io.heckel.ntfy"
    compileSdkVersion 36

    defaultConfig {
        applicationId "io.heckel.ntfy"
        minSdkVersion 26
        targetSdkVersion 36

        versionCode 57
        versionName "1.22.1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        /* Required for Room schema migrations */
        ksp {
            arg("room.schemaLocation", "$projectDir/schemas")
        }

        buildFeatures {
            buildConfig true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            debuggable false
            // DEV/TEST ONLY: Uncomment this to test the release build with a debug key.
            //                This is required to test against the production Firebase config.
            // signingConfig signingConfigs.debug
        }
        debug {
            minifyEnabled false
            shrinkResources false
            debuggable true
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }
    }

    flavorDimensions "store"
    productFlavors {
        play {
            buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'true'
            buildConfigField 'boolean', 'RATE_APP_AVAILABLE', 'true'
            buildConfigField 'boolean', 'PAYMENT_LINKS_AVAILABLE', 'false' // Google Play Payments Policy, see #1463
        }
        fdroid {
            buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'false'
            buildConfigField 'boolean', 'RATE_APP_AVAILABLE', 'false'
            buildConfigField 'boolean', 'PAYMENT_LINKS_AVAILABLE', 'true'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlin {
        compilerOptions {
            jvmTarget = JvmTarget.JVM_17
            freeCompilerArgs = [
                '-Xjvm-default=all-compatibility' // https://stackoverflow.com/a/71234042/1440785
            ]
        }
    }
}

// Disables GoogleServices tasks for F-Droid variant
android.applicationVariants.all { variant ->
    def shouldProcessGoogleServices = variant.flavorName == "play"
    def googleTask = tasks.named("process${variant.name.capitalize()}GoogleServices").get()
    googleTask.enabled = shouldProcessGoogleServices
}

dependencies {
    // AndroidX, The Basics
    implementation "androidx.appcompat:appcompat:1.7.1"
    implementation "androidx.core:core-ktx:1.17.0"
    implementation "androidx.constraintlayout:constraintlayout:2.2.1"
    implementation "androidx.activity:activity-ktx:1.12.2"
    implementation "androidx.fragment:fragment-ktx:1.8.9"
    implementation "androidx.work:work-runtime-ktx:2.11.0"
    implementation 'androidx.preference:preference-ktx:1.2.1'

    // JSON serialization
    implementation 'com.google.code.gson:gson:2.13.2'

    // Room (SQLite)
    def room_version = "2.8.4"
    implementation "androidx.room:room-runtime:$room_version"
    ksp "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-ktx:$room_version"

    // OkHttp (HTTP library)
    implementation 'com.squareup.okhttp3:okhttp:5.3.2'

    // Firebase, sigh ... (only Google Play)
    playImplementation 'com.google.firebase:firebase-messaging:25.0.1'

    // RecyclerView
    implementation "androidx.recyclerview:recyclerview:1.4.0"

    // Swipe down to refresh
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0'

    // Material design
    implementation "com.google.android.material:material:1.13.0"

    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.10.0"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    // Image viewer
    implementation 'com.github.stfalcon-studio:StfalconImageViewer:1.0.1'

    // Glide (GIF support)
    def glide_version = "5.0.5"
    implementation "com.github.bumptech.glide:glide:$glide_version"
    ksp "com.github.bumptech.glide:ksp:$glide_version"

    // Better click handling for links
    implementation 'me.saket:better-link-movement-method:2.2.0'

    // Markdown
    implementation 'io.noties.markwon:core:4.6.2'
    implementation 'io.noties.markwon:image-picasso:4.6.2'
    implementation 'io.noties.markwon:image:4.6.2'
    implementation 'io.noties.markwon:linkify:4.6.2'
    implementation 'io.noties.markwon:ext-tables:4.6.2'
    implementation 'io.noties.markwon:ext-strikethrough:4.6.2'

    // Used by Markdown library, R8 complains if these are not here
    implementation "pl.droidsonroids.gif:android-gif-drawable:1.2.30"
    implementation "com.caverock:androidsvg:1.4"
}
