plugins {
    id "com.android.application"
    id "org.jetbrains.kotlin.android"
    id "kotlin-kapt"
    id "dagger.hilt.android.plugin"
    id "androidx.navigation.safeargs.kotlin"
}

def gitCommitHash = "git rev-parse --verify --short HEAD".execute().text.trim()
def keyProps = new Properties()
def keyPropsFile = rootProject.file("signature/keystore.properties")
if (keyPropsFile.exists()) {
    println("Loading keystore properties from ${keyPropsFile.absolutePath}")
    keyProps.load(new FileInputStream(keyPropsFile))
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "me.ash.reader"
        minSdk 26
        targetSdk 32
        versionCode 13
        versionName "0.8.3"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }

        javaCompileOptions {
            annotationProcessorOptions {
                arguments += [
                        "room.schemaLocation": "$projectDir/schemas".toString(),
                        "room.incremental"   : "true"
                ]
            }
        }
    }

    flavorDimensions "channel"
    productFlavors {
        fdroid {
            dimension "channel"
        }
        github {
            dimension "channel"
        }
    }
    signingConfigs {
        release {
            keyAlias keyProps["keyAlias"]
            keyPassword keyProps["keyPassword"]
            storeFile keyProps["storeFile"] ? file(keyProps["storeFile"]) : null
            storePassword keyProps["storePassword"]
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFileName = "ReadYou-${defaultConfig.versionName}-${gitCommitHash}.apk"
        }
    }
    kotlinOptions {
        freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose
    }
    packagingOptions {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {
    implementation "com.github.ireward:compose-html:1.0.2"

    // http://bigbadaboom.github.io/androidsvg/release_notes.html
    implementation "com.caverock:androidsvg-aar:$androidSVG"

    // https://github.com/mdewilde/opml-parser
    implementation "be.ceau:opml-parser:$opmlParser"

    // https://github.com/dankito/Readability4J
    implementation "net.dankito.readability4j:readability4j:$readability4j"

    // https://mvnrepository.com/artifact/com.rometools/rome
    implementation "com.rometools:rome:$rome"

    // https://coil-kt.github.io/coil/changelog/
    implementation("io.coil-kt:coil-base:$coil")
    implementation("io.coil-kt:coil-compose:$coil")
    implementation("io.coil-kt:coil-svg:$coil")
    implementation("io.coil-kt:coil-gif:$coil")

    implementation 'org.conscrypt:conscrypt-android:2.5.2'

    // https://square.github.io/okhttp/changelogs/changelog/
    implementation "com.squareup.okhttp3:okhttp:$okhttp"
    implementation "com.squareup.okhttp3:okhttp-coroutines-jvm:$okhttp"
    implementation "com.squareup.retrofit2:retrofit:$retrofit2"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit2"

    // https://developer.android.com/jetpack/androidx/releases/profileinstaller
    implementation "androidx.profileinstaller:profileinstaller:$profileinstaller"

    // https://developer.android.com/jetpack/androidx/releases/work
    implementation "androidx.work:work-runtime-ktx:$work"

    // https://developer.android.com/jetpack/androidx/releases/datastore
    implementation "androidx.datastore:datastore-preferences:$datastore"

    // https://developer.android.com/jetpack/androidx/releases/room
    implementation "androidx.room:room-paging:$room"
    implementation "androidx.room:room-common:$room"
    implementation "androidx.room:room-ktx:$room"
    kapt "androidx.room:room-compiler:$room"

    // https://developer.android.com/jetpack/androidx/releases/paging
    implementation "androidx.paging:paging-common:$paging"
    implementation "androidx.paging:paging-runtime:$paging"
    implementation "androidx.paging:paging-compose:1.0.0-alpha14"

    // https://developer.android.com/jetpack/androidx/releases/navigation
    implementation "androidx.navigation:navigation-compose:$navigation"

    // https://developer.android.com/jetpack/androidx/releases/lifecycle
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle"

    // https://developer.android.com/jetpack/androidx/releases/compose-material3
    implementation "androidx.compose.material3:material3:$material3"

    // https://github.com/google/accompanist/releases
    implementation "com.google.accompanist:accompanist-insets:$accompanist"
    implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist"
    implementation "com.google.accompanist:accompanist-pager:$accompanist"
    implementation "com.google.accompanist:accompanist-flowlayout:$accompanist"
    implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist"
    implementation "com.google.accompanist:accompanist-swiperefresh:$accompanist"

    // https://developer.android.com/jetpack/androidx/releases/compose-animation
    implementation "androidx.compose.animation:animation-graphics:$compose"
    // https://developer.android.com/jetpack/androidx/releases/compose-ui
    implementation "androidx.compose.ui:ui:$compose"
    implementation "androidx.compose.ui:ui-util:$compose"
    // https://developer.android.com/jetpack/androidx/releases/compose-material
    implementation "androidx.compose.material:material:$compose"
    implementation "androidx.compose.material:material-icons-extended:$compose"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose"
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose"

    // hilt
    implementation "androidx.hilt:hilt-work:1.0.0"
    implementation "com.google.dagger:hilt-android:2.40.5"
    kapt "com.google.dagger:hilt-android-compiler:2.40.5"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    implementation "androidx.hilt:hilt-navigation-compose:1.0.0"

    // android
    implementation "androidx.core:core-ktx:1.7.0"
    implementation "androidx.activity:activity-compose:1.4.0"
    testImplementation "junit:junit:4.13.2"
    androidTestImplementation "androidx.test.ext:junit:1.1.3"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
}
