Giter Club home page Giter Club logo

singlerowcalendar's Introduction

SingleRowCalendar

With this library, you aren't attached to library built-in UI. You can create really beautiful and customizable UI and use selection features without hands getting dirty with RecyclerView and SelectionTracker.

Download License Donate Sample Sample

FEATURES

  • single selection
  • multiple selection
  • enable/disable long press to start selection
  • enable/disable deselection
  • set count of dates in past or future, or you can provide your dates
  • initial position
  • easily observe for changes in selection
  • control selection of particular items using selection manager
  • programmatically deselect and select items
  • check if the item is selected
  • set selection
  • clear selection
  • and more...

INSTALLATION

GRADLE

dependencies {
    implementation 'com.michalsvec:single-row-calednar:1.0.0'
}

MAVEN

<dependency>
	<groupId>com.michalsvec</groupId>
	<artifactId>single-row-calednar</artifactId>
	<version>1.0.0</version>
	<type>pom</type>
</dependency>

USAGE

1. create calendar item view layout files

  • create layout files, which will be defining how you calendar will look like
  • basic item - selected and deselected

2. create special calendar item view layout files (optional)

  • if you need some special items, which will be displayed accroding to your logic you can add them
  • special item - selected and deselected

3. add SingleRowCalendar to your activty or fragment layout file

<com.michalsvec.singlerowcalendar.calendar.SingleRowCalendar
        android:id="@+id/main_single_row_calendar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        app:deselection="false"
        app:longPress="false"
        app:multiSelection="false" />

4. setup CalendarViewManager

val myCalendarViewManager = object : CalendarViewManager {  
    override fun setCalendarViewResourceId(                 
        position: Int,                                      
        date: Date,                                         
        isSelected: Boolean                                 
    ): Int {                                                
        // return item layout files, which you have created 
    }                                                       
                                                            
    override fun bindDataToCalendarView(                    
        holder: SingleRowCalendarAdapter.CalendarViewHolder,
        date: Date,                                         
        position: Int,                                      
        isSelected: Boolean                                 
    ) {                                                     
        // bind data to calendar item views                 
    }                                                       
}  

5. setup CalendarSelectionManager

val mySelectionManager = object : CalendarSelectionManager {             
    override fun canBeItemSelected(position: Int, date: Date): Boolean { 
        // return true if item can be selected                           
    }                                                                    
}

6. setup CalendarChangesObserver

val myCalendarChangesObserver = object : CalendarChangesObserver {                                                            
    override fun whenWeekMonthYearChanged(weekNumber: String,monthNumber: String,monthName: String,year: String,date: Date) { 
        super.whenWeekMonthYearChanged(weekNumber, monthNumber, monthName, year, date)                                        
    }                                                                                                                         
                                                                                                                              
    override fun whenSelectionChanged(isSelected: Boolean, position: Int, date: Date) {                                       
        super.whenSelectionChanged(isSelected, position, date)                                                                
    }                                                                                                                         
                                                                                                                              
    override fun whenCalendarScrolled(dx: Int, dy: Int) {                                                                     
        super.whenCalendarScrolled(dx, dy)                                                                                    
    }                                                                                                                         
                                                                                                                              
    override fun whenSelectionRestored() {                                                                                    
        super.whenSelectionRestored()                                                                                         
    }                                                                                                                         
                                                                                                                              
    override fun whenSelectionRefreshed() {                                                                                   
        super.whenSelectionRefreshed()                                                                                        
    }   

}

7. provide dates and init SingleRowCalendar in your code

You can choose between two ways of doing it. If you want simple provide few past of future days, you should specify these attributes pastDaysCount, futureDaysCount and includeCurrentDate in an XML or directly in code.  If you are not satisfied with the previous solution you can specify your own list of dates using setDates function.  When you provide dates to the calendar you can also set you initial position using this property initialPositionIndex.

val singleRowCalendar = main_single_row_calendar.apply {        
    calendarViewManager = myCalendarViewManager                
    calendarChangesObserver = myCalendarChangesObserver        
    calendarSelectionManager = mySelectionManager              
    futureDaysCount = 30                                       
    includeCurrentDate = true                                  
    init()                                                     
}                                                              

