Skip to content

Commit d50f9cf

Browse files
committed
handle null in contact data
1 parent 028d20a commit d50f9cf

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

app/src/main/java/io/frappe/frappeauthenticator/sync/ContactsHelper.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public static void addContact(Account account, JSONObject contactInfo, ContentRe
5757
e.printStackTrace();
5858
}
5959

60-
if (firstName!=null && lastName!=null){
60+
if (!firstName.equals("null") && !lastName.equals("null")){
6161
displayName = firstName + " " + lastName;
6262
}
63-
else if (firstName!=null && lastName.isEmpty()){
63+
else if (!firstName.equals("null") && lastName.equals("null")){
6464
displayName = firstName;
6565
}
66-
else if (lastName!=null && firstName.isEmpty()){
66+
else if (!lastName.equals("null") && firstName.equals("null")){
6767
displayName = lastName;
6868
}
6969

@@ -73,7 +73,7 @@ else if (lastName!=null && firstName.isEmpty()){
7373
ContactsContract.RawContacts.CONTENT_URI, true))
7474
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type)
7575
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, account.name)
76-
.withValue(ContactsContract.RawContacts.RAW_CONTACT_IS_READ_ONLY,"1")git
76+
.withValue(ContactsContract.RawContacts.RAW_CONTACT_IS_READ_ONLY,"1")
7777
.withValue(ContactsContract.RawContacts.SYNC1,contactName)
7878
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
7979
.build());
@@ -88,23 +88,23 @@ else if (lastName!=null && firstName.isEmpty()){
8888
.build());
8989
}
9090

91-
if (firstName!=null && !firstName.isEmpty()){
91+
if (!firstName.equals("null")){
9292
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
9393
.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0)
9494
.withValue(ContactsContract.RawContacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
9595
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName)
9696
.build());
9797
}
9898

99-
if (lastName!=null && !lastName.isEmpty()){
99+
if (!lastName.equals("null")){
100100
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
101101
.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0)
102102
.withValue(ContactsContract.RawContacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
103103
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName)
104104
.build());
105105
}
106106
// add phone number
107-
if (phone!=null && !phone.isEmpty()) {
107+
if (!phone.equals("null")) {
108108
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
109109
.withValueBackReference(ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID, 0)
110110
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
@@ -114,7 +114,7 @@ else if (lastName!=null && firstName.isEmpty()){
114114
}
115115

116116
//add mobile number
117-
if (mobileNo!=null && !mobileNo.isEmpty()) {
117+
if (!mobileNo.equals("null")) {
118118
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
119119
.withValueBackReference(ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID, 0)
120120
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
@@ -124,7 +124,7 @@ else if (lastName!=null && firstName.isEmpty()){
124124
}
125125

126126
//add email
127-
if (emailID!=null && !emailID.isEmpty()) {
127+
if (!emailID.equals("null")) {
128128
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
129129
.withValueBackReference(ContactsContract.CommonDataKinds.Email.RAW_CONTACT_ID, 0)
130130
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
@@ -134,7 +134,7 @@ else if (lastName!=null && firstName.isEmpty()){
134134
}
135135

136136
//add Customer
137-
if(customerName!=null && !customerName.isEmpty()){
137+
if(!customerName.equals("null")){
138138
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
139139
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
140140
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -143,7 +143,7 @@ else if (lastName!=null && firstName.isEmpty()){
143143
}
144144

145145
//add Supplier
146-
if(supplierName!=null && !supplierName.isEmpty()){
146+
if(!supplierName.equals("null")){
147147
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
148148
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
149149
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -152,7 +152,7 @@ else if (lastName!=null && firstName.isEmpty()){
152152
}
153153

154154
//add Sales Partner
155-
if(salePartnerName!=null && !salePartnerName.isEmpty()){
155+
if(!salePartnerName.equals("null")){
156156
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
157157
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
158158
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -161,7 +161,7 @@ else if (lastName!=null && firstName.isEmpty()){
161161
}
162162

163163
//add Department
164-
if(department!=null && !department.isEmpty()){
164+
if(!department.equals("null")){
165165
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
166166
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
167167
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -170,7 +170,7 @@ else if (lastName!=null && firstName.isEmpty()){
170170
}
171171

172172
//add Designation
173-
if(designation!=null && !designation.isEmpty()){
173+
if(!designation.equals("null")){
174174
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
175175
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
176176
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)

app/src/main/java/io/frappe/frappeauthenticator/sync/ProfileActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,49 +44,49 @@ public void onCreate(Bundle savedInstanceState)
4444
// }
4545

4646
String mobileNo = cursor.getString(cursor.getColumnIndex("DATA1"));
47-
if (mobileNo!=null && !mobileNo.isEmpty()){
47+
if (!mobileNo.equals("null")){
4848
contactInfo.add("Mobile No");
4949
contactInfo.add(mobileNo);
5050
}
5151

5252
String phone = cursor.getString(cursor.getColumnIndex("DATA4"));
53-
if (phone!=null && !phone.isEmpty()){
53+
if (!phone.equals("null")){
5454
contactInfo.add("Phone");
5555
contactInfo.add(phone);
5656
}
5757

5858
String emailID = cursor.getString(cursor.getColumnIndex("DATA5"));
59-
if (emailID!= null && !emailID.isEmpty()){
59+
if (!emailID.equals("null")){
6060
contactInfo.add("EMail");
6161
contactInfo.add(emailID);
6262
}
6363

6464
String customerName = cursor.getString(cursor.getColumnIndex("DATA10"));
65-
if (customerName!=null && !customerName.isEmpty()){
65+
if (!customerName.equals("null")){
6666
contactInfo.add("Customer Name");
6767
contactInfo.add(customerName);
6868
}
6969

7070
String supplierName = cursor.getString(cursor.getColumnIndex("DATA11"));
71-
if (supplierName!=null && !supplierName.isEmpty()){
71+
if (!supplierName.equals("null")){
7272
contactInfo.add("Supplier Name");
7373
contactInfo.add(supplierName);
7474
}
7575

7676
String salesPartnerName = cursor.getString(cursor.getColumnIndex("DATA12"));
77-
if (salesPartnerName!=null && !salesPartnerName.isEmpty()){
77+
if (!salesPartnerName.equals("null")){
7878
contactInfo.add("Sales Partner Name");
7979
contactInfo.add(salesPartnerName);
8080
}
8181

8282
String designation = cursor.getString(cursor.getColumnIndex("DATA8"));
83-
if (designation!=null && !designation.isEmpty()){
83+
if (!designation.equals("null")){
8484
contactInfo.add("Designation");
8585
contactInfo.add(designation);
8686
}
8787

8888
String department = cursor.getString(cursor.getColumnIndex("DATA9"));
89-
if (department!=null && !department.isEmpty()){
89+
if (!department.equals("null")){
9090
contactInfo.add("Department");
9191
contactInfo.add(department);
9292
}

0 commit comments

Comments
 (0)