Skip to content

Commit 716fa6f

Browse files
committed
Added Contact viewing activity which raises intent
1 parent ab53739 commit 716fa6f

File tree

11 files changed

+147
-73
lines changed

11 files changed

+147
-73
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion "25.0.2"
66
defaultConfig {
77
applicationId "io.frappe.frappeauthenticator"
8-
minSdkVersion 19
8+
minSdkVersion 21
99
targetSdkVersion 25
1010
versionCode 1
1111
versionName "1.0"
@@ -20,16 +20,17 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
//compile fileTree(dir: 'libs', include: ['*.jar'])
2424
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})
27-
compile 'com.android.support:appcompat-v7:25.1.1'
28-
testCompile 'junit:junit:4.12'
29-
compile 'com.android.volley:volley:1.0.0'
30-
compile 'commons-codec:commons-codec:1.3'
31-
compile 'com.google.code.gson:gson:2.2.+'
27+
//compile 'com.android.support:appcompat-v7:25.1.1'
3228
// https://mvnrepository.com/artifact/commons-io/commons-io
3329
compile group: 'commons-io', name: 'commons-io', version: '2.4'
3430
compile group: 'org.aksw.gson', name: 'gson-utils-core', version: '1.0.0'
31+
compile 'com.android.volley:volley:1.0.0'
32+
compile 'commons-codec:commons-codec:1.10'
33+
compile 'com.google.code.gson:gson:2.2.4'
34+
compile 'com.android.support:support-v4:25.1.1'
35+
testCompile 'junit:junit:4.12'
3536
}

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,17 @@
6464
android:name=".sync.ProfileActivity"
6565
android:exported="true"
6666
android:label="ERPNext Contact">
67-
6867
<intent-filter>
69-
<action android:name="android.intent.action.VIEW"/>
70-
<category android:name="android.intent.category.DEFAULT"/>
71-
<data android:mimeType="vnd.android.cursor.item/vnd.io.frappe.frappeauthenticator.contact"/>
72-
</intent-filter>
68+
<action android:name="android.intent.action.VIEW" />
69+
70+
<category android:name="android.intent.category.DEFAULT" />
7371

72+
<data android:mimeType="vnd.android.cursor.item/vnd.io.frappe.frappeauthenticator.contact" />
73+
</intent-filter>
7474
</activity>
75+
<activity
76+
android:name=".sync.ViewingActivity"
77+
android:label="@string/title_activity_viewing"></activity>
7578
</application>
7679

7780
</manifest>

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

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

60+
if (firstName!=null && lastName!=null){
61+
displayName = firstName + " " + lastName;
62+
}
63+
else if (firstName!=null && lastName.isEmpty()){
64+
displayName = firstName;
65+
}
66+
else if (lastName!=null && firstName.isEmpty()){
67+
displayName = lastName;
68+
}
69+
6070
//Create our RawContact
6171
ArrayList<ContentProviderOperation> op_list = new ArrayList<ContentProviderOperation>();
6272
op_list.add(ContentProviderOperation.newInsert(addCallerIsSyncAdapterParameter(
6373
ContactsContract.RawContacts.CONTENT_URI, true))
6474
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type)
6575
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, account.name)
6676
.withValue(ContactsContract.RawContacts.RAW_CONTACT_IS_READ_ONLY,"1")
77+
.withValue(ContactsContract.Settings.UNGROUPED_VISIBLE, 1)
6778
.withValue(ContactsContract.RawContacts.SYNC1,contactName)
6879
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
6980
.build());
7081

71-
// this is for display name
72-
op_list.add(ContentProviderOperation.newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Settings.CONTENT_URI, true))
73-
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, AccountGeneral.ACCOUNT_NAME)
74-
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE)
75-
.withValue(ContactsContract.Settings.UNGROUPED_VISIBLE, 1)
76-
.build());
77-
7882
// first and last names
79-
if (firstName!=null){
83+
84+
if (displayName!=null && !displayName.isEmpty()){
8085
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
8186
.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0)
8287
.withValue(ContactsContract.RawContacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
83-
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName)
88+
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName)
8489
.build());
8590
}
86-
if (lastName!=null){
91+
92+
if (firstName!=null && !firstName.isEmpty()){
8793
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
8894
.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0)
8995
.withValue(ContactsContract.RawContacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
90-
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName)
96+
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName)
9197
.build());
9298
}
9399

