Skip to content

Commit 4dfe663

Browse files
author
kgoel
committed
Moved to androidx and added gesture for left and right swipe
1 parent 187161d commit 4dfe663

File tree

10 files changed

+261
-129
lines changed

10 files changed

+261
-129
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/shrikanthravi/collapsiblecalendarview/MainActivity.kt

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ package com.shrikanthravi.collapsiblecalendarview
33
import android.graphics.Color
44
import androidx.appcompat.app.AppCompatActivity
55
import android.os.Bundle
6+
import android.util.Log
7+
import android.view.MotionEvent
68
import android.view.View
9+
import android.widget.RelativeLayout
10+
import android.widget.ScrollView
11+
import android.widget.TextView
12+
import androidx.constraintlayout.widget.ConstraintLayout
13+
import com.shrikanthravi.collapsiblecalendarview.data.Day
14+
import com.shrikanthravi.collapsiblecalendarview.view.OnSwipeTouchListener
715

816
import com.shrikanthravi.collapsiblecalendarview.widget.CollapsibleCalendar
917
import com.shrikanthravi.collapsiblecalendarview.widget.UICalendar
@@ -13,23 +21,51 @@ import java.util.Date
1321
import java.util.GregorianCalendar
1422

1523

16-
class MainActivity : AppCompatActivity() {
24+
class MainActivity : AppCompatActivity(){
25+
companion object{
26+
var TAG = "MainActivity";
27+
}
28+
29+
lateinit var collapsibleCalendar:CollapsibleCalendar
30+
1731

1832
override fun onCreate(savedInstanceState: Bundle?) {
1933
super.onCreate(savedInstanceState)
2034
setContentView(R.layout.activity_main)
2135
supportActionBar!!.elevation = 0f
2236
window.statusBarColor = resources.getColor(R.color.google_red)
37+
var relativeLayout = findViewById<ScrollView>(R.id.scrollView)
38+
var textView = findViewById<TextView>(R.id.tv_date)
39+
40+
collapsibleCalendar = findViewById(R.id.collapsibleCalendarView)
41+
relativeLayout.setOnTouchListener(object:OnSwipeTouchListener(this@MainActivity){
42+
override fun onSwipeRight() {
43+
44+
}
45+
46+
override fun onSwipeLeft() {
2347

24-
val collapsibleCalendar = findViewById<CollapsibleCalendar>(R.id.collapsibleCalendarView)
48+
}
49+
50+
override fun onSwipeTop() {
51+
if(collapsibleCalendar.expanded){
52+
collapsibleCalendar.collapse(400)
53+
}
54+
}
55+
56+
override fun onSwipeBottom() {
57+
if(!collapsibleCalendar.expanded){
58+
collapsibleCalendar.expand(400)
59+
}
60+
}
61+
});
2562
//To hide or show expand icon
2663
collapsibleCalendar.setExpandIconVisible(true)
2764
val today = GregorianCalendar()
2865
collapsibleCalendar.addEventTag(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH))
2966
today.add(Calendar.DATE, 1)
3067
collapsibleCalendar.addEventTag(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH), Color.BLUE)
31-
32-
println("Testing date " + collapsibleCalendar.selectedDay.day + "/" + collapsibleCalendar.selectedDay.month + "/" + collapsibleCalendar.selectedDay.year)
68+
collapsibleCalendar.params = CollapsibleCalendar.Params(-10, 90)
3369
collapsibleCalendar.setCalendarListener(object : CollapsibleCalendar.CalendarListener {
3470
override fun onClickListener() {
3571
if(collapsibleCalendar.expanded){
@@ -41,7 +77,7 @@ class MainActivity : AppCompatActivity() {
4177
}
4278

4379
override fun onDaySelect() {
44-
80+
textView.text = collapsibleCalendar.selectedDay?.toUnixTime().toString()
4581
}
4682

4783
override fun onItemClick(v: View) {
Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<ScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
6+
android:id="@+id/scrollView"
57
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
tools:context="com.shrikanthravi.collapsiblecalendarview.MainActivity">
8-
<com.shrikanthravi.collapsiblecalendarview.widget.CollapsibleCalendar
9-
android:layout_width="match_parent"
8+
android:layout_height="match_parent">
9+
10+
<androidx.constraintlayout.widget.ConstraintLayout
1011
android:layout_height="wrap_content"
11-
app:primaryColor="@color/google_red"
12-
app:textColor="@android:color/white"
13-
app:selectedItem_textColor="@color/google_red"
14-
android:id="@+id/collapsibleCalendarView"
15-
app:todayItem_textColor="@android:color/white"
16-
app:todayItem_background="@drawable/circle_white_stroke_background"
17-
app:selectedItem_background="@drawable/circle_white_solid_background"
18-
app:buttonLeft_drawableTintColor="@android:color/white"
19-
app:buttonRight_drawableTintColor="@android:color/white"
20-
app:expandIconColor="@android:color/white"
21-
app:eventColor="@android:color/white"
22-
></com.shrikanthravi.collapsiblecalendarview.widget.CollapsibleCalendar>
23-
</RelativeLayout>
12+
tools:context="com.shrikanthravi.collapsiblecalendarview.MainActivity"
13+
android:id="@+id/main_layout"
14+
android:layout_width="match_parent">
15+
16+
<com.shrikanthravi.collapsiblecalendarview.widget.CollapsibleCalendar
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
app:primaryColor="@color/google_red"
20+
app:textColor="@android:color/white"
21+
app:selectedItem_textColor="@color/google_red"
22+
android:id="@+id/collapsibleCalendarView"
23+
app:todayItem_textColor="@android:color/white"
24+
app:todayItem_background="@drawable/circle_white_stroke_background"
25+
app:selectedItem_background="@drawable/circle_white_solid_background"
26+
app:buttonLeft_drawableTintColor="@android:color/white"
27+
app:buttonRight_drawableTintColor="@android:color/white"
28+
app:expandIconColor="@android:color/white"
29+
app:eventColor="@android:color/white"
30+
app:layout_constraintTop_toTopOf="parent"
31+
app:layout_constraintStart_toStartOf="parent"/>
32+
<TextView
33+
app:layout_constraintStart_toStartOf="parent"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:id="@+id/tv_date"
37+
app:layout_constraintTop_toBottomOf="@id/collapsibleCalendarView"
38+
tools:text="hi"/>
39+
</androidx.constraintlayout.widget.ConstraintLayout>
40+
</ScrollView>

collapsiblecalendarview2/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies {
4545
androidTestImplementation 'androidx.test:runner:1.2.0'
4646
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4747
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
48+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4849
}
4950
repositories {
5051
mavenCentral()

collapsiblecalendarview2/src/main/java/com/shrikanthravi/collapsiblecalendarview/data/Day.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import android.os.Parcel;
55
import android.os.Parcelable;
66

7+
import java.util.Calendar;
8+
import java.util.Date;
9+
710
/**
811
* Created by shrikanthravi on 06/03/18.
912
*/
@@ -63,5 +66,15 @@ public Day[] newArray(int size) {
6366
}
6467
};
6568

69+
public long toUnixTime(){
70+
Date date = new Date(this.mYear, this.mMonth, this.mDay);
71+
return date.getTime();
72+
}
6673

74+
public int getDiff(){
75+
Calendar todayCal = Calendar.getInstance();
76+
Day day = new Day(todayCal.get(Calendar.YEAR), todayCal.get(Calendar.MONTH),todayCal.get(Calendar.DAY_OF_MONTH));
77+
return (int)( (this.toUnixTime() - day.toUnixTime())
78+
/ (1000 * 60 * 60 * 24) );
79+
}
6780
}

collapsiblecalendarview2/src/main/java/com/shrikanthravi/collapsiblecalendarview/widget/CollapsibleCalendar.kt

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@ import android.widget.LinearLayout
1717
import android.widget.TableLayout
1818
import android.widget.TableRow
1919
import android.widget.TextView
20-
2120
import com.shrikanthravi.collapsiblecalendarview.R
2221
import com.shrikanthravi.collapsiblecalendarview.data.CalendarAdapter
2322
import com.shrikanthravi.collapsiblecalendarview.data.Day
2423
import com.shrikanthravi.collapsiblecalendarview.data.Event
2524
import com.shrikanthravi.collapsiblecalendarview.view.ExpandIconView
26-
2725
import java.text.SimpleDateFormat
28-
import java.util.Calendar
26+
import java.util.*
2927

30-
class CollapsibleCalendar : UICalendar,View.OnClickListener {
28+
class CollapsibleCalendar : UICalendar, View.OnClickListener {
3129
override fun onClick(view: View?) {
3230
view?.let {
33-
mListener.let { mListener->
34-
if(mListener==null){
31+
mListener.let { mListener ->
32+
if (mListener == null) {
3533
expandIconView.performClick()
36-
}
37-
else{
34+
} else {
3835
mListener.onClickListener()
3936
}
4037
}
@@ -76,7 +73,10 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
7673
val month: Int
7774
get() = mAdapter!!.calendar.get(Calendar.MONTH)
7875

79-
val selectedDay: Day
76+
/**
77+
* The date has been selected and can be used on Calender Listener
78+
*/
79+
var selectedDay: Day? = null
8080
get() {
8181
if (selectedItem == null) {
8282
val cal = Calendar.getInstance()
@@ -93,6 +93,10 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
9393
selectedItem!!.month,
9494
selectedItem!!.day)
9595
}
96+
set(value: Day?) {
97+
field = value
98+
redraw()
99+
}
96100

97101
val selectedItemPosition: Int
98102
get() {
@@ -225,16 +229,28 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
225229
txtDay.setBackgroundDrawable(selectedItemBackgroundDrawable)
226230
txtDay.setTextColor(selectedItemTextColor)
227231
}
232+
233+
if (isGreaterThanDesiredMonth(day) || isLessThanDesiredMonth(day)) {
234+
235+
}
228236
}
229237
}
230238
}
231239

240+
private fun isLessThanDesiredMonth(day: Day?): Boolean {
241+
return false
242+
}
243+
244+
private fun isGreaterThanDesiredMonth(day: Day?): Boolean {
245+
return false
246+
}
247+
232248
override fun reload() {
233-
mAdapter?.let {mAdapter->
249+
mAdapter?.let { mAdapter ->
234250
mAdapter.refresh()
235251

236252
// reset UI
237-
val dateFormat = SimpleDateFormat("MMM yyyy")
253+
val dateFormat = SimpleDateFormat(datePattern)
238254
dateFormat.timeZone = mAdapter.calendar.timeZone
239255
mTxtTitle.text = dateFormat.format(mAdapter.calendar.time)
240256
mTableHead.removeAllViews()
@@ -275,7 +291,14 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
275291
0,
276292
ViewGroup.LayoutParams.WRAP_CONTENT,
277293
1f)
278-
view.setOnClickListener { v -> onItemClicked(v, mAdapter!!.getItem(i)) }
294+
params.let { params ->
295+
if (params!=null && (mAdapter.getItem(i).diff < params.prevDays || mAdapter.getItem(i).diff > params.nextDaysBlocked)){
296+
view.isClickable = false
297+
}
298+
else {
299+
view.setOnClickListener { v -> onItemClicked(v, mAdapter.getItem(i)) }
300+
}
301+
}
279302
rowCurrent.addView(view)
280303
}
281304

@@ -402,7 +425,7 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
402425
/**
403426
* collapse in milliseconds
404427
*/
405-
fun collapse(duration: Int) {
428+
open fun collapse(duration: Int) {
406429

407430
if (state == STATE_EXPANDED) {
408431
state = STATE_PROCESSING
@@ -450,11 +473,12 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
450473
}
451474

452475
expandIconView.setState(ExpandIconView.MORE, true)
476+
reload()
453477
}
454478

455479
private fun collapseTo(index: Int) {
456480
var index = index
457-
if (state == UICalendar.Companion.STATE_COLLAPSED) {
481+
if (state == STATE_COLLAPSED) {
458482
if (index == -1) {
459483
index = mTableBody.childCount - 1
460484
}
@@ -513,6 +537,7 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
513537
}
514538

515539
expandIconView.setState(ExpandIconView.LESS, true)
540+
reload()
516541
}
517542

518543
fun select(day: Day) {
@@ -567,6 +592,11 @@ class CollapsibleCalendar : UICalendar,View.OnClickListener {
567592
}
568593
}
569594

595+
data class Params(val prevDays: Int, val nextDaysBlocked: Int)
570596

597+
var params: Params? = null
598+
set(value) {
599+
field = value
600+
}
571601
}
572602

0 commit comments

Comments
 (0)