Skip to content

Commit bbf617f

Browse files
committed
Added ktlint and reformatted the whole project.
1 parent 6c35c37 commit bbf617f

File tree

15 files changed

+88
-92
lines changed

15 files changed

+88
-92
lines changed

app/src/main/java/de/tobiasschuerg/weekview/sample/SampleActivity.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ package de.tobiasschuerg.weekview.sample
22

33
import android.graphics.Color
44
import android.os.Bundle
5-
import androidx.appcompat.app.AppCompatActivity
65
import android.util.Log
76
import android.view.ContextMenu
87
import android.view.Menu
98
import android.view.MenuItem
109
import android.view.View
1110
import android.widget.Toast
11+
import androidx.appcompat.app.AppCompatActivity
1212
import com.jakewharton.threetenabp.AndroidThreeTen
1313
import de.tobiasschuerg.weekview.data.Event
1414
import de.tobiasschuerg.weekview.data.EventConfig
1515
import de.tobiasschuerg.weekview.data.WeekData
1616
import de.tobiasschuerg.weekview.view.EventView
17-
import kotlinx.android.synthetic.main.activity_sample.*
17+
import kotlinx.android.synthetic.main.activity_sample.week_view_foo
1818
import org.threeten.bp.LocalDate
1919
import org.threeten.bp.LocalTime
20-
import java.util.*
20+
import java.util.Calendar
21+
import java.util.Random
2122
import kotlin.math.absoluteValue
2223

