Skip to content

Commit 2f1fb56

Browse files
Merge pull request StephenVinouze#13 from StephenVinouze/task/danger
Danger and ktlint
2 parents d15e00f + 6b3f9e0 commit 2f1fb56

File tree

10 files changed

+219
-59
lines changed

10 files changed

+219
-59
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[*]
2+
charset=utf-8
3+
end_of_line=lf
4+
insert_final_newline=false
5+
indent_style=space
6+
indent_size=4
7+
max_line_length=150
8+
9+
[*.json]
10+
indent_style=space
11+
indent_size=2
12+

Dangerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Handle labels
2+
message "Please add labels to this PR" if github.pr_labels.empty?
3+
4+
can_merge = github.pr_json["mergeable"]
5+
message("This PR cannot be merged yet.", sticky: false) unless can_merge
6+
7+
message "This PR does not have any assignees yet." unless github.pr_json["assignee"]
8+
9+
# Handle milestones
10+
has_milestone = github.pr_json["milestone"] != nil
11+
message("This PR does not refer to an existing milestone", sticky: false) unless has_milestone
12+
13+
# Ignore issues out of PR scope
14+
github.dismiss_out_of_range_messages({
15+
error: false,
16+
warning: false,
17+
message: true,
18+
markdown: true
19+
})
20+
21+
# Ktlint
22+
checkstyle_dir = "**/reports/ktlint/ktlint*.xml"
23+
Dir[checkstyle_dir].each do |file_name|
24+
checkstyle_reports.inline_comment = true
25+
checkstyle_reports.report file_name
26+
end
27+
28+
# Lint
29+
lint_dir = "**/reports/lint-*.xml"
30+
Dir[lint_dir].each do |file_name|
31+
android_lint.skip_gradle_task = true
32+
android_lint.filtering = true
33+
android_lint.report_file = file_name
34+
android_lint.lint(inline_mode: true)
35+
end
36+
37+
# Unit tests
38+
junit_tests_dir = "**/test-results/**/*.xml"
39+
Dir[junit_tests_dir].each do |file_name|
40+
junit.parse file_name
41+
junit.show_skipped_tests = true
42+
junit.report
43+
end

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6+
7+
gem 'danger'
8+
gem 'danger-android_lint'
9+
gem "danger-checkstyle_reports"
10+
gem 'danger-junit'

Gemfile.lock

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.6.0)
5+
public_suffix (>= 2.0.2, < 4.0)
6+
ansi (1.5.0)
7+
ast (2.4.0)
8+
claide (1.0.2)
9+
claide-plugins (0.9.2)
10+
cork
11+
nap
12+
open4 (~> 1.3)
13+
colored2 (3.1.2)
14+
cork (0.3.0)
15+
colored2 (~> 3.1)
16+
danger (6.0.9)
17+
claide (~> 1.0)
18+
claide-plugins (>= 0.9.2)
19+
colored2 (~> 3.1)
20+
cork (~> 0.1)
21+
faraday (~> 0.9)
22+
faraday-http-cache (~> 2.0)
23+
git (~> 1.5)
24+
kramdown (~> 2.0)
25+
kramdown-parser-gfm (~> 1.0)
26+
no_proxy_fix
27+
octokit (~> 4.7)
28+
terminal-table (~> 1)
29+
danger-android_lint (0.0.7)
30+
danger-plugin-api (~> 1.0)
31+
oga
32+
danger-checkstyle_reports (0.1.0)
33+
danger-plugin-api (~> 1.0)
34+
danger-junit (1.0.0)
35+
danger (> 2.0)
36+
ox (~> 2.0)
37+
danger-plugin-api (1.0.0)
38+
danger (> 2.0)
39+
faraday (0.15.4)
40+
multipart-post (>= 1.2, < 3)
41+
faraday-http-cache (2.0.0)
42+
faraday (~> 0.8)
43+
git (1.5.0)
44+
kramdown (2.1.0)
45+
kramdown-parser-gfm (1.1.0)
46+
kramdown (~> 2.0)
47+
multipart-post (2.1.1)
48+
nap (1.1.0)
49+
no_proxy_fix (0.1.2)
50+
octokit (4.14.0)
51+
sawyer (~> 0.8.0, >= 0.5.3)
52+
oga (2.15)
53+
ast
54+
ruby-ll (~> 2.1)
55+
open4 (1.3.4)
56+
ox (2.10.1)
57+
public_suffix (3.1.0)
58+
ruby-ll (2.1.2)
59+
ansi
60+
ast
61+
sawyer (0.8.2)
62+
addressable (>= 2.3.5)
63+
faraday (> 0.8, < 2.0)
64+
terminal-table (1.8.0)
65+
unicode-display_width (~> 1.1, >= 1.1.1)
66+
unicode-display_width (1.6.0)
67+
68+
PLATFORMS
69+
ruby
70+
71+
DEPENDENCIES
72+
danger
73+
danger-android_lint
74+
danger-checkstyle_reports
75+
danger-junit
76+
77+
BUNDLED WITH
78+
2.0.1

