Giter Site home page Giter Site logo

Comments (15)

emanueleDiVizio avatar emanueleDiVizio commented on May 7, 2024 1

I was facing the same problem and this code solves it.

@Override
    public List<WeekViewEvent> onMonthChange(final int i, final int i2) {
        List<WeekViewEvent> newEvents= new ArrayList<WeekViewEvent>();
        List<WeekViewEvent> events = Manager.events;
        for (WeekViewEvent event : events) {
            Calendar dateTime = event .getStartTime();
            Calendar dateEndTime = event .getEndTime();
            Calendar monCal = getFirstDay(i2 - 1, i, dateTime.get(Calendar.DAY_OF_WEEK));
            int hday = dateTime.get(Calendar.HOUR_OF_DAY);
            int mday = dateTime.get(Calendar.MINUTE);
            int ehday = dateEndTime.get(Calendar.HOUR_OF_DAY);
            int emday = dateEndTime.get(Calendar.MINUTE);
            for (int k = monCal.get(Calendar.DAY_OF_MONTH); k <= monCal.getActualMaximum(Calendar.DAY_OF_MONTH); k += 7) {
                Calendar startTime = Calendar.getInstance();
                startTime.set(Calendar.MONTH, i2 - 1);
                startTime.set(Calendar.DAY_OF_MONTH, k);
                startTime.set(Calendar.YEAR, i);
                startTime.set(Calendar.HOUR_OF_DAY, hday);
                startTime.set(Calendar.MINUTE, mday);
                startTime.set(Calendar.SECOND, 0);
                startTime.set(Calendar.MILLISECOND, 0);

                Calendar endTime = (Calendar) startTime.clone();
                endTime.set(Calendar.HOUR_OF_DAY, ehday);
                endTime.set(Calendar.MINUTE, emday - 1);
                endTime.set(Calendar.MONTH, i2 - 1);
                endTime.set(Calendar.SECOND, 59);
                endTime.set(Calendar.MILLISECOND, 999);


                WeekViewEvent newEvent = new WeekViewEvent(1, event .getName(), startTime, endTime);
                newEvent.setColor(event .getColor());
                newEvents.add(newEvent);
            }
        }

        return newEvents;
    }

from android-week-view.

entropitor avatar entropitor commented on May 7, 2024

Currently not. But isn't this easy to implement in your data provider? (for example using the excellent joda time library: http://www.joda.org/joda-time/). That library allows to add one day, one week, ... to a date.

from android-week-view.

Shajeel-Afzal avatar Shajeel-Afzal commented on May 7, 2024

@caske33 thanks for your reply, yes i think the workaround will be to get the date(s) of the visible day, 3 days, or week and query the data provider with those dates.

from android-week-view.

entropitor avatar entropitor commented on May 7, 2024

You can already do this in your onMonthChangeListener(int newYear, int newMonth):

public List<WeekViewEvent> onMonthChangeListener(int newYear, int newMonth){
    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
    event = getFirstOccuenceInRange(newYear, newMonth);
    while(event.isInRange(newYear, newMonth)){
        events.add(event);
        event = event.nextOccurence();
    }
    return events;
}

from android-week-view.

loopiezlol avatar loopiezlol commented on May 7, 2024

Can somebody help me modify the onMonthChange as to repeat each event every 7 between two dates ( ex 15 September and 22 May) or as long as the calendar permits?

tried to follow your approach @hellchoseme, yet can't find getFirstDay method

from android-week-view.

entropitor avatar entropitor commented on May 7, 2024

The getfirstday is a method you have to write that returns the first event of the series that falls in the certain month.

A way you can implent that method is by getting the first day over all, convert it to milliseconds (a). Get the first day of the month that is requested in milliseconds (b), and convert 7 days to milliseconds (c).
Then you know that a+c*k are all events that are part of the series of events. (with k an integer). And you know that a+c*k>b => k = Math.ceil((b-a)/c). From that, you can calculate the first event (in milliseconds) as a+c*Math.ceil((b-a)/c)

I hope that is clear enough for you. Otherwise, just ask for more help ;)

from android-week-view.

loopiezlol avatar loopiezlol commented on May 7, 2024

@caske33 or @caske33 can one of you post the method here? I'm having little trouble implementing it

particularly, caske33 what do you mean by first day overall? ( a)

from android-week-view.

loopiezlol avatar loopiezlol commented on May 7, 2024

managed to achieve repeated events rudimentaly

 @Override
    public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
        List<WeekViewEvent> weekViewEvents = new ArrayList<WeekViewEvent>();
        List <WeekViewEvent> repeatevents = new ArrayList<>();


        for(WeekViewEvent event : events){

            int startHour = event.getStartTime().get(Calendar.HOUR_OF_DAY);
            int dayOfWeek = event.getStartTime().get(Calendar.DAY_OF_WEEK);
            int endHour = event.getEndTime().get(Calendar.HOUR_OF_DAY);
            String eventName = event.getName();

            for (int i = -1000; i <= 1000; i = i + 7) {
                Calendar startTime = Calendar.getInstance();
                startTime.set(Calendar.HOUR_OF_DAY, startHour);
                startTime.set(Calendar.MINUTE, 0);
                startTime.set(Calendar.DAY_OF_WEEK, dayOfWeek);
                startTime.add(Calendar.DATE, i);
                startTime.add(Calendar.SECOND,1);
                Calendar endTime = (Calendar) startTime.clone();
                endTime.set(Calendar.HOUR_OF_DAY, endHour);
                endTime.add(Calendar.MINUTE, -2);
                WeekViewEvent event1 = new WeekViewEvent(id++, eventName, startTime, endTime);

                event1.setColor(event.getColor());
                repeatevents.add(event1);
            }
        }

        for (WeekViewEvent event : repeatevents) {
            if (event.getStartTime().get(Calendar.MONTH)== newMonth && event.getStartTime().get(Calendar.YEAR) == newYear) {
                weekViewEvents.add(event);
            }
        }

        return weekViewEvents;


    }

Here is the code. Although, I'm looking forward to seeing yours implementation guys.

from android-week-view.

entropitor avatar entropitor commented on May 7, 2024

first day overall = the very first day the event took place.
I don't really have repeting events, so I don't have any code. But maybe @EmanueleHB can help you?

from android-week-view.

emanueleDiVizio avatar emanueleDiVizio commented on May 7, 2024

Here's my getFirstDay() method, I'm really sorry I forgot to post it:

public static Calendar getFirstDay(int i2, int i, int weekday) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.MONTH, i2);
        c.set(Calendar.YEAR, i);
        c.set(Calendar.DAY_OF_MONTH, 1);
        int day = c.get(Calendar.DAY_OF_WEEK);
        while (day != weekday) {
            c.add(Calendar.DAY_OF_MONTH, 1);
            day = c.get(Calendar.DAY_OF_WEEK);
        }
        return c;
    }

from android-week-view.

Shajeel-Afzal avatar Shajeel-Afzal commented on May 7, 2024

@EmanueleHB it works like a charm, but i see that events are also being added for the previous months too, how to modify your code so that event is show repeatedly from the event date and future, not past. I hope that you got my point.

from android-week-view.

Shajeel-Afzal avatar Shajeel-Afzal commented on May 7, 2024

@EmanueleHB i achieved what i was looking for, now next task on which i am working is to show events that "Never, Every Day, Every Week, Every Month," and "Every Year" repeating.

from android-week-view.

hova4 avatar hova4 commented on May 7, 2024

please help me to solve this problem !
i need to show an event every Monday, but i can't do this,,,
@EmanueleHB what is Manager in you code ?

from android-week-view.

hova4 avatar hova4 commented on May 7, 2024

@caske33 i recieve your mail, but i can't solve the problem, if you have a lil bit of time please help me

from android-week-view.

furqankhwaja avatar furqankhwaja commented on May 7, 2024

In this line of code : List< WeekViewEvent > events = Manager.events;
What is Manager?
Please help... @EmanueleHB @caske33

from android-week-view.

Related Issues (20)

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.