import java.text.SimpleDateFormat

plugins {
    id('com.android.application')
    id('org.jetbrains.kotlin.android')
}

android {
    namespace 'com.pengxh.daily.app'
    compileSdk 36

    defaultConfig {
        applicationId 'com.pengxh.daily.app'
        minSdk 26
        targetSdk 36
        versionCode 2210
        versionName '2.2.1.0'
    }

    flavorDimensions += 'versionCode'

    signingConfigs {
        release {
            storeFile file('DailyTask.jks')
            storePassword '123456789'
            keyAlias 'key0'
            keyPassword '123456789'
        }
    }

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

    GString id = "com.alibaba.android.${createRandomCode()}"
    productFlavors {
        daily {
            applicationId = id
        }
    }

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

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    buildFeatures {
        buildConfig true
        viewBinding true
    }

    applicationVariants.configureEach {
        outputs.configureEach {
            outputFileName = "DT_${getBuildDate()}_${android.defaultConfig.versionName}.apk"
        }
    }
}

static def createRandomCode() {
    String alphabetsInLowerCase = 'abcdefghijklmnopqrstuvwxyz'
    String randomString = ""
    for (i in 0..5) {
        int randomIndex = Math.random() * alphabetsInLowerCase.length()
        randomString += alphabetsInLowerCase[randomIndex]
    }
    return randomString
}

static def getBuildDate() {
    SimpleDateFormat dateFormat = new SimpleDateFormat('yyyyMMdd', Locale.CHINA)
    return dateFormat.format(System.currentTimeMillis())
}

dependencies {
    implementation 'androidx.core:core-ktx:1.15.0'
    implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.1.7'
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    //侧滑RecyclerView
    implementation 'com.yanzhenjie.recyclerview:x:1.3.2'
    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
    implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
    //数据库框架
    implementation 'androidx.room:room-runtime:2.6.1'
    annotationProcessor 'androidx.room:room-compiler:2.5.2'
    //邮件
    implementation 'com.sun.mail:android-mail:1.6.8'
    implementation 'com.sun.mail:android-activation:1.6.8'
    //日期、时间选择器
    implementation 'com.github.gzu-liyujiang.AndroidPicker:WheelPicker:4.1.14'
    implementation 'com.google.code.gson:gson:2.13.2'
}