build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33
buildscript {
44
ext.kotlin_version = '1.3.31'
55
repositories {
6+
google()
67
jcenter()
78
maven { url 'https://maven.google.com' }
8-
google()
9+
maven { url "https://plugins.gradle.org/m2/" }
910
}
1011
dependencies {
1112
classpath 'com.android.tools.build:gradle:3.4.1'
1213
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1314
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15+
classpath "org.jlleitschuh.gradle:ktlint-gradle:8.0.0"
1416
}
1517
}
1618

1719
allprojects {
1820
repositories {
19-
jcenter()
20-
maven { url 'https://maven.google.com' }
2121
google()
22+
jcenter()
2223
}
2324
}
2425

2526
task clean(type: Delete) {
2627
delete rootProject.buildDir
2728
}
29+
30+
ext.ReporterType = org.jlleitschuh.gradle.ktlint.reporter.ReporterType

core/src/main/java/com/github/stephenvinouze/materialnumberpickercore/MaterialNumberPicker.kt

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,31 @@ class MaterialNumberPicker : NumberPicker {
3535
field = value
3636
divider?.colorFilter = PorterDuffColorFilter(separatorColor, PorterDuff.Mode.SRC_IN)
3737
}
38-
3938
var textColor: Int = DEFAULT_TEXT_COLOR
4039
set(value) {
4140
field = value
4241
updateTextAttributes()
4342
}
44-
4543
var textStyle: Int = DEFAULT_TEXT_STYLE
4644
set(value) {
4745
field = value
4846
updateTextAttributes()
4947
}
50-
5148
var textSize: Int = DEFAULT_TEXT_SIZE
5249
set(value) {
5350
field = value
5451
updateTextAttributes()
5552
}
56-
5753
var editable: Boolean = DEFAULT_EDITABLE
5854
set(value) {
5955
field = value
6056
descendantFocusability = if (value) ViewGroup.FOCUS_AFTER_DESCENDANTS else ViewGroup.FOCUS_BLOCK_DESCENDANTS
6157
}
62-
6358
var fontName: String? = null
6459
set(value) {
6560
field = value
6661
updateTextAttributes()
6762
}
68-
6963
private val inputEditText: EditText? by lazy {
7064
try {
7165
val f = NumberPicker::class.java.getDeclaredField("mInputText")
@@ -75,7 +69,6 @@ class MaterialNumberPicker : NumberPicker {
7569
null
7670
}
7771
}
78-
7972
private val wheelPaint: Paint? by lazy {
8073
try {
8174
val selectorWheelPaintField = NumberPicker::class.java.getDeclaredField("mSelectorWheelPaint")
@@ -85,7 +78,6 @@ class MaterialNumberPicker : NumberPicker {
8578
null
8679
}
8780
}
88-
8981
private val divider: Drawable? by lazy {
9082
val dividerField = NumberPicker::class.java.declaredFields.firstOrNull { it.name == "mSelectionDivider" }
9183
dividerField?.let {
@@ -99,18 +91,19 @@ class MaterialNumberPicker : NumberPicker {
9991
}
10092

10193
@JvmOverloads
102-
constructor(context: Context,
103-
minValue: Int = DEFAULT_VALUE,
104-
maxValue: Int = MAX_VALUE,
105-
value: Int = DEFAULT_VALUE,
106-
separatorColor: Int = DEFAULT_SEPARATOR_COLOR,
107-
textColor: Int = DEFAULT_TEXT_COLOR,
108-
textSize: Int = DEFAULT_TEXT_SIZE,
109-
textStyle: Int = DEFAULT_TEXT_STYLE,
110-
editable: Boolean = DEFAULT_EDITABLE,
111-
wrapped: Boolean = DEFAULT_WRAPPED,
112-
fontName: String? = null,
113-
formatter: Formatter? = null
94+
constructor(
95+
context: Context,
96+
minValue: Int = DEFAULT_VALUE,
97+
maxValue: Int = MAX_VALUE,
98+
value: Int = DEFAULT_VALUE,
99+
separatorColor: Int = DEFAULT_SEPARATOR_COLOR,
100+
textColor: Int = DEFAULT_TEXT_COLOR,
101+
textSize: Int = DEFAULT_TEXT_SIZE,
102+
textStyle: Int = DEFAULT_TEXT_STYLE,
103+
editable: Boolean = DEFAULT_EDITABLE,
104+
wrapped: Boolean = DEFAULT_WRAPPED,
105+
fontName: String? = null,
106+
formatter: Formatter? = null
114107
) : super(context) {
115108
this.minValue = minValue
116109
this.maxValue = maxValue
@@ -159,25 +152,29 @@ class MaterialNumberPicker : NumberPicker {
159152
* Uses reflection to access text size private attribute for both wheel and edit text inside the number picker.
160153
*/
161154
private fun updateTextAttributes() {
162-
val typeface = if (fontName != null) Typeface.createFromAsset(context.assets, "fonts/$fontName") else Typeface.create(Typeface.DEFAULT, textStyle)
155+
val typeface = if (fontName != null)
156+
Typeface.createFromAsset(context.assets, "fonts/$fontName")
157+
else
158+
Typeface.create(Typeface.DEFAULT, textStyle)
159+
163160
wheelPaint?.let { paint ->
164161
paint.color = textColor
165162
paint.textSize = textSize.toFloat()
166163
paint.typeface = typeface
167-
168-
val childEditText = (0 until childCount).map { getChildAt(it) as? EditText }.firstOrNull()
169-
childEditText?.let {
170-
it.setTextColor(textColor)
171-
it.setTextSize(TypedValue.COMPLEX_UNIT_SP, pixelsToSp(context, textSize.toFloat()))
172-
it.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_NORMAL
173-
it.typeface = typeface
174-
175-
invalidate()
176-
}
164+
(0 until childCount)
165+
.map { getChildAt(it) as? EditText }
166+
.firstOrNull()
167+
?.let {
168+
it.setTextColor(textColor)
169+
it.setTextSize(TypedValue.COMPLEX_UNIT_SP, pixelsToSp(context, textSize.toFloat()))
170+
it.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_NORMAL
171+
it.typeface = typeface
172+
173+
invalidate()
174+
}
177175
}
178176
}
179177

180178
private fun pixelsToSp(context: Context, px: Float): Float =
181-
px / context.resources.displayMetrics.scaledDensity
182-
179+
px / context.resources.displayMetrics.scaledDensity
183180
}

ktlint.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apply plugin: "org.jlleitschuh.gradle.ktlint"
2+
3+
ktlint {
4+
version = "0.33.0"
5+
android = true
6+
ignoreFailures = true
7+
enableExperimentalRules = true
8+
reporters = [ReporterType.CHECKSTYLE]
9+
}

library.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
3+
apply from: '../ktlint.gradle'
34

45
group = 'com.github.stephenvinouze'
56

@@ -24,6 +25,10 @@ android {
2425
test.java.srcDirs += 'src/test/kotlin'
2526
androidTest.java.srcDirs += 'src/androidTest/kotlin'
2627
}
28+
lintOptions {
29+
xmlReport true
30+
abortOnError false
31+
}
2732
}
2833

2934
task sourcesJar(type: Jar) {

sample/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
3+
apply from: '../ktlint.gradle'
34

45
android {
56
compileSdkVersion Integer.parseInt(ANDROID_BUILD_SDK_VERSION)
@@ -18,6 +19,10 @@ android {
1819
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1920
}
2021
}
22+
lintOptions {
23+
xmlReport true
24+
abortOnError false
25+
}
2126
}
2227

2328
dependencies {

0 commit comments

Comments
 (0)