├── .DS_Store ├── .github └── FUNDING.yml ├── .gitignore ├── .idea ├── .name ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── jarRepositories.xml └── misc.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tejpratapsingh │ │ └── recyclercalendaractivity │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── com │ │ │ └── tejpratapsingh │ │ │ └── recyclercalendaractivity │ │ │ ├── MainActivity.kt │ │ │ ├── horizontal │ │ │ ├── HorizontalCalendarActivity.kt │ │ │ └── HorizontalRecyclerCalendarAdapter.kt │ │ │ ├── model │ │ │ └── SimpleEvent.kt │ │ │ ├── simple │ │ │ ├── InfiniteRecyclerCalendarActivity.kt │ │ │ └── SimpleRecyclerCalendarActivity.kt │ │ │ ├── vertical │ │ │ ├── VerticalCalendarActivity.kt │ │ │ └── VerticalRecyclerCalendarAdapter.kt │ │ │ └── viewpager │ │ │ ├── ViewPagerCalendarActivity.kt │ │ │ ├── ViewPagerRecyclerCalendarAdapter.kt │ │ │ └── ui │ │ │ └── main │ │ │ ├── PlaceholderFragment.kt │ │ │ └── SectionsPagerAdapter.kt │ └── res │ │ ├── drawable-anydpi │ │ └── ic_action_setting.xml │ │ ├── drawable-hdpi │ │ └── ic_action_setting.png │ │ ├── drawable-mdpi │ │ └── ic_action_setting.png │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xhdpi │ │ └── ic_action_setting.png │ │ ├── drawable-xxhdpi │ │ └── ic_action_setting.png │ │ ├── drawable │ │ ├── circle_shape.xml │ │ ├── circular_progress_bar.xml │ │ ├── ic_calendar.png │ │ ├── ic_launcher_background.xml │ │ ├── ic_launcher_foreground.xml │ │ ├── layout_round_corner.xml │ │ └── layout_round_corner_filled.xml │ │ ├── layout │ │ ├── activity_horizontal_calendar.xml │ │ ├── activity_infinite_recycler_calendar.xml │ │ ├── activity_main.xml │ │ ├── activity_simple_recycler_calendar.xml │ │ ├── activity_vertical_calendar.xml │ │ ├── activity_view_pager_calendar.xml │ │ ├── fragment_view_pager_calendar.xml │ │ ├── item_calendar_horizontal.xml │ │ ├── item_calendar_vertical.xml │ │ └── item_calendar_view_pager.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ic_launcher_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tejpratapsingh │ └── recyclercalendaractivity │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── recyclercalendar ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tejpratapsingh │ │ └── recyclercalendar │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tejpratapsingh │ │ │ └── recyclercalendar │ │ │ ├── adapter │ │ │ ├── InfiniteRecyclerCalenderAdapter.kt │ │ │ ├── RecyclerCalendarBaseAdapter.kt │ │ │ └── SimpleRecyclerCalendarAdapter.kt │ │ │ ├── model │ │ │ ├── InfiniteRecyclerCalendarConfiguration.kt │ │ │ ├── RecyclerCalendarConfiguration.kt │ │ │ ├── RecyclerCalenderViewItem.kt │ │ │ └── SimpleRecyclerCalendarConfiguration.kt │ │ │ ├── utilities │ │ │ └── CalendarUtils.kt │ │ │ └── views │ │ │ ├── InfiniteRecyclerCalendarView.kt │ │ │ └── SimpleRecyclerCalendarView.kt │ └── res │ │ ├── drawable-v21 │ │ ├── layout_round_corner_filled.xml │ │ ├── layout_round_corner_left_filled.xml │ │ ├── layout_round_corner_middle_filled.xml │ │ └── layout_round_corner_right_filled.xml │ │ ├── drawable │ │ ├── layout_round_corner_filled.xml │ │ ├── layout_round_corner_left_filled.xml │ │ ├── layout_round_corner_middle_filled.xml │ │ └── layout_round_corner_right_filled.xml │ │ ├── layout │ │ ├── item_infinite_calendar.xml │ │ └── item_simple_calendar.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── tejpratapsingh │ └── recyclercalendar │ └── ExampleUnitTest.kt ├── sample_images ├── .DS_Store ├── backdrop.png ├── cover.png ├── month_vertical.gif ├── month_vertical.mp4 ├── progress_sample.gif ├── progress_sample.mp4 ├── simplecalendar.jpeg ├── simplecalendar_framed.png ├── week_example.gif └── week_example.mp4 └── settings.gradle /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/.DS_Store -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: tejpratap 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.com/paypalme2/tejpratap46/3'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | RecyclerCalendarActivity -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tej Pratap Sngh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # RecyclerCalendarAndroid 4 | 5 | [![](https://jitpack.io/v/tejpratap46/RecyclerCalendarAndroid.svg)](https://jitpack.io/#tejpratap46/RecyclerCalendarAndroid) 6 | 7 | A DIY calendar generator library for android written in Kotlin. 8 | 9 | Step 1. Add the JitPack repository to your build file 10 | Add it in your root build.gradle at the end of repositories: 11 | ```gradle 12 | allprojects { 13 | repositories { 14 | ... 15 | maven { 16 | url 'https://jitpack.io' 17 | } 18 | } 19 | } 20 | ``` 21 | 22 | Step 2. Add the dependency 23 | ```gradle 24 | dependencies { 25 | implementation 'com.github.tejpratap46:RecyclerCalendarAndroid:LATEST_RELEASE_TAG' 26 | } 27 | ``` 28 | ## Try It 29 | [![Download From Play Store](https://play.google.com/intl/en_us/badges/images/badge_new.png)](https://play.google.com/store/apps/details?id=com.tejpratapsingh.recyclercalendaractivity) 30 | 31 | ### Here are sample calenders you can create with this library : 32 | 33 | | Week Calendar | Month With Events | Month With Swipe Pages | 34 | | -- | -- | -- | 35 | | Code At: [horizontal](https://github.com/tejpratap46/RecyclerCalendarAndroid/tree/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/horizontal) | Code At: [vertical](https://github.com/tejpratap46/RecyclerCalendarAndroid/tree/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/vertical) | Code At: [viewpager](https://github.com/tejpratap46/RecyclerCalendarAndroid/tree/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/viewpager) 36 | | ![Week Calender.gif](https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/master/sample_images/week_example.gif) | ![Month With Events.gif](https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/master/sample_images/month_vertical.gif) | ![Month With Events.gif](https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/master/sample_images/progress_sample.gif) | 37 | 38 | **Above sample are not the limit of this library, possiblities are endless as you can create custom view for each date as well as add custom Business Login on top of it.** 39 | 40 | ------------ 41 | 42 | Here is how you can create your own Calendar using **RecyclerCalendarAndroid**. 43 | Create a RecyclerView Adapter which extends `RecyclerCalendarBaseAdapter` 44 | 45 | 1. Implement following methods: 46 | ```kotlin 47 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 48 | val view: View = LayoutInflater.from(parent.context).inflate(R.layout.item_calendar_horizontal, parent, false) 49 | return MonthCalendarViewHolder(view) 50 | } 51 | ``` 52 | 53 | 2. Create `ViewHolder` Class for you `View` which extends `RecyclerView.ViewHolder`: 54 | ```kotlin 55 | class MonthCalendarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 56 | val textViewDay: TextView = itemView.findViewById(R.id.textCalenderItemVerticalDay) 57 | val textViewDate: TextView = itemView.findViewById(R.id.textCalenderItemVerticalDate) 58 | val viewEvent: View = itemView.findViewById(R.id.viewCalenderItemVerticalEvent) 59 | } 60 | ``` 61 | 62 | 3. Now just implament `onBindViewHolder` 63 | ```kotlin 64 | override fun onBindViewHolder( 65 | holder: RecyclerView.ViewHolder, 66 | position: Int, 67 | calendarItem: RecyclerCalenderViewItem 68 | ) { 69 | val monthViewHolder: MonthCalendarViewHolder = holder as MonthCalendarViewHolder 70 | // first reset view of current item as it will be reused for different dates and header. 71 | { 72 | // Reset all you view here... 73 | monthViewHolder.itemView.visibility = View.VISIBLE 74 | monthViewHolder.itemView.setOnClickListener(null) 75 | } 76 | 77 | // Calendar item as 3 parts 78 | // 1. Header -> Where you put month name, year etc. 79 | // 2. Empty Space -> This is empty space to fill days before first day of month start, hide every view of ViewHolder Here 80 | // 3. Date -> This is a date, customise your date with event, tecket information, Available slot OR just selection etc here 81 | if (calendarItem.isHeader) { 82 | val selectedCalendar = Calendar.getInstance(Locale.getDefault()) 83 | selectedCalendar.time = calendarItem.date 84 | 85 | val month: String = CalendarUtils.getMonth(selectedCalendar.get(Calendar.MONTH)) ?: "" 86 | val year = selectedCalendar[Calendar.YEAR].toLong() 87 | 88 | monthViewHolder.textViewDay.text = year.toString() 89 | monthViewHolder.textViewDate.text = month 90 | } else if (calendarItem.isEmpty) { 91 | monthViewHolder.itemView.visibility = View.GONE 92 | monthViewHolder.textViewDay.text = "" 93 | monthViewHolder.textViewDate.text = "" 94 | } else { 95 | val calendarDate = Calendar.getInstance(Locale.getDefault()) 96 | calendarDate.time = calendarItem.date 97 | 98 | val day: String = CalendarUtils.getDay(calendarDate.get(Calendar.DAY_OF_WEEK)) ?: "" 99 | 100 | monthViewHolder.textViewDay.text = day 101 | 102 | val dateInt: Int = 103 | (CalendarUtils.dateStringFromFormat(calendarDate.time, CalendarUtils.DB_DATE_FORMAT) 104 | ?: "0").toInt() 105 | 106 | if (eventMap.contains(dateInt)) { 107 | // As an example, here im checking if this date has any event passed from constructor 108 | monthViewHolder.viewEvent.visibility = View.VISIBLE 109 | // Set background color from event information 110 | monthViewHolder.viewEvent.setBackgroundColor(eventMap.get(dateInt)!!.color) 111 | } 112 | 113 | // Set Date to textView 114 | monthViewHolder.textViewDate.text = CalendarUtils.dateStringFromFormat(calendarDate.time, CalendarUtils.DISPLAY_DATE_FORMAT) ?: "" 115 | 116 | // Here as an example, im sending Tap data to listener 117 | monthViewHolder.itemView.setOnClickListener { 118 | dateSelectListener.onDateSelected(calendarItem.date, eventMap[dateInt]) 119 | } 120 | } 121 | } 122 | ``` 123 | *above code is direct example from [VerticalRecyclerCalendarAdapter](https://github.com/tejpratap46/RecyclerCalendarAndroid/blob/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/vertical/VerticalRecyclerCalendarAdapter.kt)* 124 | 125 | ------------ 126 | 127 | #### For People who want to just use simple date picker/selection calendar, i have created `SimpleRecyclerCalendarView` 128 | To use `SimpleRecyclerCalendarView`, just include following in your `.xml` 129 | 130 | ```xml 131 | 135 | ``` 136 | 137 | And in Your Activity, include following 138 | ```kotlin 139 | val calenderView: SimpleRecyclerCalendarView = findViewById(R.id.calendarRecyclerView) 140 | 141 | val date = Date() 142 | date.time = System.currentTimeMillis() 143 | 144 | // Start From Date 145 | val startCal = Calendar.getInstance() 146 | 147 | // End Date 148 | val endCal = Calendar.getInstance() 149 | endCal.time = date 150 | endCal.add(Calendar.MONTH, 3) 151 | 152 | val configuration: SimpleRecyclerCalendarConfiguration = 153 | SimpleRecyclerCalendarConfiguration( 154 | calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, // calendarViewType could be VERTICAL OR HORIZONTAL 155 | calendarLocale = Locale.getDefault(), 156 | includeMonthHeader = true, 157 | selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeNone() // selectionMode could be one of [SelectionModeNone, SelectionModeSingle, SelectionModeMultiple, SelectionModeRange] 158 | ) 159 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 160 | 161 | 162 | calenderView!!.initialise( 163 | startDate, 164 | endDate, 165 | configuration, 166 | object : SimpleRecyclerCalendarAdapter.OnDateSelected { 167 | override fun onDateSelected(date: Date) { 168 | Toast.makeText( 169 | calenderView!!.context, 170 | "Date Selected: ${CalendarUtils.getGmt(date)}", 171 | Toast.LENGTH_LONG 172 | ).show() 173 | } 174 | }) 175 | ``` 176 | *To know More about SimpleRecyclerCalendarView visit [SimpleRecyclerCalendarActivity](https://github.com/tejpratap46/RecyclerCalendarAndroid/blob/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/simple/SimpleRecyclerCalendarActivity.kt)* 177 | 178 | #### For People who want to just use infinite date picker/selection calendar, i have created `InfiniteRecyclerCalendarView` 179 | To use `InfiniteRecyclerCalendarView`, just include following in your `.xml` 180 | 181 | ```xml 182 | 186 | ``` 187 | 188 | And in Your Activity, include following 189 | ```kotlin 190 | val calenderView: InfiniteRecyclerCalendarView = findViewById(R.id.calendarRecyclerView) 191 | 192 | val date = Date() 193 | date.time = System.currentTimeMillis() 194 | 195 | // Start From Date 196 | val startCal = Calendar.getInstance() 197 | 198 | // End Date 199 | val endCal = Calendar.getInstance() 200 | endCal.time = date 201 | endCal.add(Calendar.MONTH, 3) 202 | 203 | val configuration: InfiniteRecyclerCalendarConfiguration = 204 | InfiniteRecyclerCalendarConfiguration( 205 | calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, // calendarViewType could be VERTICAL OR HORIZONTAL 206 | calendarLocale = Locale.getDefault(), 207 | includeMonthHeader = true, 208 | selectionMode = InfiniteRecyclerCalendarConfiguration.SelectionModeNone() // selectionMode could be one of [SelectionModeNone, SelectionModeSingle, SelectionModeMultiple, SelectionModeRange] 209 | ) 210 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 211 | 212 | calenderView!!.initialise( 213 | configuration, 214 | object : InfiniteRecyclerCalenderAdapter.OnDateSelected { 215 | override fun onDateSelected(date: Date) { 216 | Toast.makeText( 217 | calenderView!!.context, 218 | "Date Selected: ${CalendarUtils.getGmt(date)}", 219 | Toast.LENGTH_LONG 220 | ).show() 221 | } 222 | }) 223 | ``` 224 | *To know More about InfiniteRecyclerCalendarActivity visit [InfiniteRecyclerCalendarActivity](https://github.com/tejpratap46/RecyclerCalendarAndroid/blob/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/simple/InfiniteRecyclerCalendarActivity.kt)* 225 | 226 | ## Donate 227 | [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/M4M413CJC) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 30 6 | defaultConfig { 7 | applicationId "com.tejpratapsingh.recyclercalendaractivity" 8 | minSdkVersion 15 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 25 | implementation 'androidx.appcompat:appcompat:1.3.1' 26 | implementation 'androidx.core:core-ktx:1.6.0' 27 | implementation 'androidx.recyclerview:recyclerview:1.2.1' 28 | implementation project(path: ':recyclercalendar') 29 | implementation 'com.google.android.material:material:1.4.0' 30 | testImplementation 'junit:junit:4.13.2' 31 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tejpratapsingh/recyclercalendaractivity/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.tejpratapsingh.recyclercalendaractivity", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.widget.LinearLayout 6 | import androidx.appcompat.app.AppCompatActivity 7 | import com.tejpratapsingh.recyclercalendaractivity.horizontal.HorizontalCalendarActivity 8 | import com.tejpratapsingh.recyclercalendaractivity.simple.InfiniteRecyclerCalendarActivity 9 | import com.tejpratapsingh.recyclercalendaractivity.simple.SimpleRecyclerCalendarActivity 10 | import com.tejpratapsingh.recyclercalendaractivity.vertical.VerticalCalendarActivity 11 | import com.tejpratapsingh.recyclercalendaractivity.viewpager.ViewPagerCalendarActivity 12 | 13 | class MainActivity : AppCompatActivity() { 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | setContentView(R.layout.activity_main) 18 | 19 | val layoutWeekCalendar: LinearLayout = findViewById(R.id.layoutWeekCalendarActivity); 20 | layoutWeekCalendar.setOnClickListener { 21 | val intent: Intent = Intent(this@MainActivity, HorizontalCalendarActivity::class.java) 22 | startActivity(intent) 23 | } 24 | 25 | val layoutMonthCalendar: LinearLayout = findViewById(R.id.layoutMonthCalendarActivity); 26 | layoutMonthCalendar.setOnClickListener { 27 | val intent: Intent = Intent(this@MainActivity, VerticalCalendarActivity::class.java) 28 | startActivity(intent) 29 | } 30 | 31 | val layoutPageCalendar: LinearLayout = findViewById(R.id.layoutPageCalendarActivity); 32 | layoutPageCalendar.setOnClickListener { 33 | val intent: Intent = Intent(this@MainActivity, ViewPagerCalendarActivity::class.java) 34 | startActivity(intent) 35 | } 36 | 37 | val layoutSimpleCalendar: LinearLayout = findViewById(R.id.layoutSimpleCalendarActivity); 38 | layoutSimpleCalendar.setOnClickListener { 39 | val intent: Intent = 40 | Intent(this@MainActivity, SimpleRecyclerCalendarActivity::class.java) 41 | startActivity(intent) 42 | } 43 | 44 | val layoutInfiniteCalendar: LinearLayout = 45 | findViewById(R.id.layoutInfiniteCalendarActivity); 46 | layoutInfiniteCalendar.setOnClickListener { 47 | val intent: Intent = 48 | Intent(this@MainActivity, InfiniteRecyclerCalendarActivity::class.java) 49 | startActivity(intent) 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/horizontal/HorizontalCalendarActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.horizontal 2 | 3 | import android.os.Bundle 4 | import android.widget.TextView 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.recyclerview.widget.PagerSnapHelper 7 | import androidx.recyclerview.widget.RecyclerView 8 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 9 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 10 | import com.tejpratapsingh.recyclercalendaractivity.R 11 | import java.util.* 12 | 13 | class HorizontalCalendarActivity : AppCompatActivity() { 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | setContentView(R.layout.activity_horizontal_calendar) 18 | 19 | val calendarRecyclerView: RecyclerView = findViewById(R.id.calendarRecyclerView) 20 | val textViewSelectedDate: TextView = findViewById(R.id.textViewSelectedDate) 21 | 22 | val date = Date() 23 | date.time = System.currentTimeMillis() 24 | 25 | val startCal = Calendar.getInstance() 26 | 27 | val endCal = Calendar.getInstance() 28 | endCal.time = date 29 | endCal.add(Calendar.MONTH, 3) 30 | 31 | val configuration: RecyclerCalendarConfiguration = 32 | RecyclerCalendarConfiguration( 33 | calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.HORIZONTAL, 34 | calendarLocale = Locale.getDefault(), 35 | includeMonthHeader = true 36 | ) 37 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 38 | 39 | textViewSelectedDate.text = 40 | CalendarUtils.dateStringFromFormat( 41 | locale = configuration.calendarLocale, 42 | date = date, 43 | format = CalendarUtils.LONG_DATE_FORMAT 44 | ) ?: "" 45 | 46 | val calendarAdapterHorizontal: HorizontalRecyclerCalendarAdapter = 47 | HorizontalRecyclerCalendarAdapter( 48 | startDate = startCal.time, 49 | endDate = endCal.time, 50 | configuration = configuration, 51 | selectedDate = date, 52 | dateSelectListener = object : HorizontalRecyclerCalendarAdapter.OnDateSelected { 53 | override fun onDateSelected(date: Date) { 54 | textViewSelectedDate.text = 55 | CalendarUtils.dateStringFromFormat( 56 | locale = configuration.calendarLocale, 57 | date = date, 58 | format = CalendarUtils.LONG_DATE_FORMAT 59 | ) 60 | ?: "" 61 | } 62 | } 63 | ) 64 | 65 | calendarRecyclerView.adapter = calendarAdapterHorizontal 66 | 67 | val snapHelper = PagerSnapHelper() // Or LinearSnapHelper 68 | snapHelper.attachToRecyclerView(calendarRecyclerView) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/horizontal/HorizontalRecyclerCalendarAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.horizontal 2 | 3 | import android.content.Context 4 | import android.os.Build 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.TextView 9 | import androidx.core.content.ContextCompat 10 | import androidx.recyclerview.widget.RecyclerView 11 | import com.tejpratapsingh.recyclercalendar.adapter.RecyclerCalendarBaseAdapter 12 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 13 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalenderViewItem 14 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 15 | import com.tejpratapsingh.recyclercalendaractivity.R 16 | import java.util.* 17 | 18 | class HorizontalRecyclerCalendarAdapter( 19 | startDate: Date, 20 | endDate: Date, 21 | private val configuration: RecyclerCalendarConfiguration, 22 | private var selectedDate: Date, 23 | private val dateSelectListener: OnDateSelected 24 | ) : RecyclerCalendarBaseAdapter(startDate, endDate, configuration) { 25 | 26 | interface OnDateSelected { 27 | fun onDateSelected(date: Date) 28 | } 29 | 30 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 31 | val view: View = LayoutInflater.from(parent.context) 32 | .inflate(R.layout.item_calendar_horizontal, parent, false) 33 | return MonthCalendarViewHolder( 34 | view 35 | ) 36 | } 37 | 38 | override fun onBindViewHolder( 39 | holder: RecyclerView.ViewHolder, 40 | position: Int, 41 | calendarItem: RecyclerCalenderViewItem 42 | ) { 43 | val monthViewHolder: MonthCalendarViewHolder = holder as MonthCalendarViewHolder 44 | val context: Context = monthViewHolder.itemView.context 45 | monthViewHolder.itemView.visibility = View.VISIBLE 46 | 47 | monthViewHolder.itemView.setOnClickListener(null) 48 | 49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 50 | monthViewHolder.itemView.background = null 51 | } else { 52 | monthViewHolder.itemView.setBackgroundDrawable(null) 53 | } 54 | monthViewHolder.textViewDay.setTextColor( 55 | ContextCompat.getColor( 56 | context, 57 | R.color.colorBlack 58 | ) 59 | ) 60 | monthViewHolder.textViewDate.setTextColor( 61 | ContextCompat.getColor( 62 | context, 63 | R.color.colorBlack 64 | ) 65 | ) 66 | 67 | if (calendarItem.isHeader) { 68 | val selectedCalendar = Calendar.getInstance() 69 | selectedCalendar.time = calendarItem.date 70 | 71 | val month: String = CalendarUtils.dateStringFromFormat( 72 | locale = configuration.calendarLocale, 73 | date = selectedCalendar.time, 74 | format = CalendarUtils.DISPLAY_MONTH_FORMAT 75 | ) ?: "" 76 | val year = selectedCalendar[Calendar.YEAR].toLong() 77 | 78 | monthViewHolder.textViewDay.text = year.toString() 79 | monthViewHolder.textViewDate.text = month 80 | 81 | monthViewHolder.itemView.setOnClickListener(null) 82 | } else if (calendarItem.isEmpty) { 83 | monthViewHolder.itemView.visibility = View.GONE 84 | monthViewHolder.textViewDay.text = "" 85 | monthViewHolder.textViewDate.text = "" 86 | } else { 87 | val calendarDate = Calendar.getInstance() 88 | calendarDate.time = calendarItem.date 89 | 90 | val stringCalendarTimeFormat: String = 91 | CalendarUtils.dateStringFromFormat( 92 | locale = configuration.calendarLocale, 93 | date = calendarItem.date, 94 | format = CalendarUtils.DB_DATE_FORMAT 95 | ) 96 | ?: "" 97 | val stringSelectedTimeFormat: String = 98 | CalendarUtils.dateStringFromFormat( 99 | locale = configuration.calendarLocale, 100 | date = selectedDate, 101 | format = CalendarUtils.DB_DATE_FORMAT 102 | ) ?: "" 103 | 104 | if (stringCalendarTimeFormat == stringSelectedTimeFormat) { 105 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 106 | monthViewHolder.itemView.background = 107 | ContextCompat.getDrawable(context, R.drawable.layout_round_corner_filled) 108 | } else { 109 | monthViewHolder.itemView.setBackgroundDrawable( 110 | ContextCompat.getDrawable( 111 | context, 112 | R.drawable.layout_round_corner_filled 113 | ) 114 | ) 115 | } 116 | monthViewHolder.textViewDay.setTextColor( 117 | ContextCompat.getColor( 118 | context, 119 | R.color.colorWhite 120 | ) 121 | ) 122 | monthViewHolder.textViewDate.setTextColor( 123 | ContextCompat.getColor( 124 | context, 125 | R.color.colorWhite 126 | ) 127 | ) 128 | } 129 | 130 | val day: String = CalendarUtils.dateStringFromFormat( 131 | locale = configuration.calendarLocale, 132 | date = calendarDate.time, 133 | format = CalendarUtils.DISPLAY_WEEK_DAY_FORMAT 134 | ) ?: "" 135 | 136 | monthViewHolder.textViewDay.text = day 137 | 138 | monthViewHolder.textViewDate.text = 139 | CalendarUtils.dateStringFromFormat( 140 | locale = configuration.calendarLocale, 141 | date = calendarDate.time, 142 | format = CalendarUtils.DISPLAY_DATE_FORMAT 143 | ) ?: "" 144 | 145 | monthViewHolder.itemView.setOnClickListener { 146 | selectedDate = calendarItem.date 147 | dateSelectListener.onDateSelected(calendarItem.date) 148 | notifyDataSetChanged() 149 | } 150 | } 151 | } 152 | 153 | class MonthCalendarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 154 | val textViewDay: TextView = itemView.findViewById(R.id.textCalenderItemHorizontalDay) 155 | val textViewDate: TextView = itemView.findViewById(R.id.textCalenderItemHorizontalDate) 156 | } 157 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/model/SimpleEvent.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.model 2 | 3 | import java.util.* 4 | 5 | class SimpleEvent(val date: Date, val title: String, val color: Int, val progress: Int = 0) -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/simple/InfiniteRecyclerCalendarActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.simple 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import android.widget.ImageButton 6 | import android.widget.LinearLayout 7 | import android.widget.RadioButton 8 | import android.widget.Toast 9 | import androidx.appcompat.app.AppCompatActivity 10 | import com.tejpratapsingh.recyclercalendar.adapter.InfiniteRecyclerCalenderAdapter 11 | import com.tejpratapsingh.recyclercalendar.model.InfiniteRecyclerCalendarConfiguration 12 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 13 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 14 | import com.tejpratapsingh.recyclercalendar.views.InfiniteRecyclerCalendarView 15 | import com.tejpratapsingh.recyclercalendaractivity.R 16 | import java.util.* 17 | 18 | class InfiniteRecyclerCalendarActivity : AppCompatActivity() { 19 | 20 | private var calenderView: InfiniteRecyclerCalendarView? = null 21 | private var selectionMode: InfiniteRecyclerCalendarConfiguration.SelectionMode? = null 22 | private var calendarViewType: RecyclerCalendarConfiguration.CalenderViewType = 23 | RecyclerCalendarConfiguration.CalenderViewType.VERTICAL 24 | 25 | override fun onCreate(savedInstanceState: Bundle?) { 26 | super.onCreate(savedInstanceState) 27 | setContentView(R.layout.activity_infinite_recycler_calendar) 28 | 29 | calenderView = findViewById(R.id.calendarRecyclerView) 30 | 31 | val buttonSetting: ImageButton = findViewById(R.id.buttonSimpleSettings) 32 | val layoutSettingContainer: LinearLayout = findViewById(R.id.layoutSettingContainer) 33 | 34 | buttonSetting.setOnClickListener { 35 | if (layoutSettingContainer.visibility == View.VISIBLE) { 36 | layoutSettingContainer.visibility = View.GONE 37 | } else { 38 | layoutSettingContainer.visibility = View.VISIBLE 39 | } 40 | } 41 | 42 | val radioViewTypeVertical: RadioButton = findViewById(R.id.radioViewTypeVertical) 43 | val radioViewTypeHorizontal: RadioButton = findViewById(R.id.radioViewTypeHorizontal) 44 | 45 | radioViewTypeVertical.setOnClickListener { 46 | // Switch to Vertical View 47 | calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL 48 | 49 | refreshCalendarCalendar() 50 | } 51 | 52 | radioViewTypeHorizontal.setOnClickListener { 53 | // Switch to Horizontal View 54 | calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.HORIZONTAL 55 | 56 | refreshCalendarCalendar() 57 | } 58 | 59 | selectionMode = InfiniteRecyclerCalendarConfiguration.SelectionModeNone() 60 | 61 | refreshCalendarCalendar() 62 | } 63 | 64 | private fun refreshCalendarCalendar() { 65 | if (calenderView == null || selectionMode == null) { 66 | return 67 | } 68 | val configuration: InfiniteRecyclerCalendarConfiguration = 69 | InfiniteRecyclerCalendarConfiguration( 70 | calenderViewType = calendarViewType, 71 | calendarLocale = Locale.getDefault(), 72 | includeMonthHeader = true, 73 | selectionMode = selectionMode!! 74 | ) 75 | 76 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 77 | 78 | calenderView!!.initialise( 79 | configuration, 80 | object : InfiniteRecyclerCalenderAdapter.OnDateSelected { 81 | override fun onDateSelected(date: Date) { 82 | Toast.makeText( 83 | calenderView!!.context, 84 | "Date Selected: ${CalendarUtils.getGmt(date)}", 85 | Toast.LENGTH_LONG 86 | ).show() 87 | } 88 | }) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/simple/SimpleRecyclerCalendarActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.simple 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import android.widget.ImageButton 6 | import android.widget.LinearLayout 7 | import android.widget.RadioButton 8 | import android.widget.Toast 9 | import androidx.appcompat.app.AppCompatActivity 10 | import com.tejpratapsingh.recyclercalendar.adapter.SimpleRecyclerCalendarAdapter 11 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 12 | import com.tejpratapsingh.recyclercalendar.model.SimpleRecyclerCalendarConfiguration 13 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 14 | import com.tejpratapsingh.recyclercalendar.views.SimpleRecyclerCalendarView 15 | import com.tejpratapsingh.recyclercalendaractivity.R 16 | import java.util.* 17 | import kotlin.collections.HashMap 18 | 19 | class SimpleRecyclerCalendarActivity : AppCompatActivity() { 20 | 21 | private var calenderView: SimpleRecyclerCalendarView? = null 22 | private var selectionMode: SimpleRecyclerCalendarConfiguration.SelectionMode? = null 23 | private var calendarViewType: RecyclerCalendarConfiguration.CalenderViewType = 24 | RecyclerCalendarConfiguration.CalenderViewType.VERTICAL 25 | 26 | override fun onCreate(savedInstanceState: Bundle?) { 27 | super.onCreate(savedInstanceState) 28 | setContentView(R.layout.activity_simple_recycler_calendar) 29 | 30 | calenderView = findViewById(R.id.calendarRecyclerView) 31 | 32 | val date = Date() 33 | date.time = System.currentTimeMillis() 34 | 35 | val startCal = Calendar.getInstance() 36 | 37 | val endCal = Calendar.getInstance() 38 | endCal.time = date 39 | endCal.add(Calendar.MONTH, 3) 40 | 41 | val buttonSetting: ImageButton = findViewById(R.id.buttonSimpleSettings) 42 | val layoutSettingContainer: LinearLayout = findViewById(R.id.layoutSettingContainer) 43 | 44 | buttonSetting.setOnClickListener { 45 | if (layoutSettingContainer.visibility == View.VISIBLE) { 46 | layoutSettingContainer.visibility = View.GONE 47 | } else { 48 | layoutSettingContainer.visibility = View.VISIBLE 49 | } 50 | } 51 | 52 | val radioViewTypeVertical: RadioButton = findViewById(R.id.radioViewTypeVertical) 53 | val radioViewTypeHorizontal: RadioButton = findViewById(R.id.radioViewTypeHorizontal) 54 | 55 | val radioSelectNone: RadioButton = findViewById(R.id.radioSelectionNone) 56 | val radioSelectSingle: RadioButton = findViewById(R.id.radioSelectionSingle) 57 | val radioSelectMultiple: RadioButton = findViewById(R.id.radioSelectionMultiple) 58 | val radioSelectRange: RadioButton = findViewById(R.id.radioSelectionRange) 59 | 60 | radioViewTypeVertical.setOnClickListener { 61 | // Switch to Vertical View 62 | calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL 63 | 64 | refreshCalendarCalendar( 65 | startDate = startCal.time, 66 | endDate = endCal.time 67 | ) 68 | } 69 | 70 | radioViewTypeHorizontal.setOnClickListener { 71 | // Switch to Horizontal View 72 | calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.HORIZONTAL 73 | 74 | refreshCalendarCalendar( 75 | startDate = startCal.time, 76 | endDate = endCal.time 77 | ) 78 | } 79 | 80 | radioSelectNone.setOnClickListener { 81 | // Switch to Selection Mode NONE 82 | selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeNone() 83 | 84 | refreshCalendarCalendar( 85 | startDate = startCal.time, 86 | endDate = endCal.time 87 | 88 | ) 89 | } 90 | radioSelectSingle.setOnClickListener { 91 | // Switch to Selection Mode SINGLE 92 | selectionMode = 93 | SimpleRecyclerCalendarConfiguration.SelectionModeSingle(selectedDate = Date()) 94 | 95 | refreshCalendarCalendar( 96 | startDate = startCal.time, 97 | endDate = endCal.time 98 | ) 99 | } 100 | radioSelectMultiple.setOnClickListener { 101 | // Switch to Selection Mode MULTIPLE 102 | selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeMultiple( 103 | selectionStartDateList = HashMap() 104 | ) 105 | 106 | refreshCalendarCalendar( 107 | startDate = startCal.time, 108 | endDate = endCal.time 109 | ) 110 | } 111 | radioSelectRange.setOnClickListener { 112 | // Switch to Selection Mode RANGE 113 | 114 | // Range Starts from todayDate and ends on 5 days from today 115 | val selectionEndCal = Calendar.getInstance() 116 | selectionEndCal.time = date 117 | selectionEndCal.add(Calendar.DATE, 5) 118 | 119 | selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeRange( 120 | selectionStartDate = date, 121 | selectionEndDate = selectionEndCal.time 122 | ) 123 | 124 | refreshCalendarCalendar( 125 | startDate = startCal.time, 126 | endDate = endCal.time 127 | ) 128 | } 129 | 130 | // Set None As Default 131 | radioSelectNone.callOnClick() 132 | } 133 | 134 | private fun refreshCalendarCalendar( 135 | startDate: Date, 136 | endDate: Date 137 | ) { 138 | val configuration: SimpleRecyclerCalendarConfiguration = 139 | SimpleRecyclerCalendarConfiguration( 140 | calenderViewType = calendarViewType, 141 | calendarLocale = Locale.getDefault(), 142 | includeMonthHeader = true, 143 | selectionMode = selectionMode!! 144 | ) 145 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 146 | 147 | calenderView!!.initialise( 148 | startDate, 149 | endDate, 150 | configuration, 151 | object : SimpleRecyclerCalendarAdapter.OnDateSelected { 152 | override fun onDateSelected(date: Date) { 153 | Toast.makeText( 154 | calenderView!!.context, 155 | "Date Selected: ${CalendarUtils.getGmt(date)}", 156 | Toast.LENGTH_LONG 157 | ).show() 158 | } 159 | }) 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/vertical/VerticalCalendarActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.vertical 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AlertDialog 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.core.content.ContextCompat 7 | import androidx.recyclerview.widget.RecyclerView 8 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 9 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 10 | import com.tejpratapsingh.recyclercalendaractivity.R 11 | import com.tejpratapsingh.recyclercalendaractivity.model.SimpleEvent 12 | import java.util.* 13 | import kotlin.collections.HashMap 14 | 15 | class VerticalCalendarActivity : AppCompatActivity() { 16 | 17 | private val eventMap: HashMap = HashMap() 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | setContentView(R.layout.activity_vertical_calendar) 22 | 23 | val calendarRecyclerView: RecyclerView = findViewById(R.id.calendarRecyclerView) 24 | 25 | val date = Date() 26 | date.time = System.currentTimeMillis() 27 | 28 | val startCal = Calendar.getInstance() 29 | 30 | val endCal = Calendar.getInstance() 31 | endCal.time = date 32 | endCal.add(Calendar.MONTH, 12) 33 | 34 | val configuration: RecyclerCalendarConfiguration = 35 | RecyclerCalendarConfiguration( 36 | calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, 37 | calendarLocale = Locale.getDefault(), 38 | includeMonthHeader = true 39 | ) 40 | 41 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 42 | 43 | // Some Random Events 44 | for (i in 0..30 step 3) { 45 | val eventCal = Calendar.getInstance() 46 | eventCal.add(Calendar.DATE, i * 3) 47 | val eventDate: Int = 48 | (CalendarUtils.dateStringFromFormat( 49 | locale = configuration.calendarLocale, 50 | date = eventCal.time, 51 | format = CalendarUtils.DB_DATE_FORMAT 52 | ) 53 | ?: "0").toInt() 54 | eventMap[eventDate] = SimpleEvent( 55 | eventCal.time, 56 | "Event #$i", 57 | ContextCompat.getColor(applicationContext, R.color.colorAccent) 58 | ) 59 | } 60 | 61 | val calendarAdapterVertical: VerticalRecyclerCalendarAdapter = 62 | VerticalRecyclerCalendarAdapter( 63 | startDate = startCal.time, 64 | endDate = endCal.time, 65 | configuration = configuration, 66 | eventMap = eventMap, 67 | dateSelectListener = object : VerticalRecyclerCalendarAdapter.OnDateSelected { 68 | override fun onDateSelected(date: Date, event: SimpleEvent?) { 69 | val selectedDate: String = 70 | CalendarUtils.dateStringFromFormat( 71 | locale = configuration.calendarLocale, 72 | date = date, 73 | format = CalendarUtils.LONG_DATE_FORMAT 74 | ) 75 | ?: "" 76 | 77 | if (event != null) { 78 | AlertDialog.Builder(this@VerticalCalendarActivity) 79 | .setTitle("Event Clicked") 80 | .setMessage( 81 | String.format( 82 | Locale.getDefault(), 83 | "Date: %s\n\nEvent: %s", 84 | selectedDate, 85 | event.title 86 | ) 87 | ) 88 | .create() 89 | .show() 90 | } 91 | } 92 | } 93 | ); 94 | 95 | calendarRecyclerView.adapter = calendarAdapterVertical 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/vertical/VerticalRecyclerCalendarAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.vertical 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.TextView 7 | import androidx.recyclerview.widget.RecyclerView 8 | import com.tejpratapsingh.recyclercalendar.adapter.RecyclerCalendarBaseAdapter 9 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 10 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalenderViewItem 11 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 12 | import com.tejpratapsingh.recyclercalendaractivity.R 13 | import com.tejpratapsingh.recyclercalendaractivity.model.SimpleEvent 14 | import java.util.* 15 | 16 | class VerticalRecyclerCalendarAdapter( 17 | startDate: Date, 18 | endDate: Date, 19 | val configuration: RecyclerCalendarConfiguration, 20 | val eventMap: HashMap, 21 | val dateSelectListener: OnDateSelected 22 | ) : RecyclerCalendarBaseAdapter(startDate, endDate, configuration) { 23 | 24 | interface OnDateSelected { 25 | fun onDateSelected(date: Date, event: SimpleEvent?) 26 | } 27 | 28 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 29 | val view: View = LayoutInflater.from(parent.context) 30 | .inflate(R.layout.item_calendar_vertical, parent, false) 31 | return MonthCalendarViewHolder( 32 | view 33 | ) 34 | } 35 | 36 | override fun onBindViewHolder( 37 | holder: RecyclerView.ViewHolder, 38 | position: Int, 39 | calendarItem: RecyclerCalenderViewItem 40 | ) { 41 | val monthViewHolder: MonthCalendarViewHolder = holder as MonthCalendarViewHolder 42 | monthViewHolder.itemView.visibility = View.VISIBLE 43 | monthViewHolder.viewEvent.visibility = View.GONE 44 | 45 | monthViewHolder.itemView.setOnClickListener(null) 46 | 47 | if (calendarItem.isHeader) { 48 | val selectedCalendar = Calendar.getInstance(Locale.getDefault()) 49 | selectedCalendar.time = calendarItem.date 50 | 51 | val month: String = CalendarUtils.dateStringFromFormat( 52 | locale = configuration.calendarLocale, 53 | date = selectedCalendar.time, 54 | format = CalendarUtils.DISPLAY_MONTH_FORMAT 55 | ) ?: "" 56 | val year = selectedCalendar[Calendar.YEAR].toLong() 57 | 58 | monthViewHolder.textViewDay.text = year.toString() 59 | monthViewHolder.textViewDate.text = month 60 | } else if (calendarItem.isEmpty) { 61 | monthViewHolder.itemView.visibility = View.GONE 62 | monthViewHolder.textViewDay.text = "" 63 | monthViewHolder.textViewDate.text = "" 64 | } else { 65 | val calendarDate = Calendar.getInstance(Locale.getDefault()) 66 | calendarDate.time = calendarItem.date 67 | 68 | val day: String = CalendarUtils.dateStringFromFormat( 69 | locale = configuration.calendarLocale, 70 | date = calendarDate.time, 71 | format = CalendarUtils.DISPLAY_WEEK_DAY_FORMAT 72 | ) ?: "" 73 | 74 | monthViewHolder.textViewDay.text = day 75 | 76 | val dateInt: Int = 77 | (CalendarUtils.dateStringFromFormat( 78 | locale = configuration.calendarLocale, 79 | date = calendarDate.time, 80 | format = CalendarUtils.DB_DATE_FORMAT 81 | ) 82 | ?: "0").toInt() 83 | 84 | if (eventMap.contains(dateInt)) { 85 | monthViewHolder.viewEvent.visibility = View.VISIBLE 86 | monthViewHolder.viewEvent.setBackgroundColor(eventMap.get(dateInt)!!.color) 87 | } 88 | 89 | monthViewHolder.textViewDate.text = 90 | CalendarUtils.dateStringFromFormat( 91 | locale = configuration.calendarLocale, 92 | date = calendarDate.time, 93 | format = CalendarUtils.DISPLAY_DATE_FORMAT 94 | ) ?: "" 95 | 96 | monthViewHolder.itemView.setOnClickListener { 97 | dateSelectListener.onDateSelected(calendarItem.date, eventMap[dateInt]) 98 | } 99 | } 100 | } 101 | 102 | class MonthCalendarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 103 | val textViewDay: TextView = itemView.findViewById(R.id.textCalenderItemVerticalDay) 104 | val textViewDate: TextView = itemView.findViewById(R.id.textCalenderItemVerticalDate) 105 | val viewEvent: View = itemView.findViewById(R.id.viewCalenderItemVerticalEvent) 106 | } 107 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/viewpager/ViewPagerCalendarActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.viewpager 2 | 3 | import android.os.Build 4 | import android.os.Bundle 5 | import android.view.View 6 | import androidx.appcompat.app.AppCompatActivity 7 | import androidx.viewpager.widget.ViewPager 8 | import com.google.android.material.tabs.TabLayout 9 | import com.tejpratapsingh.recyclercalendaractivity.R 10 | import com.tejpratapsingh.recyclercalendaractivity.viewpager.ui.main.SectionsPagerAdapter 11 | 12 | class ViewPagerCalendarActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_view_pager_calendar) 17 | 18 | val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager) 19 | val viewPager: ViewPager = findViewById(R.id.view_pager) 20 | viewPager.adapter = sectionsPagerAdapter 21 | val tabs: TabLayout = findViewById(R.id.tabs) 22 | tabs.setupWithViewPager(viewPager) 23 | 24 | val config = resources.configuration 25 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 26 | if (config.layoutDirection == View.LAYOUT_DIRECTION_RTL) { 27 | // showAlertMsg("LTR") 28 | tabs.layoutDirection = View.LAYOUT_DIRECTION_LTR; 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/viewpager/ViewPagerRecyclerCalendarAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.viewpager 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.ProgressBar 7 | import android.widget.TextView 8 | import androidx.recyclerview.widget.RecyclerView 9 | import com.tejpratapsingh.recyclercalendar.adapter.RecyclerCalendarBaseAdapter 10 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 11 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalenderViewItem 12 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 13 | import com.tejpratapsingh.recyclercalendaractivity.R 14 | import com.tejpratapsingh.recyclercalendaractivity.model.SimpleEvent 15 | import java.util.* 16 | 17 | class ViewPagerRecyclerCalendarAdapter( 18 | startDate: Date, 19 | endDate: Date, 20 | val configuration: RecyclerCalendarConfiguration, 21 | val eventMap: HashMap, 22 | val dateSelectListener: ViewPagerRecyclerCalendarAdapter.OnDateSelected 23 | ) : RecyclerCalendarBaseAdapter(startDate, endDate, configuration) { 24 | 25 | interface OnDateSelected { 26 | fun onDateSelected(date: Date, event: SimpleEvent?) 27 | } 28 | 29 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 30 | val view: View = LayoutInflater.from(parent.context) 31 | .inflate(R.layout.item_calendar_view_pager, parent, false) 32 | return MonthCalendarViewHolder( 33 | view 34 | ) 35 | } 36 | 37 | override fun onBindViewHolder( 38 | holder: RecyclerView.ViewHolder, 39 | position: Int, 40 | calendarItem: RecyclerCalenderViewItem 41 | ) { 42 | val monthViewHolder: MonthCalendarViewHolder = holder as MonthCalendarViewHolder 43 | monthViewHolder.itemView.visibility = View.VISIBLE 44 | monthViewHolder.progressBar.visibility = View.GONE 45 | 46 | if (calendarItem.isHeader) { 47 | val selectedCalendar = Calendar.getInstance(Locale.getDefault()) 48 | selectedCalendar.time = calendarItem.date 49 | 50 | val month: String = CalendarUtils.dateStringFromFormat( 51 | locale = configuration.calendarLocale, 52 | date = selectedCalendar.time, 53 | format = CalendarUtils.DISPLAY_MONTH_FORMAT 54 | ) ?: "" 55 | val year = selectedCalendar[Calendar.YEAR].toLong() 56 | 57 | monthViewHolder.textViewDay.text = year.toString() 58 | monthViewHolder.textViewDate.text = month 59 | } else if (calendarItem.isEmpty) { 60 | monthViewHolder.itemView.visibility = View.GONE 61 | monthViewHolder.textViewDay.text = "" 62 | monthViewHolder.textViewDate.text = "" 63 | } else { 64 | val calendarDate = Calendar.getInstance(Locale.getDefault()) 65 | calendarDate.time = calendarItem.date 66 | 67 | val day: String = CalendarUtils.dateStringFromFormat( 68 | locale = configuration.calendarLocale, 69 | date = calendarDate.time, 70 | format = CalendarUtils.DISPLAY_WEEK_DAY_FORMAT 71 | ) ?: "" 72 | 73 | val dateInt: Int = 74 | (CalendarUtils.dateStringFromFormat( 75 | locale = configuration.calendarLocale, 76 | date = calendarDate.time, 77 | format = CalendarUtils.DB_DATE_FORMAT 78 | ) 79 | ?: "0").toInt() 80 | 81 | if (eventMap.contains(dateInt)) { 82 | monthViewHolder.progressBar.visibility = View.VISIBLE 83 | monthViewHolder.progressBar.progress = eventMap.get(dateInt)!!.progress 84 | } 85 | 86 | monthViewHolder.textViewDay.text = day 87 | 88 | monthViewHolder.textViewDate.text = 89 | CalendarUtils.dateStringFromFormat( 90 | locale = configuration.calendarLocale, 91 | date = calendarDate.time, 92 | format = CalendarUtils.DISPLAY_DATE_FORMAT 93 | ) ?: "" 94 | 95 | monthViewHolder.itemView.setOnClickListener { 96 | dateSelectListener.onDateSelected(calendarItem.date, eventMap[dateInt]) 97 | } 98 | } 99 | } 100 | 101 | class MonthCalendarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 102 | val textViewDay: TextView = itemView.findViewById(R.id.textCalenderItemViewPagerDay) 103 | val textViewDate: TextView = itemView.findViewById(R.id.textCalenderItemViewPagerDate) 104 | val progressBar: ProgressBar = itemView.findViewById(R.id.progressBarCalenderItemViewPager); 105 | } 106 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/viewpager/ui/main/PlaceholderFragment.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.viewpager.ui.main 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.appcompat.app.AlertDialog 8 | import androidx.core.content.ContextCompat 9 | import androidx.fragment.app.Fragment 10 | import androidx.recyclerview.widget.RecyclerView 11 | import com.tejpratapsingh.recyclercalendar.model.RecyclerCalendarConfiguration 12 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 13 | import com.tejpratapsingh.recyclercalendaractivity.R 14 | import com.tejpratapsingh.recyclercalendaractivity.model.SimpleEvent 15 | import com.tejpratapsingh.recyclercalendaractivity.viewpager.ViewPagerRecyclerCalendarAdapter 16 | import java.util.* 17 | 18 | /** 19 | * A placeholder fragment containing a simple view. 20 | */ 21 | class PlaceholderFragment : Fragment() { 22 | 23 | private val eventMap: HashMap = HashMap() 24 | 25 | override fun onCreateView( 26 | inflater: LayoutInflater, container: ViewGroup?, 27 | savedInstanceState: Bundle? 28 | ): View? { 29 | val root = inflater.inflate(R.layout.fragment_view_pager_calendar, container, false) 30 | val sectionNumber: Int = requireArguments().get(ARG_SECTION_NUMBER) as Int 31 | val calendarRecyclerView: RecyclerView = root.findViewById(R.id.calendarRecyclerView) 32 | val date = Date() 33 | date.time = System.currentTimeMillis() 34 | 35 | val startCal = Calendar.getInstance() 36 | startCal.time = date 37 | startCal.add(Calendar.MONTH, sectionNumber) 38 | 39 | val configuration: RecyclerCalendarConfiguration = 40 | RecyclerCalendarConfiguration( 41 | calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, 42 | calendarLocale = Locale.getDefault(), 43 | includeMonthHeader = false 44 | ) 45 | configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY 46 | 47 | // Some Random Events 48 | for (i in 0..30 step 3) { 49 | val eventCal = Calendar.getInstance() 50 | eventCal.add(Calendar.DATE, i * 3) 51 | val eventDate: Int = 52 | (CalendarUtils.dateStringFromFormat( 53 | locale = configuration.calendarLocale, 54 | date = eventCal.time, 55 | format = CalendarUtils.DB_DATE_FORMAT 56 | ) 57 | ?: "0").toInt() 58 | eventMap[eventDate] = SimpleEvent( 59 | date = eventCal.time, 60 | title = "Event #$i", 61 | color = ContextCompat.getColor(root.context, R.color.colorAccent), 62 | progress = i * 3 63 | ) 64 | } 65 | 66 | val calendarAdapterViewPager: ViewPagerRecyclerCalendarAdapter = 67 | ViewPagerRecyclerCalendarAdapter( 68 | startDate = startCal.time, 69 | endDate = startCal.time, 70 | configuration = configuration, 71 | eventMap = eventMap, 72 | dateSelectListener = object : ViewPagerRecyclerCalendarAdapter.OnDateSelected { 73 | override fun onDateSelected(date: Date, event: SimpleEvent?) { 74 | val selectedDate: String = 75 | CalendarUtils.dateStringFromFormat( 76 | locale = configuration.calendarLocale, 77 | date = date, 78 | format = CalendarUtils.LONG_DATE_FORMAT 79 | ) 80 | ?: "" 81 | 82 | if (event != null) { 83 | AlertDialog.Builder(activity!!) 84 | .setTitle("Event Clicked") 85 | .setMessage( 86 | String.format( 87 | Locale.getDefault(), 88 | "Date: %s\n\nEvent: %s\n\nProgress: %s", 89 | selectedDate, 90 | event.title, 91 | event.progress 92 | ) 93 | ) 94 | .create() 95 | .show() 96 | } 97 | } 98 | } 99 | ) 100 | 101 | calendarRecyclerView.adapter = calendarAdapterViewPager 102 | return root 103 | } 104 | 105 | companion object { 106 | /** 107 | * The fragment argument representing the section number for this 108 | * fragment. 109 | */ 110 | private const val ARG_SECTION_NUMBER = "section_number" 111 | 112 | /** 113 | * Returns a new instance of this fragment for the given section 114 | * number. 115 | */ 116 | @JvmStatic 117 | fun newInstance(sectionNumber: Int): PlaceholderFragment { 118 | return PlaceholderFragment().apply { 119 | arguments = Bundle().apply { 120 | putInt(ARG_SECTION_NUMBER, sectionNumber) 121 | } 122 | } 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/viewpager/ui/main/SectionsPagerAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.tejpratapsingh.recyclercalendaractivity.viewpager.ui.main 2 | 3 | import android.content.Context 4 | import androidx.fragment.app.Fragment 5 | import androidx.fragment.app.FragmentManager 6 | import androidx.fragment.app.FragmentPagerAdapter 7 | import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils 8 | import java.util.* 9 | 10 | /** 11 | * A [FragmentPagerAdapter] that returns a fragment corresponding to 12 | * one of the sections/tabs/pages. 13 | */ 14 | class SectionsPagerAdapter(private val context: Context, fm: FragmentManager) : 15 | FragmentPagerAdapter(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { 16 | 17 | override fun getItem(position: Int): Fragment { 18 | // getItem is called to instantiate the fragment for the given page. 19 | // Return a PlaceholderFragment (defined as a static inner class below). 20 | return PlaceholderFragment.newInstance(position) 21 | } 22 | 23 | override fun getPageTitle(position: Int): CharSequence? { 24 | val date = Date() 25 | date.time = System.currentTimeMillis() 26 | val selectedCalendar = Calendar.getInstance(Locale.getDefault()) 27 | selectedCalendar.time = date 28 | selectedCalendar.add(Calendar.MONTH, position) 29 | 30 | val month: String = CalendarUtils.dateStringFromFormat( 31 | locale = Locale.getDefault(), 32 | date = selectedCalendar.time, 33 | format = CalendarUtils.DISPLAY_MONTH_FORMAT 34 | ) ?: "" 35 | val year = selectedCalendar[Calendar.YEAR].toLong() 36 | 37 | return String.format(Locale.getDefault(), "%s / %d", month, year) 38 | } 39 | 40 | override fun getCount(): Int { 41 | // Show total pages. 42 | return 24 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-anydpi/ic_action_setting.xml: -------------------------------------------------------------------------------- 1 | 8 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/drawable-hdpi/ic_action_setting.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/drawable-mdpi/ic_action_setting.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/drawable-xhdpi/ic_action_setting.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/drawable-xxhdpi/ic_action_setting.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/circle_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/circular_progress_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_calendar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/drawable/ic_calendar.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/layout_round_corner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/layout_round_corner_filled.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_horizontal_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 25 | 26 | 32 | 33 | 38 | 39 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_infinite_recycler_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 26 | 27 | 34 | 35 | 36 | 41 | 42 | 51 | 52 | 57 | 58 | 64 | 65 | 70 | 71 | 72 | 73 | 74 | 78 | 79 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 23 | 24 | 32 | 33 | 39 | 40 | 52 | 53 | 54 | 55 | 63 | 64 | 70 | 71 | 83 | 84 | 85 | 93 | 94 | 100 | 101 | 113 | 114 | 115 | 124 | 125 | 133 | 134 | 140 | 141 | 153 | 154 | 155 | 163 | 164 | 170 | 171 | 183 | 184 | 185 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_simple_recycler_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 25 | 26 | 33 | 34 | 35 | 40 | 41 | 50 | 51 | 56 | 57 | 63 | 64 | 69 | 70 | 71 | 72 | 81 | 82 | 88 | 89 | 95 | 96 | 101 | 102 | 107 | 108 | 113 | 114 | 115 | 116 | 117 | 121 | 122 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_vertical_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_view_pager_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 20 | 21 | 30 | 31 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_view_pager_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_calendar_horizontal.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_calendar_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 20 | 21 | 29 | 30 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_calendar_view_pager.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | 26 | 27 | 34 | 35 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tejpratap46/RecyclerCalendarAndroid/e35596e321244fa92bd4b1d61aff07c044d3fa17/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #536DFE 6 | #C5CAE9 7 | #212121 8 | #757575 9 | #FFFFFF 10 | #BDBDBD 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 16dp 7 | 8dp 8 | 20sp 9 | 16sp 10 | 8dp 11 | 32sp 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Recycler Calendar Example 3 | Week Calendar 4 | Month Calendar 5 | Page Calendar 6 | Selected Date 7 | Simple Calendar 8 | Example 9 | Selection Mode 10 | None 11 | Single 12 | Multiple 13 | Range 14 | Vertical 15 | Horizontal 16 | Calendar Icon made by Freepik from www.flaticon.com 17 | Infinite Calendar 18 | Orientation 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |