Skip to content

Commit

Permalink
Merge pull request #73 from TheTeamPotato/task/refactor-code-before-i…
Browse files Browse the repository at this point in the history
…nitial-release

Refactor project
  • Loading branch information
isoguzay authored Mar 20, 2022
2 parents ba92701 + dee8a40 commit b4d8326
Show file tree
Hide file tree
Showing 62 changed files with 150 additions and 504 deletions.
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ lint/tmp/
# Android Profiling
*.hprof
/.idea/

.DS_Store
5 changes: 0 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ dependencies {

ANDROID_TEST
COROUTINES_TEST
LOCAL_TEST_JUNIT5
}

kapt {
correctErrorTypes = true
}

moduleConfigurations {
useJUnitRunner5 = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.navigation.*
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable

import com.theteampotato.gifit.favorites.view.FavoritesScreen
import com.theteampotato.gifit.favorites.viewmodel.FavoritesViewModel
import com.theteampotato.gifit.history.view.HistoryScreen
Expand All @@ -22,7 +23,6 @@ const val LANGUAGE_SELECTION = "language_selection"
fun NavigationGraph(
navController: NavHostController,
startDestination: String = "${BottomNavScreen.SearchNavScreen.route}?searchQuery={${BottomNavScreen.SearchNavScreen.arguments?.first()}}",
//startDestination: String = "language_selection",
languageSelectionViewModel: LanguageSelectionViewModel,
searchViewModel: SearchViewModel,
historyViewModel: HistoryViewModel,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.theteampotato.gifit.view

import android.os.Bundle

import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -14,6 +15,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController

import com.theteampotato.gifit.data.LocaleManager
import com.theteampotato.gifit.data.datastore.preferencesDataStore
import com.theteampotato.gifit.favorites.viewmodel.FavoritesViewModel
Expand All @@ -26,7 +28,9 @@ import com.theteampotato.gifit.splash.viewmodel.SplashViewModel
import com.theteampotato.gifit.ui.BottomNavScreen
import com.theteampotato.gifit.ui.GIFitTheme
import com.theteampotato.gifit.ui.view.GIFitBottomNavBar

import dagger.hilt.android.AndroidEntryPoint

import kotlinx.coroutines.delay

val LocaleActiveManager = compositionLocalOf<LocaleManager> { error("No locale manager found!") }
Expand Down
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ buildscript {
google()
gradlePluginPortal()
mavenCentral()
maven(url = "https://developer.huawei.com/repo/")
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
Expand All @@ -20,7 +19,6 @@ allprojects {
google()
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://developer.huawei.com/repo/")
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
}
}
Expand Down
8 changes: 2 additions & 6 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ repositories {
}

dependencies {
//compileOnly(gradleApi())
//implementation(kotlin("gradle-plugin"))
implementation("com.android.tools.build:gradle:7.1.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
implementation("com.google.dagger:hilt-android-gradle-plugin:2.40.5")
implementation("org.jlleitschuh.gradle:ktlint-gradle:10.2.1")
implementation("org.jetbrains.kotlin:kotlin-serialization:1.4.31")
implementation("com.google.dagger:hilt-android-gradle-plugin:2.41")
implementation("org.jetbrains.kotlin:kotlin-serialization:1.6.10")
implementation("io.ktor:ktor-serialization:1.5.1")
implementation("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.0")
}
129 changes: 5 additions & 124 deletions buildSrc/src/main/kotlin/CommonModulePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension

import org.gradle.api.Action
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.internal.file.impl.DefaultFileMetadata.file
import org.gradle.kotlin.dsl.*

import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import java.io.File

class CommonModulePlugin : Plugin<Project> {

private val isApplicationModule: Boolean
//get() = defaultConfig is AppExtension
get() = moduleName == "app"

private lateinit var moduleName: String
Expand All @@ -32,18 +25,14 @@ class CommonModulePlugin : Plugin<Project> {
apply("kotlin-android")
apply("kotlin-kapt")
apply("kotlin-parcelize")
//apply(BuildScript.JUNIT5_PLUGIN)
apply(BuildScript.KTLINT_PLUGIN)

if (moduleName == "data")
apply("kotlinx-serialization")
}

//project.applyKtLintConfigurations()

val androidExtension = project.extensions.getByName("android") as? BaseExtension ?: return

project.applyModuleConfigurations(androidExtension)
project.applyModuleConfigurations()

androidExtension.applyAndroidConfigurations()
androidExtension.applyProguardConfigurations()
Expand All @@ -59,81 +48,17 @@ class CommonModulePlugin : Plugin<Project> {
println("${ASCIIArt.A_GUY_SMASHING_COMPUTER}\n\n\n\t\t\t\t\tBuilding $moduleName module...\n")
}

private fun Project.applyKtLintConfigurations() {
val ktLint = project.extensions.getByName("ktlint")
println("ktLint is ${ktLint.javaClass.simpleName}")

// Run `ktlintCheck` task after each module prebuild
afterEvaluate {
tasks {
val ktLintCheck = tasks.named("ktlintCheck")
/*val assembleDebug = tasks.named(if (isApplicationModule) "assembleGmsDebug" else "assembleDebug")
assembleDebug {
dependsOn(ktLintCheck)
}*/

"preBuild" {
dependsOn(ktLintCheck)
}
}
}

ktlint {
//version.set("0.38.1")
android.set(true)
coloredOutput.set(true)
//debug.set(true)
enableExperimentalRules.set(true)
verbose.set(true)
ignoreFailures.set(true)
outputToConsole.set(true)
disabledRules.set(
setOf(
"colon-spacing",
"experimental:multiline-if-else",
"no-blank-line-before-rbrace",
"no-wildcard-imports",
"import-ordering"
)
)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
reporters {
//reporter(ReporterType.PLAIN)
//reporter(ReporterType.CHECKSTYLE)
reporter(ReporterType.HTML)
reporter(ReporterType.JSON)
}
}
}

private fun Project.applyModuleConfigurations(androidExtension: BaseExtension) {
private fun Project.applyModuleConfigurations() {
modulePluginExtension = project.extensions.create(
"moduleConfigurations",
CommonModulePluginExtension::class
)

project.afterEvaluate {
println("useJUnitRunner5 is ${modulePluginExtension?.useJUnitRunner5}")

with(modulePluginExtension!!) {
if (useJUnitRunner5) {
with(androidExtension) {
//project.plugins.apply(BuildScript.JUNIT5_PLUGIN)
// defaultConfig.testInstrumentationRunnerArgument(
// "runnerBuilder",
// "de.mannodermaus.junit5.AndroidJUnit5Builder"
// )
}
}

if (useRoboelectric) {
dependencies.apply {
androidInstrumentationTest(useJUnitRunner5, useRoboelectric)
roboelectricTest()
androidInstrumentationTest()
}

tasks {
Expand All @@ -158,30 +83,10 @@ class CommonModulePlugin : Plugin<Project> {

versionCode = AppConfig.VERSION_CODE
versionName = AppConfig.VERSION_NAME
minSdkVersion(AppConfig.MINIMUM_SDK)
targetSdkVersion(AppConfig.TARGET_SDK)
minSdk = AppConfig.MINIMUM_SDK
targetSdk = AppConfig.TARGET_SDK

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
//testInstrumentationRunnerArgument("runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder")
}

if (isApplicationModule) {
println("$moduleName - Creating build variants")

flavorDimensions("platform")
productFlavors {
create("gms") { dimension("platform") }
create("hms") { dimension("platform") }
}
}

signingConfigs {
/*create("releaseConfig") {
keyAlias = "key0"
keyPassword = "123456"
storeFile = File("key.jks")
storePassword = "123456"
}*/
}

sourceSets {
Expand All @@ -207,19 +112,6 @@ class CommonModulePlugin : Plugin<Project> {
add("META-INF/AL2.0")
add("META-INF/LGPL2.1")
}

/*pickFirst("META-INF/DEPENDENCIES")
pickFirst("META-INF/ASL2.0")*/

//exclude("META-INF/DEPENDENCIES")
/*exclude("META-INF/LICENSE")
exclude("META-INF/LICENSE.txt")
exclude("META-INF/license.txt")
exclude("META-INF/NOTICE")
exclude("META-INF/NOTICE.txt")
exclude("META-INF/notice.txt")*/
//exclude("META-INF/ASL2.0")
//exclude("META-INF/*.kotlin_module")
}
}

Expand All @@ -231,7 +123,6 @@ class CommonModulePlugin : Plugin<Project> {
when (this) {
is AppExtension -> buildTypes {
getByName("debug") {
//signingConfig = signingConfigs.getByName("releaseConfig")
isDebuggable = true
}
getByName("release") {
Expand All @@ -241,7 +132,6 @@ class CommonModulePlugin : Plugin<Project> {
getDefaultProguardFile("proguard-android-optimize.txt"),
proguardFile
)
//signingConfig = signingConfigs.getByName("releaseConfig")
}
}
is LibraryExtension -> defaultConfig { consumerProguardFiles(proguardFile) }
Expand All @@ -256,9 +146,7 @@ class CommonModulePlugin : Plugin<Project> {

project.tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
//freeCompilerArgs = listOf("-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check")
jvmTarget = "1.8"
//useIR = true
}
}
}
Expand All @@ -272,17 +160,10 @@ class CommonModulePlugin : Plugin<Project> {
project.tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
//useIR = true
}
}
}

/**
* Configures the [ktlint][org.jlleitschuh.gradle.ktlint.KtlintExtension] extension.
*/
private fun Project.`ktlint`(configure: Action<KtlintExtension>): Unit =
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("ktlint", configure)

companion object {
var modulePluginExtension: CommonModulePluginExtension? = null
}
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/CommonModulePluginExtension.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open class CommonModulePluginExtension {
var useJUnitRunner5: Boolean = false
var useRoboelectric: Boolean = false
}
Loading

0 comments on commit b4d8326

Please sign in to comment.