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

Unverified Commit 18fd012c authored by Michael W's avatar Michael W Committed by Michael Bestas
Browse files

Contacts: Device Contacts: Allow adding dates

* Currently, one can't add dates like birthdays to local contacts
* Copy the code from GoogleAccountType and add it to the constructor
-> We can now successfully save dates like birthdays and anniversaries
-> Disclaimer: Date is NOT synced with any calendars!

Change-Id: I9856c5ec20b6776572b3408afdc39724945e07a9
parent 89b8fdf1
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -15,14 +15,32 @@
 */
package com.android.contacts.model.account;

import android.content.ContentValues;
import android.content.Context;
import android.provider.ContactsContract.CommonDataKinds.Event;

import com.android.contacts.R;
import com.android.contacts.model.dataitem.DataKind;
import com.android.contacts.util.CommonDateUtils;
import com.android.contactsbind.FeedbackHelper;

import com.google.common.collect.Lists;

public class DeviceLocalAccountType extends FallbackAccountType {

    private static final String TAG = "DeviceLocalAccountType";

    private final boolean mGroupsEditable;

    public DeviceLocalAccountType(Context context, boolean groupsEditable) {
        super(context);

        try {
            addDataKindEvent(context);
        } catch (DefinitionException e) {
            FeedbackHelper.sendFeedback(context, TAG, "Failed to build fallback account type", e);
        }

        mGroupsEditable = groupsEditable;
    }

@@ -43,4 +61,29 @@ public class DeviceLocalAccountType extends FallbackAccountType {
                new AccountDisplayInfo(account, getDisplayLabel(context), getDisplayLabel(context),
                        getDisplayIcon(context), true), this);
    }

    private DataKind addDataKindEvent(Context context) throws DefinitionException {
        DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE,
                    R.string.eventLabelsGroup, Weight.EVENT, true));
        kind.actionHeader = new EventActionInflater();
        kind.actionBody = new SimpleInflater(Event.START_DATE);

        kind.typeColumn = Event.TYPE;
        kind.typeList = Lists.newArrayList();
        kind.dateFormatWithoutYear = CommonDateUtils.NO_YEAR_DATE_FORMAT;
        kind.dateFormatWithYear = CommonDateUtils.FULL_DATE_FORMAT;
        kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, true).setSpecificMax(1));
        kind.typeList.add(buildEventType(Event.TYPE_ANNIVERSARY, false));
        kind.typeList.add(buildEventType(Event.TYPE_OTHER, false));
        kind.typeList.add(buildEventType(Event.TYPE_CUSTOM, false).setSecondary(true)
                .setCustomColumn(Event.LABEL));

        kind.defaultValues = new ContentValues();
        kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY);

        kind.fieldList = Lists.newArrayList();
        kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT));

        return kind;
    }
}