Skip to content

Commit 6246666

Browse files
committed
Months and Week Days name support added.
1 parent 0e005f7 commit 6246666

File tree

4 files changed

+69
-38
lines changed

4 files changed

+69
-38
lines changed

CalendarView/src/main/java/com/shahzadafridi/calendarview/CalendarView.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
1414
import com.shahzadafridi.calendarview.Util.dp
1515
import java.text.SimpleDateFormat
1616
import java.util.*
17+
import kotlin.collections.ArrayList
1718

1819
class CalendarView : LinearLayout, CalenderViewInterface {
1920

@@ -77,20 +78,7 @@ class CalendarView : LinearLayout, CalenderViewInterface {
7778

7879
//Months
7980
var monthSeason = intArrayOf(2, 2, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2)
80-
var months = arrayListOf<String>().apply {
81-
add("Januari")
82-
add("Februari")
83-
add("Maart")
84-
add("April")
85-
add("Mei")
86-
add("Juni")
87-
add("Juli")
88-
add("Augustus")
89-
add("September")
90-
add("Oktober")
91-
add("November")
92-
add("December")
93-
}
81+
9482
var monthNumber: Int = currentDate.get(Calendar.MONTH)
9583

9684
var events: HashSet<Calendar>? = hashSetOf()
@@ -204,7 +192,7 @@ class CalendarView : LinearLayout, CalenderViewInterface {
204192
calendarDayRv!!.adapter = adapter
205193

206194
//update months
207-
adapterMonth = MonthAdapter(context,this,monthConfig,months,monthNumber)
195+
adapterMonth = MonthAdapter(context,this,monthConfig,Util.months,monthNumber)
208196
calendarMonthRv!!.adapter = adapterMonth
209197

210198
val sdfYear = if (dateFormat != null) SimpleDateFormat(dateFormat) else SimpleDateFormat(DATE_FORMAT)
@@ -290,8 +278,12 @@ class CalendarView : LinearLayout, CalenderViewInterface {
290278
textSize: Int?,
291279
selectedTextColor: Int?,
292280
unSelectedTextColor: Int?,
293-
background: Int?
281+
background: Int?,
282+
months: ArrayList<String>?
294283
): CalendarView {
284+
if (months != null) {
285+
Util.months = months
286+
}
295287
month_font = font
296288
month_txt_size = textSize
297289
month_selected_txt_clr = selectedTextColor
@@ -321,12 +313,17 @@ class CalendarView : LinearLayout, CalenderViewInterface {
321313
return this
322314
}
323315

324-
override fun withWeekPanel(font: Int?, textColor: Int?, textSize: Int?, background: Int?): CalendarView {
316+
override fun withWeekPanel(font: Int?, textColor: Int?, textSize: Int?, background: Int?,weekDays: ArrayList<String>?): CalendarView {
317+
if (weekDays != null) {
318+
Util.weekDays = weekDays
319+
}
325320
week_font = font
326321
week_txt_clr = textColor
327322
week_txt_size = textSize
328323
week_bg_clr = background
329324

325+
var i = 0
326+
330327
weekLayout!!.children.iterator().forEach {
331328
week_font?.let { font ->
332329
(it as TextView).typeface = ResourcesCompat.getFont(context, font)
@@ -337,6 +334,8 @@ class CalendarView : LinearLayout, CalenderViewInterface {
337334
week_txt_size?.let { size ->
338335
(it as TextView).setTextSize(size.toFloat())
339336
}
337+
(it as TextView).text = Util.weekDays[i]
338+
i++
340339
}
341340

342341
week_bg_clr?.let {

CalendarView/src/main/java/com/shahzadafridi/calendarview/CalenderViewInterface.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ interface CalenderViewInterface {
99
fun withEvents(events: HashSet<Calendar>? = null,eventDotColor: Int? = null): CalendarView
1010
fun withYearPanel(dateFormat: String? = null,textColor: Int? = null,textSize: Int? = null,font: Int? = null): CalendarView
1111
fun withYearPanleMargin(top: Int = 0,bottom: Int = 0,left: Int = 0,right: Int = 0): CalendarView
12-
fun withMonthPanel(font: Int? = null, textSize: Int? = null, selectedTextColor: Int? = null, unSelectedTextColor:Int? = null, background: Int? = null): CalendarView
12+
fun withMonthPanel(font: Int? = null, textSize: Int? = null, selectedTextColor: Int? = null, unSelectedTextColor:Int? = null, background: Int? = null,months: ArrayList<String>? = null): CalendarView
1313
fun withMonthPanleMargin(top: Int = 0,bottom: Int = 0,left: Int = 0,right: Int = 0): CalendarView
14-
fun withWeekPanel(font: Int? = null, textColor: Int? = null, textSize: Int? = null, background: Int? = null): CalendarView
14+
fun withWeekPanel(font: Int? = null, textColor: Int? = null, textSize: Int? = null, background: Int? = null,weekDays: ArrayList<String>? = null): CalendarView
1515
fun withWeekPanelMargin(top: Int = 0,bottom: Int = 0,left: Int = 0,right: Int = 0): CalendarView
1616
fun withDayPanel(font: Int? = null, textColor: Int? = null, textSize: Int? = null, selectedTextColor: Int? = null, selectedBackground:Int? = null, background: Int? = null): CalendarView
1717
fun withDayPanelMargin(top: Int = 0,bottom: Int = 0,left: Int = 0,right: Int = 0): CalendarView

CalendarView/src/main/java/com/shahzadafridi/calendarview/Util.kt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@ object Util {
1515
val Int.dp: Int
1616
get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()
1717

18-
/**
19-
* CREATE CUSTOM DIALOG
20-
*/
18+
var months = arrayListOf<String>().apply {
19+
add("Januari")
20+
add("Februari")
21+
add("Maart")
22+
add("April")
23+
add("Mei")
24+
add("Juni")
25+
add("Juli")
26+
add("Augustus")
27+
add("September")
28+
add("Oktober")
29+
add("November")
30+
add("December")
31+
}
2132

22-
fun onCreateDialog(context: Context, layout: CalendarView, cancelable: Boolean): Dialog {
23-
val dialog = Dialog(context, android.R.style.Theme_Dialog)
24-
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
25-
dialog.setContentView(layout)
26-
dialog.window!!.setGravity(Gravity.CENTER)
27-
dialog.window!!.setLayout(
28-
WindowManager.LayoutParams.MATCH_PARENT,
29-
WindowManager.LayoutParams.WRAP_CONTENT
30-
)
31-
dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
32-
dialog.window!!.attributes.windowAnimations = R.style.AnimatedDialogStyle
33-
dialog.window!!.setGravity(Gravity.TOP)
34-
dialog.setCancelable(cancelable)
35-
return dialog
33+
var weekDays = arrayListOf<String>().apply {
34+
add("ZO")
35+
add("MA")
36+
add("DI")
37+
add("WO")
38+
add("DO")
39+
add("VR")
40+
add("ZA")
3641
}
3742
}

app/src/main/java/com/shahzadafridi/sample/MainActivity.kt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ class MainActivity : AppCompatActivity() {
2525
lateinit var binding: ActivityMainBinding
2626
var dialog: CalendarViewDialog? = null
2727

28+
var months = arrayListOf<String>().apply {
29+
add("January")
30+
add("February")
31+
add("March")
32+
add("April")
33+
add("May")
34+
add("June")
35+
add("July")
36+
add("August")
37+
add("September")
38+
add("October")
39+
add("November")
40+
add("December")
41+
}
42+
43+
var weekDays = arrayListOf<String>().apply {
44+
add("SUN")
45+
add("MON")
46+
add("TUE")
47+
add("WED")
48+
add("THU")
49+
add("FRI")
50+
add("SAT")
51+
}
52+
2853
override fun onCreate(savedInstanceState: Bundle?) {
2954
super.onCreate(savedInstanceState)
3055
binding = ActivityMainBinding.inflate(layoutInflater)
@@ -60,13 +85,15 @@ class MainActivity : AppCompatActivity() {
6085
textSize = 20,
6186
selectedTextColor = R.color.black,
6287
unSelectedTextColor = R.color.greyed_out,
63-
background = R.color.white
88+
background = R.color.white,
89+
months
6490
)
6591
.withWeekPanel(
6692
font = R.font.titillium_web_semibold,
6793
textColor = R.color.black,
6894
textSize = 14,
69-
background = R.color.white
95+
background = R.color.white,
96+
weekDays
7097
)
7198
.withDayPanel(
7299
font = R.font.titillium_web_semibold,

0 commit comments

Comments
 (0)