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

decorate() being called late #33

Closed
KPrabs106 opened this issue Apr 28, 2015 · 1 comment
Closed

decorate() being called late #33

KPrabs106 opened this issue Apr 28, 2015 · 1 comment

Comments

@KPrabs106
Copy link

I'm having an issue, I think it may be with my code, but I can't seem to find what's wrong with my code.
So I'm retrieving event dates from my server and storing them in an ArrayList. Then I highlight those dates.

Here's my HighlightDecorator.java class:

public class HighlightDecorator implements DayViewDecorator {

    List<CalendarDay> dates;

    public HighlightDecorator(List<CalendarDay> dates){
        this.dates = dates;
    }

    @Override
    public boolean shouldDecorate(CalendarDay calendarDay) {
        return dates.contains(calendarDay);
    }

    @Override
    public void decorate(DayViewFacade dayViewFacade) {
        Log.e("day view", dayViewFacade.getDate().toString());
        dayViewFacade.setBackgroundUnselected(generateBackgroundDrawable());
    }

    private static Drawable generateBackgroundDrawable() {
        final int r = 0;
        final float[] outerR = new float[] {r, r, r, r, r, r, r, r};
        final int color = Color.parseColor("#660033");

        RoundRectShape rr = new RoundRectShape(outerR, null, null);

        ShapeDrawable drawable = new ShapeDrawable(rr);
        drawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
            @Override
            public Shader resize(int width, int height) {
                return new LinearGradient(0, 0, 0, 0, color, color, Shader.TileMode.REPEAT);
            }
        });
        return drawable;
    }
}

And here is a short excerpt from my fragment, which contains the MaterialCalendarView:
CalendarTab.java

MaterialCalendarView calendarView = (MaterialCalendarView) v.findViewById(R.id.calendarView);
        calendarView.setOnDateChangedListener(this);
        calendarView.setSelectedDate(Calendar.getInstance().getTime());

        JSONObject jsonObject;
        String date;
        String[] dateComponents;
        CalendarDay eventDay;
        events = new ArrayList<CalendarDay>();
        for(int i = 0; i < jsonArray.length(); i++){
            try {
                jsonObject = jsonArray.getJSONObject(i);
                date = jsonObject.getString("startDate").split(" ")[0];
                dateComponents = date.split("-");
                eventDay = new CalendarDay(Integer.parseInt(dateComponents[0]), Integer.parseInt(dateComponents[1])-1, Integer.parseInt(dateComponents[2]));
                events.add(eventDay);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        Log.e("events", events.toString());

        calendarView.addDecorator(new HighlightDecorator(events));
}

So from the log, I see that the ArrayList correctly has all the dates. Now, when I first open the app, the calendar is completely undecorated. When I move to May, I can see from the log that it is decorating the June dates. When I move to June, it is not decorating anything. When I move back to May, it is decorating April and May, but decorations for May are not shown. Then moving back to April, it decorates March.

What's going on?? This isn't happening in the sample that I downloaded, and my code is almost the same as that.

@dandc87
Copy link
Contributor

dandc87 commented May 19, 2015

Hi @KPrabs106, I just released version 0.4.0, which has a lot of fixes to decorators. The README has a section on how to migrate, and the decorator sample has also been updated to include a mock API call. Can you update to 0.4.0 and see if this helps?

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