diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-20 17:00:50 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-20 17:00:50 +0100 |
commit | c82179c0b8728a9c2cd567d4227c60c758a1e682 (patch) | |
tree | b866a099bb79225bf31a6498374f24f757af163e /src/de/gultsch/chat/ui | |
parent | 94ab61d5c0b060e2aea5caf58ac06864f980956b (diff) |
adding and removing roster items now possible. basic error display on error messages
Diffstat (limited to '')
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationActivity.java | 23 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationFragment.java | 97 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/DialogContactDetails.java | 65 |
3 files changed, 121 insertions, 64 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index 464054ad..f9a924ec 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -7,15 +7,18 @@ import java.util.List; import de.gultsch.chat.R; import de.gultsch.chat.R.id; +import de.gultsch.chat.entities.Account; import de.gultsch.chat.entities.Contact; import de.gultsch.chat.entities.Conversation; import de.gultsch.chat.entities.Message; import de.gultsch.chat.utils.UIHelper; import android.net.Uri; import android.os.Bundle; +import android.app.AlertDialog; import android.app.FragmentTransaction; import android.app.NotificationManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Typeface; import android.support.v4.widget.SlidingPaneLayout; @@ -82,6 +85,18 @@ public class ConversationActivity extends XmppActivity { }); } }; + + private DialogInterface.OnClickListener addToRoster = new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String jid = getSelectedConversation().getContactJid(); + Account account = getSelectedConversation().getAccount(); + String name = jid.split("@")[0]; + Contact contact = new Contact(account, name, jid, null); + xmppConnectionService.createContact(contact); + } + }; private boolean contactInserted = false; @@ -288,7 +303,13 @@ public class ConversationActivity extends XmppActivity { details.setContact(contact); details.show(getFragmentManager(), "details"); } else { - Log.d("xmppService","contact was null - means not in roster"); + String jid = getSelectedConversation().getContactJid(); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(jid); + builder.setMessage("The contact is not in your roster. Would you like to add it."); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Add",addToRoster); + builder.create().show(); } break; case R.id.action_security: diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index 0d2116e6..1770e7bd 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -8,6 +8,8 @@ import java.util.Hashtable; import java.util.List; import java.util.Set; +import javax.crypto.spec.PSource; + import net.java.otr4j.OtrException; import net.java.otr4j.session.SessionStatus; @@ -53,6 +55,8 @@ public class ConversationFragment extends Fragment { protected BitmapCache mBitmapCache = new BitmapCache(); private EditText chatMsg; + + protected Bitmap selfBitmap; private OnClickListener sendMsgListener = new OnClickListener() { @@ -105,47 +109,26 @@ public class ConversationFragment extends Fragment { sendButton.setOnClickListener(this.sendMsgListener); messagesView = (ListView) view.findViewById(R.id.messages_view); - - SharedPreferences sharedPref = PreferenceManager - .getDefaultSharedPreferences(getActivity() - .getApplicationContext()); - boolean showPhoneSelfContactPicture = sharedPref.getBoolean( - "show_phone_selfcontact_picture", true); - - Bitmap self; - - if (showPhoneSelfContactPicture) { - Uri selfiUri = PhoneHelper.getSefliUri(getActivity()); - try { - self = BitmapFactory.decodeStream(getActivity() - .getContentResolver().openInputStream(selfiUri)); - } catch (FileNotFoundException e) { - self = UIHelper.getUnknownContactPicture(conversation - .getAccount().getJid(), 200); - } - } else { - self = UIHelper.getUnknownContactPicture(conversation.getAccount() - .getJid(), 200); - } - - final Bitmap selfBitmap = self; - + messageListAdapter = new ArrayAdapter<Message>(this.getActivity() .getApplicationContext(), R.layout.message_sent, this.messageList) { private static final int SENT = 0; private static final int RECIEVED = 1; + private static final int ERROR = 2; @Override public int getViewTypeCount() { - return 2; + return 3; } @Override public int getItemViewType(int position) { if (getItem(position).getStatus() == Message.STATUS_RECIEVED) { return RECIEVED; + } else if (getItem(position).getStatus() == Message.STATUS_ERROR) { + return ERROR; } else { return SENT; } @@ -167,7 +150,6 @@ public class ConversationFragment extends Fragment { viewHolder.imageView.setImageBitmap(selfBitmap); break; case RECIEVED: - viewHolder = new ViewHolder(); view = (View) inflater.inflate( R.layout.message_recieved, null); viewHolder.imageView = (ImageView) view @@ -185,6 +167,12 @@ public class ConversationFragment extends Fragment { } } break; + case ERROR: + view = (View) inflater.inflate(R.layout.message_error, null); + viewHolder.imageView = (ImageView) view + .findViewById(R.id.message_photo); + viewHolder.imageView.setImageBitmap(mBitmapCache.getError()); + break; default: viewHolder = null; break; @@ -193,7 +181,6 @@ public class ConversationFragment extends Fragment { .findViewById(R.id.message_body); viewHolder.time = (TextView) view .findViewById(R.id.message_time); - view.setTag(viewHolder); } else { viewHolder = (ViewHolder) view.getTag(); @@ -238,31 +225,47 @@ public class ConversationFragment extends Fragment { return view; } + protected Bitmap findSelfPicture() { + SharedPreferences sharedPref = PreferenceManager + .getDefaultSharedPreferences(getActivity() + .getApplicationContext()); + boolean showPhoneSelfContactPicture = sharedPref.getBoolean( + "show_phone_selfcontact_picture", true); + + Bitmap self; + + if (showPhoneSelfContactPicture) { + Uri selfiUri = PhoneHelper.getSefliUri(getActivity()); + try { + self = BitmapFactory.decodeStream(getActivity() + .getContentResolver().openInputStream(selfiUri)); + } catch (FileNotFoundException e) { + self = UIHelper.getUnknownContactPicture(conversation + .getAccount().getJid(), 200); + } + } else { + self = UIHelper.getUnknownContactPicture(conversation.getAccount() + .getJid(), 200); + } + + final Bitmap selfBitmap = self; + return selfBitmap; + } + @Override public void onStart() { super.onStart(); - final ConversationActivity activity = (ConversationActivity) getActivity(); + ConversationActivity activity = (ConversationActivity) getActivity(); if (activity.xmppConnectionServiceBound) { - this.conversation = activity.getSelectedConversation(); - updateMessages(); - // rendering complete. now go tell activity to close pane - if (!activity.shouldPaneBeOpen()) { - activity.getSlidingPaneLayout().closePane(); - activity.getActionBar().setDisplayHomeAsUpEnabled(true); - activity.getActionBar().setTitle(conversation.getName()); - activity.invalidateOptionsMenu(); - if (!conversation.isRead()) { - conversation.markRead(); - activity.updateConversationList(); - } - } + this.onBackendConnected(); } } public void onBackendConnected() { final ConversationActivity activity = (ConversationActivity) getActivity(); this.conversation = activity.getSelectedConversation(); + this.selfBitmap = findSelfPicture(); updateMessages(); // rendering complete. now go tell activity to close pane if (!activity.shouldPaneBeOpen()) { @@ -353,7 +356,7 @@ public class ConversationFragment extends Fragment { } else { presences = null; } - if ((presences != null) && (presences.size() == 0)) { + if ((presences == null) || (presences.size() == 0)) { AlertDialog.Builder builder = new AlertDialog.Builder( getActivity()); builder.setTitle("Contact is offline"); @@ -412,6 +415,7 @@ public class ConversationFragment extends Fragment { private class BitmapCache { private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>(); + private Bitmap error = null; public Bitmap get(String name, Uri uri) { if (bitmaps.containsKey(name)) { @@ -432,5 +436,12 @@ public class ConversationFragment extends Fragment { return bm; } } + + public Bitmap getError() { + if (error == null) { + error = UIHelper.getErrorPicture(200); + } + return error; + } } } diff --git a/src/de/gultsch/chat/ui/DialogContactDetails.java b/src/de/gultsch/chat/ui/DialogContactDetails.java index 88bded87..20be4b39 100644 --- a/src/de/gultsch/chat/ui/DialogContactDetails.java +++ b/src/de/gultsch/chat/ui/DialogContactDetails.java @@ -9,7 +9,6 @@ import android.app.Dialog; import android.app.DialogFragment; 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; @@ -18,7 +17,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; -import android.widget.ImageView; import android.widget.QuickContactBadge; import android.widget.TextView; @@ -27,13 +25,53 @@ public class DialogContactDetails extends DialogFragment { private Contact contact = null; boolean displayingInRoster = false; + private DialogContactDetails mDetailsDialog = this; + private XmppActivity activity; + + 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,ConversationActivity.INSERT_CONTACT); + mDetailsDialog.dismiss(); + } + }; + public void setContact(Contact contact) { this.contact = contact; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + 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); @@ -96,28 +134,15 @@ public class DialogContactDetails extends DialogFragment { UIHelper.prepareContactBadge(getActivity(), badge, contact); if (contact.getSystemAccount()==null) { - final DialogContactDetails details = this; badge.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle("Add to contacts"); - builder.setMessage("Do you want to add "+contact.getJid()+" to your contact list?"); + 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", 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,ConversationActivity.INSERT_CONTACT); - details.dismiss(); - } - }); + builder.setPositiveButton("Add",addToPhonebook); builder.create().show(); } }); @@ -127,7 +152,7 @@ public class DialogContactDetails extends DialogFragment { builder.setTitle(contact.getDisplayName()); builder.setNeutralButton("Done", null); - builder.setPositiveButton("Remove from roster", null); + builder.setPositiveButton("Remove from roster", this.askRemoveFromRoster); return builder.create(); } } |