Skip to content

Commit b19ee50

Browse files
AndroidDeveloperLBhermansje
authored andcommitted
-converted project to Kotlin. Code can be shortened a lot, but requires some delicate work.
-fixed some time/date formatting related issues: alamkanak#497 alamkanak#495 (but not fixed RTL alignment issue) -created a new activity to demonstrate the paging of entire view (example: week by week snapping), based on this pull request: Quivr#88
1 parent 0f2acef commit b19ee50

20 files changed

+633
-620
lines changed

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4+
ext.kotlin_version = '1.2.41'
45
repositories {
56
jcenter()
67
google()
78
}
89
dependencies {
910
classpath 'com.android.tools.build:gradle:3.2.0-alpha13'
11+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1012

1113
// NOTE: Do not place your application dependencies here; they belong
1214
// in the individual module build.gradle files

library/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
24

35
repositories {
46
mavenCentral()
@@ -19,6 +21,7 @@ configurations {
1921
dependencies {
2022
compile 'com.android.support:appcompat-v7:27.1.1'
2123
javadocDeps 'com.android.support:appcompat-v7:27.1.1'
24+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2225
}
2326

2427
apply from: 'gradle-mvn-push.gradle'

library/gradle-mvn-push.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ apply plugin: 'maven'
1818
apply plugin: 'signing'
1919

2020
def isReleaseBuild() {
21-
return VERSION_NAME.contains("SNAPSHOT") == false
21+
return !VERSION_NAME.contains("SNAPSHOT")
2222
}
2323

2424
def getReleaseRepositoryUrl() {
@@ -112,4 +112,4 @@ afterEvaluate { project ->
112112
archives androidSourcesJar
113113
// archives androidJavadocsJar
114114
}
115-
}
115+
}

library/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<manifest package="com.alamkanak.weekview"></manifest>
1+
<manifest package="com.alamkanak.weekview"/>

library/src/main/java/com/alamkanak/weekview/DateTimeInterpreter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.alamkanak.weekview
22

3-
import java.util.Calendar
3+
import java.util.*
44

55
/**
66
* Created by Raquib on 1/6/2015.

library/src/main/java/com/alamkanak/weekview/MonthLoader.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.alamkanak.weekview
22

3-
import java.util.Calendar
3+
import java.util.*
44

55
class MonthLoader(var onMonthChangeListener: MonthChangeListener?) : WeekViewLoader {
66

77
override fun toWeekViewPeriodIndex(instance: Calendar): Double {
88
return (instance.get(Calendar.YEAR) * 12).toDouble() + instance.get(Calendar.MONTH).toDouble() + (instance.get(Calendar.DAY_OF_MONTH) - 1) / 30.0
99
}
1010

11-
override fun onLoad(periodIndex: Int): List<WeekViewEvent> {
11+
override fun onLoad(periodIndex: Int): List<WeekViewEvent>? {
1212
return onMonthChangeListener!!.onMonthChange(periodIndex / 12, periodIndex % 12 + 1)
1313
}
1414

@@ -25,6 +25,6 @@ class MonthLoader(var onMonthChangeListener: MonthChangeListener?) : WeekViewLoa
2525
*month of the events required by the view **1 based (not like JAVA API) : January = 1 and December = 12**.
2626
* @return a list of the events happening **during the specified month**.
2727
*/
28-
fun onMonthChange(newYear: Int, newMonth: Int): List<WeekViewEvent>
28+
fun onMonthChange(newYear: Int, newMonth: Int): List<WeekViewEvent>?
2929
}
3030
}

library/src/main/java/com/alamkanak/weekview/WeekView.kt

+308-294
Large diffs are not rendered by default.

library/src/main/java/com/alamkanak/weekview/WeekViewEvent.kt

+11-54
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package com.alamkanak.weekview
22

33
import android.graphics.Shader
44
import android.support.annotation.ColorInt
5-
6-
import java.util.ArrayList
7-
import java.util.Calendar
8-
95
import com.alamkanak.weekview.WeekViewUtil.isSameDay
6+
import java.util.*
107

