Giter Site home page Giter Site logo

Comments (31)

entropitor avatar entropitor commented on May 8, 2024 1

onMonthChange is called three times (when you don't scroll)
This is in the README!

Please remember that the calendar pre-loads events of three consecutive months to enable lag-free scrolling.

That's why it's being shown multiple times.

(You have to take in account the newMonth and newYear variables. They are there for a reason)

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

Because that WeekViewEvent constructor uses a more logical month index: januari = 1.

But you can construct it using
new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime)

@alamkanak this issue can be closed.

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

It's ok?
WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime.get(Calendar.YEAR) , startTime.get(Calendar.MONTH) + 1, startTime.get(Calendar.DAY_OF_MONTH), startTime.get(Calendar.HOUR_OF_DAY), startTime.get(Calendar.MINUTE), endTime.get(Calendar.YEAR) , endTime.get(Calendar.MONTH) +1, endTime.get(Calendar.DAY_OF_MONTH), endTime.get(Calendar.HOUR_OF_DAY), endTime.get(Calendar.MINUTE));

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

yes, but I don't see why you don't just pass in the calendar objects. Now the calendar objects are "destructed" by you to be constructed again in the library...

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime)
that don't work, event don't show, as it should be properly?

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

Have you taken a look at the sample app? https://github.com/alamkanak/Android-Week-View/blob/master/sample/src/main/java/com/alamkanak/weekview/sample/MainActivity.java#L107

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

Yes it works, but i have timestamp and I don't know how use timestamp.

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

Calender start = Calender.getInstance();
start.setTimeInMillis(1421330400000)
Calender end = Calender.getInstance();
end.setTimeInMillis(1421330400000)

events.add(new WeekViewEvent(1, getEventTitle(start), startTime, endTime))

PS remember that the newMonth from the onMonthChangeListener is also 1-based instead of 0-based.

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

Still don't work:
Calendar start = Calendar.getInstance();
start.setTimeInMillis(1421330400000L);
Calendar end = Calendar.getInstance();
end.setTimeInMillis(1421330400000L);

    events.add(new WeekViewEvent(1, getEventTitle(start), start, end));

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

end.setTimeInMillis(1421334000L);

You were passing in an event that last for 0 milliseconds.

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

14213304000 = Tue, 26 May 2420 20:00:00 GMT

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

I meant end.setTimeInMillis(1421334000000L);

=>
start.setTimeInMillis(1421330400000L);
end.setTimeInMillis(1421334000000L);

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

When i set like this:
start.setTimeInMillis(1421330400000L);
end.setTimeInMillis(1421334000000L);
my calendar view it's like this:
http://oi59.tinypic.com/4ine5c.jpg

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

Why when I set event like this:
@OverRide
public List onMonthChange(int newYear, int newMonth) {

    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();

    Calendar  start = Calendar.getInstance();
    start.set(Calendar.HOUR_OF_DAY, 16);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.DAY_OF_MONTH, 15);
    start.set(Calendar.MONTH, 2);
    start.set(Calendar.YEAR, 2015);
    Calendar end = (Calendar) start.clone();
    end.set(Calendar.HOUR_OF_DAY, 17);


    WeekViewEvent event = new WeekViewEvent(10, getEventTitle(start), start, end);
    event.setColor(getResources().getColor(R.color.event_color_03));
    events.add(event);

    return events;
}

calendar views like this:
http://oi59.tinypic.com/10saihc.jpg

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

so I do not think it should be?

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

I really do not know how I set the event for example 15-01-2015. So that two months after scrolling forward and return to the event, was displayed only once?

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

just only add it if newMonth==1 and newYear==2015

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

This is a bad idea, because I have list with dates, ie: 15-01-2015, 23-03-2015, 07-06-2015...and I have set all dates.

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

This seriously doesn't belong in an issue for this library.

Just only add the events which have a matching month and year (matching = event falls in the month that is requested by newMonth and newYear: event.getMonth() == newMonth && event.getYear() == newYear). That's what I am saying.
When you scroll, eventually the right month will be requested and the event will be loaded.

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

Please show me example.

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

Remember this is pseudo-code, not real java code

weekviewEvents = new ArrayList()
for(Event event : allEvents){
    if(event.getMonth() == newMonth && event.getYear() == newYear){
         weekviewEvents.add(event)
    }
}
return weekviewEvents

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

