1 /*
2  * Copyright (C) 2016 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.enrichedcall;
18 
19 import android.net.Uri;
20 import android.support.annotation.NonNull;
21 import android.support.annotation.Nullable;
22 import com.android.dialer.common.Assert;
23 import com.google.auto.value.AutoValue;
24 
25 /**
26  * Value type holding references to all data that could be provided for the call composer.
27  *
28  * <p>Note: Either the subject, the image data, or both must be specified, e.g.
29  *
30  * <pre>
31  *   OutgoingCallComposerData.builder.build(); // throws exception, no data set
32  *   OutgoingCallComposerData.builder
33  *       .setText(subject)
34  *       .build(); // Success
35  *   OutgoingCallComposerData.builder
36  *       .setImageData(uri, contentType)
37  *       .build(); // Success
38  *   OutgoingCallComposerData.builder
39  *      .setText(subject)
40  *      .setImageData(uri, contentType)
41  *      .build(); // Success
42  * </pre>
43  */
44 @AutoValue
45 public abstract class OutgoingCallComposerData {
46 
builder()47   public static Builder builder() {
48     return new AutoValue_OutgoingCallComposerData.Builder();
49   }
50 
hasImageData()51   public boolean hasImageData() {
52     return getImageUri() != null && getImageContentType() != null;
53   }
54 
55   @Nullable
getSubject()56   public abstract String getSubject();
57 
58   @Nullable
getImageUri()59   public abstract Uri getImageUri();
60 
61   @Nullable
getImageContentType()62   public abstract String getImageContentType();
63 
64   /** Builds instances of {@link OutgoingCallComposerData}. */
65   @AutoValue.Builder
66   public abstract static class Builder {
setSubject(String subject)67     public abstract Builder setSubject(String subject);
68 
setImageData(@onNull Uri imageUri, @NonNull String imageContentType)69     public Builder setImageData(@NonNull Uri imageUri, @NonNull String imageContentType) {
70       setImageUri(Assert.isNotNull(imageUri));
71       setImageContentType(Assert.isNotNull(imageContentType));
72       return this;
73     }
74 
setImageUri(Uri imageUri)75     abstract Builder setImageUri(Uri imageUri);
76 
setImageContentType(String imageContentType)77     abstract Builder setImageContentType(String imageContentType);
78 
autoBuild()79     abstract OutgoingCallComposerData autoBuild();
80 
81     /**
82      * Returns the OutgoingCallComposerData from this builder.
83      *
84      * @return the OutgoingCallComposerData.
85      * @throws IllegalStateException if neither {@link #setSubject(String)} nor {@link
86      *     #setImageData(Uri, String)} were called.
87      */
build()88     public OutgoingCallComposerData build() {
89       OutgoingCallComposerData data = autoBuild();
90       Assert.checkState(data.getSubject() != null || data.hasImageData());
91       return data;
92     }
93   }
94 }
95