Skip to content

Commit 5fd0a03

Browse files
committed
Version bump to 1.4.0 and some clean up.
1 parent f0c75c7 commit 5fd0a03

File tree

9 files changed

+39
-61
lines changed

9 files changed

+39
-61
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SampleActivity : AppCompatActivity() {
5959
week_view_foo.eventConfig = config
6060

6161
// set up the WeekView with the data
62-
week_view_foo.addLessonsToTimetable(data)
62+
week_view_foo.addEvents(data)
6363
// optional: add an onClickListener for each event
6464
week_view_foo.setLessonClickListener {
6565
Toast.makeText(applicationContext, "Removing " + it.event.title, Toast.LENGTH_SHORT).show()
@@ -126,7 +126,7 @@ class SampleActivity : AppCompatActivity() {
126126
val day = DayOfWeek.values().asList().shuffled().first()
127127
val newEvents = listOf(createSampleEntry(day, startTime, endTime))
128128
newEvents.forEach { data.add(it) }
129-
week_view_foo.addLessonsToTimetable(data)
129+
week_view_foo.addEvents(data)
130130
registerForContextMenu(week_view_foo)
131131
return true
132132
}

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
defaultConfig {
1111
minSdkVersion 16
1212
targetSdkVersion 28
13-
versionCode 2
14-
versionName "1.3.0"
13+
versionCode 3
14+
versionName "1.4.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ internal object DayOfWeekUtil {
1818
* Considers the first day of the week for the given [Locale],
1919
* as well as if a day is 'enabled' and skips it.
2020
*/
21-
fun mapDayToColumn(calendarDay: DayOfWeek, saturdayEnabled: Boolean, sundayEnabled: Boolean): Int {
21+
fun mapDayToColumn(day: DayOfWeek, saturdayEnabled: Boolean, sundayEnabled: Boolean): Int {
2222
val firstDayOfTheWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek
2323

24-
if (calendarDay == DayOfWeek.SATURDAY && !saturdayEnabled) {
24+
if (day == DayOfWeek.SATURDAY && !saturdayEnabled) {
2525
throw java.lang.IllegalStateException("Passed saturday although it is disabled")
2626
}
2727

28-
if (calendarDay == DayOfWeek.SUNDAY && !sundayEnabled) {
28+
if (day == DayOfWeek.SUNDAY && !sundayEnabled) {
2929
throw java.lang.IllegalStateException("Passed sunday although it is disabled")
3030
}
3131

3232
when (firstDayOfTheWeek) {
3333

3434
DayOfWeek.MONDAY -> {
3535
// mo: 0, fr:4, su:6
36-
val column = calendarDay.value
37-
return if (!saturdayEnabled && calendarDay == DayOfWeek.SUNDAY) {
36+
val column = day.value
37+
return if (!saturdayEnabled && day == DayOfWeek.SUNDAY) {
3838
5
3939
} else {
4040
column - 1
@@ -45,40 +45,40 @@ internal object DayOfWeekUtil {
4545
// sa: 0, su: 1, fr: 6,
4646
if (saturdayEnabled) {
4747
return if (sundayEnabled) {
48-
when (calendarDay) {
48+
when (day) {
4949
DayOfWeek.SATURDAY -> 0
5050
DayOfWeek.SUNDAY -> 1
51-
else -> calendarDay.value + 1
51+
else -> day.value + 1
5252
}
5353
} else {
54-
return when (calendarDay) {
54+
return when (day) {
5555
DayOfWeek.SATURDAY -> 0
56-
else -> calendarDay.value
56+
else -> day.value
5757
}
5858
}
5959
} else {
6060
return if (sundayEnabled) {
61-
when (calendarDay) {
61+
when (day) {
6262
DayOfWeek.SUNDAY -> 0
63-
else -> calendarDay.value
63+
else -> day.value
6464
}
6565
} else {
66-
return calendarDay.value - 1
66+
return day.value - 1
6767
}
6868
}
6969
}
7070

7171
DayOfWeek.SUNDAY -> {
7272
return if (sundayEnabled) {
7373
// su: 0, mo: 1 fr: 5, sa: 6
74-
if (calendarDay == DayOfWeek.SUNDAY) {
74+
if (day == DayOfWeek.SUNDAY) {
7575
0
7676
} else {
77-
calendarDay.value
77+
day.value
7878
}
7979
} else {
8080
// mo: 0 fr: 4, sa: 5, su: -1
81-
calendarDay.value - 1
81+
day.value - 1
8282
}
8383
}
8484
else -> throw IllegalStateException("$firstDayOfTheWeek das is not supported as start day")
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package de.tobiasschuerg.weekview.util
22

3-
import android.content.Context
4-
import android.text.format.DateFormat.getTimeFormat
53
import org.threeten.bp.LocalTime
64
import org.threeten.bp.format.DateTimeFormatter
7-
import java.text.SimpleDateFormat
5+
import org.threeten.bp.format.FormatStyle
86

9-
fun LocalTime.toLocalString(context: Context): String {
10-
val sdf: SimpleDateFormat = getTimeFormat(context) as SimpleDateFormat
11-
val format: DateTimeFormatter = DateTimeFormatter.ofPattern(sdf.toPattern())
12-
return format.format(this)
7+
private val localTimeFormat: DateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
8+
9+
internal fun LocalTime.toLocalString(): String {
10+
return localTimeFormat.format(this)
1311
}

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

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

3-
import android.content.Context
43
import android.view.View.MeasureSpec
54

6-
object ViewHelper {
7-
8-
fun dp2px(dip: Float, context: Context): Float = context.dipToPixelF(dip)
5+
internal object ViewHelper {
96

107
fun debugMeasureSpec(spec: Int): String {
118
val mode = MeasureSpec.getMode(spec)

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import de.tobiasschuerg.weekview.util.toLocalString
2424
/** this view is only constructed during runtime. */
2525
@SuppressLint("ViewConstructor")
2626
class EventView(
27-
context: Context,
28-
val event: Event.Single,
29-
val config: EventConfig,
30-
var scalingFactor: Float = 1f
27+
context: Context,
28+
val event: Event.Single,
29+
val config: EventConfig,
30+
var scalingFactor: Float = 1f
3131

3232
) : View(context) {
3333

@@ -94,18 +94,18 @@ class EventView(
9494
canvas.drawText(subjectName, (width / 2 - textBounds.centerX()).toFloat(), subjectY.toFloat(), textPaint)
9595

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

9999
// start time
100100
if (config.showTimeStart) {
101-
val startText = event.startTime.toLocalString(context)
101+
val startText = event.startTime.toLocalString()
102102
textPaint.getTextBounds(startText, 0, startText.length, textBounds)
103103
canvas.drawText(startText, (textBounds.left + paddingLeft).toFloat(), (textBounds.height() + paddingTop).toFloat(), textPaint)
104104
}
105105

106106
// end time
107107
if (config.showTimeEnd) {
108-
val endText = event.endTime.toLocalString(context)
108+
val endText = event.endTime.toLocalString()
109109
textPaint.getTextBounds(endText, 0, endText.length, textBounds)
110110
canvas.drawText(endText, (width - (textBounds.right + paddingRight)).toFloat(), (height - paddingBottom).toFloat(), textPaint)
111111
}
@@ -162,10 +162,10 @@ class EventView(
162162
override fun onAttachedToWindow() {
163163
super.onAttachedToWindow()
164164
val anim = ScaleAnimation(
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
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
169169
anim.fillAfter = true // Needed to keep the result of the animation
170170
anim.duration = 1000
171171
this.startAnimation(anim)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
9797
val minutes = nowOffset.toMinutes()
9898
val y = topOffsetPx + context.dipToPixelF(minutes * scalingFactor)
9999
accentPaint.alpha = 200
100-
canvas.drawLine(0f, y.toFloat(), canvas.width.toFloat(), y.toFloat(), accentPaint)
100+
canvas.drawLine(0f, y, canvas.width.toFloat(), y, accentPaint)
101101
}
102102
}
103103

@@ -112,7 +112,7 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
112112
drawLine(0f, y, width.toFloat(), y, paintDivider)
113113

114114
// final String timeString = localTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT));
115-
val timeString = localTime.toLocalString(context)
115+
val timeString = localTime.toLocalString()
116116
drawMultiLineText(this, timeString, context.dipToPixelF(25f), y + context.dipToPixelF(20f), mPaintLabels)
117117

118118
last = localTime

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class WeekView(context: Context, attributeSet: AttributeSet) : RelativeLayout(co
117117
}
118118
}
119119

120-
fun addLessonsToTimetable(weekData: WeekData) {
120+
fun addEvents(weekData: WeekData) {
121121
Log.d(TAG, "Adding ${weekData.getSingleEvents().size} weekData to timetable")
122122

123123
backgroundView.updateTimes(weekData.earliestStart, weekData.latestEnd)

library/src/test/java/de/tobiasschuerg/weekview/ExampleUnitTest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)