Open abuicke opened 7 years ago
refreshView()
also doesn't seem to work. I'm not sue if this is related.
I eventually got it working by using nested Fargments instead of extending CaldroidFragment and by using Dates instead of DateTimes. I have seen another issue where someone reported setBackgroundDrawableForDateTime
not working. This is a fairly significant issue. I will investigate this problem and hopefully be able to create a pull request when I have time. However, given your lack of responsiveness to my issue is there any point? Will you accept a fix if I provide one?
Here is the code I used to get it working:
public class CalendarFragment extends Fragment {
private CaldroidFragment mCaldroidFragment;
public static CalendarFragment newInstance() {
return new CalendarFragment();
}
@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, final Bundle savedInstanceState) {
final View layout = inflater.inflate(R.layout.calendar_fragment_layout, container, false);
mCaldroidFragment = new CaldroidFragment();
final Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
args.putBoolean(CaldroidFragment.ENABLE_SWIPE, true);
args.putBoolean(CaldroidFragment.SIX_WEEKS_IN_CALENDAR, true);
mCaldroidFragment.setArguments(args);
final CaldroidListener listener = new DateListener();
mCaldroidFragment.setCaldroidListener(listener);
final FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
t.replace(R.id.caldroid_layout, mCaldroidFragment);
t.commit();
return layout;
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/caldroid_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Here is code related to the Date/DateTime background drawable issue. If it's not clear enough for anyone please let me know and I can explain more. The main thing I did was create a helper method in a util class called toJavaDate
which you can see below:
private void loadTasksIntoView(@NonNull final Task[] tasks) {
assertNotNull(tasks);
if (tasks.length == 0) {
Log.w(TAG, "tasks are empty");
if (TaskManagerApplication.ASSERTIONS_ON) throw new AssertionError("tasks are empty");
}
final Resources resources = getResources();
// noinspection deprecation
final int colorAccent = resources.getColor(R.color.colorAccent);
final Drawable startDateBgDrawable = new ColorDrawable(colorAccent);
final Drawable endDateBgDrawable = new ColorDrawable(Color.RED);
for (final Task task: tasks) {
final DateTime startDateTime = task.getStartDate();
final DateTime endDateTime = task.getEndDate();
final Date startDate = toJavaDate(startDateTime);
final Date endDate = toJavaDate(endDateTime);
mCaldroidFragment.setTextColorForDate(R.color.caldroid_white, startDate);
mCaldroidFragment.setTextColorForDate(R.color.caldroid_white, endDate);
mCaldroidFragment.setBackgroundDrawableForDate(startDateBgDrawable, startDate);
Log.v(TAG, "added start date " + startDate + " to calendar fragment");
mCaldroidFragment.setBackgroundDrawableForDate(endDateBgDrawable, endDate);
Log.v(TAG, "added end date " + endDate + " to calendar fragment");
}
mCaldroidFragment.refreshView();
}
public final class DateTimeUtils {
public static Date toJavaDate(final DateTime jodaDateTime) {
final TimeZone timeZone = TimeZone.getDefault();
return toJavaDate(jodaDateTime, timeZone);
}
public static Date toJavaDate(final DateTime jodaDateTime, final TimeZone timeZone) {
final long jodaMillis = jodaDateTime.getMilliseconds(timeZone);
return new Date(jodaMillis);
}
}
I don't think this issue is a duplicate of #185 unless I'm missing something, because the same issue occurs on my phone as well as my tablet. I'm using the CaldroidFragment with a TabLayout like this:
Here is the layout XML for my main activity
Here is my MainActivity which sets up the CaldroidFragment with the tabs
Here is my custom FragmentPagerAdapter
And this is a subclass of the CaldroidFragment I'm using (some methods removed for simplicity), although the problem occurs even with the normal CaldroidFragement.