Skip to content

Commit

Permalink
Fixed #7: Added option to set start of week in Configuration
Browse files Browse the repository at this point in the history
call following API while setting up your adapter
`configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY`

Only 3 days [SATURDAY, SUNDAY, MONDAY] are allowed as start of week, which should be sufficient for all cases.
  • Loading branch information
tejpratap46 committed Sep 6, 2021
1 parent e136aa6 commit fe5151b
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 125 deletions.
16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

79 changes: 41 additions & 38 deletions README.md
Expand Up @@ -150,26 +150,28 @@ endCal.time = date
endCal.add(Calendar.MONTH, 3)

val configuration: SimpleRecyclerCalendarConfiguration =
SimpleRecyclerCalendarConfiguration(
calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, // calendarViewType could be VERTICAL OR HORIZONTAL
calendarLocale = Locale.getDefault(),
includeMonthHeader = true,
selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeNone() // selectionMode could be one of [SelectionModeNone, SelectionModeSingle, SelectionModeMultiple, SelectionModeRange]
)

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()
}
})
SimpleRecyclerCalendarConfiguration(
calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, // calendarViewType could be VERTICAL OR HORIZONTAL
calendarLocale = Locale.getDefault(),
includeMonthHeader = true,
selectionMode = SimpleRecyclerCalendarConfiguration.SelectionModeNone() // selectionMode could be one of [SelectionModeNone, SelectionModeSingle, SelectionModeMultiple, SelectionModeRange]
)
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()
}
})
```
*To know More about SimpleRecyclerCalendarView visit [SimpleRecyclerCalendarActivity](https://github.com/tejpratap46/RecyclerCalendarAndroid/blob/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/simple/SimpleRecyclerCalendarActivity.kt)*

Expand Down Expand Up @@ -199,24 +201,25 @@ endCal.time = date
endCal.add(Calendar.MONTH, 3)

val configuration: InfiniteRecyclerCalendarConfiguration =
InfiniteRecyclerCalendarConfiguration(
calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, // calendarViewType could be VERTICAL OR HORIZONTAL
calendarLocale = Locale.getDefault(),
includeMonthHeader = true,
selectionMode = InfiniteRecyclerCalendarConfiguration.SelectionModeNone() // selectionMode could be one of [SelectionModeNone, SelectionModeSingle, SelectionModeMultiple, SelectionModeRange]
)

calenderView!!.initialise(
configuration,
object : InfiniteRecyclerCalenderAdapter.OnDateSelected {
override fun onDateSelected(date: Date) {
Toast.makeText(
calenderView!!.context,
"Date Selected: ${CalendarUtils.getGmt(date)}",
Toast.LENGTH_LONG
).show()
}
})
InfiniteRecyclerCalendarConfiguration(
calenderViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL, // calendarViewType could be VERTICAL OR HORIZONTAL
calendarLocale = Locale.getDefault(),
includeMonthHeader = true,
selectionMode = InfiniteRecyclerCalendarConfiguration.SelectionModeNone() // selectionMode could be one of [SelectionModeNone, SelectionModeSingle, SelectionModeMultiple, SelectionModeRange]
)
configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY

calenderView!!.initialise(
configuration,
object : InfiniteRecyclerCalenderAdapter.OnDateSelected {
override fun onDateSelected(date: Date) {
Toast.makeText(
calenderView!!.context,
"Date Selected: ${CalendarUtils.getGmt(date)}",
Toast.LENGTH_LONG
).show()
}
})
```
*To know More about InfiniteRecyclerCalendarActivity visit [InfiniteRecyclerCalendarActivity](https://github.com/tejpratap46/RecyclerCalendarAndroid/blob/master/app/src/main/java/com/tejpratapsingh/recyclercalendaractivity/simple/InfiniteRecyclerCalendarActivity.kt)*

Expand Down
17 changes: 7 additions & 10 deletions app/build.gradle
@@ -1,9 +1,6 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
defaultConfig {
Expand All @@ -25,13 +22,13 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation project(path: ':recyclercalendar')
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Expand Up @@ -34,6 +34,7 @@ class HorizontalCalendarActivity : AppCompatActivity() {
calendarLocale = Locale.getDefault(),
includeMonthHeader = true
)
configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY

textViewSelectedDate.text =
CalendarUtils.dateStringFromFormat(
Expand Down
Expand Up @@ -14,7 +14,6 @@ import com.tejpratapsingh.recyclercalendar.utilities.CalendarUtils
import com.tejpratapsingh.recyclercalendar.views.InfiniteRecyclerCalendarView
import com.tejpratapsingh.recyclercalendaractivity.R
import java.util.*
import kotlin.collections.HashMap

class InfiniteRecyclerCalendarActivity : AppCompatActivity() {

Expand All @@ -29,15 +28,6 @@ class InfiniteRecyclerCalendarActivity : AppCompatActivity() {

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)

Expand All @@ -56,35 +46,22 @@ class InfiniteRecyclerCalendarActivity : AppCompatActivity() {
// Switch to Vertical View
calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.VERTICAL

refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
refreshCalendarCalendar()
}

radioViewTypeHorizontal.setOnClickListener {
// Switch to Horizontal View
calendarViewType = RecyclerCalendarConfiguration.CalenderViewType.HORIZONTAL

refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time
)
refreshCalendarCalendar()
}

selectionMode = InfiniteRecyclerCalendarConfiguration.SelectionModeNone()

refreshCalendarCalendar(
startDate = startCal.time,
endDate = endCal.time

)
refreshCalendarCalendar()
}

private fun refreshCalendarCalendar(
startDate: Date,
endDate: Date
) {
private fun refreshCalendarCalendar() {
if (calenderView == null || selectionMode == null) {
return
}
Expand All @@ -96,6 +73,8 @@ class InfiniteRecyclerCalendarActivity : AppCompatActivity() {
selectionMode = selectionMode!!
)

configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY

calenderView!!.initialise(
configuration,
object : InfiniteRecyclerCalenderAdapter.OnDateSelected {
Expand Down
Expand Up @@ -142,6 +142,7 @@ class SimpleRecyclerCalendarActivity : AppCompatActivity() {
includeMonthHeader = true,
selectionMode = selectionMode!!
)
configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY

calenderView!!.initialise(
startDate,
Expand Down
Expand Up @@ -38,6 +38,8 @@ class VerticalCalendarActivity : AppCompatActivity() {
includeMonthHeader = true
)

configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY

// Some Random Events
for (i in 0..30 step 3) {
val eventCal = Calendar.getInstance()
Expand Down
Expand Up @@ -27,7 +27,7 @@ class PlaceholderFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.fragment_view_pager_calendar, container, false)
val sectionNumber: Int = arguments!!.get(ARG_SECTION_NUMBER) as Int
val sectionNumber: Int = requireArguments().get(ARG_SECTION_NUMBER) as Int
val calendarRecyclerView: RecyclerView = root.findViewById(R.id.calendarRecyclerView)
val date = Date()
date.time = System.currentTimeMillis()
Expand All @@ -42,6 +42,7 @@ class PlaceholderFragment : Fragment() {
calendarLocale = Locale.getDefault(),
includeMonthHeader = false
)
configuration.weekStartOffset = RecyclerCalendarConfiguration.START_DAY_OF_WEEK.MONDAY

// Some Random Events
for (i in 0..30 step 3) {
Expand Down Expand Up @@ -95,7 +96,7 @@ class PlaceholderFragment : Fragment() {
}
}
}
);
)

calendarRecyclerView.adapter = calendarAdapterViewPager
return root
Expand Down
9 changes: 4 additions & 5 deletions build.gradle
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.10'
ext.kotlin_version = '1.5.21'
repositories {
google()
jcenter()
mavenCentral()

}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -19,8 +19,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()

mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
2 changes: 2 additions & 0 deletions jitpack.yml
@@ -0,0 +1,2 @@
jdk:
- openjdk11
18 changes: 6 additions & 12 deletions recyclercalendar/build.gradle
@@ -1,18 +1,12 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

apply plugin: 'com.github.dcendents.android-maven'
group='com.github.tejpratap46'

android {
compileSdkVersion 30

defaultConfig {
minSdkVersion 15
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -30,10 +24,10 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.core:core-ktx:1.3.2'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.core:core-ktx:1.6.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

0 comments on commit fe5151b

Please sign in to comment.