CompactCalendarView icon indicating copy to clipboard operation
CompactCalendarView copied to clipboard

Problem to select day after current day

Open filipiandrader opened this issue 8 years ago • 30 comments

I'm having trouble selecting day after the current day. For example: 04/26/2017, I can select, but the next day, 04/27/2017, I can not. I'll only be able to select 3 or 4 days after the current one.

filipiandrader avatar Apr 26 '17 15:04 filipiandrader

What version are you using? What phone are you debugging with? Can I also see your xml layout file?

SundeepK avatar Apr 26 '17 15:04 SundeepK

Version: lastest (2.0.1) Phone: Moto G3 XML: I just using the calendar: <com.github.sundeepk.compactcalendarview.CompactCalendarView android:id="@+id/cvMonth" android:layout_width="match_parent" android:layout_height="250dp" android:layout_marginTop="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" app:compactCalendarBackgroundColor="@android:color/transparent" app:compactCalendarCurrentDayBackgroundColor="@android:color/transparent" app:compactCalendarCurrentSelectedDayBackgroundColor="@color/colorAccent" app:compactCalendarMultiEventIndicatorColor="#fff" app:compactCalendarTargetHeight="250dp" app:compactCalendarTextColor="@color/colorPrimaryText" app:compactCalendarShouldSelectFirstDayOfMonthOnScroll="true" app:compactCalendarTextSize="12sp" />

filipiandrader avatar Apr 26 '17 15:04 filipiandrader

Can I suggest you download the project. I has a sample app. If you can debug that app, can you replicate the same problem?

SundeepK avatar Apr 26 '17 15:04 SundeepK

I'll try with the sample app.

filipiandrader avatar Apr 26 '17 17:04 filipiandrader

With the sample, I dont have this problem. I'll compare my code with your code and try again. Thanks!

filipiandrader avatar Apr 26 '17 17:04 filipiandrader

To click on the day, I have to use this method, right?

compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
            @Override
            public void onDayClick(Date dateClicked) {               
            }
});

filipiandrader avatar Apr 26 '17 17:04 filipiandrader

To click on the day, you just need to tap on it and then to receive a callback as to what day was click you use the CompactCalendarViewListener as you have already done so. Should be simple as that.

SundeepK avatar Apr 27 '17 09:04 SundeepK

I already did that, but doesn't work properly. On your sample app works, but on my app doesn't.

filipiandrader avatar Apr 27 '17 13:04 filipiandrader

Is it possible to show me some code on how you are using the library?

SundeepK avatar Apr 28 '17 09:04 SundeepK

