Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 69d47da2 authored by Marten Gajda's avatar Marten Gajda Committed by GitHub
Browse files

Add RowData to create recurring tasks. Implements #460 (#604)

This certainly needs to be revisited, but it should be ok for now when it's mostly required to write unit tests.
parent ed50e422
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ dependencies {
        exclude module: 'jems'
    }
    implementation 'org.dmfs:rfc5545-datetime:' + RFC5545_DATETIME_VERSION
    implementation 'org.dmfs:lib-recur:' + LIB_RECUR_VERSION
    implementation 'org.dmfs:jems:' + JEMS_VERSION
    implementation 'com.github.dmfs.bolts:color-bolts:' + BOLTS_VERSION

+58 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.opentaskspal.rowdata;

import android.content.ContentProviderOperation;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import org.dmfs.android.contentpal.RowData;
import org.dmfs.android.contentpal.TransactionContext;
import org.dmfs.jems.iterable.decorators.Mapped;
import org.dmfs.rfc5545.DateTime;


/**
 * {@link RowData} for a field of {@link DateTime}s.
 *
 * @param <Contract>
 *         The contract of the table this row data goes to.
 *
 * @author Marten Gajda
 */
public final class DateTimeListData<Contract> implements RowData<Contract>
{
    private final String mField;
    private final Iterable<DateTime> mDateTimes;


    public DateTimeListData(String field, @NonNull Iterable<DateTime> dateTimes)
    {
        mField = field;
        mDateTimes = dateTimes;
    }


    @NonNull
    @Override
    public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder)
    {
        String value = TextUtils.join(",",
                new Mapped<>(DateTime::toString, new Mapped<>(dt -> dt.isFloating() ? dt : dt.shiftTimeZone(DateTime.UTC), mDateTimes)));
        return builder.withValue(mField, value.isEmpty() ? null : value);
    }
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.opentaskspal.tasks;

import android.support.annotation.NonNull;

import org.dmfs.android.contentpal.RowData;
import org.dmfs.android.contentpal.rowdata.DelegatingRowData;
import org.dmfs.opentaskspal.rowdata.DateTimeListData;
import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.contract.TaskContract;


/**
 * {@link RowData} for tasks with EXDATEs
 * <p>
 * TODO: how to make sure this is only ever used with tasks having a start and/or due date?
 *
 * @author Marten Gajda
 */
public final class ExDatesTaskData extends DelegatingRowData<TaskContract.Tasks>
{
    public ExDatesTaskData(@NonNull Iterable<DateTime> exdates)
    {
        super(new DateTimeListData<>(TaskContract.Tasks.EXDATE, exdates));
    }
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.opentaskspal.tasks;

import android.support.annotation.NonNull;

import org.dmfs.android.contentpal.RowData;
import org.dmfs.android.contentpal.rowdata.DelegatingRowData;
import org.dmfs.opentaskspal.rowdata.DateTimeListData;
import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.contract.TaskContract;


/**
 * {@link RowData} for tasks with RDATEs.
 * <p>
 * TODO: how to make sure this is only ever used with tasks having a start and/or due date?
 *
 * @author Marten Gajda
 */
public final class RDatesTaskData extends DelegatingRowData<TaskContract.Tasks>
{
    public RDatesTaskData(@NonNull Iterable<DateTime> rdates)
    {
        super(new DateTimeListData<>(TaskContract.Tasks.RDATE, rdates));
    }
}
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.opentaskspal.tasks;

import android.content.ContentProviderOperation;
import android.support.annotation.NonNull;

import org.dmfs.android.contentpal.RowData;
import org.dmfs.android.contentpal.TransactionContext;
import org.dmfs.rfc5545.recur.RecurrenceRule;
import org.dmfs.tasks.contract.TaskContract;


/**
 * {@link RowData} for tasks with a recurrence rule.
 * <p>
 * TODO: how to make sure this is only ever used with tasks having a start and/or due date?
 *
 * @author Marten Gajda
 */
public final class RRuleTaskData implements RowData<TaskContract.Tasks>
{
    private final RecurrenceRule mRule;


    public RRuleTaskData(@NonNull RecurrenceRule rule)
    {
        mRule = rule;
    }


    @NonNull
    @Override
    public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder)
    {
        return builder.withValue(TaskContract.Tasks.RRULE, mRule.toString());
    }
}
Loading