From 78312d71dd1f281f494a2a1c04e4a80f34898d2c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 5 Mar 2014 15:41:14 +0100 Subject: [PATCH] reworked contact details --- AndroidManifest.xml | 8 +- gen/eu/siacs/conversations/R.java | 209 ++++++++-------- res/drawable-hdpi/ic_action_discard.png | Bin 0 -> 454 bytes res/drawable-mdpi/ic_action_discard.png | Bin 0 -> 333 bytes res/drawable-xhdpi/ic_action_discard.png | Bin 0 -> 552 bytes res/drawable-xxhdpi/ic_action_discard.png | Bin 0 -> 781 bytes ...tails.xml => activity_contact_details.xml} | 73 +++--- ...c_options.xml => activity_muc_details.xml} | 0 res/layout/edit_contact_name.xml | 28 +++ res/menu/contact_details.xml | 27 +++ res/menu/muc_details.xml | 15 ++ res/values/strings.xml | 2 + .../siacs/conversations/entities/Contact.java | 4 + .../persistance/DatabaseBackend.java | 14 +- .../services/XmppConnectionService.java | 17 +- .../ui/ContactDetailsActivity.java | 226 ++++++++++++++++++ .../ui/ConversationActivity.java | 22 +- .../ui/ConversationFragment.java | 4 +- .../ui/DialogContactDetails.java | 218 ----------------- ...sActivity.java => MucDetailsActivity.java} | 31 ++- .../ui/NewConversationActivity.java | 15 +- .../siacs/conversations/ui/XmppActivity.java | 14 ++ 22 files changed, 529 insertions(+), 398 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_discard.png create mode 100644 res/drawable-mdpi/ic_action_discard.png create mode 100644 res/drawable-xhdpi/ic_action_discard.png create mode 100644 res/drawable-xxhdpi/ic_action_discard.png rename res/layout/{dialog_contact_details.xml => activity_contact_details.xml} (64%) rename res/layout/{muc_options.xml => activity_muc_details.xml} (100%) create mode 100644 res/layout/edit_contact_name.xml create mode 100644 res/menu/contact_details.xml create mode 100644 res/menu/muc_details.xml create mode 100644 src/eu/siacs/conversations/ui/ContactDetailsActivity.java delete mode 100644 src/eu/siacs/conversations/ui/DialogContactDetails.java rename src/eu/siacs/conversations/ui/{MucOptionsActivity.java => MucDetailsActivity.java} (88%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8a1a4028c..0e59383c0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -46,9 +46,13 @@ android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" > + + @ONhf8TOv;h()s(F`$i?JmhXN47$G|vltF{(YLoOlw$_UP`}Dy(;Cxwyr^B`pgzo{m`*>Tg<$)jx`RM7V=?%1t;9R9 z159dGvc+OFeCcD25*!QQ4dvwZD3RhG$mW!Vqz=SD;LZ@s-6w&Lfj}n`5&|$`{Ln>}1B}lL;%Nk5tb@0ZG2r&=I2NUj9e|vK?f60vF zPHl@1H$?FE|4ECoW?-wDcw7B8mxkk&!;dHb@9nX>N z4L>XvnmGE1Y+*7K=bR_hmK5OhmGP02*W!lmCV^**+@yB6HZtc0E|qC`R{O<7q31{) z_fd^Z28sXuD}$mKWfMHLZI4W2=5$~d_UPb?a4em3i*=&Z*4IpGZH#Qr#~AOQF!(KP zD*K^@huucfmw7SYf@RDnR!+#{U7b@gXGYOnnXgYwPG4Pcbpyw&E7Ad>JZqZr4SSjb d9hew63>ac_jO4A4-U4}@!PC{xWt~$(698OZd+h)K literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_discard.png b/res/drawable-xhdpi/ic_action_discard.png new file mode 100644 index 0000000000000000000000000000000000000000..db69d6c25478faddd522c43927c39e699eb4951d GIT binary patch literal 552 zcmV+@0@wYCP) ztO?kVU$1w#%iMaKd2@jeYk}4~fLED)`y!>^M@@rd;7n3pE{4tyNP$DV*o?lM5*u=% z)*S(2G^e^!42}sVpr-MzLB>SE_*==@Dey)lyrvFd31}1Q-+Cb6 zfyOd{@k^2IqYjV)=aR-;@_(*ua3l2qSBoo({+;{#03wA+IF;JqeDtgMVaoWNu$3*| zTigo(3afoDD;`@;&aylnhWH%6Am!STziOQDh9mM2SB6si$?IuwCZlvvDWVVp0fq!v zR)j4GfD3>C5P%o}0^kB500cN9U~8y%=aB%*AlSeKKmZ7EM?i0=ckhk>%d2ZmS#SXm zpo`i-=h`y?&)N6(mNwQRLk&@SgCPWNl9bt3Z$M+!YYKkqUFhhKrRA+KcXYUWTWdP)tQ$^RZ zR_X*Jtjx@;9eEKL`v$xN1B|dxiM3f1sS91p00Vd6N})oaR;hh9-zQn_fD-3^_MOj8 zOqKxv000000001h7h0AZHy8|h4P2%gkH>QaSk3TVsfJSW1}>+@ABhNs#b@0z+A+=> zGQQH5a$$7@SQVhx@bz*8fFIe3q@ACBe1*Tiu-xlo6rfrqh)NKDmg+Qy2TRojy~ff| zVgLdVgrmVFXnU!+A2XS7&9H~A-b4V^AYM9wCR$5iFaMnYV(hj{w6t_LkaVppjMjzk zb)%L?!}naz?i=?CI)%OSwRY6<)Z>Q+dipveW3=fJ;bRsQqwzD>=3xrc&=`&Ht?lFi zBw`2vi3>1`*gmrq1kiQ-d4$Gabq~UBBIa@dO~Q^c`x_mOY*Hcvu;A2Q;;k!6Sl zi=~KX-)~O@UyO5t=&0DQ39>0+idy}my*>2nD%M}j%9mVL+l`#RdUM@%sF7oy2mmCE zR~IBM&xMfk7n+a00000004mRd + android:background="#e5e5e5"> + + android:layout_height="88dp" + android:padding="8dp"> - - + android:paddingLeft="8dp" > + android:text="something@jabber.example.com" + android:textColor="#5b5b5b" + android:textSize="18sp" /> - - - + android:textStyle="bold" /> + + - - + android:padding="8dp" + android:text="Your account" /> - - + + android:padding="8dp" + android:text="Subscription" /> + android:textSize="18sp" + android:textColor="#5b5b5b" /> + android:textSize="18sp" + android:textColor="#5b5b5b" /> \ No newline at end of file diff --git a/res/layout/muc_options.xml b/res/layout/activity_muc_details.xml similarity index 100% rename from res/layout/muc_options.xml rename to res/layout/activity_muc_details.xml diff --git a/res/layout/edit_contact_name.xml b/res/layout/edit_contact_name.xml new file mode 100644 index 000000000..206c74323 --- /dev/null +++ b/res/layout/edit_contact_name.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/res/menu/contact_details.xml b/res/menu/contact_details.xml new file mode 100644 index 000000000..5d4a8d56b --- /dev/null +++ b/res/menu/contact_details.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/res/menu/muc_details.xml b/res/menu/muc_details.xml new file mode 100644 index 000000000..4f9b6da05 --- /dev/null +++ b/res/menu/muc_details.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index a9e1fb994..3b575db15 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -20,4 +20,6 @@ Moderator Participant Visitor + Enter a new name: + Do you want to delete %s from your roster. The conversation assoziated with this account will not be removed. diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index 0eed39ed2..4b97cc41e 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -293,4 +293,8 @@ public class Contact extends AbstractEntity implements Serializable { public boolean isInRoster() { return this.inRoster; } + + public String getAccountUuid() { + return this.accountUuid; + } } diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index 1a6f934a7..e2067141c 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -228,7 +228,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { } } - public List getContacts(Account account) { + public List getContactsByAccount(Account account) { List list = new ArrayList(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor; @@ -246,7 +246,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { return list; } - public List getContats(String where) { + public List getContacts(String where) { List list = new ArrayList(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(Contact.TABLENAME, null, where, null, null, null, null); @@ -280,5 +280,15 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.delete(Contact.TABLENAME, Contact.UUID + "=?", args); } + public Contact getContact(String uuid) { + SQLiteDatabase db = this.getWritableDatabase(); + String[] args = { uuid }; + Cursor cursor = db.query(Contact.TABLENAME, null, Contact.UUID + "=?", args, null, null, null); + if (cursor.getCount() == 0) + return null; + cursor.moveToFirst(); + return Contact.fromCursor(cursor); + } + } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 48f0e4702..e973afa9d 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -535,7 +535,7 @@ public class XmppConnectionService extends Service { public void getRoster(Account account, final OnRosterFetchedListener listener) { - List contacts = databaseBackend.getContacts(account); + List contacts = databaseBackend.getContactsByAccount(account); for (int i = 0; i < contacts.size(); ++i) { contacts.get(i).setAccount(account); } @@ -575,7 +575,7 @@ public class XmppConnectionService extends Service { mWhere.append(account.getUuid()); mWhere.append("\""); List contactsToDelete = databaseBackend - .getContats(mWhere.toString()); + .getContacts(mWhere.toString()); for (Contact contact : contactsToDelete) { databaseBackend.deleteContact(contact); replaceContactInConversation(contact.getJid(), @@ -604,7 +604,7 @@ public class XmppConnectionService extends Service { public void onPhoneContactsLoaded( Hashtable phoneContacts) { List contacts = databaseBackend - .getContacts(null); + .getContactsByAccount(null); for (int i = 0; i < contacts.size(); ++i) { Contact contact = contacts.get(i); if (phoneContacts.containsKey(contact.getJid())) { @@ -938,6 +938,7 @@ public class XmppConnectionService extends Service { public void updateContact(Contact contact) { databaseBackend.updateContact(contact); + replaceContactInConversation(contact.getJid(), contact); } public void updateMessage(Message message) { @@ -1035,4 +1036,14 @@ public class XmppConnectionService extends Service { public void updateConversation(Conversation conversation) { this.databaseBackend.updateConversation(conversation); } + + public Contact findContact(String uuid) { + Contact contact = this.databaseBackend.getContact(uuid); + for(Account account : getAccounts()) { + if (contact.getAccountUuid().equals(account.getUuid())) { + contact.setAccount(account); + } + } + return contact; + } } \ No newline at end of file diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java new file mode 100644 index 000000000..23fb68a16 --- /dev/null +++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -0,0 +1,226 @@ +package eu.siacs.conversations.ui; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.provider.ContactsContract.CommonDataKinds; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Intents; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.QuickContactBadge; +import android.widget.TextView; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.Presences; +import eu.siacs.conversations.utils.UIHelper; + +public class ContactDetailsActivity extends XmppActivity { + public static final String ACTION_VIEW_CONTACT = "view_contact"; + + protected ContactDetailsActivity activity = this; + + private String uuid; + private Contact contact; + + private EditText name; + private TextView contactJid; + private TextView accountJid; + private TextView status; + private CheckBox send; + private CheckBox receive; + private QuickContactBadge badge; + + private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + activity.xmppConnectionService.deleteContact(contact); + activity.finish(); + } + }; + + private DialogInterface.OnClickListener editContactNameListener = new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + contact.setDisplayName(name.getText().toString()); + activity.xmppConnectionService.updateContact(contact); + populateView(); + } + }; + + private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.setType(Contacts.CONTENT_ITEM_TYPE); + intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid()); + intent.putExtra(Intents.Insert.IM_PROTOCOL, + CommonDataKinds.Im.PROTOCOL_JABBER); + intent.putExtra("finishActivityOnSaveCompleted", true); + activity.startActivityForResult(intent, 0); + } + }; + private OnClickListener onBadgeClick = new OnClickListener() { + + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle("Add to phone book"); + builder.setMessage("Do you want to add " + contact.getJid() + + " to your phones contact list?"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Add", addToPhonebook); + builder.create().show(); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) { + this.uuid = getIntent().getExtras().getString("uuid"); + } + setContentView(R.layout.activity_contact_details); + + contactJid = (TextView) findViewById(R.id.details_contactjid); + accountJid = (TextView) findViewById(R.id.details_account); + status = (TextView) findViewById(R.id.details_contactstatus); + send = (CheckBox) findViewById(R.id.details_send_presence); + receive = (CheckBox) findViewById(R.id.details_receive_presence); + badge = (QuickContactBadge) findViewById(R.id.details_contact_badge); + + getActionBar().setHomeButtonEnabled(true); + getActionBar().setDisplayHomeAsUpEnabled(true); + + } + + @Override + public boolean onOptionsItemSelected(MenuItem menuItem) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setNegativeButton("Cancel", null); + switch (menuItem.getItemId()) { + case android.R.id.home: + finish(); + break; + case R.id.action_delete_contact: + builder.setTitle("Delete from roster") + .setMessage(getString(R.string.remove_contact_text, contact.getJid())) + .setPositiveButton("Delete", removeFromRoster).create() + .show(); + break; + case R.id.action_edit_contact: + if (contact.getSystemAccount() == null) { + + View view = (View) getLayoutInflater().inflate(R.layout.edit_contact_name, null); + name = (EditText) view.findViewById(R.id.editText1); + name.setText(contact.getDisplayName()); + builder.setView(view) + .setTitle(contact.getJid()) + .setPositiveButton("Edit", editContactNameListener) + .create().show(); + + } else { + Intent intent = new Intent(Intent.ACTION_EDIT); + String[] systemAccount = contact.getSystemAccount().split("#"); + long id = Long.parseLong(systemAccount[0]); + Uri uri = Contacts.getLookupUri(id, systemAccount[1]); + intent.setDataAndType(uri,Contacts.CONTENT_ITEM_TYPE); + intent.putExtra("finishActivityOnSaveCompleted", true); + startActivity(intent); + } + break; + } + return super.onOptionsItemSelected(menuItem); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.contact_details, menu); + return true; + } + + private void populateView() { + setTitle(contact.getDisplayName()); + if (contact.getSubscriptionOption(Contact.Subscription.FROM)) { + send.setChecked(true); + } else { + send.setText("Preemptively grant subscription request"); + if (contact + .getSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT)) { + send.setChecked(true); + } else { + send.setChecked(false); + } + } + if (contact.getSubscriptionOption(Contact.Subscription.TO)) { + receive.setChecked(true); + } else { + receive.setText("Request presence updates"); + if (contact + .getSubscriptionOption(Contact.Subscription.ASKING)) { + receive.setChecked(true); + } else { + receive.setChecked(false); + } + } + + switch (contact.getMostAvailableStatus()) { + case Presences.CHAT: + status.setText("free to chat"); + status.setTextColor(0xFF83b600); + break; + case Presences.ONLINE: + status.setText("online"); + status.setTextColor(0xFF83b600); + break; + case Presences.AWAY: + status.setText("away"); + status.setTextColor(0xFFffa713); + break; + case Presences.XA: + status.setText("extended away"); + status.setTextColor(0xFFffa713); + break; + case Presences.DND: + status.setText("do not disturb"); + status.setTextColor(0xFFe92727); + break; + case Presences.OFFLINE: + status.setText("offline"); + status.setTextColor(0xFFe92727); + break; + default: + status.setText("offline"); + status.setTextColor(0xFFe92727); + break; + } + contactJid.setText(contact.getJid()); + accountJid.setText(contact.getAccount().getJid()); + + UIHelper.prepareContactBadge(this, badge, contact); + + if (contact.getSystemAccount() == null) { + badge.setOnClickListener(onBadgeClick); + } + } + + @Override + public void onBackendConnected() { + if (uuid != null) { + this.contact = xmppConnectionService.findContact(uuid); + if (this.contact != null) { + populateView(); + } + } + } + +} diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 4815957e3..d4d0e5655 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -162,9 +162,9 @@ public class ConversationActivity extends XmppActivity { } ((TextView) view.findViewById(R.id.conversation_lastupdate)) - .setText(UIHelper.readableTimeDifference(getItem(position).getLatestMessage().getTimeSent())); + .setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent())); - Uri profilePhoto = getItem(position).getProfilePhotoUri(); + Uri profilePhoto = conv.getProfilePhotoUri(); ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image); if (profilePhoto!=null) { imageView.setImageURI(profilePhoto); @@ -272,12 +272,6 @@ public class ConversationActivity extends XmppActivity { case android.R.id.home: spl.openPane(); break; - case R.id.action_settings: - startActivity(new Intent(this, SettingsActivity.class)); - break; - case R.id.action_accounts: - startActivity(new Intent(this, ManageAccountActivity.class)); - break; case R.id.action_add: startActivity(new Intent(this, NewConversationActivity.class)); break; @@ -290,12 +284,12 @@ public class ConversationActivity extends XmppActivity { selectedConversation = conversationList.get(0); break; case R.id.action_contact_details: - DialogContactDetails details = new DialogContactDetails(); Contact contact = this.getSelectedConversation().getContact(); if (contact != null) { - contact.setAccount(this.selectedConversation.getAccount()); - details.setContact(contact); - details.show(getFragmentManager(), "details"); + Intent intent = new Intent(this,ContactDetailsActivity.class); + intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); + intent.putExtra("uuid", contact.getUuid()); + startActivity(intent); } else { String jid = getSelectedConversation().getContactJid(); AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -307,8 +301,8 @@ public class ConversationActivity extends XmppActivity { } break; case R.id.action_muc_details: - Intent intent = new Intent(this,MucOptionsActivity.class); - intent.setAction(MucOptionsActivity.ACTION_VIEW_MUC); + Intent intent = new Intent(this,MucDetailsActivity.class); + intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); intent.putExtra("uuid", getSelectedConversation().getUuid()); startActivity(intent); break; diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index b64fe5b2b..6c88fcb39 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -109,8 +109,8 @@ public class ConversationFragment extends Fragment { @Override public void onClick(View v) { - Intent intent = new Intent(getActivity(),MucOptionsActivity.class); - intent.setAction(MucOptionsActivity.ACTION_VIEW_MUC); + Intent intent = new Intent(getActivity(),MucDetailsActivity.class); + intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); intent.putExtra("uuid", conversation.getUuid()); startActivity(intent); } diff --git a/src/eu/siacs/conversations/ui/DialogContactDetails.java b/src/eu/siacs/conversations/ui/DialogContactDetails.java deleted file mode 100644 index 1210bc3cb..000000000 --- a/src/eu/siacs/conversations/ui/DialogContactDetails.java +++ /dev/null @@ -1,218 +0,0 @@ -package eu.siacs.conversations.ui; - -import eu.siacs.conversations.R; -import eu.siacs.conversations.entities.Contact; -import eu.siacs.conversations.entities.Presences; -import eu.siacs.conversations.utils.UIHelper; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.provider.ContactsContract.CommonDataKinds; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.Intents; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.QuickContactBadge; -import android.widget.TextView; - -public class DialogContactDetails extends DialogFragment { - - private Contact contact = null; - boolean displayingInRoster = false; - - private DialogContactDetails mDetailsDialog = this; - private XmppActivity activity; - - private CheckBox send; - private CheckBox receive; - - private DialogInterface.OnClickListener askRemoveFromRoster = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle("Delete from roster"); - builder.setMessage("Do you want to delete "+contact.getJid()+" from your roster. The conversation assoziated with this account will not be removed."); - builder.setNegativeButton("Cancel", null); - builder.setPositiveButton("Delete",removeFromRoster); - builder.create().show(); - } - }; - - private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - activity.xmppConnectionService.deleteContact(contact); - mDetailsDialog.dismiss(); - } - }; - - private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); - intent.setType(Contacts.CONTENT_ITEM_TYPE); - intent.putExtra(Intents.Insert.IM_HANDLE,contact.getJid()); - intent.putExtra(Intents.Insert.IM_PROTOCOL,CommonDataKinds.Im.PROTOCOL_JABBER); - intent.putExtra("finishActivityOnSaveCompleted", true); - getActivity().startActivityForResult(intent,0); - mDetailsDialog.dismiss(); - } - }; - - private DialogInterface.OnClickListener updateSubscriptions = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - boolean needsUpdating = false; - if (contact.getSubscriptionOption(Contact.Subscription.FROM)) { - if (!send.isChecked()) { - contact.resetSubscriptionOption(Contact.Subscription.FROM); - contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT); - activity.xmppConnectionService.stopPresenceUpdatesTo(contact); - needsUpdating=true; - } - } else { - if (contact.getSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT)) { - if (!send.isChecked()) { - contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT); - needsUpdating=true; - } - } else { - if (send.isChecked()) { - contact.setSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT); - needsUpdating=true; - } - } - } - if (contact.getSubscriptionOption(Contact.Subscription.TO)) { - if (!receive.isChecked()) { - contact.resetSubscriptionOption(Contact.Subscription.TO); - activity.xmppConnectionService.stopPresenceUpdatesFrom(contact); - needsUpdating=true; - } - } else { - if (contact.getSubscriptionOption(Contact.Subscription.ASKING)) { - if (!receive.isChecked()) { - contact.resetSubscriptionOption(Contact.Subscription.ASKING); - activity.xmppConnectionService.stopPresenceUpdatesFrom(contact); - needsUpdating=true; - } - } else { - if (receive.isChecked()) { - contact.setSubscriptionOption(Contact.Subscription.ASKING); - activity.xmppConnectionService.requestPresenceUpdatesFrom(contact); - needsUpdating=true; - } - } - } - if (needsUpdating) { - activity.xmppConnectionService.updateContact(contact); - } - } - }; - - public void setContact(Contact contact) { - this.contact = contact; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - this.activity = (XmppActivity) getActivity(); - AlertDialog.Builder builder = new AlertDialog.Builder(this.activity); - LayoutInflater inflater = getActivity().getLayoutInflater(); - View view = inflater.inflate(R.layout.dialog_contact_details, null); - TextView contactJid = (TextView) view.findViewById(R.id.details_contactjid); - TextView accountJid = (TextView) view.findViewById(R.id.details_account); - TextView status = (TextView) view.findViewById(R.id.details_contactstatus); - send = (CheckBox) view.findViewById(R.id.details_send_presence); - receive = (CheckBox) view.findViewById(R.id.details_receive_presence); - //ImageView contactPhoto = (ImageView) view.findViewById(R.id.details_contact_picture); - QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.details_contact_badge); - - if (contact.getSubscriptionOption(Contact.Subscription.FROM)) { - send.setChecked(true); - } else { - send.setText("Preemptively grant subscription request"); - if (contact.getSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT)) { - send.setChecked(true); - } else { - send.setChecked(false); - } - } - if (contact.getSubscriptionOption(Contact.Subscription.TO)) { - receive.setChecked(true); - } else { - receive.setText("Request presence updates"); - if (contact.getSubscriptionOption(Contact.Subscription.ASKING)) { - receive.setChecked(true); - } else { - receive.setChecked(false); - } - } - - switch (contact.getMostAvailableStatus()) { - case Presences.CHAT: - status.setText("free to chat"); - status.setTextColor(0xFF83b600); - break; - case Presences.ONLINE: - status.setText("online"); - status.setTextColor(0xFF83b600); - break; - case Presences.AWAY: - status.setText("away"); - status.setTextColor(0xFFffa713); - break; - case Presences.XA: - status.setText("extended away"); - status.setTextColor(0xFFffa713); - break; - case Presences.DND: - status.setText("do not disturb"); - status.setTextColor(0xFFe92727); - break; - case Presences.OFFLINE: - status.setText("offline"); - status.setTextColor(0xFFe92727); - break; - default: - status.setText("offline"); - status.setTextColor(0xFFe92727); - break; - } - contactJid.setText(contact.getJid()); - accountJid.setText(contact.getAccount().getJid()); - - UIHelper.prepareContactBadge(getActivity(), badge, contact); - - if (contact.getSystemAccount()==null) { - badge.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle("Add to phone book"); - builder.setMessage("Do you want to add "+contact.getJid()+" to your phones contact list?"); - builder.setNegativeButton("Cancel", null); - builder.setPositiveButton("Add",addToPhonebook); - builder.create().show(); - } - }); - } - - builder.setView(view); - builder.setTitle(contact.getDisplayName()); - - builder.setNeutralButton("Done", this.updateSubscriptions); - builder.setPositiveButton("Remove from roster", this.askRemoveFromRoster); - return builder.create(); - } -} diff --git a/src/eu/siacs/conversations/ui/MucOptionsActivity.java b/src/eu/siacs/conversations/ui/MucDetailsActivity.java similarity index 88% rename from src/eu/siacs/conversations/ui/MucOptionsActivity.java rename to src/eu/siacs/conversations/ui/MucDetailsActivity.java index 4381eac4c..f28fb480b 100644 --- a/src/eu/siacs/conversations/ui/MucOptionsActivity.java +++ b/src/eu/siacs/conversations/ui/MucDetailsActivity.java @@ -12,6 +12,8 @@ import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; @@ -22,15 +24,13 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -public class MucOptionsActivity extends XmppActivity { +public class MucDetailsActivity extends XmppActivity { public static final String ACTION_VIEW_MUC = "view_muc"; - private XmppActivity activity = this; private Conversation conversation; private EditText mYourNick; private TextView mRoleAffiliaton; private TextView mFullJid; private LinearLayout membersView; - private TextView mTextParticipantsHead; private LinearLayout mMoreDetails; private String uuid = null; private ArrayAdapter contactsAdapter; @@ -56,9 +56,8 @@ public class MucOptionsActivity extends XmppActivity { if (getIntent().getAction().equals(ACTION_VIEW_MUC)) { this.uuid = getIntent().getExtras().getString("uuid"); } - setContentView(R.layout.muc_options); + setContentView(R.layout.activity_muc_details); mYourNick = (EditText) findViewById(R.id.muc_your_nick); - mTextParticipantsHead = (TextView) findViewById(R.id.muc_participants_header); mFullJid = (TextView) findViewById(R.id.muc_jabberid); ImageButton imageButton = (ImageButton) findViewById(R.id.muc_edit_nick); imageButton.setOnClickListener(this.changeNickListener); @@ -86,10 +85,18 @@ public class MucOptionsActivity extends XmppActivity { return view; } }; + getActionBar().setHomeButtonEnabled(true); + getActionBar().setDisplayHomeAsUpEnabled(true); + } - - public void setConversation(Conversation conversation) { - this.conversation = conversation; + + @Override + public boolean onOptionsItemSelected(MenuItem menuItem) { + switch (menuItem.getItemId()) { + case android.R.id.home: + finish(); + } + return super.onOptionsItemSelected(menuItem); } public String getReadableRole(int role) { @@ -104,6 +111,12 @@ public class MucOptionsActivity extends XmppActivity { return ""; } } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.muc_details, menu); + return true; + } @Override void onBackendConnected() { @@ -114,6 +127,7 @@ public class MucOptionsActivity extends XmppActivity { } } if (this.conversation != null) { + setTitle(conversation.getName()); mFullJid.setText(conversation.getContactJid().split("/")[0]); mYourNick.setText(conversation.getMucOptions().getNick()); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); @@ -139,6 +153,7 @@ public class MucOptionsActivity extends XmppActivity { this.users.addAll(conversation.getMucOptions().getUsers()); contactsAdapter.notifyDataSetChanged(); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + membersView.removeAllViews(); for(User contact : conversation.getMucOptions().getUsers()) { View view = (View) inflater.inflate(R.layout.contact, null); diff --git a/src/eu/siacs/conversations/ui/NewConversationActivity.java b/src/eu/siacs/conversations/ui/NewConversationActivity.java index 628a30479..4b323c267 100644 --- a/src/eu/siacs/conversations/ui/NewConversationActivity.java +++ b/src/eu/siacs/conversations/ui/NewConversationActivity.java @@ -39,7 +39,6 @@ import android.content.Intent; public class NewConversationActivity extends XmppActivity { - protected List phoneContacts = new ArrayList(); protected List rosterContacts = new ArrayList(); protected List aggregatedContacts = new ArrayList(); protected ListView contactsView; @@ -188,10 +187,10 @@ public class NewConversationActivity extends XmppActivity { @Override public boolean onItemLongClick(AdapterView arg0, View arg1, int pos, long arg3) { - Contact clickedContact = aggregatedContacts.get(pos); - DialogContactDetails dialog = new DialogContactDetails(); - dialog.setContact(clickedContact); - dialog.show(getFragmentManager(), "details"); + Intent intent = new Intent(activity,ContactDetailsActivity.class); + intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); + intent.putExtra("uuid", aggregatedContacts.get(pos).getUuid()); + startActivity(intent); return true; } }); @@ -278,12 +277,6 @@ public class NewConversationActivity extends XmppActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.action_settings: - startActivity(new Intent(this, SettingsActivity.class)); - break; - case R.id.action_accounts: - startActivity(new Intent(this, ManageAccountActivity.class)); - break; case R.id.action_refresh_contacts: refreshContacts(); break; diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 6b1d12891..a2951c65a 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.ui; +import eu.siacs.conversations.R; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import android.app.Activity; @@ -10,6 +11,7 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; +import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -79,4 +81,16 @@ public abstract class XmppActivity extends Activity { } abstract void onBackendConnected(); + + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_settings: + startActivity(new Intent(this, SettingsActivity.class)); + break; + case R.id.action_accounts: + startActivity(new Intent(this, ManageAccountActivity.class)); + break; + } + return super.onOptionsItemSelected(item); + } }