23-
2424
class SampleActivity : AppCompatActivity() {
2525

2626
private val random = Random()
@@ -50,7 +50,6 @@ class SampleActivity : AppCompatActivity() {
5050
super.onCreate(savedInstanceState)
5151
setContentView(R.layout.activity_sample)
5252

53-
5453
val config = EventConfig(showSubtitle = false, showTimeEnd = false)
5554
week_view_foo.eventConfig = config
5655

@@ -69,12 +68,10 @@ class SampleActivity : AppCompatActivity() {
6968
1 -> {
7069
Log.d("Scroll", "1-pointer touch")
7170
v.parent.requestDisallowInterceptTouchEvent(false)
72-
7371
}
7472
2 -> {
7573
Log.d("Zoom", "2-pointer touch")
7674
v.parent.requestDisallowInterceptTouchEvent(true)
77-
7875
}
7976
}
8077
false
@@ -93,7 +90,7 @@ class SampleActivity : AppCompatActivity() {
9390
day,
9491
startTime,
9592
endTime,
96-
null, //"upper",
93+
null, // "upper",
9794
null, // "lower",
9895
Color.WHITE,
9996
randomColor()
@@ -128,5 +125,4 @@ class SampleActivity : AppCompatActivity() {
128125
registerForContextMenu(week_view_foo)
129126
return true
130127
}
131-
132128
}

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@ buildscript {
55
repositories {
66
google()
77
jcenter()
8+
maven { url "https://plugins.gradle.org/m2/" }
89
}
910
dependencies {
1011
classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
1112
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1213
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
14+
classpath "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:6.2.1"
1315
}
1416
}
1517

18+
plugins {
19+
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
20+
}
21+
22+
subprojects {
23+
apply plugin: "org.jlleitschuh.gradle.ktlint"
24+
}
25+
1626
allprojects {
1727
repositories {
1828
google()

library/src/androidTest/java/de/tobiasschuerg/weekview/ExampleInstrumentedTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package de.tobiasschuerg.weekview;
22

33
import android.content.Context;
4-
import androidx.test.InstrumentationRegistry;
5-
import androidx.test.runner.AndroidJUnit4;
64

75
import org.junit.Test;
86
import org.junit.runner.RunWith;
97

10-
import static org.junit.Assert.*;
8+
import androidx.test.InstrumentationRegistry;
9+
import androidx.test.runner.AndroidJUnit4;
10+
11+
import static org.junit.Assert.assertEquals;
1112

1213
/**
1314
* Instrumented test, which will execute on an Android device.

library/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<manifest package="de.tobiasschuerg.weekview"/>
1+
<manifest package="de.tobiasschuerg.weekview" />

library/src/main/java/de/tobiasschuerg/weekview/data/Event.kt

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,38 @@ sealed class Event {
1212
abstract val shortTitle: String
1313

1414
data class Single(
15-
override val id: Long,
16-
override val date: LocalDate,
17-
override val title: String,
18-
override val shortTitle: String,
19-
val subTitle: String?,
15+
override val id: Long,
16+
override val date: LocalDate,
17+
override val title: String,
18+
override val shortTitle: String,
19+
val subTitle: String?,
2020

21-
val day: Int,
22-
val startTime: LocalTime,
23-
val endTime: LocalTime,
21+
val day: Int,
22+
val startTime: LocalTime,
23+
val endTime: LocalTime,
2424

25-
val upperText: String?,
26-
val lowerText: String?,
25+
val upperText: String?,
26+
val lowerText: String?,
2727

28-
val textColor: Int,
29-
val backgroundColor: Int
28+
val textColor: Int,
29+
val backgroundColor: Int
3030
) : Event() {
3131
val duration: Duration = Duration.between(startTime, endTime)
3232
}
3333

3434
data class AllDay(
35-
override val id: Long,
36-
override val date: LocalDate,
37-
override val title: String,
38-
override val shortTitle: String
35+
override val id: Long,
36+
override val date: LocalDate,
37+
override val title: String,
38+
override val shortTitle: String
3939
) : Event()
4040

4141
data class MultiDay(
42-
override val id: Long,
43-
override val date: LocalDate,
44-
override val title: String,
45-
override val shortTitle: String,
42+
override val id: Long,
43+
override val date: LocalDate,
44+
override val title: String,
45+
override val shortTitle: String,
4646

47-
val lastDate: LocalDate
47+
val lastDate: LocalDate
4848
) : Event()
49-
5049
}

library/src/main/java/de/tobiasschuerg/weekview/data/EventConfig.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ package de.tobiasschuerg.weekview.data
66
* Created by Tobias Schürg on 04.03.2018.
77
*/
88
data class EventConfig(
9-
val useShortNames: Boolean = true,
10-
val showTimeStart: Boolean = true,
11-
val showUpperText: Boolean = true,
12-
val showSubtitle: Boolean = true,
13-
val showLowerText: Boolean = true,
14-
val showTimeEnd: Boolean = true
9+
val useShortNames: Boolean = true,
10+
val showTimeStart: Boolean = true,
11+
val showUpperText: Boolean = true,
12+
val showSubtitle: Boolean = true,
13+
val showLowerText: Boolean = true,
14+
val showTimeEnd: Boolean = true
1515
)

library/src/main/java/de/tobiasschuerg/weekview/util/Animation.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ internal object Animation {
1313
blinkAnimation.repeatCount = Animation.INFINITE
1414
return blinkAnimation
1515
}
16-
1716
}

library/src/main/java/de/tobiasschuerg/weekview/util/DayHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package de.tobiasschuerg.weekview.util
22

33
import java.text.DateFormatSymbols
4-
import java.util.*
4+
import java.util.ArrayList
5+
import java.util.Calendar
56

67
internal object DayHelper {
78

@@ -24,5 +25,4 @@ internal object DayHelper {
2425
}
2526
return days
2627
}
27-
2828
}

library/src/main/java/de/tobiasschuerg/weekview/util/TextHelper.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ internal object TextHelper {
2929
// Use lo so that we undershoot rather than overshoot
3030
return lo
3131
}
32-
3332
}

library/src/main/java/de/tobiasschuerg/weekview/util/ViewHelper.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package de.tobiasschuerg.weekview.util
33
import android.content.Context
44
import android.view.View.MeasureSpec
55

6-
76
object ViewHelper {
87

98
fun dp2px(dip: Float, context: Context): Float = context.dipToPixelF(dip)
@@ -18,7 +17,4 @@ object ViewHelper {
1817
else -> "? $size px"
1918
}
2019
}
21-
2220
}
23-
24-

library/src/main/java/de/tobiasschuerg/weekview/view/EventView.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ import android.view.animation.ScaleAnimation
1515
import de.tobiasschuerg.weekview.BuildConfig
1616
import de.tobiasschuerg.weekview.data.Event
1717
import de.tobiasschuerg.weekview.data.EventConfig
18-
import de.tobiasschuerg.weekview.util.*
18+
import de.tobiasschuerg.weekview.util.TextHelper
19+
import de.tobiasschuerg.weekview.util.ViewHelper
20+
import de.tobiasschuerg.weekview.util.dipToPixelF
21+
import de.tobiasschuerg.weekview.util.dipToPixelI
22+
import de.tobiasschuerg.weekview.util.toLocalString
1923

