Android calendar library provides easy to use widget with events

Overview

Kotlin-AgendaCalendarView

Kotlin-AgendaCalendarView based on AgendaCalendarView

Kotlin-AgendaCalendarView is a awesome calendar widget with a list of events. Events can be dynamically added to the calendar. Please feel free to contribute to this project by creating pull request on feauture or bugfix branches.

Demo:

alt text

Import project

Gradle:

        compile 'com.ognev.kotlin.agendacalendarview:kotlin-agendacalendarview:1.0'

Maven:

        <dependency>
          <groupId>com.ognev.kotlin.agendacalendarview</groupId>
          <artifactId>kotlin-agendacalendarview</artifactId>
          <version>1.0</version>
          <type>pom</type>
        </dependency>

Usage

Layout xml file

    <com.ognev.kotlin.agendacalendarview.AgendaCalendarView
        android:id="@+id/agenda_calendar_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        agendaCalendar:calendarCurrentDayTextColor="@color/main_blue"
        agendaCalendar:calendarSelectedDayTextColor="@color/white"
        agendaCalendar:calendarMonthTextColor="@color/black"
        agendaCalendar:calendarHeaderColor="@color/main_blue"
        agendaCalendar:circleBackgroundColor="@drawable/selected_day_background"
        agendaCalendar:calendarPastDayTextColor="@android:color/darker_gray"
        agendaCalendar:cellPastBackgroundColor="@color/calendar_past_days_bg"
        agendaCalendar:cellNowadaysDayColor="@color/white"
        tools:layout_editor_absoluteY="8dp"
        tools:layout_editor_absoluteX="8dp" />

Implement your activity/fragment from CalendarController

    fun getEmptyEventLayout(): Int

    fun getEventLayout() : Int

    fun onDaySelected(dayItem: IDayItem)

    fun onScrollToDate(calendar: Calendar)

Create your Model class:

    class SampleEvent(name: String, description: String) {
        var id: Long = 0
        var name: String = name
        var desciption: String = description
    }

Create model wrapper class for calendar widget:

    class MyCalendarEvent: BaseCalendarEvent {

    override lateinit var startTime: Calendar
    override lateinit var endTime: Calendar
    override var event: Any? = null

    override lateinit var instanceDay: Calendar


    override lateinit var dayReference: IDayItem

    override lateinit var weekReference: IWeekItem

    override fun setEventInstanceDay(instanceDay: Calendar): MyCalendarEvent {
        this.instanceDay = instanceDay
        this.instanceDay.set(Calendar.HOUR, 0)
        this.instanceDay.set(Calendar.MINUTE, 0)
        this.instanceDay.set(Calendar.SECOND, 0)
        this.instanceDay.set(Calendar.MILLISECOND, 0)
        this.instanceDay.set(Calendar.AM_PM, 0)
        return this
    }

    constructor(calendarEvent: CalendarEvent) {
    }


    constructor(startTime: Calendar,
                endTime: Calendar,
                dayItem: DayItem,
                event: SampleEvent?)  {
        this.startTime = startTime
        this.endTime = endTime
        this.dayReference = dayItem
        this.event = event
    }


    override
    fun copy(): MyCalendarEvent {
        return MyCalendarEvent(this)
    }

    override fun hasEvent(): Boolean {
        return event != null
    }

    override
    fun toString(): String {
        return super.toString()
     }
    }

Create adapter:

    class SampleEventAgendaAdapter(var context: Context) : DefaultEventAdapter() {
        private var format: SimpleDateFormat? = null

    init {
        format = SimpleDateFormat(context.getString(com.ognev.kotlin.agendacalendarview.R.string.header_date),
                Locale.ENGLISH)
    }

    override fun getHeaderLayout(): Int {
        return R.layout.view_agenda_header
    }

    override fun getHeaderItemView(view: View, day: Calendar) {
        val txtDayOfMonth = view.findViewById(R.id.view_agenda_day_of_month) as TextView
        val today = CalendarManager.instance!!.today

        if (DateHelper.sameDate(day, today)) {
            txtDayOfMonth.setTextColor(context.resources.getColor(R.color.main_blue))
        } else{
            txtDayOfMonth.setTextColor(context.resources.getColor(R.color.text_light_color))
        }

        txtDayOfMonth.text = format!!.format(day.time)
    }

    override fun getEventItemView(view: View, event: CalendarEvent, position: Int) {
        val myEvent = event as MyCalendarEvent
        val myObject: SampleEvent? = myEvent.event as SampleEvent?

        if(myEvent.hasEvent()) {
            (view.findViewById(R.id.name)
                    as TextView).text = myObject!!.name

            (view.findViewById(R.id.description)
                    as TextView).text = myObject.desciption
        }

        view.setOnClickListener {
            Toast.makeText(view.context, "Item: ".plus(position), Toast.LENGTH_SHORT).show()
        }
    }

    override fun getEventLayout(hasEvent: Boolean): Int {
        return if(hasEvent) R.layout.view_agenda_event else R.layout.view_agenda_empty_event
     }
    }

