apply plugin: 'com.android.application'

def secretsPropertiesFile = rootProject.file("secrets.properties")
def secretsProperties = new Properties()

if (secretsPropertiesFile.exists()) {
    secretsProperties.load(new FileInputStream(secretsPropertiesFile))
} else {
    secretsProperties.setProperty("LONDON_UNIFIED_TIMINGS_API_KEY", "${System.getenv('LONDON_UNIFIED_TIMINGS_API_KEY')}")
    secretsProperties.setProperty("ERROR_EMAIL_ADDRESS", "${System.getenv('ERROR_EMAIL_ADDRESS')}")
    secretsProperties.setProperty("ERROR_GITHUB_ISSUE_URL", "${System.getenv('ERROR_GITHUB_ISSUE_URL')}")
    secretsProperties.setProperty("PRIVACY_POLICY_URL", "${System.getenv('PRIVACY_POLICY_URL')}")
    secretsProperties.setProperty("QURAN_IMAGES_ZIP_URL", "${System.getenv('QURAN_IMAGES_ZIP_URL')}")
    secretsProperties.setProperty("QURAN_IMAGES_FOLDER_NAME", "${System.getenv('QURAN_IMAGES_FOLDER_NAME')}")
    secretsProperties.setProperty("CUSTOM_ADHAN_SOUNDS_FOLDER_NAME", "${System.getenv('CUSTOM_ADHAN_SOUNDS_FOLDER_NAME')}")
    secretsProperties.setProperty("SIGNING_KEYSTORE_FILE", "${System.getenv('SIGNING_KEYSTORE_FILE')}")
    secretsProperties.setProperty("SIGNING_KEYSTORE_PASSWORD", "${System.getenv('SIGNING_KEYSTORE_PASSWORD')}")
    secretsProperties.setProperty("SIGNING_KEY_PASSWORD", "${System.getenv('SIGNING_KEY_PASSWORD')}")
    secretsProperties.setProperty("SIGNING_KEY_ALIAS", "${System.getenv('SIGNING_KEY_ALIAS')}")
    secretsProperties.setProperty("GITHUB_TOKEN", "${System.getenv('GITHUB_TOKEN')}")
}

