-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
SimpleRecyclerCalendarActivity.kt
161 lines (134 loc) · 5.92 KB
/
SimpleRecyclerCalendarActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.tejpratapsingh.recyclercalendaractivity.simple
import android.os.Bundle
import android.view.View
import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.RadioButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.tejpratapsingh.recyclercalendar.adapter.SimpleRecyclerCalendarAdapter
import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration
import com.tejpratapsingh.recyclercalendar.model.SimpleRecyclerCalendarConfiguration
import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils
import com.tejpratapsingh.recyclercalendar.views.SimpleRecyclerCalendarView
import com.tejpratapsingh.recyclercalendaractivity.R
import java.util.*
import kotlin.collections.HashMap
class SimpleRecyclerCalendarActivity : AppCompatActivity() {
private var calenderView: SimpleRecyclerCalendarView? = null
private var selectionMode: SimpleRecyclerCalendarConfiguration.SelectionMode? = null
private var calendarViewType: RecyclerCalendarConfiguration.CalenderViewType =
RecyclerCalendarConfiguration.CalenderViewType.VERTICAL
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_simple_recycler_calendar)
calenderView = findViewById(R.id.calendarRecyclerView)
val date = Date()
date.time = System.currentTimeMillis()
val startCal = Calendar.getInstance()
val endCal = Calendar.getInstance()
endCal.time = date
endCal.add(Calendar.MONTH, 3)
val buttonSetting: ImageButton = findViewById(R.id.buttonSimpleSettings)
val layoutSettingContainer: LinearLayout = findViewById(R.id.layoutSettingContainer)
buttonSetting.setOnClickListener {
if (layoutSettingContainer.visibility == View.VISIBLE) {
layoutSettingContainer.visibility = View.GONE
} else {
layoutSettingContainer.visibility = View.VISIBLE
}
}
val radioViewTypeVertical: RadioButton = findViewById(R.id.radioViewTypeVertical)
val radioViewTypeHorizontal: RadioButton = findViewById(R.id.radioViewTypeHorizontal)
val radioSelectNone: RadioButton = findViewById(R.id.radioSelectionNone)
val radioSelectSingle: RadioButton = findViewById(R.id.radioSelectionSingle)
val radioSelectMultiple: RadioButton = findViewById(R.id.radioSelectionMultiple)
val radioSelectRange: RadioButton = findViewById(R.id.radioSelectionRange)
radioViewTypeVertical.setOnClickListener {
// Switch to Vertical View
calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL
refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
}
radioViewTypeHorizontal.setOnClickListener {
// Switch to Horizontal View
calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.HORIZONTAL
refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
}
radioSelectNone.setOnClickListener {
// Switch to Selection Mode NONE
selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeNone()
refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
}
radioSelectSingle.setOnClickListener {
// Switch to Selection Mode SINGLE
selectionMode =
SimpleRecyclerCalendarConfiguration.SelectionModeSingle(selectedDate = Date())
refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
}
radioSelectMultiple.setOnClickListener {
// Switch to Selection Mode MULTIPLE
selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeMultiple(
selectionStartDateList = HashMap()
)
refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
}
radioSelectRange.setOnClickListener {
// Switch to Selection Mode RANGE
// Range Starts from todayDate and ends on 5 days from today
val selectionEndCal = Calendar.getInstance()
selectionEndCal.time = date
selectionEndCal.add(Calendar.DATE, 5)
selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeRange(
selectionStartDate = date,
selectionEndDate = selectionEndCal.time
)
refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
}
// Set None As Default
radioSelectNone.callOnClick()
}
private fun refreshCalendarCalendar(
startDate: Date,
endDate: Date
) {
val configuration: SimpleRecyclerCalendarConfiguration =
SimpleRecyclerCalendarConfiguration(
calenderViewType = calendarViewType,
calendarLocale = Locale.getDefault(),
includeMonthHeader = true,
selectionMode = selectionMode!!
)
configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY
calenderView!!.initialise(
startDate,
endDate,
configuration,
object : SimpleRecyclerCalendarAdapter.OnDateSelected {
override fun onDateSelected(date: Date) {
Toast.makeText(
calenderView!!.context,
"Date Selected: ${CalendarUtils.getGmt(date)}",
Toast.LENGTH_LONG
).show()
}
})
}
}