1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.dialer.searchfragment.cp2;
18 
19 import android.database.Cursor;
20 import android.support.annotation.Nullable;
21 import com.android.dialer.searchfragment.common.Projections;
22 import com.google.auto.value.AutoValue;
23 
24 /** POJO Representation for contacts returned in {@link SearchContactsCursorLoader}. */
25 @AutoValue
26 public abstract class Cp2Contact {
27 
phoneId()28   public abstract long phoneId();
29 
phoneType()30   public abstract int phoneType();
31 
32   @Nullable
phoneLabel()33   public abstract String phoneLabel();
34 
phoneNumber()35   public abstract String phoneNumber();
36 
37   @Nullable
displayName()38   public abstract String displayName();
39 
photoId()40   public abstract int photoId();
41 
42   @Nullable
photoUri()43   public abstract String photoUri();
44 
lookupKey()45   public abstract String lookupKey();
46 
carrierPresence()47   public abstract int carrierPresence();
48 
contactId()49   public abstract int contactId();
50 
51   @Nullable
companyName()52   public abstract String companyName();
53 
54   @Nullable
nickName()55   public abstract String nickName();
56 
mimeType()57   public abstract String mimeType();
58 
59   /** Builder for {@link Cp2Contact}. */
60   @AutoValue.Builder
61   public abstract static class Builder {
setPhoneId(long id)62     public abstract Builder setPhoneId(long id);
63 
setPhoneType(int type)64     public abstract Builder setPhoneType(int type);
65 
setPhoneLabel(@ullable String label)66     public abstract Builder setPhoneLabel(@Nullable String label);
67 
setPhoneNumber(String number)68     public abstract Builder setPhoneNumber(String number);
69 
setDisplayName(@ullable String name)70     public abstract Builder setDisplayName(@Nullable String name);
71 
setPhotoId(int id)72     public abstract Builder setPhotoId(int id);
73 
setPhotoUri(@ullable String uri)74     public abstract Builder setPhotoUri(@Nullable String uri);
75 
setLookupKey(String lookupKey)76     public abstract Builder setLookupKey(String lookupKey);
77 
setCarrierPresence(int presence)78     public abstract Builder setCarrierPresence(int presence);
79 
setContactId(int id)80     public abstract Builder setContactId(int id);
81 
setCompanyName(@ullable String name)82     public abstract Builder setCompanyName(@Nullable String name);
83 
setNickName(@ullable String nickName)84     public abstract Builder setNickName(@Nullable String nickName);
85 
setMimeType(String mimeType)86     public abstract Builder setMimeType(String mimeType);
87 
build()88     public abstract Cp2Contact build();
89   }
90 
builder()91   public static Builder builder() {
92     return new AutoValue_Cp2Contact.Builder();
93   }
94 
fromCursor(Cursor cursor)95   public static Cp2Contact fromCursor(Cursor cursor) {
96     return Cp2Contact.builder()
97         .setPhoneId(cursor.getLong(Projections.CONTACT_ID))
98         .setPhoneType(cursor.getInt(Projections.PHONE_TYPE))
99         .setPhoneLabel(cursor.getString(Projections.PHONE_LABEL))
100         .setPhoneNumber(cursor.getString(Projections.PHONE_NUMBER))
101         .setDisplayName(cursor.getString(Projections.DISPLAY_NAME))
102         .setPhotoId(cursor.getInt(Projections.PHOTO_ID))
103         .setPhotoUri(cursor.getString(Projections.PHOTO_URI))
104         .setLookupKey(cursor.getString(Projections.LOOKUP_KEY))
105         .setCarrierPresence(cursor.getInt(Projections.CARRIER_PRESENCE))
106         .setContactId(cursor.getInt(Projections.CONTACT_ID))
107         .setCompanyName(cursor.getString(Projections.COMPANY_NAME))
108         .setNickName(cursor.getString(Projections.NICKNAME))
109         .setMimeType(cursor.getString(Projections.MIME_TYPE))
110         .build();
111   }
112 
toCursorRow()113   public Object[] toCursorRow() {
114     Object[] row = new Object[Projections.CP2_PROJECTION.length];
115     row[Projections.ID] = phoneId();
116     row[Projections.PHONE_TYPE] = phoneType();
117     row[Projections.PHONE_LABEL] = phoneLabel();
118     row[Projections.PHONE_NUMBER] = phoneNumber();
119     row[Projections.DISPLAY_NAME] = displayName();
120     row[Projections.PHOTO_ID] = photoId();
121     row[Projections.PHOTO_URI] = photoUri();
122     row[Projections.LOOKUP_KEY] = lookupKey();
123     row[Projections.CARRIER_PRESENCE] = carrierPresence();
124     row[Projections.CONTACT_ID] = contactId();
125     row[Projections.COMPANY_NAME] = companyName();
126     row[Projections.NICKNAME] = nickName();
127     row[Projections.MIME_TYPE] = mimeType();
128     return row;
129   }
130 
toBuilder()131   public abstract Builder toBuilder();
132 }
133