• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.speeddial.database;
18 
19 import android.provider.ContactsContract.CommonDataKinds.Phone;
20 import android.support.annotation.IntDef;
21 import android.support.annotation.Nullable;
22 import com.google.auto.value.AutoValue;
23 import com.google.common.base.Optional;
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 
27 /** POJO representation of database rows returned by {@link SpeedDialEntryDao}. */
28 @AutoValue
29 public abstract class SpeedDialEntry {
30 
31   /**
32    * Unique ID
33    *
34    * <p>Must be null when inserting, and an ID will be generated and returned after inserting.
35    */
36   @Nullable
id()37   public abstract Long id();
38 
39   /** Position the contact is pinned to in the UI. Will be absent if it hasn't be set yet. */
pinnedPosition()40   public abstract Optional<Integer> pinnedPosition();
41 
42   /** @see {@link Contacts#_ID} */
contactId()43   public abstract long contactId();
44 
45   /** @see {@link Contacts#LOOKUP_KEY} */
lookupKey()46   public abstract String lookupKey();
47 
48   /**
49    * {@link Channel} that is associated with this entry.
50    *
51    * <p>Contacts with multiple channels do not have a default until specified by the user. Once the
52    * default channel is determined, all calls should be placed to this channel.
53    */
54   @Nullable
defaultChannel()55   public abstract Channel defaultChannel();
56 
toBuilder()57   public abstract Builder toBuilder();
58 
builder()59   public static Builder builder() {
60     return new AutoValue_SpeedDialEntry.Builder().setPinnedPosition(Optional.absent());
61   }
62 
63   /** Builder class for speed dial entry. */
64   @AutoValue.Builder
65   public abstract static class Builder {
66 
setId(Long id)67     public abstract Builder setId(Long id);
68 
setPinnedPosition(Optional<Integer> pinnedPosition)69     public abstract Builder setPinnedPosition(Optional<Integer> pinnedPosition);
70 
setContactId(long contactId)71     public abstract Builder setContactId(long contactId);
72 
setLookupKey(String lookupKey)73     public abstract Builder setLookupKey(String lookupKey);
74 
setDefaultChannel(@ullable Channel defaultChannel)75     public abstract Builder setDefaultChannel(@Nullable Channel defaultChannel);
76 
build()77     public abstract SpeedDialEntry build();
78   }
79 
80   /** POJO representation of a relevant phone number columns in {@link SpeedDialEntryDao}. */
81   @AutoValue
82   public abstract static class Channel {
83 
84     public static final int UNKNOWN = 0;
85     public static final int VOICE = 1;
86     public static final int IMS_VIDEO = 2;
87     public static final int DUO = 3;
88 
89     /** Whether the Channel is for an audio or video call. */
90     @Retention(RetentionPolicy.SOURCE)
91     @IntDef({UNKNOWN, VOICE, IMS_VIDEO, DUO})
92     public @interface Technology {}
93 
isVideoTechnology()94     public boolean isVideoTechnology() {
95       return technology() == IMS_VIDEO || technology() == DUO;
96     }
97 
98     /**
99      * Raw phone number as the user entered it.
100      *
101      * @see Phone#NUMBER
102      */
number()103     public abstract String number();
104 
105     /** @see Phone#TYPE */
phoneType()106     public abstract int phoneType();
107 
108     /** @see Phone#LABEL */
label()109     public abstract String label();
110 
technology()111     public abstract @Technology int technology();
112 
toBuilder()113     public abstract Builder toBuilder();
114 
builder()115     public static Builder builder() {
116       return new AutoValue_SpeedDialEntry_Channel.Builder();
117     }
118 
119     /** Builder class for {@link Channel}. */
120     @AutoValue.Builder
121     public abstract static class Builder {
122 
setNumber(String number)123       public abstract Builder setNumber(String number);
124 
setPhoneType(int phoneType)125       public abstract Builder setPhoneType(int phoneType);
126 
setLabel(String label)127       public abstract Builder setLabel(String label);
128 
setTechnology(@echnology int technology)129       public abstract Builder setTechnology(@Technology int technology);
130 
build()131       public abstract Channel build();
132     }
133   }
134 }
135