Skip to content

Commit 3e11806

Browse files
split the padding of the header into top+bottom
added getters to some of the inner fields, so that you can put views on top of the WeekView on the correct places. replaced the time auto-update mechanism that used Handler to update every minute. Now uses proper BroadcastReceiver instead.
1 parent 068fdfb commit 3e11806

File tree

6 files changed

+124
-82
lines changed

6 files changed

+124
-82
lines changed

library/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ dependencies {
2222
implementation 'com.android.support:appcompat-v7:27.1.1'
2323
javadocDeps 'com.android.support:appcompat-v7:27.1.1'
2424
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
25-
//implementation 'androidx.core:core-ktx:0.3'
26-
2725
}
2826

2927
apply from: 'gradle-mvn-push.gradle'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.alamkanak.weekview
2+
3+
import android.content.BroadcastReceiver
4+
import android.content.Context
5+
import android.content.Intent
6+
import android.content.IntentFilter
7+
import java.util.*
8+
9+
/**a broadcast receiver that tells you when the time has changed (minute, date, configuration of time/date...), based on: https://stackoverflow.com/a/48782963/878126 */
10+
abstract class TimeChangedBroadcastReceiver : BroadcastReceiver() {
11+
private var curCal = Calendar.getInstance()
12+
13+
abstract fun onTimeChanged()
14+
15+
@Suppress("MemberVisibilityCanBePrivate")
16+
fun register(context: Context, cal: Calendar) {
17+
curCal = cal
18+
val filter = IntentFilter()
19+
filter.addAction(Intent.ACTION_TIME_CHANGED)
20+
filter.addAction(Intent.ACTION_DATE_CHANGED)
21+
filter.addAction(Intent.ACTION_TIME_TICK)
22+
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED)
23+
context.registerReceiver(this, filter)
24+
val newDate = Calendar.getInstance()
25+
if (!WeekViewUtil.isSameDayAndHourAndMinute(newDate, curCal)) {
26+
curCal = newDate
27+
onTimeChanged()
28+
}
29+
}
30+
31+
override fun onReceive(context: Context, intent: Intent) {
32+
val newTime = Calendar.getInstance()
33+
if (!WeekViewUtil.isSameDayAndHourAndMinute(newTime, curCal)) {
34+
curCal = newTime
35+
onTimeChanged()
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)