118
/**
129
* Created by Raquib-ul-Alam Kanak on 7/21/2014.
@@ -26,15 +23,13 @@ class WeekViewEvent {
2623

2724
var id: Long
2825
@Deprecated("")
29-
get() = java.lang.Long.parseLong(identifier!!)
26+
get() = java.lang.Long.parseLong(identifier)
3027
@Deprecated("")
3128
set(id) {
3229
this.identifier = id.toString()
3330
}
3431

35-
constructor() {
36-
37-
}
32+
constructor()
3833

3934
/**
4035
* Initializes the event for week view.
@@ -103,7 +98,7 @@ class WeekViewEvent {
10398
* @param allDay Is the event an all day event.
10499
* @param shader the Shader of the event rectangle
105100
*/
106-
@JvmOverloads constructor(id: String, name: String, location: String?, startTime: Calendar, endTime: Calendar, allDay: Boolean = false, shader: Shader? = null) {
101+
@JvmOverloads constructor(id: String, name: String?, location: String?, startTime: Calendar, endTime: Calendar, allDay: Boolean = false, shader: Shader? = null) {
107102
this.identifier = id
108103
this.name = name
109104
this.location = location
@@ -150,11 +145,11 @@ class WeekViewEvent {
150145
constructor(id: Long, name: String, startTime: Calendar, endTime: Calendar) : this(id, name, null, startTime, endTime) {
151146
}
152147

153-
override fun equals(o: Any?): Boolean {
154-
if (this === o) return true
155-
if (o == null || javaClass != o.javaClass) return false
148+
override fun equals(other: Any?): Boolean {
149+
if (this === other) return true
150+
if (other == null || javaClass != other.javaClass) return false
156151

157-
val that = o as WeekViewEvent?
152+
val that = other as WeekViewEvent?
158153

159154
return identifier == that!!.identifier
160155
}
@@ -173,7 +168,7 @@ class WeekViewEvent {
173168
endTime = this.startTime!!.clone() as Calendar
174169
endTime.set(Calendar.HOUR_OF_DAY, 23)
175170
endTime.set(Calendar.MINUTE, 59)
176-
val event1 = WeekViewEvent(this.identifier, this.name, this.location, this.startTime, endTime, this.isAllDay)
171+
val event1 = WeekViewEvent(this.identifier!!, this.name, this.location, this.startTime!!, endTime, this.isAllDay)
177172
event1.color = this.color
178173
events.add(event1)
179174

@@ -187,7 +182,7 @@ class WeekViewEvent {
187182
val endOfOverDay = overDay.clone() as Calendar
188183
endOfOverDay.set(Calendar.HOUR_OF_DAY, 23)
189184
endOfOverDay.set(Calendar.MINUTE, 59)
190-
val eventMore = WeekViewEvent(this.identifier, this.name, null, overDay, endOfOverDay, this.isAllDay)
185+
val eventMore = WeekViewEvent(this.identifier!!, this.name, null, overDay, endOfOverDay, this.isAllDay)
191186
eventMore.color = this.color
192187
events.add(eventMore)
193188

@@ -199,7 +194,7 @@ class WeekViewEvent {
199194
val startTime = this.endTime!!.clone() as Calendar
200195
startTime.set(Calendar.HOUR_OF_DAY, 0)
201196
startTime.set(Calendar.MINUTE, 0)
202-
val event2 = WeekViewEvent(this.identifier, this.name, this.location, startTime, this.endTime, this.isAllDay)
197+
val event2 = WeekViewEvent(this.identifier!!, this.name, this.location, startTime, this.endTime!!, this.isAllDay)
203198
event2.color = this.color
204199
events.add(event2)
205200
} else {
@@ -209,41 +204,3 @@ class WeekViewEvent {
209204
return events
210205
}
211206
}
212-
/**
213-
* Initializes the event for week view.
214-
*
215-
* @param id The id of the event as String.
216-
* @param name Name of the event.
217-
* @param location The location of the event.
218-
* @param startTime The time when the event starts.
219-
* @param endTime The time when the event ends.
220-
* @param allDay Is the event an all day event
221-
*/
222-
/**
223-
* Initializes the event for week view.
224-
*
225-
* @param id The id of the event.
226-
* @param name Name of the event.
227-
* @param location The location of the event.
228-
* @param startTime The time when the event starts.
229-
* @param endTime The time when the event ends.
230-
* @param allDay Is the event an all day event
231-
*/
232-
/**
233-
* Initializes the event for week view.
234-
*
235-
* @param id The id of the event as String.
236-
* @param name Name of the event.
237-
* @param location The location of the event.
238-
* @param startTime The time when the event starts.
239-
* @param endTime The time when the event ends.
240-
*/
241-
/**
242-
* Initializes the event for week view.
243-
*
244-
* @param id The id of the event.
245-
* @param name Name of the event.
246-
* @param location The location of the event.
247-
* @param startTime The time when the event starts.
248-
* @param endTime The time when the event ends.
249-
*/
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
package com.alamkanak.weekview
2-
3-
import java.util.Calendar
4-
5-
interface WeekViewLoader {
6-
/**
7-
* Convert a date into a double that will be used to reference when you're loading data.
8-
*
9-
*
10-
* All periods that have the same integer part, define one period. Dates that are later in time
11-
* should have a greater return value.
12-
*
13-
* @param instance the date
14-
* @return The period index in which the date falls (floating point number).
15-
*/
16-
fun toWeekViewPeriodIndex(instance: Calendar): Double
17-
18-
/**
19-
* Load the events within the period
20-
*
21-
* @param periodIndex the period to load
22-
* @return A list with the events of this period
23-
*/
24-
fun onLoad(periodIndex: Int): List<WeekViewEvent>
25-
}
1+
package com.alamkanak.weekview
2+
3+
import java.util.*
4+
5+
interface WeekViewLoader {
6+
/**
7+
* Convert a date into a double that will be used to reference when you're loading data.
8+
*
9+
*
10+
* All periods that have the same integer part, define one period. Dates that are later in time
11+
* should have a greater return value.
12+
*
13+
* @param instance the date
14+
* @return The period index in which the date falls (floating point number).
15+
*/
16+
fun toWeekViewPeriodIndex(instance: Calendar): Double
17+
18+
/**
19+
* Load the events within the period
20+
*
21+
* @param periodIndex the period to load
22+
* @return A list with the events of this period
23+
*/
24+
fun onLoad(periodIndex: Int): List<WeekViewEvent>?
25+
}

0 commit comments

Comments
 (0)