Skip to content

Commit

Permalink
refactor: autoformat using ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasschuerg committed Feb 11, 2022
1 parent ada9603 commit 57522b1
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 55 deletions.
40 changes: 20 additions & 20 deletions app/src/main/java/de/tobiasschuerg/weekview/sample/EventCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ object EventCreator {
private val titles = listOf("Title", "Event", "Android", "Sport", "Yoga", "Shopping", "Meeting")
private val subTitles = listOf("City Center", "@Home", "urgent", "New York", null)
private val weekDays = DayOfWeek.values()
// Filter the weekend
.filter { it != DayOfWeek.SATURDAY }
.filter { it != DayOfWeek.SUNDAY }
// Filter the weekend
.filter { it != DayOfWeek.SATURDAY }
.filter { it != DayOfWeek.SUNDAY }

private const val minEventLength = 30
private const val maxEventLength = 90
Expand All @@ -25,14 +25,14 @@ object EventCreator {
WeekData().apply {
var startTime: LocalTime
weekDays
.map { dayOfWeek ->
startTime = LocalTime.of(8 + random.nextInt(1), random.nextInt(60))
while (startTime.isBefore(LocalTime.of(15, 0))) {
val endTime = startTime.plusMinutes(minEventLength + random.nextInt(maxEventLength - minEventLength).toLong())
this.add(createSampleEntry(dayOfWeek, startTime, endTime))
startTime = endTime.plusMinutes(5 + random.nextInt(95).toLong())
}
.map { dayOfWeek ->
startTime = LocalTime.of(8 + random.nextInt(1), random.nextInt(60))
while (startTime.isBefore(LocalTime.of(15, 0))) {
val endTime = startTime.plusMinutes(minEventLength + random.nextInt(maxEventLength - minEventLength).toLong())
this.add(createSampleEntry(dayOfWeek, startTime, endTime))
startTime = endTime.plusMinutes(5 + random.nextInt(95).toLong())
}
}
}
}

Expand All @@ -47,19 +47,19 @@ object EventCreator {
val name = titles[random.nextInt(titles.size)]
val subTitle = subTitles[random.nextInt(subTitles.size)]
return Event.Single(
id = random.nextLong(),
date = LocalDate.now().with(day),
title = name,
shortTitle = name,
subTitle = subTitle,
startTime = startTime,
endTime = endTime,
textColor = Color.WHITE,
backgroundColor = randomColor()
id = random.nextLong(),
date = LocalDate.now().with(day),
title = name,
shortTitle = name,
subTitle = subTitle,
startTime = startTime,
endTime = endTime,
textColor = Color.WHITE,
backgroundColor = randomColor()
)
}

private fun randomColor(): Int {
return Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class SampleActivity : AppCompatActivity() {
weekView.addEvents(EventCreator.weekData)

val nowEvent = Event.Single(
id = 1337,
date = LocalDate.now(),
title = "Current hour",
shortTitle = "Now",
startTime = LocalTime.now().truncatedTo(ChronoUnit.HOURS),
endTime = LocalTime.now().truncatedTo(ChronoUnit.HOURS).plusMinutes(59),
backgroundColor = Color.RED,
textColor = Color.WHITE
id = 1337,
date = LocalDate.now(),
title = "Current hour",
shortTitle = "Now",
startTime = LocalTime.now().truncatedTo(ChronoUnit.HOURS),
endTime = LocalTime.now().truncatedTo(ChronoUnit.HOURS).plusMinutes(59),
backgroundColor = Color.RED,
textColor = Color.WHITE
)
weekView.addEvent(nowEvent)

Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:6.2.1"
}
}

plugins {
id "org.jlleitschuh.gradle.ktlint" version "9.2.1"
id "org.jlleitschuh.gradle.ktlint" version "10.2.1"
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ sealed class Event {

val lastDate: LocalDate
) : Event()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data class EventConfig(
val showSubtitle: Boolean = true,
val showLowerText: Boolean = true,
val showTimeEnd: Boolean = true
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ class WeekData {
singleEvents.clear()
allDays.clear()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class WeekViewConfig(val prefs: SharedPreferences) {
field = value
prefs.edit().putFloat(SCALING_FACTOR, value).apply()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ internal object Animation {
blinkAnimation.repeatCount = Animation.INFINITE
return blinkAnimation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ internal fun Context.dipToPixelF(dip: Float): Float {

internal fun Context.dipToPixelI(dip: Float): Int {
return dipToPixelF(dip).toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ internal object DayOfWeekUtil {
else -> throw IllegalStateException("$firstDayOfTheWeek das is not supported as start day")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ private val localTimeFormat: DateTimeFormatter = DateTimeFormatter.ofLocalizedTi

internal fun LocalTime.toLocalString(): String {
return localTimeFormat.format(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ internal object TextHelper {
// Use lo so that we undershoot rather than overshoot
return lo
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ class EventView(
val subjectY = getY(weight, weightTitle, textBounds)
canvas.drawText(subjectName, (width / 2 - textBounds.centerX()).toFloat(), subjectY.toFloat(), textPaint)

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

// start time
if (config.showTimeStart) {
Expand Down Expand Up @@ -162,10 +164,11 @@ class EventView(
override fun onAttachedToWindow() {
super.onAttachedToWindow()
val anim = ScaleAnimation(
0f, 1f, // Start and end values for the X axis scaling
0f, 1f, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, 0.5f) // Pivot point of Y scaling
0f, 1f, // Start and end values for the X axis scaling
0f, 1f, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, 0.5f
) // Pivot point of Y scaling
anim.fillAfter = true // Needed to keep the result of the animation
anim.duration = 1000
this.startAnimation(anim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
private var drawCount = 0

val days: MutableList<DayOfWeek> = DayOfWeekUtil.createList()
.toMutableList()
.apply {
remove(DayOfWeek.SATURDAY)
remove(DayOfWeek.SUNDAY)
}
.toMutableList()
.apply {
remove(DayOfWeek.SATURDAY)
remove(DayOfWeek.SUNDAY)
}

var startTime: LocalTime = LocalTime.of(10, 0)
private set
Expand Down Expand Up @@ -157,11 +157,11 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
private fun drawMultiLineText(canvas: Canvas, text: String, initialX: Float, initialY: Float, paint: Paint) {
var currentY = initialY
text.split(" ")
.dropLastWhile(String::isEmpty)
.forEach {
canvas.drawText(it, initialX, currentY, paint)
currentY += (-paint.ascent() + paint.descent()).toInt()
}
.dropLastWhile(String::isEmpty)
.forEach {
canvas.drawText(it, initialX, currentY, paint)
currentY += (-paint.ascent() + paint.descent()).toInt()
}
}

/**
Expand Down

0 comments on commit 57522b1

Please sign in to comment.