PARAMETERS AND FUNCTIONS

  • pastDaysCount
    • number of days in past displayed in the calendar
  • futureDaysCount
    • number of days in future displayed in the calendar
  • includeCurrentDate
    • include current date in the calendar
  • initialPositionIndex
    • first displayed item in the calendar
  • multiSelection
    • enable or disable multi selection
  • deselection
    • enable or disable deselection
  • longPress
    • first selected item starts with a long press
  • calendarChangesObserver
    • using this callback we can observe for changes in the calendar
  • calendarViewManager
    • this callback is responsible for inflating item views to calendar
  • calendarSelectionManager
    • using this callback we can enable or disable selection for particular items
  • setDates(newDateList: List<Date>)
    • when you don't want to use pastDaysCount and futureDaysCount you can specify your list of dates
  • getDates()
    • returns used dates in the calendar
  • getSelectedIndexes()
    • returns list of selected postions
  • getSelectedDates()
    • returns list of selected dates
  • onSaveInstanceState(state: Bundle)
    • preserves selection
  • onRestoreInstanceState(state: Bundle)
    • restores selection from previously saved state
  • hasSelection()
    • returns true if calednar has any item selected
  • isSelected(position: Int)
    • check if particular item is selected
  • deselect(position: Int)
    • attempts to deselect an item
  • select(position: Int)
    • attempts to select an item
  • setItemsSelected(positionList: List<Int>, selected: Boolean) * you can select or deselect multiple items at once
  • clearSelection()
    • deselect all items in the calendar

DateUtils class

You can use DateUtils class when you want get some values from date.

  • getDayName(date: Date)
    • returns day name, for example Friday, Thursday, Monday, etc...
  • getDay3LettersName(date: Date)
    • returns day abbreviation, for example Fri, Thu, Mon, etc...
  • getDay1LetterName(date: Date)
    • returns day abbreviation, for example F, T, M, S, etc...
  • getMonthNumber(date: Date)
    • returns month number, for example 1, 3, 12, 9, etc...
  • getMonthName(date: Date)
    • returns month name, for example December, September, January, etc...
  • getMonth3LettersName(date: Date)
    • returns month abbreviation, for example Jan, Feb, Dec, etc...
  • getYear(date: Date)
    • returns year, for example 2010, 2019, 2020, 2034...
  • getDayNumber(date: Date)
    • returns number of day in a month, for example 15, 16, 17, etc...
  • getNumberOfWeek(date: Date)
    • returns number of week in a year, for example 1, 5, 22, 50 etc...
  • getFutureDates(count: Int)
    • returns a list of future dates with specified length
  • getPastDates(count: Int)
    • returns a list of past dates with specified length
  • getDates(pastDays: Int, futureDays: Int, includeCurrentDate: Boolean)
    • returns a list of dates with specified parameters

CONTRIBUTE

  • the best way to submit a patch is to send me a pull request
  • to report a specific problem or feature request, open a new issue on Github
  • follow this contribution rules

SEND ME YOUR CREATIONS

  • feel free to contact me and send me your app here
  • potentially your calendar can be here as a presentation of the library

LICENSE 

The library is licensed under Apache License.

singlerowcalendar's People

Contributors

misosvec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

singlerowcalendar's Issues

java.lang.ClassNotFoundException: android.view.shape

android.view.InflateException: Binary XML file line #2 in com.example.horizontalcalendar:drawable/round_rectangle_shape: Binary XML file line #2 in com.example.horizontalcalendar:drawable/round_rectangle_shape: Error inflating class shape
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.horizontalcalendar:drawable/round_rectangle_shape: Error inflating class shape
Caused by: java.lang.ClassNotFoundException: android.view.shape
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at android.view.LayoutInflater.createView(LayoutInflater.java:830)
    at android.view.LayoutInflater.createView(LayoutInflater.java:791)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:969)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:986)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:1006)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1062)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1017)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:674)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:549)
    at com.michalsvec.singlerowcalendar.calendar.SingleRowCalendarAdapter.onCreateViewHolder(SingleRowCalendarAdapter.kt:67)
    at com.michalsvec.singlerowcalendar.calendar.SingleRowCalendarAdapter.onCreateViewHolder(SingleRowCalendarAdapter.kt:16)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
    at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
    at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
    at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
    at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
    at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3540)
    at android.view.View.measure(View.java:24851)
    at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
    at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
    at android.view.View.measure(View.java:24851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6908)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:221)
    at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146)
    at android.view.View.measure(View.java:24851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6908)
    at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:490)
    at android.view.View.measure(View.java:24851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6908)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:221)
    at android.view.View.measure(View.java:24851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6908)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
    at android.view.View.measure(View.java:24851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6908)
    at com.android.internal.policy.DecorView.measureChildWithMargins(DecorView.java:3029)

2020-08-17 15:38:27.480 13881-13881/com.example.horizontalcalendar E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:221)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:863)
at android.view.View.measure(View.java:24851)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3231)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2004)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2296)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1888)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7939)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1105)
at android.view.Choreographer.doCallbacks(Choreographer.java:921)
at android.view.Choreographer.doFrame(Choreographer.java:851)
at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1028)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:230)
at android.app.ActivityThread.main(ActivityThread.java:7806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:508)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.shape" on path: DexPathList[[zip file "/data/app/com.example.horizontalcalendar-T7kuAygDUvOz3oOTmo3Flw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.horizontalcalendar-T7kuAygDUvOz3oOTmo3Flw==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 63 more
2020-08-17 15:38:27.538 13881-13881/com.example.horizontalcalendar I/Process: Sending signal. PID: 13881 SIG: 9

