1package de.gultsch.chat.ui;
2
3import de.gultsch.chat.R;
4import de.gultsch.chat.entities.Contact;
5import de.gultsch.chat.entities.Presences;
6import de.gultsch.chat.utils.UIHelper;
7import android.app.AlertDialog;
8import android.app.Dialog;
9import android.app.DialogFragment;
10import android.content.DialogInterface;
11import android.content.Intent;
12import android.os.Bundle;
13import android.provider.ContactsContract.CommonDataKinds;
14import android.provider.ContactsContract.Contacts;
15import android.provider.ContactsContract.Intents;
16import android.view.LayoutInflater;
17import android.view.View;
18import android.view.View.OnClickListener;
19import android.widget.CheckBox;
20import android.widget.QuickContactBadge;
21import android.widget.TextView;
22
23public class DialogContactDetails extends DialogFragment {
24
25 private Contact contact = null;
26 boolean displayingInRoster = false;
27
28 private DialogContactDetails mDetailsDialog = this;
29 private XmppActivity activity;
30
31 private DialogInterface.OnClickListener askRemoveFromRoster = new DialogInterface.OnClickListener() {
32
33 @Override
34 public void onClick(DialogInterface dialog, int which) {
35 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
36 builder.setTitle("Delete from roster");
37 builder.setMessage("Do you want to delete "+contact.getJid()+" from your roster. The conversation assoziated with this account will not be removed.");
38 builder.setNegativeButton("Cancel", null);
39 builder.setPositiveButton("Delete",removeFromRoster);
40 builder.create().show();
41 }
42 };
43
44 private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
45
46 @Override
47 public void onClick(DialogInterface dialog, int which) {
48 activity.xmppConnectionService.deleteContact(contact);
49 mDetailsDialog.dismiss();
50 }
51 };
52
53 private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() {
54
55 @Override
56 public void onClick(DialogInterface dialog, int which) {
57 Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
58 intent.setType(Contacts.CONTENT_ITEM_TYPE);
59 intent.putExtra(Intents.Insert.IM_HANDLE,contact.getJid());
60 intent.putExtra(Intents.Insert.IM_PROTOCOL,CommonDataKinds.Im.PROTOCOL_JABBER);
61 intent.putExtra("finishActivityOnSaveCompleted", true);
62 getActivity().startActivityForResult(intent,ConversationActivity.INSERT_CONTACT);
63 mDetailsDialog.dismiss();
64 }
65 };
66
67 public void setContact(Contact contact) {
68 this.contact = contact;
69 }
70
71 @Override
72 public Dialog onCreateDialog(Bundle savedInstanceState) {
73 this.activity = (XmppActivity) getActivity();
74 AlertDialog.Builder builder = new AlertDialog.Builder(this.activity);
75 LayoutInflater inflater = getActivity().getLayoutInflater();
76 View view = inflater.inflate(R.layout.dialog_contact_details, null);
77 TextView contactJid = (TextView) view.findViewById(R.id.details_contactjid);
78 TextView accountJid = (TextView) view.findViewById(R.id.details_account);
79 TextView status = (TextView) view.findViewById(R.id.details_contactstatus);
80 CheckBox send = (CheckBox) view.findViewById(R.id.details_send_presence);
81 CheckBox receive = (CheckBox) view.findViewById(R.id.details_receive_presence);
82 //ImageView contactPhoto = (ImageView) view.findViewById(R.id.details_contact_picture);
83 QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.details_contact_badge);
84
85 boolean subscriptionSend = false;
86 boolean subscriptionReceive = false;
87 if (contact.getSubscription()!=null) {
88 if (contact.getSubscription().equals("both")) {
89 subscriptionReceive = true;
90 subscriptionSend = true;
91 } else if (contact.getSubscription().equals("from")) {
92 subscriptionSend = true;
93 } else if (contact.getSubscription().equals("to")) {
94 subscriptionReceive = true;
95 }
96 }
97
98 switch (contact.getMostAvailableStatus()) {
99 case Presences.CHAT:
100 status.setText("free to chat");
101 status.setTextColor(0xFF83b600);
102 break;
103 case Presences.ONLINE:
104 status.setText("online");
105 status.setTextColor(0xFF83b600);
106 break;
107 case Presences.AWAY:
108 status.setText("away");
109 status.setTextColor(0xFFffa713);
110 break;
111 case Presences.XA:
112 status.setText("extended away");
113 status.setTextColor(0xFFffa713);
114 break;
115 case Presences.DND:
116 status.setText("do not disturb");
117 status.setTextColor(0xFFe92727);
118 break;
119 case Presences.OFFLINE:
120 status.setText("offline");
121 status.setTextColor(0xFFe92727);
122 break;
123 default:
124 status.setText("offline");
125 status.setTextColor(0xFFe92727);
126 break;
127 }
128
129 send.setChecked(subscriptionSend);
130 receive.setChecked(subscriptionReceive);
131 contactJid.setText(contact.getJid());
132 accountJid.setText(contact.getAccount().getJid());
133
134 UIHelper.prepareContactBadge(getActivity(), badge, contact);
135
136 if (contact.getSystemAccount()==null) {
137 badge.setOnClickListener(new OnClickListener() {
138
139 @Override
140 public void onClick(View v) {
141 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
142 builder.setTitle("Add to phone book");
143 builder.setMessage("Do you want to add "+contact.getJid()+" to your phones contact list?");
144 builder.setNegativeButton("Cancel", null);
145 builder.setPositiveButton("Add",addToPhonebook);
146 builder.create().show();
147 }
148 });
149 }
150
151 builder.setView(view);
152 builder.setTitle(contact.getDisplayName());
153
154 builder.setNeutralButton("Done", null);
155 builder.setPositiveButton("Remove from roster", this.askRemoveFromRoster);
156 return builder.create();
157 }
158}