Call<ArrayList<ObjectivesReturn>> call = mApiInterface.getApplicationsYearMonth(user_id, classroom_id, year, month_number);
call.enqueue(new Callback<ArrayList<ObjectivesReturn>>() {
    @Override
    public void onResponse(Call<ArrayList<ObjectivesReturn>> call, Response<ArrayList<ObjectivesReturn>> response) {
        if (response.body().get(0).isValid()) {
            try {
                ArrayList<ObjApplications> objApplications = response.body().get(0).getObjectives();
                ArrayList<Applications> applications = new ArrayList<>();
                ArrayList<Applications> list;
                for (int i = 0; i < objApplications.size(); i++) {
                    list = response.body().get(0).getObjectives().get(i).getApplications();
                    for (int j = 0; j < list.size(); j++) {
                        applications.add(list.get(j));
                    }
                }

                List<Event> eventList = new ArrayList<>();
                for (int i = 0; i < applications.size(); i++) {
                    Date date = mSimpleDateFormat.parse(applications.get(i).getDate());
                    long timeInMillis = date.getTime();
                    Event event = new Event(Color.DKGRAY, timeInMillis, applications.get(i));
                    eventList.add(event);
                }

                mCalendarView.addEvents(eventList);
                mCalendarView.shouldDrawIndicatorsBelowSelectedDays(true);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onFailure(Call<ArrayList<ObjectivesReturn>> call, Throwable t) {
        t.printStackTrace();
    }
});

mCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
    @Override
    public void onDayClick(Date dateClicked) {
        String dateString = mSimpleDateFormat.format(dateClicked);
        List<Event> eventList = mCalendarView.getEvents(dateClicked);
        Log.i(TAG, "onDayClick: " + dateString + " with events: " + eventList);

        /*if (mCalendarView.getEvents(dateClicked).isEmpty()) {
            Toast.makeText(getActivity(), "Esse dia não possue atividade cadastrada!", Toast.LENGTH_SHORT).show();
        } else {
            startActivity(new Intent(getActivity(), PlanningMonthlyActivity.class)
                    .putExtra("date", dateString));
        }*/
    }

    @Override
    public void onMonthScroll(Date firstDayOfNewMonth) {
        tvMonth.setText(mSimpleYearFormat.format(mCalendarView.getFirstDayOfCurrentMonth());
    }
});

First of all, I get the events with Retrofit (I using an API) and after I get the events when I click on the day what I want

filipiandrader avatar Apr 28 '17 12:04 filipiandrader

Hi did you manage to find the problem. I had a look through the code above and I could not see anything that would cause a problem. The only other thing I can say is that if you can upload an example project to github then I can clone the project and have a further look.

SundeepK avatar May 08 '17 12:05 SundeepK

I will make a sample app and create a repo on my github.

filipiandrader avatar May 08 '17 13:05 filipiandrader

Thank you, I should have suggested this from the start!

SundeepK avatar May 08 '17 13:05 SundeepK

Its true. I'll start doing it now, I'll send you the link

filipiandrader avatar May 08 '17 13:05 filipiandrader

I've copied the same code that I use in my application to demo app, and it works. I don't understand this! After that I tested it on my app and it didn't work. I don't know why it's like this.

filipiandrader avatar May 08 '17 19:05 filipiandrader

Interesting. I would suggest start stripping bits of code and testing it to see what might be causing the problem. Maybe there's something in the layout causing some problem?

SundeepK avatar May 09 '17 09:05 SundeepK

I'll change layout and try agian.

filipiandrader avatar May 09 '17 12:05 filipiandrader

I created an activity and tested it and it worked. I created a fragment and tested it, it works until a certain date and then it doesn't click any more. I'm using the same code in both.

filipiandrader avatar May 09 '17 13:05 filipiandrader

If you have a working sample that I can have a look at, that would be perfect then. It should work as expected in a fragment since thats what the sample app it self also uses.

SundeepK avatar May 09 '17 13:05 SundeepK

I'll end the sample app to send you

filipiandrader avatar May 09 '17 13:05 filipiandrader

Thanks for your help, if you upload to github I can check the project out.

SundeepK avatar May 09 '17 13:05 SundeepK

You're welcome! I'll upload on my github.

filipiandrader avatar May 09 '17 13:05 filipiandrader

Project: https://github.com/filipiandrader/demo-compact-calendar-view Works on activity and fragment, but in my real app doesn't work on fragment.

filipiandrader avatar May 09 '17 13:05 filipiandrader

Nothing to solve my problem?

filipiandrader avatar May 17 '17 13:05 filipiandrader

I did try the sample application but I couldn't reproduce any problems yet. Is there any specific steps that you followed to get the problem?

SundeepK avatar May 17 '17 14:05 SundeepK

To get this problem, first I use Retrofit to get events to populate in CalendarView, I have problem after that, and I cant select some days.

filipiandrader avatar May 17 '17 14:05 filipiandrader

But, I use your code in other activity and still get this problem.

filipiandrader avatar May 17 '17 14:05 filipiandrader

So I have spent some more time debugging the demo app you uploaded and I'm still unable to replicate the problem. I tried with some emulators also.

Steps I followed: -Launch the demo app -Try selecting some day -Scroll some months both in future and past -Select more days

I was checking to see if some days are not selecting but I didn't see any problems. Can I suggest a few more things?

Have you tried with any other device/emulator? Does this problem happen without retrofit? Are you sure there are no errors happening when you call your api with retro fit? I see you are calling e.printStackTrace(); to print errors but I usually use the android Log class to log errors and messages.

I would suggest when you get a response from retro fit, add some dummy events without using the response from your api(comment your code out) and simply add something simple like so

Event ev1 = new Event(Color.GREEN, 1433701251000L, "Some extra data that I want to store.");
mCalendarView.addEvent(ev1);

Do you still get a problem?

One other thing you can try is fork the code and import the library into your project. Put the app in debug mode. Run your application and set a debug point in the onResponse method and step through. Without access to a project where I can reproduce the problem, it will be difficult for me to debug the problem otherwise.

SundeepK avatar May 17 '17 22:05 SundeepK

I'll test again without Retrofit.

filipiandrader avatar May 18 '17 12:05 filipiandrader

Hey and hows it going thanks so much for the awesome library but am stuck with an issue am using version 3.0.0 and when I click on a day on the Calendar the Callback for onDayClick is not being called, what could be the issue ??

KingsleyUsoroeno avatar Oct 29 '20 10:10 KingsleyUsoroeno