ViewBinding

Since the kotlinx.android.synthetic is deprecated, is it possible to use ViewBinding with this library? And more specifically how to set the item views in the calendar? In my case I have inside the CalendarViewManager initialization:

holder.itemView.tv_date_calendar_item.text = DateUtils.getDayNumber(date)
holder.itemView.tv_day_calendar_item.text = DateUtils.getDay3LettersName(date)

Is it possible to be done with ViewBinding?

Migrating from jcenter()

Hi! when the lib will be migrated from jcenter()?
Thank you very much for respond beforehand!

Usage in Java android Project

This library seems very helpful. Someone could you help me to get equivalent Java code snippets for implementation in a Java android project. Especially for below sections

  1. setup CalendarViewManager
  2. setup CalendarSelectionManager
  3. setup CalendarChangesObserver
  4. Provide dates and init SingleRowCalendar

Thanks in advance.

The selected date wont change color after click button next/previous month

I have an UI Issue here which I don't know how to solve it.

The Calendar will display current selected date correct, the selected date will change it background. But when click the next/previous month and go back to the current month of year and try to select a date, the background wont change it color anymore.

I tested to debug & compare with the sample code from repo and I figured out object CalendarViewManager in my project does not triggered during the date selection after month has been changed. But when I tried the sample code from repo, the CalendarViewManager actually triggered and worked fine.

Does anyone had the same issue just like me?

calling init() several times

it seems that the init() function must be called after setting the data for the selection tracker to work properly.
the problem is that doing so makes the whenSelectionChanged() function to fire several time.
is there a solution for this issue?

thanks

Load dates dynamically

Hello, does anybody have an idea how to load dates dynamically when nearing the end of current set of dates?
Thank you in advance!

Remove previous day from view

It seems that previous day stays in the list unless the user restarts the app. In my use case I don't care about days before the current day. Is there a way for me to discard the previous day?

How to disable previous date and current date is selected by default

Hello sir,

I have to implement your library but I can't find how to disable the previous date and how to by default selected the current date.
And the second thing when we scroll to last then month is not changed automatically how to change the month automatically when scrolling to the last position?

Thank you

CoordinatorLayout does not handle setCalendarViewResourceId correctly.

I started with the sample provided and have since changed my layout from ConstraintLayout to CoordinatorLayout.

The result of this is that it would work fine until I press either "btnRight" or "btnLeft" then the SingleRowCalendar items would stop updating their appearance to "R.layout.selected_calendar_item" on selection; the TextViews "tvDate" and "tvDay" are still updated correctly.

I found that adding singleRowCalendar.init() to the setOnClickListeners for the buttons fixed this issue but there is now a 1-second delay between selection and appearance change.

I believe I have narrowed the issue down to my change of layout type.

JCenter is dead

Request to replace JCenter repository and move it onto a new one because I can't seem to import it
image

Put selected item in center

When by default some date is selected, or when we select certain date, is it possible to put that item in center of row?

Could not find com.michalsvec:single-row-calednar:1.0.0.

I'm using Android Studio Giraffe | 2022.3.1 Patch 3 with

    compileSdk = 34
    minSdk = 30
    targetSdk = 34

wrote this ino build.gradle/kts

dependencies {
...
implementation ("com.michalsvec:single-row-calednar:1.0.0")
...
}

And this error

Execution failed for task ':app:checkDebugAarMetadata'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.michalsvec:single-row-calednar:1.0.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/michalsvec/single-row-calednar/1.0.0/single-row-calednar-1.0.0.pom
- https://repo.maven.apache.org/maven2/com/michalsvec/single-row-calednar/1.0.0/single-row-calednar-1.0.0.pom
Required by:
project :app

Look around and couldn't find a solution.

How can I resolve this issue?

note that I've tested with https://github.com/hdodenhof/CircleImageView library and it installed fine.

show dates weekly

How can i show dates on weekly basis and initially with current week and current date selected ?

Use in JAVA

Is there any way to use this library in the JAVA project or I need to use strictly Koitlin for this?

How to choose the style of the calendar ?

Hi,

I see on the presentation page of this lib that there are several styles of calendar. When I run the app, I get the first style ; how to try another style ?

Thanks.

Crash with recyclerview-selection:1.1.0-rc01

with 'androidx.recyclerview:recyclerview-selection:1.1.0-alpha06' buton next month and prev month work fine.
But with 'androidx.recyclerview:recyclerview-selection:1.1.0-rc01' it crash.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.