Skip to content

Commit

Permalink
Merge pull request #116 from Polidea/development
Browse files Browse the repository at this point in the history
Merge development
  • Loading branch information
martawoldanska authored Apr 25, 2019
2 parents ad4a17c + d47f9bf commit f2158eb
Show file tree
Hide file tree
Showing 59 changed files with 969 additions and 508 deletions.
8 changes: 4 additions & 4 deletions CockpitCore/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
buildscript {
ext.kotlin_version = '1.2.51'
ext.kotlin_version = '1.3.10'
repositories {
jcenter()
maven { url 'https://maven.google.com' }
maven { url "https://repo1.maven.org/maven2"}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.0'
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
}

group 'com.polidea.cockpit'
version '3.0.1'
version '3.1.0'

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.polidea.cockpit.core

const val GROUP_DELIMITER = '/'

data class CockpitParamGroup(val name: String?, val subgroups: List<CockpitParamGroup>, val params: List<CockpitParam<Any>>) {
val displayName: String?
get() = name?.split(GROUP_DELIMITER)?.last()

val displaySize: Int
get() = subgroups.size + params.size

fun isChild(): Boolean = name?.contains(GROUP_DELIMITER) == true
}

data class MutableCockpitParamGroup(val name: String?,
val subgroups: MutableList<MutableCockpitParamGroup> = mutableListOf(),
val params: MutableList<CockpitParam<Any>> = mutableListOf()) {

fun toReadOnly(): CockpitParamGroup = CockpitParamGroup(name, subgroups.map { it.toReadOnly() }, params)
}
8 changes: 4 additions & 4 deletions CockpitPlugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext.kotlin_version = '1.2.51'
ext.cockpit_core_version = '3.0.1'
ext.kotlin_version = '1.3.10'
ext.cockpit_core_version = '3.1.0'
repositories {
maven {
url "https://plugins.gradle.org/m2/"
Expand All @@ -16,12 +16,12 @@ plugins {
id 'groovy'
id 'maven'
id "com.gradle.plugin-publish" version "0.9.10"
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
id 'java-gradle-plugin'
}

group = 'com.polidea.cockpit'
version = '3.0.1'
version = '3.1.0'

sourceCompatibility = 1.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal abstract class BaseCockpitGenerator {
private val cockpitPackage = "com.polidea.cockpit.cockpit"
private val cockpitManagerPackage = "com.polidea.cockpit.manager"
private val androidxPackage = "androidx.fragment.app"
private val androidxLifecyclePackage = "androidx.lifecycle"
private val cockpitDialogPackage = "com.polidea.cockpit.paramsedition"
private val cockpitEventPackage = "com.polidea.cockpit.event"
private val cockpitMapperPackage = "com.polidea.cockpit.mapper"
Expand All @@ -24,6 +25,7 @@ internal abstract class BaseCockpitGenerator {
private val cockpit = "Cockpit"
private val cockpitManager = "CockpitManager"
private val fragmentManager = "FragmentManager"
private val lifecycleOwner = "LifecycleOwner"
private val cockpitDialog = "CockpitDialog"
private val propertyChangeListener = "PropertyChangeListener"
private val actionRequestCallback = "ActionRequestCallback"
Expand All @@ -41,6 +43,7 @@ internal abstract class BaseCockpitGenerator {

protected val cockpitManagerClassName = ClassName.get(cockpitManagerPackage, cockpitManager)
protected val androidFragmentManagerClassName = ClassName.get(androidxPackage, fragmentManager)
protected val androidLifecycleOwnerClassName = ClassName.get(androidxLifecyclePackage, lifecycleOwner)
protected val cockpitDialogClassName = ClassName.get(cockpitDialogPackage, cockpitDialog)
protected val propertyChangeListenerClassName = ClassName.get(cockpitEventPackage, propertyChangeListener)
protected val actionRequestCallbackClassName = ClassName.get(cockpitEventPackage, actionRequestCallback)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ internal class Util {
companion object {
// Kotlin version of following deep merge map method:
// http://blog.mathieu.photography/post/103163278870/deep-merge-map-in-groovy
//
// Merges `overrides` into `onto`.
// Merging strategy is as follows:
// 1. if value doesn't exist in destination, add it to destination
// 2. if value is a map, merge it using the same algorithm
// 3. if value exists, overwrites it with value from last of the `overrides`
fun <K : Any?, V : Any?> deepMerge(onto: MutableMap<K, V>, vararg overrides: Map<K, V>): MutableMap<K, V> {
if (overrides.isEmpty()) {
return onto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForBooleanParamTest() {
val booleanParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForParam("boolParam", false)
val booleanParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForParam("boolParam", false)

val expectedBooleanParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnBoolParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Boolean> listener) {
| com.polidea.cockpit.manager.CockpitManager.INSTANCE.addOnParamChangeListener("boolParam", listener);
Expand All @@ -225,9 +228,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForIntParamTest() {
val integerParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForParam("intParam", 0)
val integerParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForParam("intParam", 0)

val expectedIntegerParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnIntParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Integer> listener) {
| com.polidea.cockpit.manager.CockpitManager.INSTANCE.addOnParamChangeListener("intParam", listener);
Expand All @@ -237,9 +243,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForDoubleParamTest() {
val doubleParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForParam("doubleParam", .0)
val doubleParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForParam("doubleParam", .0)

val expectedDoubleParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnDoubleParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Double> listener) {
| com.polidea.cockpit.manager.CockpitManager.INSTANCE.addOnParamChangeListener("doubleParam", listener);
Expand All @@ -249,9 +258,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForStringParamTest() {
val stringParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForParam("stringParam", "")
val stringParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForParam("stringParam", "")

val expectedStringParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnStringParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.String> listener) {
| com.polidea.cockpit.manager.CockpitManager.INSTANCE.addOnParamChangeListener("stringParam", listener);
Expand All @@ -261,9 +273,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForStepIntParamTest() {
val stepStepParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForStepParam("stepIntParam", 1)
val stepStepParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForStepParam("stepIntParam", 1)

val expectedStepIntParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnStepIntParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Integer> listener) {
| com.polidea.cockpit.event.PropertyChangeListener<com.polidea.cockpit.core.type.CockpitStep<java.lang.Integer>> stepIntParamListener = new com.polidea.cockpit.mapper.MappingPropertyChangeListener<com.polidea.cockpit.core.type.CockpitStep<java.lang.Integer>, java.lang.Integer>(listener, cockpitStepIntegerMapper);
Expand All @@ -275,9 +290,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForStepDoubleParamTest() {
val stepStepParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForStepParam("stepDoubleParam", 1.0)
val stepStepParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForStepParam("stepDoubleParam", 1.0)

val expectedStepDoubleParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnStepDoubleParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Double> listener) {
| com.polidea.cockpit.event.PropertyChangeListener<com.polidea.cockpit.core.type.CockpitStep<java.lang.Double>> stepDoubleParamListener = new com.polidea.cockpit.mapper.MappingPropertyChangeListener<com.polidea.cockpit.core.type.CockpitStep<java.lang.Double>, java.lang.Double>(listener, cockpitStepDoubleMapper);
Expand All @@ -289,9 +307,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForRangeIntParamTest() {
val rangeIntParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForRangeParam("rangeIntParam", 1)
val rangeIntParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForRangeParam("rangeIntParam", 1)

val expectedRangeIntParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnRangeIntParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Integer> listener) {
| com.polidea.cockpit.event.PropertyChangeListener<com.polidea.cockpit.core.type.CockpitRange<java.lang.Integer>> rangeIntParamListener = new com.polidea.cockpit.mapper.MappingPropertyChangeListener<com.polidea.cockpit.core.type.CockpitRange<java.lang.Integer>, java.lang.Integer>(listener, cockpitRangeIntegerMapper);
Expand All @@ -303,9 +324,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForRangeDoubleParamTest() {
val rangeDoubleParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForRangeParam("rangeDoubleParam", 1.0)
val rangeDoubleParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForRangeParam("rangeDoubleParam", 1.0)

val expectedRangeDoubleParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnRangeDoubleParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.Double> listener) {
| com.polidea.cockpit.event.PropertyChangeListener<com.polidea.cockpit.core.type.CockpitRange<java.lang.Double>> rangeDoubleParamListener = new com.polidea.cockpit.mapper.MappingPropertyChangeListener<com.polidea.cockpit.core.type.CockpitRange<java.lang.Double>, java.lang.Double>(listener, cockpitRangeDoubleMapper);
Expand All @@ -317,9 +341,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddActionRequestCallbackMethodSpecForStringParamTest() {
val actionCallbackMethodSpec = cockpitGenerator.createAddActionRequestCallbackMethodSpecForParam(CockpitParam("value", CockpitAction("show")))
val actionCallbackMethodSpec = cockpitGenerator.createDeprecatedAddActionRequestCallbackMethodSpecForParam(CockpitParam("value", CockpitAction("show")))

val expectedActionRequestCallbackMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addValueActionRequestCallback(
| com.polidea.cockpit.event.ActionRequestCallback callback) {
| com.polidea.cockpit.manager.CockpitManager.INSTANCE.addActionRequestCallback("value", callback);
Expand All @@ -329,9 +356,12 @@ class DebugCockpitGeneratorTest {

@Test
fun createAddParamChangeListenerMethodSpecForCockpitColorParamTest() {
val colorParamChangeListenerMethodSpec = cockpitGenerator.createAddPropertyChangeListenerMethodSpecForColorParam("colorParam", CockpitColor("#112233"))
val colorParamChangeListenerMethodSpec = cockpitGenerator.createDeprecatedAddPropertyChangeListenerMethodSpecForColorParam("colorParam", CockpitColor("#112233"))

val expectedStringParamChangeListenerMethodSpecString = """
|@kotlin.Deprecated(
| message = "This method might leak context. Consider using overload taking lifecycleOwner or switch to addForever(...)"
|)
|public static void addOnColorParamChangeListener(
| com.polidea.cockpit.event.PropertyChangeListener<java.lang.String> listener) {
| com.polidea.cockpit.event.PropertyChangeListener<com.polidea.cockpit.core.type.CockpitColor> colorParamListener = new com.polidea.cockpit.mapper.MappingPropertyChangeListener<com.polidea.cockpit.core.type.CockpitColor, java.lang.String>(listener, cockpitColorMapper);
Expand Down
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It consists of three parts:
- Android library containing classes to manage and display those params,
- CockpitCore module containing classes common for plugin and the library.

<img src="https://github.com/Polidea/Cockpit/blob/master/images/cockpit-3.0.gif" width="270" height="480">
<img src="https://github.com/Polidea/Cockpit/blob/a5d9b822b7bccbebf1800a5cc9a25f67429a7a92/images/cockpit-3.1.0.gif" width="270" height="480">

Each defined value is called `param`. The set of params is called `cockpit`.

Expand All @@ -33,9 +33,9 @@ showDescription: true
After you've built your project, `Cockpit.java` file will get generated for you. You can use it like any other code in your project.

<p float="left">
<img src="https://github.com/Polidea/Cockpit/blob/master/images/cockpit-full.png" width="216" height="384" />
<img src="https://github.com/Polidea/Cockpit/blob/master/images/cockpit-half.png" width="216" height="384" />
<img src="https://github.com/Polidea/Cockpit/blob/master/images/cockpit-list.png" width="216" height="384" />
<img src="https://github.com/Polidea/Cockpit/blob/a5d9b822b7bccbebf1800a5cc9a25f67429a7a92/images/cockpit-full.png" width="216" height="384" />
<img src="https://github.com/Polidea/Cockpit/blob/a5d9b822b7bccbebf1800a5cc9a25f67429a7a92/images/cockpit-half.png" width="216" height="384" />
<img src="https://github.com/Polidea/Cockpit/blob/a5d9b822b7bccbebf1800a5cc9a25f67429a7a92/images/cockpit-list.png" width="216" height="384" />
</p>

### Documentation
Expand Down Expand Up @@ -141,6 +141,21 @@ fontColor:
group: "Header"
```

> You can create **paged subgroups** as well. To define a paged subgroup, use slashes in group name. If you begin your subgroup's name with `/`, it will be placed inside `Default` group. You can embed the subgroups as deep as you see fit. To navigate between the subgroups, use home button on the action bar or `NAVIGATE TO` button.
The following snippet will create group named `Display` with subgroup `Header` and parameters `fontSize` and `fontColor` inside.
```
fontSize:
description: "Font size"
value: 18
group: "Display/Header"
fontColor:
type: color
description: "Font color"
value: "#223344"
group: "Display/Header"
```

#### Generating Cockpit

CockpitPlugin will generate `Cockpit.java` file for you.
Expand Down Expand Up @@ -198,15 +213,15 @@ Then add CockpitPlugin classpath into your `buildscript#dependencies`:
```
buildscript {
dependencies {
classpath "gradle.plugin.com.polidea.cockpit:CockpitPlugin:3.0.1"
classpath "gradle.plugin.com.polidea.cockpit:CockpitPlugin:3.1.0"
}
}
```
Last thing is to add Cockpit library dependency:

```
dependencies {
debugImplementation 'com.polidea.cockpit:cockpit:3.0.1'
debugImplementation 'com.polidea.cockpit:cockpit:3.1.0'
}
```

Expand Down Expand Up @@ -259,7 +274,7 @@ To get it to work, you need to disable configuration on demand in your Android S

## License
```
Copyright 2018 Polidea
Copyright 2018-2019 Polidea
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions cockpit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply from: rootProject.file('gradle/publishing.gradle')
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath files("../CockpitCore/build/libs/CockpitCore-{$cockpit_core_version}.jar")
}
Expand Down Expand Up @@ -51,6 +51,6 @@ dependencies {
api 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation 'io.mockk:mockk:1.7.15'
testImplementation 'io.mockk:mockk:1.9.3'
api files("../CockpitCore/build/libs/CockpitCore-${cockpit_core_version}.jar")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ internal fun List<CockpitParam<Any>>.toGroupedParams(): Map<String?, List<Cockpi
}

return mutableGroupedParams
}
}
Loading

0 comments on commit f2158eb

Please sign in to comment.