This is my code, event don't show:
List events = new ArrayList();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Get a reference for the week view in the layout.
    mWeekView = (WeekView) findViewById(R.id.weekView);

    DateTimeInterpreter dateTimeInterpreter = new DateTimeInterpreter() {
        @Override
        public String interpretDate(Calendar calendar) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
            return simpleDateFormat.format(calendar.getTime());
        }

        @Override
        public String interpretTime(int i) {
            return String.valueOf(i + ":00");
        }
    };
    mWeekView.setDateTimeInterpreter(dateTimeInterpreter);
    mWeekView.setOnEventClickListener(this);
    mWeekView.setMonthChangeListener(this);
    mWeekView.setNumberOfVisibleDays(1);

    // Lets change some dimensions to best fit the view.
    mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
    mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
    mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));


    Calendar startTime = Calendar.getInstance();
    Calendar endTime = Calendar.getInstance();

    startTime.setTimeInMillis(1421506800 * 1000L);
    endTime.setTimeInMillis(1421510400 * 1000L);
    WeekViewEvent event = new WeekViewEvent(1, "fddsdsdsd", startTime, endTime);
    event.setColor(getResources().getColor(R.color.event_color_01));
    events.add(event);
}

@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    List<WeekViewEvent> weekviewEvents = new ArrayList<WeekViewEvent>();
    for (WeekViewEvent event : events) {
        if(event.getStartTime().get(Calendar.MONTH) == newMonth && event.getStartTime().get(Calendar.YEAR) == newYear){
            weekviewEvents.add(event);
        }
    }

    return weekviewEvents;
}

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

How many times do I need to say that newMonth is 1-based and Calendar is 0-based?

=> event.getStartTime().get(Calendar.MONTH)+1 == newMonth

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

Sorry my fault, now i have that code:
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();

    startTime.setTimeInMillis(1421506800 * 1000L);
    endTime.setTimeInMillis(1421510400 * 1000L);
    WeekViewEvent event = new WeekViewEvent(1, "first event", startTime, endTime);
    event.setColor(getResources().getColor(R.color.event_color_01));
    events.add(event);

    startTime.setTimeInMillis(1421596800 * 1000L);
    endTime.setTimeInMillis(1421600400 * 1000L);
    event = new WeekViewEvent(1, "second event", startTime, endTime);
    event.setColor(getResources().getColor(R.color.event_color_01));
    events.add(event);
}

@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    List<WeekViewEvent> weekviewEvents = new ArrayList<WeekViewEvent>();
    for (WeekViewEvent event : events) {
        if(event.getStartTime().get(Calendar.MONTH)+1 == newMonth && event.getStartTime().get(Calendar.YEAR) == newYear){
            weekviewEvents.add(event);
        }
    }

    return weekviewEvents;
}

and my calendar look like this
http://oi57.tinypic.com/14xz790.jpg

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

I'm guessing you should pass in a different id for the second event...

from android-week-view.

wojtkuju avatar wojtkuju commented on May 8, 2024

I change id and doesn't work.

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

you have to create new instances of the Calendar object (startTime, endTime) for your second event, otherwise you change the time of the first event too.

from android-week-view.

KimPark89 avatar KimPark89 commented on May 8, 2024

Yes, caske33's answer is right. I had a similar problem and I lost about half day of work to resolve it.

Btw i don't understand why this API preloads 3 months events.
You must add your events by matching your actual month and year with nextMonth and nextYear variables of onMonthChange for avoiding the creations of duplicate events, but in this way you lose the benefit of the 3 months preload.
So probably it's better adding the matching also for your previous and following month events, but in this case you have again the "duplicate events problem".

from android-week-view.

entropitor avatar entropitor commented on May 8, 2024

The reason why there's a 3 month preload is to smooth the swiping. This way the library won't have to wait for you to provide the events when the user scrolls to the next month, they will already be loaded.

And most people don't match all their events with the nextMonth and nextYear variables but they load their events based on those variables (e.g. they look in the database for the events that fall within the month requested)

from android-week-view.

KimPark89 avatar KimPark89 commented on May 8, 2024

Thank you, i undestand.

from android-week-view.

alamkanak avatar alamkanak commented on May 8, 2024

Answer from @caske33 is correct

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.