/*
 * Copyright (c) 2017 Nam Nguyen, nam@ene.im
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'com.android.application'
apply plugin: 'com.getkeepsafe.dexcount'

def haveFabricApiKey = !propOrDef("toro_yt_fabric_api_key", "").isEmpty()
if (haveFabricApiKey) {
  apply plugin: 'io.fabric'
}

android {
  signingConfigs {
    release {
      keyAlias "debug"
      keyPassword "android"
      storeFile file("debug.jks")
      storePassword "android"
    }

    debug {
      keyAlias "debug"
      keyPassword "android"
      storeFile file("debug.jks")
      storePassword "android"
    }
  }

  compileSdkVersion rootProject.ext.androidVersion

  defaultConfig {
    applicationId "im.ene.toro.youtube"
    minSdkVersion rootProject.ext.demoMinSDK //rootProject.ext.minSupportSDKVersion
    targetSdkVersion rootProject.ext.androidVersion
    versionCode releaseVersionCode
    versionName "v" + releaseVersion
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    vectorDrawables.useSupportLibrary = true
    buildConfigField("String", "API_KEY", "\"${toro_youtube_apikey}\"")

    manifestPlaceholders += ["fabric_api_key": propOrDef("toro_yt_fabric_api_key", "")]
    ext.enableCrashlytics = false

    multiDexEnabled true
  }

  buildTypes {
    release {
      signingConfig signingConfigs.release
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }

    debug {
      applicationIdSuffix ".debug"
      signingConfig signingConfigs.debug
      // multiDexEnabled true
      minifyEnabled false
    }
  }

  packagingOptions {
    exclude 'META-INF/services/javax.annotation.processing.Processor'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
  }

  lintOptions {
    disable 'InvalidPackage'
    abortOnError false
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

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

  implementation 'com.google.android.material:material:1.0.0'
  implementation 'androidx.appcompat:appcompat:1.1.0'
  implementation 'androidx.cardview:cardview:1.0.0'

  implementation "com.google.apis:google-api-services-youtube:v3-rev20190827-${rootProject.ext.googleApiClient}"
  implementation "com.google.http-client:google-http-client-android:${rootProject.ext.googleApiClient}"
  implementation "com.google.api-client:google-api-client-android:${rootProject.ext.googleApiClient}"
  implementation "com.google.api-client:google-api-client-gson:${rootProject.ext.googleApiClient}"

  implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'

  implementation "com.github.bumptech.glide:glide:${rootProject.ext.glide}"
  annotationProcessor "com.github.bumptech.glide:compiler:${rootProject.ext.glide}"

  // rxJava 2
  implementation("io.reactivex.rxjava2:rxandroid:2.1.1", {
    exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
  })

  implementation "io.reactivex.rxjava2:rxjava:2.2.13"

  // implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

  implementation('com.crashlytics.sdk.android:crashlytics:2.9.7@aar') {
    transitive = true
  }

  implementation('com.crashlytics.sdk.android:crashlytics-ndk:2.0.5@aar') {
    transitive = true
  }

  debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leackCanary}"
  releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"
  testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"
  // implementation 'com.squareup.leakcanary:leaksentry:2.0-alpha-2'

  // implementation "com.android.support:multidex:1.0.3"

  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  androidTestImplementation 'androidx.test:core:1.2.0'
  androidTestImplementation 'androidx.test:rules:1.2.0'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
}

if (haveFabricApiKey) {
  crashlytics {
    enableNdk true
    androidNdkOut 'src/main/obj'
    androidNdkLibsOut 'src/main/libs'
  }
}