android {
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.hbouzidi.fiveprayers"
        minSdkVersion 16
        targetSdkVersion 33
        versionCode 41
        versionName "2.10.1"
        archivesBaseName = "$applicationId-v$versionCode($versionName)"

        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        // Required when setting minSdkVersion to 20 or lower
        multiDexEnabled true

        buildConfigField("String", "LONDON_UNIFIED_TIMINGS_API_KEY", secretsProperties['LONDON_UNIFIED_TIMINGS_API_KEY'])
        buildConfigField("String", "ERROR_EMAIL_ADDRESS", secretsProperties['ERROR_EMAIL_ADDRESS'])
        buildConfigField("String", "ERROR_GITHUB_ISSUE_URL", secretsProperties['ERROR_GITHUB_ISSUE_URL'])
        buildConfigField("String", "PRIVACY_POLICY_URL", secretsProperties['PRIVACY_POLICY_URL'])
        buildConfigField("String", "QURAN_IMAGES_ZIP_URL", secretsProperties['QURAN_IMAGES_ZIP_URL'])
        buildConfigField("String", "QURAN_IMAGES_FOLDER_NAME", secretsProperties['QURAN_IMAGES_FOLDER_NAME'])
        buildConfigField("String", "CUSTOM_ADHAN_SOUNDS_FOLDER_NAME", secretsProperties['CUSTOM_ADHAN_SOUNDS_FOLDER_NAME'])
    }

    signingConfigs {
        release {
            storeFile file("${secretsProperties['SIGNING_KEYSTORE_FILE']}")
            storePassword "${secretsProperties['SIGNING_KEYSTORE_PASSWORD']}"
            keyAlias "${secretsProperties['SIGNING_KEY_ALIAS']}"
            keyPassword "${secretsProperties['SIGNING_KEY_PASSWORD']}"
        }
    }

    buildTypes {
        debug {
            versionNameSuffix "-T"
        }
        release {
            versionNameSuffix "-R"

            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    testOptions {
        unitTests.returnDefaultValues = true
        unitTests.includeAndroidResources = true

        // Fix OutOfMemory errors
        unitTests {
            all {
                maxParallelForks = 2
                forkEvery = 80 // means only 80 tests will get ran in a single process,
                                // so they never hit the heap size.
                maxHeapSize = "2048m"
                minHeapSize = "1024m"
            }
        }
    }

    bundle {
        language {
            enableSplit = false
        }
    }
    buildFeatures {
        viewBinding true
    }
}

githubRelease {
    token "${secretsProperties['GITHUB_TOKEN']}"
    owner "five-Prayers"
    repo "five-prayers-android"
    tagName "${android.defaultConfig.versionName}"
    targetCommitish "main"
    releaseName "${android.defaultConfig.versionName}"
    draft false
    prerelease false
    releaseAssets "app/build/outputs/apk/release/${archivesBaseName}-release.apk"
    overwrite false
    dryRun false
    apiEndpoint "https://api.github.com"
    client
}

tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "androidx.work:work-runtime:2.8.1"
    implementation "androidx.work:work-rxjava3:2.8.1"
    implementation 'androidx.core:core:1.9.0'
    implementation 'androidx.media:media:1.6.0'
    implementation "androidx.preference:preference:1.2.0"
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.core:core-splashscreen:1.0.0'
    implementation group: 'com.grack', name: 'nanojson', version: '1.6'

    implementation 'com.google.dagger:dagger:2.33'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.33'

    //RxJava 3
    implementation "io.reactivex.rxjava3:rxjava:3.0.7"
    implementation "io.reactivex.rxjava3:rxandroid:3.0.0"

    //Retrofit 2
    implementation('com.squareup.retrofit2:retrofit') {
        exclude group: 'com.squareup.okhttp3', module: 'okhttp'
        version {
            strictly '2.9.0'
        }
    }

    implementation('com.squareup.retrofit2:converter-gson') {
        exclude group: 'com.squareup.okhttp3', module: 'okhttp'
        version {
            strictly '2.9.0'
        }
    }

    //noinspection GradleDependency --> do not update okhttp to keep supporting Android 4.4 users
    implementation("com.squareup.okhttp3:okhttp") {
        version {
            strictly '3.12.13'
        }
    }

    //noinspection GradleDependency --> do not update okhttp to keep supporting Android 4.4 users
    implementation("com.squareup.okhttp3:logging-interceptor") {
        version {
            strictly '3.12.13'
        }
    }

    //Apache Commons Lang
    implementation 'org.apache.commons:commons-lang3:3.10'

    //Circular Progress Bar: https://github.com/lopspower/CircularProgressBar
    implementation 'com.mikhaellopez:circularprogressbar:3.0.3'

    //Skeleton Layout: https://github.com/Faltenreich/SkeletonLayout
    implementation 'com.faltenreich:skeletonlayout:4.0.0'

    // https://github.com/evrencoskun/TableView
    implementation 'com.evrencoskun.library:tableview:0.8.9.4'

    //https://github.com/Gericop/Android-Support-Preference-V7-Fix
    implementation 'com.takisoft.preferencex:preferencex:1.1.0'

    //https://github.com/Cutta/GifView
    implementation 'com.github.Cutta:GifView:1.4'

    //https://github.com/travijuu/NumberPicker
    implementation 'com.github.travijuu:numberpicker:1.0.7'

    //https://github.com/kizitonwose/CalendarView
    implementation 'com.github.kizitonwose:CalendarView:1.0.4'

    //https://github.com/greenrobot/EventBus
    implementation 'org.greenrobot:eventbus:3.3.1'

    //https://github.com/AppIntro/AppIntro
    implementation 'com.github.AppIntro:AppIntro:6.2.0'

    //https://github.com/Ereza/CustomActivityOnCrash
    implementation 'cat.ereza:customactivityoncrash:2.3.0'

    //https://github.com/yarolegovich/LovelyDialog
    implementation 'com.yarolegovich:lovely-dialog:1.1.1'

    //https://github.com/batoulapps/adhan-java
    implementation 'com.batoulapps.adhan:adhan:1.2.1'

    //https://github.com/aminography/PrimeCalendar
    implementation 'com.aminography:primecalendar:1.7.0'

    //https://github.com/jesualex/sTooltip
    implementation 'com.github.luisvasquez:sTooltip:1.5.1'

    //https://github.com/owl-93/Determinate-Progress-View
    implementation 'com.github.owl-93.Determinate-Progress-View:release:v1.4.4'

    //https://github.com/intuit/ssp
    implementation 'com.intuit.ssp:ssp-android:1.1.0'

    implementation project(":compassqibla")

    //Testing
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'androidx.test:core:1.5.0'
    testImplementation 'androidx.work:work-testing:2.8.1'
    testImplementation 'org.mockito:mockito-core:4.5.1'
    testImplementation 'org.robolectric:robolectric:4.8.1'
    testImplementation 'org.threeten:threetenbp:1.6.0'

    //https://github.com/andrzejchm/RESTMock
    //noinspection GradleDependency --> depend on okhttp version.
    testImplementation('com.github.andrzejchm.RESTMock:android:0.3.2') {
        exclude module: 'okhttp'
    }
    testImplementation 'com.squareup.assertj:assertj-android:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

tasks.withType(Test) {
    testLogging {
        events TestLogEvent.FAILED,
                TestLogEvent.SKIPPED,
                TestLogEvent.STANDARD_ERROR,
                TestLogEvent.STANDARD_OUT
        exceptionFormat TestExceptionFormat.FULL
        showCauses true
        showExceptions true
        showStackTraces true
        showStandardStreams true
    }
}