94-
if (firstName!=null && lastName!=null){
95-
displayName = firstName + " " + lastName;
96-
}
97-
else if (firstName!=null && lastName.isEmpty()){
98-
displayName = firstName;
99-
}
100-
else if (lastName!=null && firstName.isEmpty()){
101-
displayName = lastName;
102-
}
103-
104-
if (displayName!=null){
100+
if (lastName!=null && !lastName.isEmpty()){
105101
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
106102
.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0)
107103
.withValue(ContactsContract.RawContacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
108-
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName)
104+
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName)
109105
.build());
110106
}
111107
// add phone number
112-
if (phone!=null) {
108+
if (phone!=null && !phone.isEmpty()) {
113109
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
114110
.withValueBackReference(ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID, 0)
115111
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
@@ -119,7 +115,7 @@ else if (lastName!=null && firstName.isEmpty()){
119115
}
120116

121117
//add mobile number
122-
if (mobileNo!=null) {
118+
if (mobileNo!=null && !mobileNo.isEmpty()) {
123119
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
124120
.withValueBackReference(ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID, 0)
125121
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
@@ -129,17 +125,17 @@ else if (lastName!=null && firstName.isEmpty()){
129125
}
130126

131127
//add email
132-
if (emailID!=null) {
128+
if (emailID!=null && !emailID.isEmpty()) {
133129
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
134130
.withValueBackReference(ContactsContract.CommonDataKinds.Email.RAW_CONTACT_ID, 0)
135131
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
136-
.withValue(ContactsContract.CommonDataKinds.Email.DATA, emailID)
132+
.withValue(ContactsContract.CommonDataKinds.Email.ADDRESS, emailID)
137133
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK)
138134
.build());
139135
}
140136

141137
//add Customer
142-
if(customerName!=null){
138+
if(customerName!=null && !customerName.isEmpty()){
143139
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
144140
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
145141
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -148,7 +144,7 @@ else if (lastName!=null && firstName.isEmpty()){
148144
}
149145

150146
//add Supplier
151-
if(supplierName!=null){
147+
if(supplierName!=null && !supplierName.isEmpty()){
152148
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
153149
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
154150
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -157,7 +153,7 @@ else if (lastName!=null && firstName.isEmpty()){
157153
}
158154

159155
//add Sales Partner
160-
if(salePartnerName!=null){
156+
if(salePartnerName!=null && !salePartnerName.isEmpty()){
161157
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
162158
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
163159
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -166,7 +162,7 @@ else if (lastName!=null && firstName.isEmpty()){
166162
}
167163

168164
//add Department
169-
if(department!=null){
165+
if(department!=null && !department.isEmpty()){
170166
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
171167
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
172168
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
@@ -175,7 +171,7 @@ else if (lastName!=null && firstName.isEmpty()){
175171
}
176172

177173
//add Designation
178-
if(designation!=null){
174+
if(designation!=null && !designation.isEmpty()){
179175
op_list.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
180176
.withValueBackReference(ContactsContract.CommonDataKinds.Organization.RAW_CONTACT_ID, 0)
181177
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)

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

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
import android.app.Activity;
44
import android.app.ListActivity;
5+
import android.content.Intent;
56
import android.database.Cursor;
67
import android.database.DatabaseUtils;
78
import android.net.Uri;
89
import android.os.Bundle;
910
import android.provider.ContactsContract;
11+
import android.view.View;
12+
import android.widget.AdapterView;
1013
import android.widget.ArrayAdapter;
1114
import android.widget.ListView;
1215
import android.widget.TextView;
16+
import android.widget.Toast;
1317

1418
import java.util.ArrayList;
19+
import java.util.List;
1520

1621
import io.frappe.frappeauthenticator.R;
1722

@@ -26,30 +31,92 @@ public void onCreate(Bundle savedInstanceState)
2631
Uri intentData = getIntent().getData();
2732
if ((intentData)!=null)
2833
{
34+
List<String> contactInfo = new ArrayList<String>();
35+
ArrayAdapter adapter = new ArrayAdapter<String>(ProfileActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, contactInfo);
2936
Cursor cursor = managedQuery(intentData, null, null, null, null);
3037
System.out.println(DatabaseUtils.dumpCursorToString(cursor));
3138
if (cursor.moveToNext())
3239
{
33-
ArrayList<String> listItems=new ArrayList<String>();
34-
ArrayAdapter<String> adapter;
40+
String displayName = cursor.getString(cursor.getColumnIndex("DATA2"));
41+
// if (displayName!=null && !displayName.isEmpty()){
42+
// contactInfo.add("Name");
43+
// contactInfo.add(displayName);
44+
// }
3545

3646
String mobileNo = cursor.getString(cursor.getColumnIndex("DATA1"));
37-
listItems.add(mobileNo);
38-
String displayName = cursor.getString(cursor.getColumnIndex("DATA2")); listItems.add(displayName);
39-
String contactName = cursor.getString(cursor.getColumnIndex("DATA3")); listItems.add(contactName);
40-
String phone = cursor.getString(cursor.getColumnIndex("DATA4")); listItems.add(phone);
41-
String emailID = cursor.getString(cursor.getColumnIndex("DATA5")); listItems.add(emailID);
42-
String firstName = cursor.getString(cursor.getColumnIndex("DATA6")); listItems.add(firstName);
43-
String lastName = cursor.getString(cursor.getColumnIndex("DATA7")); listItems.add(lastName);
44-
String designation = cursor.getString(cursor.getColumnIndex("DATA8")); listItems.add(designation);
45-
String department = cursor.getString(cursor.getColumnIndex("DATA9")); listItems.add(department);
46-
String customerName = cursor.getString(cursor.getColumnIndex("DATA10")); listItems.add(customerName);
47-
String supplierName = cursor.getString(cursor.getColumnIndex("DATA11")); listItems.add(supplierName);
48-
String salesPartnerName = cursor.getString(cursor.getColumnIndex("DATA12")); listItems.add(salesPartnerName);
47+
if (mobileNo!=null && !mobileNo.isEmpty()){
48+
contactInfo.add("Mobile No");
49+
contactInfo.add(mobileNo);
50+
}
51+
52+
String phone = cursor.getString(cursor.getColumnIndex("DATA4"));
53+
if (phone!=null && !phone.isEmpty()){
54+
contactInfo.add("Phone");
55+
contactInfo.add(phone);
56+
}
57+
58+
String emailID = cursor.getString(cursor.getColumnIndex("DATA5"));
59+
if (emailID!= null && !emailID.isEmpty()){
60+
contactInfo.add("EMail");
61+
contactInfo.add(emailID);
62+
}
63+
64+
String customerName = cursor.getString(cursor.getColumnIndex("DATA10"));
65+
if (customerName!=null && !customerName.isEmpty()){
66+
contactInfo.add("Customer Name");
67+
contactInfo.add(customerName);
68+
}
69+
70+
String supplierName = cursor.getString(cursor.getColumnIndex("DATA11"));
71+
if (supplierName!=null && !supplierName.isEmpty()){
72+
contactInfo.add("Supplier Name");
73+
contactInfo.add(supplierName);
74+
}
75+
76+
String salesPartnerName = cursor.getString(cursor.getColumnIndex("DATA12"));
77+
if (salesPartnerName!=null && !salesPartnerName.isEmpty()){
78+
contactInfo.add("Sales Partner Name");
79+
contactInfo.add(salesPartnerName);
80+
}
81+
82+
String designation = cursor.getString(cursor.getColumnIndex("DATA8"));
83+
if (designation!=null && !designation.isEmpty()){
84+
contactInfo.add("Designation");
85+
contactInfo.add(designation);
86+
}
87+
88+
String department = cursor.getString(cursor.getColumnIndex("DATA9"));
89+
if (department!=null && !department.isEmpty()){
90+
contactInfo.add("Department");
91+
contactInfo.add(department);
92+
}
93+
94+
String firstName = cursor.getString(cursor.getColumnIndex("DATA6"));
95+
String lastName = cursor.getString(cursor.getColumnIndex("DATA7"));
96+
String contactName = cursor.getString(cursor.getColumnIndex("DATA3"));
97+
4998
adapter=new ArrayAdapter<String>(ProfileActivity.this,
50-
android.R.layout.simple_list_item_1,
51-
listItems);
99+
android.R.layout.simple_list_item_1, android.R.id.text1,
100+
contactInfo);
101+
52102
listView.setAdapter(adapter);
103+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
104+
@Override
105+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
106+
if (parent.getItemAtPosition(position-1) == "Phone"){
107+
Intent phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", parent.getItemAtPosition(position).toString(), null));
108+
startActivity(phoneIntent);
109+
} else if (parent.getItemAtPosition(position-1) == "Mobile No"){
110+
Intent phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", parent.getItemAtPosition(position).toString(), null));
111+
startActivity(phoneIntent);
112+
} else if (parent.getItemAtPosition(position-1) == "EMail"){
113+
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
114+
"mailto",parent.getItemAtPosition(position).toString(), null));
115+
startActivity(Intent.createChooser(emailIntent, "Send email..."));
116+
}
117+
}
118+
});
119+
53120
}
54121
}
55122
}

app/src/main/res/layout/act_login.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:orientation="vertical"
5-
android:layout_width="fill_parent"
6-
android:layout_height="fill_parent">
5+
android:layout_width="fill_parent"
6+
android:layout_height="fill_parent"
7+
android:theme="@android:style/Theme.Material.Light"
8+
android:background="@android:color/background_light">
79
<WebView
810
android:id="@+id/webv"
911
android:layout_width="fill_parent"

app/src/main/res/layout/activity_profile.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
android:paddingLeft="@dimen/activity_horizontal_margin"
99
android:paddingRight="@dimen/activity_horizontal_margin"
1010
android:paddingTop="@dimen/activity_vertical_margin"
11-
tools:context="io.frappe.frappeauthenticator.sync.ProfileActivity">
11+
tools:context="io.frappe.frappeauthenticator.sync.ProfileActivity"
12+
android:theme="@android:style/Theme.Material.Light.DarkActionBar"
13+
>
1214
<ListView
1315
android:layout_width="fill_parent"
1416
android:layout_height="fill_parent"
1517
android:id="@+id/profiletext"
1618
android:layout_alignParentTop="true"
17-
android:layout_alignParentStart="true"/>
19+
android:layout_alignParentStart="true"
20+
android:textColor="#474343"/>
1821
</RelativeLayout>

app/src/main/res/values/colors.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#3F51B5</color>
4-
<color name="colorPrimaryDark">#303F9F</color>
5-
<color name="colorAccent">#FF4081</color>
3+
<!--<color name="colorPrimary">#3F51B5</color>-->
4+
<!--<color name="colorPrimaryDark">#303F9F</color>-->
5+
<!--<color name="colorAccent">#FF4081</color>-->
66
</resources>

0 commit comments

Comments
 (0)