Configure calendar in your code with a CalendarContentManager:

        minDate = Calendar.getInstance()
        maxDate = Calendar.getInstance()
        minDate.add(Calendar.MONTH, -10)
        minDate.add(Calendar.YEAR, -1)
        minDate.set(Calendar.DAY_OF_MONTH, 1)
        maxDate.add(Calendar.YEAR, 1)

        eventList = ArrayList()

        contentManager = CalendarContentManager(this, agenda_calendar_view, SampleEventAgendaAdapter(applicationContext))

        contentManager.locale = Locale.ENGLISH
        contentManager.setDateRange(minDate, maxDate)

Add events to calendar from start

       contentManager.loadItemsFromStart(eventList!!)

Add events to calendar to End of list

        contentManager.loadFromEndCalendar(eventList!!)

Licence


Copyright 2017 Ognev Zair

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Comments
  • new logo

    new logo

    Hi @ognev-zair , I am a graphic designer, I want to help others in graphic design.

    After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

    opened by luthfirangers 3
  • Awesome library! Thank you. I do have a question though

    Awesome library! Thank you. I do have a question though

    Hi @ognev-zair I was able to configure the calendar and it loads and works very smoothly. What I couldn't figure out yet, is how can I make the top bar that contains the days to start from Monday, and not from Sunday. Could you give me a hit, please? I've tried to set the locale to some local that has the week starting with Monday, but it only changes the calendar language, not the week day name bar.

    Thanks you!

    opened by trifagabriel 1
  • Sample code clean-up

    Sample code clean-up

    • Update MainActivity code formatting
    • Update kotlin version to 1.1.60
    • Add extension function for Calendar.isSameDay
    • Make SampleEvent a data class
    • Format code
    opened by victornicro 1
  • ,ckdk;udizogmzjhflm

    ,ckdk;udizogmzjhflm

    https://github.com/ognev-zair/Kotlin-AgendaCalendarView/blob/c4a881485acc49ef4850cc1e0183db1310be2f9c/app/src/main/java/com/ognev/kotlin/agendacalendarview/sample/MainActivity.kt#L194

    opened by kescatefou 0
  • Notify for new values

    Notify for new values

    Hi,

    How can we update the list of adapter ?

    val calendarView : AgendaCalendarView = view.findViewById(R.id.agenda_calendar_view) adapter = AgendaAdapter(this.requireContext()) contentManager = CalendarContentManager(this, calendarView, adapter) contentManager.setDateRange(minDate, maxDate) contentManager.locale = Locale.FRENCH

        viewModel.interventionsListOfUser.observe(viewLifecycleOwner) { intervention ->
            eventList.clear()
            intervention.forEach { inter ->
                val dayStart = Calendar.getInstance()
                dayStart.time = Date(inter.startAt!!)
                val dayEnd = Calendar.getInstance()
                dayEnd.time = Date(inter.finishAt!!)
    
                val dayItem = DayItem.buildDayItemFromCal(dayStart)
                eventList.add(AgendaEvent(dayStart, dayEnd, dayItem, inter))
            }
           
        }
    
    opened by FlorianStock 1
  • [SOLVED] IllegalStateException: Handling non empty state of parent class is not implemented

    [SOLVED] IllegalStateException: Handling non empty state of parent class is not implemented

    If you're getting the [IllegalStateException: Handling non empty state of parent class is not implemented] crash, you can solve it by adding this line in your activity/fragment, where the agenda calendar view is instantiated. Most probably to happen on Android O, Google phones.

    agendaCalendarView.getAgendaView().getAgendaListView().setSaveEnabled(false);

    opened by trifagabriel 0
  • why it is get black screen before open the calendar

    why it is get black screen before open the calendar

    I tried to use this library on a button click event. It is working but it gets a little bit of time to open the calendar & before open it shows a black screen.

    opened by PrihanNimsara 0
  • Question and bug: making

    Question and bug: making "notifyDataSetChanged" stay on same place

    I've noticed that whether you scroll to the top or to the bottom, after it finishes loading, you call notifyDataSetChanged , but the scrolling stay almost on same place, almost perfectly.

    How did you do this?

    I've written about it here: https://stackoverflow.com/q/47458429/878126

    Also, found an issue about this. If I let it load, and then I scroll a bit, it doesn't stay on the current place. Attached video to show issue. device-2017-11-26-114106.zip

    opened by AndroidDeveloperLB 1
