Skip to content

Commit

Permalink
-converted project to Kotlin. Code can be shortened a lot, but requir…
Browse files Browse the repository at this point in the history
…es 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
  • Loading branch information
AndroidDeveloperLB authored and hermansje committed May 15, 2018
1 parent 0f2acef commit b19ee50
Show file tree
Hide file tree
Showing 20 changed files with 633 additions and 620 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.41'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha13'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
3 changes: 3 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

repositories {
mavenCentral()
Expand All @@ -19,6 +21,7 @@ configurations {
dependencies {
compile 'com.android.support:appcompat-v7:27.1.1'
javadocDeps 'com.android.support:appcompat-v7:27.1.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

apply from: 'gradle-mvn-push.gradle'
4 changes: 2 additions & 2 deletions library/gradle-mvn-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'maven'
apply plugin: 'signing'

def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
return !VERSION_NAME.contains("SNAPSHOT")
}

def getReleaseRepositoryUrl() {
Expand Down Expand Up @@ -112,4 +112,4 @@ afterEvaluate { project ->
archives androidSourcesJar
// archives androidJavadocsJar
}
}
}
2 changes: 1 addition & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<manifest package="com.alamkanak.weekview"></manifest>
<manifest package="com.alamkanak.weekview"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alamkanak.weekview

import java.util.Calendar
import java.util.*

/**
* Created by Raquib on 1/6/2015.
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/com/alamkanak/weekview/MonthLoader.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.alamkanak.weekview

import java.util.Calendar
import java.util.*

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

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

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

Expand All @@ -25,6 +25,6 @@ class MonthLoader(var onMonthChangeListener: MonthChangeListener?) : WeekViewLoa
*month of the events required by the view **1 based (not like JAVA API) : January = 1 and December = 12**.
* @return a list of the events happening **during the specified month**.
*/
fun onMonthChange(newYear: Int, newMonth: Int): List<WeekViewEvent>
fun onMonthChange(newYear: Int, newMonth: Int): List<WeekViewEvent>?
}
}
602 changes: 308 additions & 294 deletions library/src/main/java/com/alamkanak/weekview/WeekView.kt

Large diffs are not rendered by default.

65 changes: 11 additions & 54 deletions library/src/main/java/com/alamkanak/weekview/WeekViewEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package com.alamkanak.weekview

import android.graphics.Shader
import android.support.annotation.ColorInt

import java.util.ArrayList
import java.util.Calendar

import com.alamkanak.weekview.WeekViewUtil.isSameDay
import java.util.*

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

var id: Long
@Deprecated("")
get() = java.lang.Long.parseLong(identifier!!)
get() = java.lang.Long.parseLong(identifier)
@Deprecated("")
set(id) {
this.identifier = id.toString()
}

constructor() {

}
constructor()

/**
* Initializes the event for week view.
Expand Down Expand Up @@ -103,7 +98,7 @@ class WeekViewEvent {
* @param allDay Is the event an all day event.
* @param shader the Shader of the event rectangle
*/
@JvmOverloads constructor(id: String, name: String, location: String?, startTime: Calendar, endTime: Calendar, allDay: Boolean = false, shader: Shader? = null) {
@JvmOverloads constructor(id: String, name: String?, location: String?, startTime: Calendar, endTime: Calendar, allDay: Boolean = false, shader: Shader? = null) {
this.identifier = id
this.name = name
this.location = location
Expand Down Expand Up @@ -150,11 +145,11 @@ class WeekViewEvent {
constructor(id: Long, name: String, startTime: Calendar, endTime: Calendar) : this(id, name, null, startTime, endTime) {
}

override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false

val that = o as WeekViewEvent?
val that = other as WeekViewEvent?

return identifier == that!!.identifier
}
Expand All @@ -173,7 +168,7 @@ class WeekViewEvent {
endTime = this.startTime!!.clone() as Calendar
endTime.set(Calendar.HOUR_OF_DAY, 23)
endTime.set(Calendar.MINUTE, 59)
val event1 = WeekViewEvent(this.identifier, this.name, this.location, this.startTime, endTime, this.isAllDay)
val event1 = WeekViewEvent(this.identifier!!, this.name, this.location, this.startTime!!, endTime, this.isAllDay)
event1.color = this.color
events.add(event1)

Expand All @@ -187,7 +182,7 @@ class WeekViewEvent {
val endOfOverDay = overDay.clone() as Calendar
endOfOverDay.set(Calendar.HOUR_OF_DAY, 23)
endOfOverDay.set(Calendar.MINUTE, 59)
val eventMore = WeekViewEvent(this.identifier, this.name, null, overDay, endOfOverDay, this.isAllDay)
val eventMore = WeekViewEvent(this.identifier!!, this.name, null, overDay, endOfOverDay, this.isAllDay)
eventMore.color = this.color
events.add(eventMore)

Expand All @@ -199,7 +194,7 @@ class WeekViewEvent {
val startTime = this.endTime!!.clone() as Calendar
startTime.set(Calendar.HOUR_OF_DAY, 0)
startTime.set(Calendar.MINUTE, 0)
val event2 = WeekViewEvent(this.identifier, this.name, this.location, startTime, this.endTime, this.isAllDay)
val event2 = WeekViewEvent(this.identifier!!, this.name, this.location, startTime, this.endTime!!, this.isAllDay)
event2.color = this.color
events.add(event2)
} else {
Expand All @@ -209,41 +204,3 @@ class WeekViewEvent {
return events
}
}
/**
* Initializes the event for week view.
*
* @param id The id of the event as String.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
* @param allDay Is the event an all day event
*/
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
* @param allDay Is the event an all day event
*/
/**
* Initializes the event for week view.
*
* @param id The id of the event as String.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
*/
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
*/
50 changes: 25 additions & 25 deletions library/src/main/java/com/alamkanak/weekview/WeekViewLoader.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.alamkanak.weekview

import java.util.Calendar

interface WeekViewLoader {
/**
* Convert a date into a double that will be used to reference when you're loading data.
*
*
* All periods that have the same integer part, define one period. Dates that are later in time
* should have a greater return value.
*
* @param instance the date
* @return The period index in which the date falls (floating point number).
*/
fun toWeekViewPeriodIndex(instance: Calendar): Double

/**
* Load the events within the period
*
* @param periodIndex the period to load
* @return A list with the events of this period
*/
fun onLoad(periodIndex: Int): List<WeekViewEvent>
}
package com.alamkanak.weekview

import java.util.*

interface WeekViewLoader {
/**
* Convert a date into a double that will be used to reference when you're loading data.
*
*
* All periods that have the same integer part, define one period. Dates that are later in time
* should have a greater return value.
*
* @param instance the date
* @return The period index in which the date falls (floating point number).
*/
fun toWeekViewPeriodIndex(instance: Calendar): Double

/**
* Load the events within the period
*
* @param periodIndex the period to load
* @return A list with the events of this period
*/
fun onLoad(periodIndex: Int): List<WeekViewEvent>?
}
Loading

0 comments on commit b19ee50

Please sign in to comment.