Skip to content

Commit

Permalink
Fix incremental compilation, apply new code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Orgaz committed Oct 3, 2019
1 parent e22faac commit dd8ab7f
Show file tree
Hide file tree
Showing 354 changed files with 1,237 additions and 1,842 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,47 @@ dependencies {
implementation "com.github.minikorp.mini:mini-android:$mini_version" //Android utilities
}
```

## Issues

Jetifier might crash your build without reason,
add this line to gradle.properties to exclude the compiler or fully disable it.

```properties
android.jetifier.blacklist=mini-processor.*\\.jar #Blacklist
android.enableJetifier=false #Or disable
```

Compiling JDK >8 might fail, make sure you set compatibility to java 8
both for Android and kapt.

```groovy
android {
compileOptions {
sourceCompatibility "1.8"
targetCompatibility "1.8"
}
}
kapt {
javacOptions {
option("-source", "8")
option("-target", "8")
}
}
```

## Build performance

Make sure to enable incremental apt and worker api for faster builds with kapt.

```properties
# Some performance improvements
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.daemon=true
kapt.incremental.apt=true
kapt.use.worker.api=true
```
15 changes: 11 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ kotlin {
}
}

kapt {
javacOptions {
option("-source", "8")
option("-target", "8")
}
}

//Android
android {
compileSdkVersion target_sdk_version
Expand All @@ -54,8 +61,8 @@ android {
}

compileOptions {
sourceCompatibility "1.7"
targetCompatibility "1.7"
sourceCompatibility "1.8"
targetCompatibility "1.8"
}

lintOptions {
Expand Down Expand Up @@ -88,8 +95,8 @@ dependencies {
implementation "io.reactivex.rxjava2:rxjava:$rx"

//Support
implementation "androidx.core:core:1.0.1"
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation "androidx.core:core:1.1.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

//Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/sample/SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ data class DummyState(val text: String = "dummy")
class DummyStore : Store<DummyState>() {

@Reducer
fun hello(action: ActionInterface) {
fun didIChange(action: ActionInterface) {

}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'maven-publish'
buildscript {
ext {
kotlin_version = "1.3.50"
mini_version = "4.1.0"
mini_version = "4.2.0"
}

repositories {
Expand All @@ -13,7 +13,7 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:3.5.0"
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0"
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
Expand Down
11 changes: 9 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
kotlin.coroutines=enable
android.useAndroidX=true
android.enableJetifier=true
android.enableJetifier=false
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# Some performance improvements
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.daemon=true
kapt.incremental.apt=true
kapt.use.worker.api=true
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import android.content.Context;

import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
Expand All @@ -17,11 +17,11 @@
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.mini.test", appContext.getPackageName());
}
assertEquals("com.mini.test", appContext.getPackageName());
}
}
4 changes: 2 additions & 2 deletions mini-android/src/main/java/com/mini/android/FluxActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import mini.DefaultCloseableTracker
import kotlin.coroutines.CoroutineContext

abstract class FluxActivity : AppCompatActivity(),
CloseableTracker by DefaultCloseableTracker(),
CoroutineScope {
CloseableTracker by DefaultCloseableTracker(),
CoroutineScope {

override val coroutineContext: CoroutineContext
get() = lifecycleScope.coroutineContext
Expand Down
4 changes: 2 additions & 2 deletions mini-android/src/main/java/com/mini/android/FluxFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import mini.DefaultCloseableTracker
import kotlin.coroutines.CoroutineContext

abstract class FluxFragment : Fragment(),
CloseableTracker by DefaultCloseableTracker(),
CoroutineScope {
CloseableTracker by DefaultCloseableTracker(),
CoroutineScope {

override val coroutineContext: CoroutineContext
get() = lifecycleScope.coroutineContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mini.CloseableTracker
import mini.DefaultCloseableTracker

abstract class FluxViewModel : ViewModel(),
CloseableTracker by DefaultCloseableTracker() {
CloseableTracker by DefaultCloseableTracker() {

@CallSuper
override fun onCleared() {
Expand Down
4 changes: 2 additions & 2 deletions mini-android/src/main/java/com/mini/android/ViewUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fun toggleViewsVisibility(
when {
resource.isSuccess -> Triple(View.VISIBLE, invisibilityType, invisibilityType)
resource.isLoading -> Triple(invisibilityType, View.VISIBLE, invisibilityType)
resource.isEmpty -> Triple(invisibilityType, invisibilityType, View.VISIBLE)
else -> return
resource.isEmpty -> Triple(invisibilityType, invisibilityType, View.VISIBLE)
else -> return
}
contentView.visibility = content
loadingView.visibility = loading
Expand Down
20 changes: 12 additions & 8 deletions mini-common/src/main/java/mini/Dispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class Dispatcher(val actionTypes: Map<KClass<*>, List<KClass<*>>>) {
override fun proceed(action: Any): Any {
synchronized(subscriptions) {
val types = actionTypes[action::class]
?: error("Object $action [${action::class}] is not action, " +
"register it in type map or use ```MiniGen.newDispatcher``` " +
"if using " +
"code generation")
?: error("Object $action [${action::class}] is not action, " +
"register it in type map or use ```MiniGen.newDispatcher``` " +
"if using " +
"code generation")
types.forEach { type ->
subscriptions[type]?.forEach { it.fn(action) }
}
Expand Down Expand Up @@ -60,12 +60,15 @@ class Dispatcher(val actionTypes: Map<KClass<*>, List<KClass<*>>>) {
}
}

inline fun <reified A : Any> subscribe(priority: Int = 100, noinline callback: (A) -> Unit): Closeable {
inline fun <reified A : Any> subscribe(priority: Int = 100,
noinline callback: (A) -> Unit): Closeable {
return subscribe(A::class, priority, callback)
}

@Suppress("UNCHECKED_CAST")
fun <T : Any> subscribe(clazz: KClass<T>, priority: Int = 100, callback: (T) -> Unit): Closeable {
fun <T : Any> subscribe(clazz: KClass<T>,
priority: Int = 100,
callback: (T) -> Unit): Closeable {
synchronized(subscriptions) {
val reg = DispatcherSubscription(this, clazz, priority, callback as (Any) -> Unit)
val set = subscriptions.getOrPut(clazz) {
Expand Down Expand Up @@ -117,7 +120,7 @@ class Dispatcher(val actionTypes: Map<KClass<*>, List<KClass<*>>>) {
private fun doDispatch(action: Any) {
if (dispatching != null) {
throw IllegalStateException("Nested dispatch calls. Currently dispatching: " +
"$dispatching. Nested action: $action ")
"$dispatching. Nested action: $action ")
}
dispatching = action
interceptorChain.proceed(action)
Expand All @@ -129,7 +132,8 @@ class Dispatcher(val actionTypes: Map<KClass<*>, List<KClass<*>>>) {
*/
data class DispatcherSubscription internal constructor(val dispatcher: Dispatcher,
val type: KClass<*>,
val priority: Int, val fn: (Any) -> Unit) : Closeable {
val priority: Int,
val fn: (Any) -> Unit) : Closeable {
companion object {
private val idCounter = AtomicInteger()
}
Expand Down
4 changes: 2 additions & 2 deletions mini-common/src/main/java/mini/LoggerInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class LoggerInterceptor constructor(stores: Collection<Store<*>>,
sb.append('\n')
sb.append("┌────────────────────────────────────────────\n")
sb.append(String.format("├─> %s %dms [+%dms][%d] - %s",
action.javaClass.simpleName, processTime, timeSinceLastAction, actionCounter % 10, action))
.append("\n")
action.javaClass.simpleName, processTime, timeSinceLastAction, actionCounter % 10, action))
.append("\n")

for (i in beforeStates.indices) {
val oldState = beforeStates[i]
Expand Down
8 changes: 4 additions & 4 deletions mini-common/src/main/java/mini/Resource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ open class Resource<out T> @PublishedApi internal constructor(val value: Any?) {
fun getOrNull(): T? =
when {
isSuccess -> value as T?
else -> null
else -> null
}

fun exceptionOrNull(): Throwable? =
when (value) {
is Failure -> value.exception
else -> null
else -> null
}

companion object {
Expand Down Expand Up @@ -74,8 +74,8 @@ class Task(value: Any?) : Resource<Unit>(value) {
isSuccess -> "Success"
isFailure -> "Failure"
isLoading -> "Loading"
isIdle -> "Idle"
else -> value.toString()
isIdle -> "Idle"
else -> value.toString()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mini-common/src/test/kotlin/mini/ResourceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ResourceTest {
@Test
fun exceptionOrNull() {
Resource.failure<Any>(RuntimeException()).exceptionOrNull().`should not be null`()
Resource.success<Any>("abc").exceptionOrNull(). `should be null` ()
Resource.success<Any>("abc").exceptionOrNull().`should be null`()
}

@Test
Expand Down
1 change: 1 addition & 0 deletions mini-flow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Binary file not shown.
Binary file not shown.
Binary file removed mini-flow/build/kotlin/compileKotlin/build-history.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed mini-flow/build/kotlin/compileKotlin/last-build.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion mini-flow/build/kotlin/miniflow405jar-classes.txt

This file was deleted.

1 change: 0 additions & 1 deletion mini-flow/build/kotlin/miniflow410jar-classes.txt

This file was deleted.

27 changes: 0 additions & 27 deletions mini-flow/build/poms/pom-default.xml

This file was deleted.

Loading

0 comments on commit dd8ab7f

Please sign in to comment.