2024
/** this view is only constructed during runtime. */
2125
@SuppressLint("ViewConstructor")
2226
class EventView(
23-
context: Context,
24-
val event: Event.Single,
25-
val config: EventConfig,
26-
var scalingFactor: Float = 1f
27-
27+
context: Context,
28+
val event: Event.Single,
29+
val config: EventConfig,
30+
var scalingFactor: Float = 1f
2831

2932
) : View(context) {
3033

@@ -45,7 +48,6 @@ class EventView(
4548
private val weightLowerText: Int
4649
private val weightEndTime: Int
4750

48-
4951
init {
5052
val padding = this.context.dipToPixelI(2f)
5153
setPadding(padding, padding, padding, padding)
@@ -92,7 +94,7 @@ class EventView(
9294
canvas.drawText(subjectName, (width / 2 - textBounds.centerX()).toFloat(), subjectY.toFloat(), textPaint)
9395

9496
textPaint.textSize = TextHelper.fitText("123456", maxTextSize, width / 2,
95-
getY(position = 1, bounds = textBounds) - getY(position = 0, bounds = textBounds))
97+
getY(position = 1, bounds = textBounds) - getY(position = 0, bounds = textBounds))
9698

9799
// start time
98100
if (config.showTimeStart) {
@@ -128,7 +130,6 @@ class EventView(
128130
val locationY = getY(position = weightStartTime + weightUpperText + weightTitle + weightSubTitle, bounds = textBounds)
129131
canvas.drawText(event.lowerText, (width / 2 - textBounds.centerX()).toFloat(), locationY.toFloat(), textPaint)
130132
}
131-
132133
}
133134

134135
private fun getY(position: Int, weight: Int = 1, bounds: Rect): Int {
@@ -161,10 +162,10 @@ class EventView(
161162
override fun onAttachedToWindow() {
162163
super.onAttachedToWindow()
163164
val anim = ScaleAnimation(
164-
0f, 1f, // Start and end values for the X axis scaling
165-
0f, 1f, // Start and end values for the Y axis scaling
166-
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
167-
Animation.RELATIVE_TO_SELF, 0.5f) // Pivot point of Y scaling
165+
0f, 1f, // Start and end values for the X axis scaling
166+
0f, 1f, // Start and end values for the Y axis scaling
167+
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
168+
Animation.RELATIVE_TO_SELF, 0.5f) // Pivot point of Y scaling
168169
anim.fillAfter = true // Needed to keep the result of the animation
169170
anim.duration = 1000
170171
this.startAnimation(anim)

library/src/main/java/de/tobiasschuerg/weekview/view/WeekBackgroundView.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import org.threeten.bp.Duration
1515
import org.threeten.bp.LocalTime
1616
import org.threeten.bp.temporal.ChronoUnit
1717
import java.text.DateFormatSymbols
18-
import java.util.*
18+
import java.util.Calendar
1919
import kotlin.math.roundToInt
2020

21-
2221
internal class WeekBackgroundView constructor(context: Context) : View(context) {
2322

2423
private val accentPaint: Paint by lazy {
@@ -49,11 +48,11 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
4948
private var drawCount = 0
5049

5150
val days: MutableList<Int> = DayHelper.createListStartingOn()
52-
.toMutableList()
53-
.apply {
54-
remove(Calendar.SATURDAY)
55-
remove(Calendar.SUNDAY)
56-
}
51+
.toMutableList()
52+
.apply {
53+
remove(Calendar.SATURDAY)
54+
remove(Calendar.SUNDAY)
55+
}
5756

5857
var startTime: LocalTime = LocalTime.of(10, 0)
5958
private set
@@ -156,11 +155,11 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
156155
private fun drawMultiLineText(canvas: Canvas, text: String, initialX: Float, initialY: Float, paint: Paint) {
157156
var currentY = initialY
158157
text.split(" ")
159-
.dropLastWhile(String::isEmpty)
160-
.forEach {
161-
canvas.drawText(it, initialX, currentY, paint)
162-
currentY += (-paint.ascent() + paint.descent()).toInt()
163-
}
158+
.dropLastWhile(String::isEmpty)
159+
.forEach {
160+
canvas.drawText(it, initialX, currentY, paint)
161+
currentY += (-paint.ascent() + paint.descent()).toInt()
162+
}
164163
}
165164

166165
/**
@@ -194,7 +193,6 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
194193
super.onMeasure(widthMeasureSpec, heightMeasureSpec2)
195194
}
196195

197-
198196
fun setScreenshotMode(screenshotMode: Boolean) {
199197
isInScreenshotMode = screenshotMode
200198
}

0 commit comments

Comments
 (0)