apply plugin: 'com.android.application'
//apply plugin: "io.freefair.android-checkstyle"
//apply plugin: "io.freefair.android-javadoc-jar"
//apply plugin: "io.freefair.android-ci"

def gitSha = null
try {
    gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
} catch (Exception e) {
    logger.warn("git not available", e)
}

//def isCi = "true".equals(System.getenv("CI"))     // We're not using CI here

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'

    defaultConfig {
        applicationId "zz.aimsicd.lite"             // com.SecUpwN.AIMSICD
        minSdkVersion 18                            //
        targetSdkVersion 19                         // Do not change: Working Icons on Android 5+
        versionCode 42                              // 41
        versionName "0503"                          // Last Release: "2.x.x"
        testApplicationId "zz.aimsicd.lite.test"    // com.SecUpwN.AIMSICD.test

        buildConfigField 'String', 'BUILD_NUMBER', (getBuildNumber() == null ? 'null' : "\"${buildNumber}\"")
        buildConfigField 'String', 'GIT_SHA', (gitSha == null ? 'null' : "\"${gitSha}\"")

        jackOptions {
            enabled true
        }
    }

    buildTypes {
        debug {
            try {
                buildConfigField 'String', 'OPEN_CELLID_API_KEY', '\"' + open_cellid_api_key + '\"'
            } catch (MissingPropertyException e) {
                buildConfigField 'String', 'OPEN_CELLID_API_KEY', '"NA"'
            }
            versionNameSuffix '-debug'
        }
        release {
            buildConfigField 'String', 'OPEN_CELLID_API_KEY', '"NA"'
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

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

    lintOptions {
        //--- lint (self) ---------------------------------------------------------------
        warning 'InvalidPackage'        // Default:  ?
        warning 'MissingRegistered'     // Default:  ?
        warning 'Registered'            // Default:  disabled
        warning 'NewerVersionAvailable' // Default:  disabled
        warning 'StopShip'              // Default:  disabled  -- "// STOPSHIP" can be used to flag code that should not be shipped until the issue is fixed
        warning 'UnpackedNativeCode'    // Default:  disabled  -- app loads native libraries using System.loadLibrary()/ android:extractNativeLibs="false"

        abortOnError false              // true by default
        htmlReport true                 // !isCi    // We do want the lint report in HTML
        textReport false                // isCi     // We don't want text reports on CLI
        xmlReport false                 //
        textOutput 'stdout'             //
        //checkAllWarnings false        //
        //checkReleaseBuilds false      //
        //ignoreWarnings true           // false by default
        //quiet true                    // false by default

        //disable 'deprecation'         // Does this exists (as shown in -Xlint gradle output)?
        //disable 'unchecked'           // Does this exists (as shown in -Xlint gradle output)?

        disable 'ApplySharedPref'       // We want our preference changes to be immediate
//        disable 'AppCompatResource'   // Menu namespace: appcompat library resources should refer "showAsAction" in the app:namespace
        disable 'MissingTranslation'    // Strings declared in one language should also be translated in all other languages
        //disable 'ExtraTranslation'    // Make sure all labelled strings appear in all locales
//        disable 'ValidFragment'       //
//        disable 'CommitPrefEdits'     // We want out preferences to be stored immediately! Contrary to apply().
        //disable 'SdCardPath'          // Use non-specific API independent external sdcard paths
        disable 'Typos'                 //
        disable 'HardwareIds'           // Using getSubscriberId to get device identifiers (IMSI) is not recommended
//        disable 'SetJavaScriptEnabled'  // Used in:
//        disable 'Wakelock'            // lint wakelock check is buggy, we're probably doing it right.
//        disable 'Overdraw'            // @color/common_sectionBackground
        disable 'UnusedAttribute'       // New attributes in AndroidManifest, not supported in lower API's
//        disable 'UnusedResources'     // Many unused strings and images: <placeholders?>
        //disable 'UselessParent'       //
        //disable 'TooManyViews'        //
        //disable 'EasterEgg'           // ...is code deliberately hidden in the code. Where?

//        disable 'GoogleAppIndexingWarning'      // Ignore Googles Firebase App Indexing ?
        //disable 'AppLinksAutoVerifyError'     // where?
        //disable 'AppLinksAutoVerifyWarning'   // where?
        //disable 'ClickableViewAccessibility'  // lint require View#performClick:

        //--- UI: Icons & Images --------------------------------------------------------
        disable 'IconColors'                // Ugly Material design only allow Gray/White icons..we ignore.
//        disable 'IconDipSize'             // ToDo: Fix icons
//        disable 'IconDuplicatesConfig'    // ToDo: maybe nothing
//        disable 'IconDensities'           // ToDo: Fix icons
        //disable 'IconExpectedSize'        // Use predefined sizes (for each density) for launcher icons
//        disable 'IconLocation'            // ToDo: Fix icons: "Found bitmap drawable in densityless folder..."
        disable 'ContentDescription'        // Images without contentDescription

        //--- UI: Text & Typography -----------------------------------------------------
        disable 'TypographyEllipsis'            //
        disable 'SmallSp'                       // "Avoid using sizes smaller than 12sp: 10sp"
        //disable 'SetTextI18n'                 // We don't translate button strings
        disable 'HardcodedText'                 // We don't care about hardcoded text for numbers...

        //--- UI: RTL -------------------------------------------------------------------
        // NOTE: [1] If your minSdkVersion is less than 17, you should add BOTH the older
        //           left/right attributes as well as the new start/right attributes.
        //       [2] To enable RTL support, when running on API 17 and higher, you must
        //           set the android:supportsRtl attribute in the Android manifest
        //-------------------------------------------------------------------------------
        //disable 'RtlSymmetry'                 // ToDo: Do we need to check all "Padding and margin symmetry"?
        //disable 'RtlHardcoded'                // We (currently) don't care about RTL layouts (L/R vs Start/End)
        //disable 'RtlEnabled'                  // See [2].

        //--- UI: Buttons ---------------------------------------------------------------
        // https://material.google.com/components/buttons.html
        // http://stackoverflow.com/a/25610531/1147688
        //-------------------------------------------------------------------------------
//        disable 'BackButton'                              // Should we have a more clearly defined "back" button?
        disable 'ButtonStyle'                               // We don't want ugly borderless buttons: "Button should be borderless"

//        disable 'TrulyRandom'                             //
        //disable 'NewApi'                                  // If there are new API calls used on older minSdkVersion
//        disable 'LabelFor'                                // API 17+ : Text fields should be labelled with a "labelFor" attribute
//        disable 'SSLCertificateSocketFactoryCreateSocket' //
          disable 'UnsafeProtectedBroadcastReceiver'        // check origin of Broadcast receivers to avoid spoofing
        //disable ''                                        //
    }

    packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }

    productFlavors {
        // We disable system flavors for now
        /*system {
            versionName "$project.version-system"           // For system apps
        }*/
        normal {
            versionName "$project.version-normal"           // For normal apps
        }
    }
}

