Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to skip days? Skip weekend days? #12

Open
defeloper opened this issue Feb 28, 2019 · 3 comments
Open

Is it possible to skip days? Skip weekend days? #12

defeloper opened this issue Feb 28, 2019 · 3 comments

Comments

@defeloper
Copy link

Just as the title says. I want to skip sundays and saturdays. Is this posible?

@reilem
Copy link
Member

reilem commented Mar 14, 2019

Not currently. It might not be a bad idea to add some sort of array that you can choose to contain the days you want to be made visible. I'll consider adding something like that in the future.

@defeloper
Copy link
Author

defeloper commented Mar 15, 2019

Not currently. It might not be a bad idea to add some sort of array that you can choose to contain the days you want to be made visible. I'll consider adding something like that in the future.

Ok. I am using the library in two of my apps. I am working on it for about 5 monts I started implementing skipping days. I also already implemented "page" scrolling - so if the user wants it can scroll through weeks. I think it needs some more cleanup (with your help - so it reaches the standard) but I thing it would improve this library.

Do you want that I make a pull request so you can add this?

EDIT:
Do you have any pointers on how to skip days?

@reilem
Copy link
Member

reilem commented Mar 19, 2019

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    if let dayViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: CellKeys.dayViewCell, for: indexPath) as? DayViewCell {
        dayViewCell.clearValues()
        dayViewCell.delegate = self
        dayViewCells[dayViewCell.id] = dayViewCell
        let dayDateForCell = getDayDate(forIndexPath: indexPath)
        dayViewCell.setDate(as: dayDateForCell)
        if let eventDataForCell = eventsData[dayDateForCell], let eventFramesForCell = eventFrames[dayDateForCell] {
            dayViewCell.setEventsData(eventDataForCell, andFrames: eventFramesForCell)
        }
        return dayViewCell
    }
    return UICollectionViewCell(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
}

This function in DayScrollView will determine the DayDate allocated to a certain DayViewCell. Specifically this line let dayDateForCell = getDayDate(forIndexPath: indexPath). You could thus make changes to this function:

func getDayDate(forIndexPath indexPath: IndexPath) -> DayDate {
    let date = DateSupport.getDate(fromDayOfYear: indexPath.row, forYear: activeYear)
    return DayDate(date: date)
}

And basically use a different algorithm for converting IndexPaths to DayDates. A brute force method would be to check what the week day is of the found DayDate and skip those that are undesired. getDayDate(forIndexPath indexPath: IndexPath) is not used anywhere else so I'm pretty confident there shouldn't be any unwanted side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants