Skip to content

Commit

Permalink
Merge pull request #86 from Polidea/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
martawoldanska authored Aug 20, 2018
2 parents ebb1037 + f477791 commit a1c7f97
Show file tree
Hide file tree
Showing 69 changed files with 996 additions and 242 deletions.
3 changes: 2 additions & 1 deletion CockpitCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ buildscript {
jcenter()
maven { url 'https://maven.google.com' }
maven { url "https://repo1.maven.org/maven2"}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ internal class YamlToParamMapper {
CockpitAction(valueMap[MapperConsts.KEY_ACTION_BUTTON_TEXT] as? String)

private fun createCockpitListType(paramName: String, valueMap: Map<*, *>): CockpitListType<Any> {
val values = valueMap[MapperConsts.KEY_LIST_VALUES] as? List<*>
?: throw CockpitParseException("$paramName parameter must contain list of elements in `${MapperConsts.KEY_LIST_VALUES}` field")
val values = (valueMap[MapperConsts.KEY_LIST_VALUES] as? List<*>
?: throw CockpitParseException("$paramName parameter must contain list of elements in `${MapperConsts.KEY_LIST_VALUES}` field")).filterNotNull()

val types = values.distinctBy { it::class.java }.count()
if (types > 1) {
throw CockpitParseException("In $paramName: list with mixed types is not supported!")
}

val selectedIndex = (valueMap[MapperConsts.KEY_LIST_SELECTION_INDEX] as Int?) ?: 0
return CockpitListType(ArrayList<Any>(values), selectedIndex)
}
Expand All @@ -64,9 +70,9 @@ internal class YamlToParamMapper {

private fun createCockpitRange(paramName: String, valueMap: Map<*, *>): CockpitRange<*> {
val min = valueMap[MapperConsts.KEY_RANGE_MIN] as? Number
?: throw CockpitParseException("$paramName parameter must contain min field")
?: throw CockpitParseException("$paramName parameter must contain min and max fields")
val max = valueMap[MapperConsts.KEY_RANGE_MAX] as? Number
?: throw CockpitParseException("$paramName parameter must contain max field")
?: throw throw CockpitParseException("$paramName parameter must contain min and max fields")
val step = valueMap[MapperConsts.KEY_RANGE_STEP] as? Number ?: 1
val selectedValue = valueMap[MapperConsts.KEY_RANGE_VALUE] as? Number ?: min

Expand Down
13 changes: 12 additions & 1 deletion 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/development/images/cockpit-2.1.gif" width="270" height="480">
<img src="https://github.com/Polidea/Cockpit/blob/development/images/cockpit-2.1.1.gif" width="270" height="480">

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

Expand Down Expand Up @@ -109,6 +109,17 @@ fontColor:
> Please note that param names are case-sensitive and have to be unique.
> You can create **groups of params** and name them. To define a group, you need to use extended structure of a param and add "group" field. All parameters without defined groups will be listed as part of "Default" group.
```
fontSize:
description: "Font size"
value: 18
group: "Header"
fontColor:
type: color
description: "Font color"
value: "#223344"
group: "Header"
```

#### Generating Cockpit

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
3 changes: 2 additions & 1 deletion 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.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath files("../CockpitCore/build/libs/CockpitCore-{$cockpit_core_version}.jar")
}
Expand All @@ -16,6 +16,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.google.com' }
maven { url "https://repo1.maven.org/maven2"}
google()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import android.support.design.widget.BottomSheetBehavior
import android.support.design.widget.BottomSheetDialogFragment
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageButton
import com.polidea.cockpit.R
import com.polidea.cockpit.utils.getScreenHeight
import com.polidea.cockpit.extensions.removeDimmedBackground
import com.polidea.cockpit.utils.getScreenHeight

internal class CockpitDialog internal constructor() : BottomSheetDialogFragment(), ParamsEditionContract.View {

Expand All @@ -33,6 +34,11 @@ internal class CockpitDialog internal constructor() : BottomSheetDialogFragment(
setupViews(view)
presenter.start()
retainInstance = true

// force showing Cockpit as full screen when expanded
val bottomSheetDialogLayoutParams = dialog.findViewById<FrameLayout>(R.id.design_bottom_sheet).layoutParams
bottomSheetDialogLayoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT

return dialog
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal abstract class RangeParamViewHolder<T : Number>(view: View) : ParamBase
valueSelector.setOnSeekBarChangeListener(null)

valueSelector.max = getStepsCount(param.value)
valueSelector.progress = rangeToSeekBarProgress(param.value)
value.text = rangeValueString(param.value)

valueSelector.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
Expand All @@ -36,6 +35,8 @@ internal abstract class RangeParamViewHolder<T : Number>(view: View) : ParamBase

override fun onStopTrackingTouch(seekBar: SeekBar?) {}
})

valueSelector.progress = rangeToSeekBarProgress(param.value)
}

private fun getStepsCount(range: CockpitRange<T>): Int =
Expand Down
Binary file added images/cockpit-2.1.1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/cockpit-2.1.gif
Binary file not shown.
Binary file modified images/cockpit-full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/cockpit-half.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/cockpit-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 1 addition & 9 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {
}
}

flavorDimensions "api", "theme"
flavorDimensions "theme"

productFlavors {
red {
Expand All @@ -63,14 +63,6 @@ android {
applicationIdSuffix ".blue"
versionNameSuffix "-blue"
}
prod {
dimension "api"
applicationIdSuffix ".prod"
}
staging {
dimension "api"
applicationIdSuffix ".staging"
}
}

}
Expand Down
58 changes: 39 additions & 19 deletions sample/cockpit/cockpit.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
color:
type: color
description: "Text color"
value: "#00ff33"
colorDescription: "Calm green"
fontSize:
type: "range"
min: 5
max: 50
value: 30
style:
type: list
description: "Choose style"
values: ["Red", "Blue"]
group: "Theme"

animationSpeed:
description: "Animation speed"
value: 500
group: "Checkout Button"

totalPriceFontSize:
type: range
description: "Total price font size"
min: 20
max: 60
step: 1
description: "Font size"
footer: "Created by Polidea"
showFooter: true
version:
value: 36
group: "Cart"

resetCount:
type: action
description: "About application"
buttonText: "Show"
fontList:
type: list
values: [ "sans-serif", "sans-serif-thin", "sans-serif-medium", "sans-serif-condensed" ]
description: "Set item count to default"
buttonText: "Reset"
group: "Cart"

headingText:
description: "Heading text"
value: "Shopping cart"
group: "Heading"

footerFontColor:
type: color
description: "Font color"
value: "#FFFFFF"
group: "Footer"

showFooter:
description: "Show footer"
value: true
group: "Footer"
10 changes: 4 additions & 6 deletions sample/cockpit/cockpitBlue.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
color:
type: color
description: "Text color"
value: "#2C75FF"
colorDescription: "Electric blue"
footer: "Created with 💙 by Polidea"
footer:
description: "Footer"
value: "Created with 💙 by Polidea"
group: "Footer"
1 change: 0 additions & 1 deletion sample/cockpit/cockpitDebug.yml

This file was deleted.

3 changes: 0 additions & 3 deletions sample/cockpit/cockpitProd.yml

This file was deleted.

11 changes: 4 additions & 7 deletions sample/cockpit/cockpitRed.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
color:
type: color
description: "Text color"
value: "#ff0033"
colorDescription: "Torch red"
footer: "Created with ❤️ by Polidea"
showFooter: true
footer:
description: "Footer"
value: "Created with ❤️ by Polidea"
group: "Footer"
3 changes: 0 additions & 3 deletions sample/cockpit/cockpitStaging.yml

This file was deleted.

1 change: 0 additions & 1 deletion sample/cockpit/cockpitStagingRedDebug.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.polidea.cockpit.sample.sampleparams
interface SampleContract {

interface View : SampleBaseContract.View<Presenter> {
fun setDebugDescription(description: String)

fun showCockpitUi()

fun showMessage(message: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import android.content.Context
import android.hardware.SensorManager
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.polidea.cockpit.cockpit.Cockpit
import com.polidea.cockpit.sample.R
import com.squareup.seismic.ShakeDetector
import kotlinx.android.synthetic.main.fragment_sample.*

class SampleFragment : SampleBaseFragment<SampleContract.Presenter>(), SampleContract.View, ShakeDetector.Listener {
override lateinit var presenter: SampleContract.Presenter

private val debugDescriptionView: TextView by lazy {
variant_include_container.findViewById<TextView>(R.id.cockpit_debug_textview)
}
override lateinit var presenter: SampleContract.Presenter

private val shakeDetector = ShakeDetector(this)

Expand All @@ -29,10 +23,6 @@ class SampleFragment : SampleBaseFragment<SampleContract.Presenter>(), SampleCon
shakeDetector.start(sensorManager)
}

override fun setDebugDescription(description: String) {
debugDescriptionView.text = description
}

override fun showCockpitUi() {
Cockpit.showCockpit(fragmentManager)
}
Expand Down
Loading

0 comments on commit a1c7f97

Please sign in to comment.