dependencies {
    // Android Support Libraries
    compile 'com.android.support:appcompat-v7:25.3.1'               // app compat ...

    compile 'au.com.bytecode:opencsv:2.4'                           // OpenCSV (comma-separated values) parser library
    compile 'com.github.Stericson:RootShell:d708ae1f0a'             // Easy to use Root Shell for Android Applications
    compile 'com.github.MKergall.osmbonuspack:OSMBonusPack:v5.6'    // OSMBonusPack library to interact with OpenStreetMap data
    compile 'com.github.kaichunlin.transition:core:0.9.5'           // Transition library for animated transition effects [0.9.2]
    //compile 'com.github.amlcurran.showcaseview:library:5.3.0'     // ShowcaseView library to highlight specific app elements

    // Dependency Injection for Android
//    compile 'io.freefair.android-injection:injection:2.0.0-beta1'
//    compile 'io.freefair.android-injection:logging:2.0.0-beta1'
//    compile 'io.freefair.android-injection:okhttp:2.0.0-beta1'
    compile 'io.freefair.android-injection:injection:2.0.0-beta1'   // any updates?
    //compile 'io.freefair.android-injection:logging:2.0.0-beta1'     // any updates?
    //compile 'io.freefair.android-injection:okhttp:2.0.0-beta1'      // any updates?
    compile 'com.squareup.okhttp3:okhttp:3.7.0'


    //compile 'io.freefair.android-util:function:3.0.0'             // new
    //compile 'io.freefair:slf4j-android:1.7.21'                    // new
    //compile 'io.freefair.android-colors:material:1.2.0'             // Used in Status.java ..

    // IF you want to enable lombok:
    //  1) Enable plugin: "Settings > Build > Compiler > Annotation Processors"
    //  2) Uncomment these, AND then:  File >> Invalidate Cashes / Restart
    // provided "org.projectlombok:lombok:1.16.16"                  // new
    // annotationProcessor "org.projectlombok:lombok:1.16.16"       // new

    // OTHERS
    //compile 'com.squareup.okio:okio:1.12.0'                         // a new library that complements java.io and java.nio
}

apply from: "signing.gradle"
//apply plugin: "io.freefair.android-checkstyle"

/*
checkstyle {
    toolVersion = "7.+"
}*/

String getBuildNumber() {
    String travisBuildNumber = System.getenv("TRAVIS_BUILD_NUMBER")
    if(travisBuildNumber != null) {
        return "T-$travisBuildNumber"
    }
    String buildozerBuildNumber = System.getenv("BUILDOZER_BUILDNUMBER")
    if(buildozerBuildNumber != null) {
        return "B-$buildozerBuildNumber"
    }
    return null;
}