Owner
Ognev Zair
Software Engineer | Work Hard Dream Big
Ognev Zair
Server Sent Events (SSE) client multiplatform library made with Kotlin and backed by coroutines

OkSSE OkSSE is an client for Server Sent events protocol written in Kotlin Multiplatform. The implementation is written according to W3C Recommendatio

BioWink GmbH 39 Nov 4, 2022
Kotlin Multiplatfom app for Droidcon Events

Sessionize/Droidcon Mobile Clients General Info This project has a pair of native mobile applications backed by the Sessionize data api for use in eve

Touchlab 838 Jan 4, 2023
Simple Android Library, that provides easy way to start the Activities with arguments.

Warning: Library is not maintained anymore. If you want to take care of this library, propose it via Pull Request. It needs adjustmensts for newer ver

Marcin Moskała 429 Dec 15, 2022
A highly customizable calendar library for Android, powered by RecyclerView.

CalendarView A highly customizable calendar library for Android, powered by RecyclerView. With this library, your calendar will look however you want

Kizito Nwose 3.4k Jan 3, 2023
A beautiful material calendar with endless scroll, range selection and a lot more!

CrunchyCalendar A light, powerful and easy to use Calendar Widget with a number out of the box features: Infinite vertical scrolling in both direction

CleverPumpkin 483 Dec 25, 2022
Workout Journal is a mobile app based on Multi-Module and Clean Architecture for those who want to track their progress over a workout and a calendar period.

Workout-Journal Workout Journal is a mobile app for those who want to track their progress over a workout and a calendar period. The app allows you to

Maxim Smolyakov 4 Oct 23, 2022
Modern Calendar View Supporting Both Hijri and Gregorian Calendars but in highly dynamic way

KCalendar-View Modern calendar view supporting both Hijri and Gregorian calendar

Ahmed Ibrahim 8 Oct 29, 2022
Kotlin parser library with an easy-to-use DSL

Pratt Library for parsing expressions and a beautiful Kotlin DSL Just define your operators and operands with the Kotlin DSL and the parser is ready!

furetur 9 Oct 17, 2022
A library with many useful and easy-to-use features

This library was made as a replacement for qLib and in the future cubed. These 2 plugins are hard to get you hands on and one of them has many outdated methods so this is a more modern version of those things

Max 1 May 6, 2022
A simple 'Slide to Unlock' Material widget for Android, written in Kotlin 📱🎨🦄

Slide To Act A simple Slide to Unlock Material widget for Android, written in Kotlin ??. Getting Started Example Features Attributes area_margin inner

Nicola Corti 984 Jan 2, 2023
An Easy-to-use Kotlin based Customizable Modules Collection with Material Layouts by BlackBeared.

Fusion By BlackBeared An Easy-to-use Kotlin based Customizable Library with Material Layouts by @blackbeared. Features Custom Floating Action Buttons

Sandip Savaliya 38 Oct 5, 2022
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Jan 8, 2023
An easy to use package manager for Fabric Minecraft mods.

pacmc pacmc is a package manager for Fabric Minecraft mods. The aim of this project is to massively reduce the effort you have to put in to installing

Jakob K 109 Dec 30, 2022
kinstall is an easy way to install gradle-based command-line kotlin projects that use the application plugin.

kinstall kinstall is an easy way to install gradle-based command-line kotlin projects that use the application plugin. use First, install kinstall its

david kilmer 0 Apr 24, 2022
Clay is an Android library project that provides image trimming which is originally an UI component of LINE Creators Studio

Clay Clay is an Android library project that provides image trimming. Fully written in Kotlin, Clay is originally a UI component of LINE Creators Stud

LINE 119 Dec 27, 2022
An Android Library that provides social login for 15 platforms within by RxJava2, Kotlin and Firebase Authentication.

RxSocialLogin The license information for logo is located at the bottom of the document. These instructions are available in their respective language

WindSekirun (wind.seo) 124 Nov 21, 2022
This library provides common speech features for ASR including MFCCs and filterbank energies for Android and iOS.

Kotlin Speech Features Quick Links ?? Introduction This library is a complete port of python_speech_features in pure Kotlin available for Android and

Merlyn Mind 13 Oct 7, 2022
This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.

Clean-architecture This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture. Why i should us

Kareem Aboelatta 10 Dec 13, 2022
AbstractMvp 0.8 0.0 Kotlin is a library that provides abstract components for MVP architecture realization, with problems solutions that are exist in classic MVP.

MinSDK 14+ AbstractMvp AbstractMvp is a library that provides abstract components for MVP architecture realization, with problems solutions that are e

Robert 12 Apr 5, 2022