• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.google.phonenumbers.demoapp.phonenumbers;
2 
3 import java.io.Serializable;
4 
5 /**
6  * Represents a phone number and the conversion of it in the app (between reading from and writing
7  * to contacts).
8  */
9 public class PhoneNumberInApp implements Serializable, Comparable<PhoneNumberInApp> {
10 
11   /** ID to identify the phone number in the device's contacts. */
12   private final String id;
13   /** Display name of the contact the phone number belongs to. */
14   private final String contactName;
15 
16   /** Phone number as originally in contacts. */
17   private final String originalPhoneNumber;
18   /**
19    * The in E.164 formatted {@link PhoneNumberInApp#originalPhoneNumber} (e.g. {@code +41446681800})
20    * if formattable, else {@code null}.
21    */
22   private String formattedPhoneNumber = null;
23 
24   private FormattingState formattingState = FormattingState.PENDING;
25 
26   /**
27    * Equal to the value of the checkbox in the UI. Only if {@code true} the phone number should be
28    * updated in the contacts.
29    */
30   private boolean shouldContactBeUpdated = false;
31 
PhoneNumberInApp(String id, String contactName, String originalPhoneNumber)32   public PhoneNumberInApp(String id, String contactName, String originalPhoneNumber) {
33     this.id = id;
34     this.contactName = contactName;
35     this.originalPhoneNumber = originalPhoneNumber;
36   }
37 
getId()38   public String getId() {
39     return id;
40   }
41 
getContactName()42   public String getContactName() {
43     return contactName;
44   }
45 
getOriginalPhoneNumber()46   public String getOriginalPhoneNumber() {
47     return originalPhoneNumber;
48   }
49 
getFormattedPhoneNumber()50   public String getFormattedPhoneNumber() {
51     return formattedPhoneNumber;
52   }
53 
setFormattedPhoneNumber(String formattedPhoneNumber)54   public void setFormattedPhoneNumber(String formattedPhoneNumber) {
55     this.formattedPhoneNumber = formattedPhoneNumber;
56   }
57 
getFormattingState()58   public FormattingState getFormattingState() {
59     return formattingState;
60   }
61 
setFormattingState(FormattingState formattingState)62   public void setFormattingState(FormattingState formattingState) {
63     this.formattingState = formattingState;
64   }
65 
shouldContactBeUpdated()66   public boolean shouldContactBeUpdated() {
67     return shouldContactBeUpdated;
68   }
69 
setShouldContactBeUpdated(boolean shouldContactBeUpdated)70   public void setShouldContactBeUpdated(boolean shouldContactBeUpdated) {
71     this.shouldContactBeUpdated = shouldContactBeUpdated;
72   }
73 
74   @Override
compareTo(PhoneNumberInApp o)75   public int compareTo(PhoneNumberInApp o) {
76     return getContactName().compareTo(o.getContactName());
77   }
78 
79   /**
80    * Represents the state the formatting of {@link PhoneNumberInApp#originalPhoneNumber} can be at.
81    */
82   public enum FormattingState {
83     /** Used before the formatting is tried/done. */
84     PENDING,
85     /** Formatting completed to {@link PhoneNumberInApp#formattedPhoneNumber} without errors. */
86     COMPLETED,
87     /** Error while parsing the {@link PhoneNumberInApp#originalPhoneNumber}. */
88     PARSING_ERROR,
89     /** {@link PhoneNumberInApp#originalPhoneNumber} is a short number. */
90     NUMBER_IS_SHORT_NUMBER,
91     /** {@link PhoneNumberInApp#originalPhoneNumber} is not a valid number. */
92     NUMBER_IS_NOT_VALID,
93     /** {@link PhoneNumberInApp#originalPhoneNumber} is already in E.164 format. */
94     NUMBER_IS_ALREADY_IN_E164
95   }
96 }
97