diff options
Diffstat (limited to 'src/eu/siacs/conversations/ui')
7 files changed, 334 insertions, 174 deletions
diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java index 5dc6eb3b..1ed3fa13 100644 --- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -227,10 +227,14 @@ public class ContactDetailsActivity extends XmppActivity { status.setTextColor(0xFFe92727); break; } - contactJid.setText(contact.getJid()); + if (contact.getPresences().size() > 1) { + contactJid.setText(contact.getJid()+" ("+contact.getPresences().size()+")"); + } else { + contactJid.setText(contact.getJid()); + } accountJid.setText(contact.getAccount().getJid()); - UIHelper.prepareContactBadge(this, badge, contact); + UIHelper.prepareContactBadge(this, badge, contact, getApplicationContext()); if (contact.getSystemAccount() == null) { badge.setOnClickListener(onBadgeClick); diff --git a/src/eu/siacs/conversations/ui/ContactsActivity.java b/src/eu/siacs/conversations/ui/ContactsActivity.java index 2e9e55f5..e403450a 100644 --- a/src/eu/siacs/conversations/ui/ContactsActivity.java +++ b/src/eu/siacs/conversations/ui/ContactsActivity.java @@ -381,8 +381,7 @@ public class ContactsActivity extends XmppActivity { contactJid.setText(contact.getJid()); ImageView imageView = (ImageView) view .findViewById(R.id.contact_photo); - imageView.setImageBitmap(UIHelper.getContactPicture(contact, - null, 90, this.getContext())); + imageView.setImageBitmap(UIHelper.getContactPicture(contact, 48, this.getContext(), false)); return view; } }; diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index f47e8a8c..6e56d2b3 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui; import java.util.ArrayList; +import java.util.Hashtable; import java.util.List; import eu.siacs.conversations.R; @@ -13,16 +14,17 @@ import eu.siacs.conversations.utils.UIHelper; import android.os.Bundle; import android.preference.PreferenceManager; import android.app.AlertDialog; +import android.app.AlertDialog.Builder; import android.app.FragmentTransaction; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.Typeface; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; -import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -43,39 +45,43 @@ public class ConversationActivity extends XmppActivity { public static final String VIEW_CONVERSATION = "viewConversation"; public static final String CONVERSATION = "conversationUuid"; public static final String TEXT = "text"; - + public static final String PRESENCE = "eu.siacs.conversations.presence"; + public static final int REQUEST_SEND_MESSAGE = 0x75441; public static final int REQUEST_DECRYPT_PGP = 0x76783; + private static final int ATTACH_FILE = 0x48502; protected SlidingPaneLayout spl; private List<Conversation> conversationList = new ArrayList<Conversation>(); private Conversation selectedConversation = null; private ListView listView; - + private boolean paneShouldBeOpen = true; private boolean useSubject = true; private ArrayAdapter<Conversation> listAdapter; - + private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() { - + @Override public void onConversationListChanged() { runOnUiThread(new Runnable() { - + @Override - public void run() { + public void run() { updateConversationList(); - if(paneShouldBeOpen) { + if (paneShouldBeOpen) { if (conversationList.size() >= 1) { swapConversationFragment(); } else { - startActivity(new Intent(getApplicationContext(), ContactsActivity.class)); + startActivity(new Intent(getApplicationContext(), + ContactsActivity.class)); finish(); } } - ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); - if (selectedFragment!=null) { + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment != null) { selectedFragment.updateMessages(); } } @@ -83,19 +89,8 @@ 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); - } - }; protected ConversationActivity activity = this; - + public List<Conversation> getConversationList() { return this.conversationList; } @@ -103,19 +98,19 @@ public class ConversationActivity extends XmppActivity { public Conversation getSelectedConversation() { return this.selectedConversation; } - + public ListView getConversationListView() { return this.listView; } - + public SlidingPaneLayout getSlidingPaneLayout() { return this.spl; } - + public boolean shouldPaneBeOpen() { return paneShouldBeOpen; } - + @Override protected void onCreate(Bundle savedInstanceState) { @@ -141,7 +136,7 @@ public class ConversationActivity extends XmppActivity { return view; } if (!spl.isSlideable()) { - if (conv==getSelectedConversation()) { + if (conv == getSelectedConversation()) { view.setBackgroundColor(0xffdddddd); } else { view.setBackgroundColor(Color.TRANSPARENT); @@ -149,29 +144,34 @@ public class ConversationActivity extends XmppActivity { } else { view.setBackgroundColor(Color.TRANSPARENT); } - TextView convName = (TextView) view.findViewById(R.id.conversation_name); + TextView convName = (TextView) view + .findViewById(R.id.conversation_name); convName.setText(conv.getName(useSubject)); - TextView convLastMsg = (TextView) view.findViewById(R.id.conversation_lastmsg); + TextView convLastMsg = (TextView) view + .findViewById(R.id.conversation_lastmsg); convLastMsg.setText(conv.getLatestMessage().getBody()); - - if(!conv.isRead()) { - convName.setTypeface(null,Typeface.BOLD); - convLastMsg.setTypeface(null,Typeface.BOLD); + + if (!conv.isRead()) { + convName.setTypeface(null, Typeface.BOLD); + convLastMsg.setTypeface(null, Typeface.BOLD); } else { - convName.setTypeface(null,Typeface.NORMAL); - convLastMsg.setTypeface(null,Typeface.NORMAL); + convName.setTypeface(null, Typeface.NORMAL); + convLastMsg.setTypeface(null, Typeface.NORMAL); } - + ((TextView) view.findViewById(R.id.conversation_lastupdate)) - .setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent())); - - ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image); - imageView.setImageBitmap(UIHelper.getContactPicture(conv.getContact(), conv.getName(useSubject),200, activity.getApplicationContext())); + .setText(UIHelper.readableTimeDifference(conv + .getLatestMessage().getTimeSent())); + + ImageView imageView = (ImageView) view + .findViewById(R.id.conversation_image); + imageView.setImageBitmap(UIHelper.getContactPicture( + conv, 56, activity.getApplicationContext(), false)); return view; } }; - + listView.setAdapter(this.listAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @@ -182,7 +182,7 @@ public class ConversationActivity extends XmppActivity { paneShouldBeOpen = false; if (selectedConversation != conversationList.get(position)) { selectedConversation = conversationList.get(position); - swapConversationFragment(); //.onBackendConnected(conversationList.get(position)); + swapConversationFragment(); // .onBackendConnected(conversationList.get(position)); } else { spl.closePane(); } @@ -206,13 +206,16 @@ public class ConversationActivity extends XmppActivity { @Override public void onPanelClosed(View arg0) { paneShouldBeOpen = false; - if ((conversationList.size() > 0)&&(getSelectedConversation()!=null)) { + if ((conversationList.size() > 0) + && (getSelectedConversation() != null)) { getActionBar().setDisplayHomeAsUpEnabled(true); - getActionBar().setTitle(getSelectedConversation().getName(useSubject)); + getActionBar().setTitle( + getSelectedConversation().getName(useSubject)); invalidateOptionsMenu(); if (!getSelectedConversation().isRead()) { getSelectedConversation().markRead(); - UIHelper.updateNotification(getApplicationContext(), getConversationList(), null, false); + UIHelper.updateNotification(getApplicationContext(), + getConversationList(), null, false); listView.invalidateViews(); } } @@ -231,29 +234,36 @@ public class ConversationActivity extends XmppActivity { getMenuInflater().inflate(R.menu.conversations, menu); MenuItem menuSecure = (MenuItem) menu.findItem(R.id.action_security); MenuItem menuArchive = (MenuItem) menu.findItem(R.id.action_archive); - MenuItem menuMucDetails = (MenuItem) menu.findItem(R.id.action_muc_details); - MenuItem menuContactDetails = (MenuItem) menu.findItem(R.id.action_contact_details); - MenuItem menuInviteContacts = (MenuItem) menu.findItem(R.id.action_invite); - - if ((spl.isOpen()&&(spl.isSlideable()))) { + MenuItem menuMucDetails = (MenuItem) menu + .findItem(R.id.action_muc_details); + MenuItem menuContactDetails = (MenuItem) menu + .findItem(R.id.action_contact_details); + MenuItem menuInviteContacts = (MenuItem) menu + .findItem(R.id.action_invite); + MenuItem menuAttach = (MenuItem) menu.findItem(R.id.action_attach_file); + MenuItem menuClearHistory = (MenuItem) menu.findItem(R.id.action_clear_history); + + if ((spl.isOpen() && (spl.isSlideable()))) { menuArchive.setVisible(false); menuMucDetails.setVisible(false); menuContactDetails.setVisible(false); menuSecure.setVisible(false); menuInviteContacts.setVisible(false); + menuAttach.setVisible(false); + menuClearHistory.setVisible(false); } else { - ((MenuItem) menu.findItem(R.id.action_add)).setVisible(!spl.isSlideable()); - if (this.getSelectedConversation()!=null) { + ((MenuItem) menu.findItem(R.id.action_add)).setVisible(!spl + .isSlideable()); + if (this.getSelectedConversation() != null) { if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) { - menuMucDetails.setVisible(true); menuContactDetails.setVisible(false); menuSecure.setVisible(false); - menuInviteContacts.setVisible(true); + menuAttach.setVisible(false); } else { - menuContactDetails.setVisible(true); menuMucDetails.setVisible(false); menuInviteContacts.setVisible(false); - if (this.getSelectedConversation().getLatestMessage().getEncryption() != Message.ENCRYPTION_NONE) { + if (this.getSelectedConversation().getLatestMessage() + .getEncryption() != Message.ENCRYPTION_NONE) { menuSecure.setIcon(R.drawable.ic_action_secure); } } @@ -268,6 +278,21 @@ public class ConversationActivity extends XmppActivity { case android.R.id.home: spl.openPane(); break; + case R.id.action_attach_file: + selectPresence(getSelectedConversation(), new OnPresenceSelected() { + + @Override + public void onPresenceSelected(boolean success, String presence) { + if (success) { + Intent attachFileIntent = new Intent(); + attachFileIntent.setType("image/*"); + attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); + Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); + startActivityForResult(chooser, ATTACH_FILE); + } + } + }); + break; case R.id.action_add: startActivity(new Intent(this, ContactsActivity.class)); break; @@ -286,22 +311,16 @@ public class ConversationActivity extends XmppActivity { case R.id.action_contact_details: Contact contact = this.getSelectedConversation().getContact(); if (contact != null) { - Intent intent = new Intent(this,ContactDetailsActivity.class); + 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); - 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(); + showAddToRosterDialog(getSelectedConversation()); } break; case R.id.action_muc_details: - Intent intent = new Intent(this,MucDetailsActivity.class); + Intent intent = new Intent(this, MucDetailsActivity.class); intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); intent.putExtra("uuid", getSelectedConversation().getUuid()); startActivity(intent); @@ -310,17 +329,18 @@ public class ConversationActivity extends XmppActivity { Intent inviteIntent = new Intent(getApplicationContext(), ContactsActivity.class); inviteIntent.setAction("invite"); - inviteIntent.putExtra("uuid",selectedConversation.getUuid()); + inviteIntent.putExtra("uuid", selectedConversation.getUuid()); startActivity(inviteIntent); break; case R.id.action_security: final Conversation selConv = getSelectedConversation(); View menuItemView = findViewById(R.id.action_security); PopupMenu popup = new PopupMenu(this, menuItemView); - final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); - if (fragment!=null) { + final ConversationFragment fragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (fragment != null) { popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { - + @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { @@ -344,40 +364,66 @@ public class ConversationActivity extends XmppActivity { return true; } }); - popup.inflate(R.menu.encryption_choices); - switch (selConv.nextMessageEncryption) { + popup.inflate(R.menu.encryption_choices); + switch (selConv.nextMessageEncryption) { case Message.ENCRYPTION_NONE: - popup.getMenu().findItem(R.id.encryption_choice_none).setChecked(true); + popup.getMenu().findItem(R.id.encryption_choice_none) + .setChecked(true); break; case Message.ENCRYPTION_OTR: - popup.getMenu().findItem(R.id.encryption_choice_otr).setChecked(true); + popup.getMenu().findItem(R.id.encryption_choice_otr) + .setChecked(true); break; case Message.ENCRYPTION_PGP: - popup.getMenu().findItem(R.id.encryption_choice_pgp).setChecked(true); + popup.getMenu().findItem(R.id.encryption_choice_pgp) + .setChecked(true); break; case Message.ENCRYPTION_DECRYPTED: - popup.getMenu().findItem(R.id.encryption_choice_pgp).setChecked(true); + popup.getMenu().findItem(R.id.encryption_choice_pgp) + .setChecked(true); break; default: - popup.getMenu().findItem(R.id.encryption_choice_none).setChecked(true); + popup.getMenu().findItem(R.id.encryption_choice_none) + .setChecked(true); break; } - popup.show(); - } + popup.show(); + } break; + case R.id.action_clear_history: + clearHistoryDialog(getSelectedConversation()); + break; default: break; } return super.onOptionsItemSelected(item); } + + protected void clearHistoryDialog(Conversation conversation) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.clear_conversation_history)); + View dialogView = getLayoutInflater().inflate(R.layout.dialog_clear_history, null); + builder.setView(dialogView); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.setPositiveButton(getString(R.string.delete_messages), new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub + + } + }); + builder.create().show(); + } protected ConversationFragment swapConversationFragment() { ConversationFragment selectedFragment = new ConversationFragment(); - + FragmentTransaction transaction = getFragmentManager() .beginTransaction(); - transaction.replace(R.id.selected_conversation, selectedFragment,"conversation"); + transaction.replace(R.id.selected_conversation, selectedFragment, + "conversation"); transaction.commit(); return selectedFragment; } @@ -392,24 +438,25 @@ public class ConversationActivity extends XmppActivity { } return super.onKeyDown(keyCode, event); } - + @Override public void onStart() { super.onStart(); - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(this); this.useSubject = preferences.getBoolean("use_subject_in_muc", true); if (this.xmppConnectionServiceBound) { this.onBackendConnected(); } - if (conversationList.size()>=1) { + if (conversationList.size() >= 1) { onConvChanged.onConversationListChanged(); } } - + @Override protected void onStop() { if (xmppConnectionServiceBound) { - xmppConnectionService.removeOnConversationListChangedListener(); + xmppConnectionService.removeOnConversationListChangedListener(); } super.onStop(); } @@ -417,18 +464,20 @@ public class ConversationActivity extends XmppActivity { @Override void onBackendConnected() { this.registerListener(); - if (conversationList.size()==0) { + if (conversationList.size() == 0) { updateConversationList(); } - if ((getIntent().getAction()!=null)&&(getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { + if ((getIntent().getAction() != null) + && (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { if (getIntent().getType().equals( ConversationActivity.VIEW_CONVERSATION)) { handledViewIntent = true; - String convToView = (String) getIntent().getExtras().get(CONVERSATION); + String convToView = (String) getIntent().getExtras().get( + CONVERSATION); - for(int i = 0; i < conversationList.size(); ++i) { + for (int i = 0; i < conversationList.size(); ++i) { if (conversationList.get(i).getUuid().equals(convToView)) { selectedConversation = conversationList.get(i); } @@ -442,46 +491,108 @@ public class ConversationActivity extends XmppActivity { startActivity(new Intent(this, ManageAccountActivity.class)); finish(); } else if (conversationList.size() <= 0) { - //add no history + // add no history startActivity(new Intent(this, ContactsActivity.class)); finish(); } else { spl.openPane(); - //find currently loaded fragment - ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); - if (selectedFragment!=null) { + // find currently loaded fragment + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment != null) { selectedFragment.onBackendConnected(); } else { selectedConversation = conversationList.get(0); swapConversationFragment(); } - ExceptionHelper.checkForCrash(this,this.xmppConnectionService); + ExceptionHelper.checkForCrash(this, this.xmppConnectionService); } } } + public void registerListener() { - if (xmppConnectionServiceBound) { - xmppConnectionService.setOnConversationListChangedListener(this.onConvChanged); - } + if (xmppConnectionServiceBound) { + xmppConnectionService + .setOnConversationListChangedListener(this.onConvChanged); + } } @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { + protected void onActivityResult(int requestCode, int resultCode, final Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK) { if (requestCode == REQUEST_DECRYPT_PGP) { - ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); - if (selectedFragment!=null) { + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment != null) { selectedFragment.hidePgpPassphraseBox(); } + } else if (requestCode == ATTACH_FILE) { + Conversation conversation = getSelectedConversation(); + String presence = conversation.getNextPresence(); + xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); + } - } - } + } + } public void updateConversationList() { conversationList.clear(); - conversationList.addAll(xmppConnectionService - .getConversations()); + conversationList.addAll(xmppConnectionService.getConversations()); listView.invalidateViews(); } + + public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) { + Contact contact = conversation.getContact(); + if (contact==null) { + showAddToRosterDialog(conversation); + listener.onPresenceSelected(false,null); + } else { + Hashtable<String, Integer> presences = contact.getPresences(); + if (presences.size() == 0) { + listener.onPresenceSelected(false, null); + } else if (presences.size() == 1) { + String presence = (String) presences.keySet().toArray()[0]; + conversation.setNextPresence(presence); + listener.onPresenceSelected(true, presence); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.choose_presence)); + final String[] presencesArray = new String[presences.size()]; + presences.keySet().toArray(presencesArray); + builder.setItems(presencesArray, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + String presence = presencesArray[which]; + conversation.setNextPresence(presence); + listener.onPresenceSelected(true,presence); + } + }); + builder.create().show(); + } + } + } + + private void showAddToRosterDialog(final Conversation conversation) { + String jid = conversation.getContactJid(); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(jid); + builder.setMessage(getString(R.string.not_in_roster)); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.setPositiveButton(getString(R.string.add_contact), new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String jid = conversation.getContactJid(); + Account account = getSelectedConversation().getAccount(); + String name = jid.split("@")[0]; + Contact contact = new Contact(account, name, jid, null); + xmppConnectionService.createContact(contact); + } + }); + builder.create().show(); + } } diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 51caafbd..f43f37a3 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -33,6 +33,7 @@ import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; +import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -89,7 +90,6 @@ public class ConversationFragment extends Fragment { @Override public void onClick(View v) { - Log.d("gultsch", "clicked to decrypt"); if (askForPassphraseIntent != null) { try { getActivity().startIntentSenderForResult( @@ -97,7 +97,7 @@ public class ConversationFragment extends Fragment { ConversationActivity.REQUEST_DECRYPT_PGP, null, 0, 0, 0); } catch (SendIntentException e) { - Log.d("gultsch", "couldnt fire intent"); + Log.d("xmppService", "couldnt fire intent"); } } } @@ -124,20 +124,20 @@ public class ConversationFragment extends Fragment { public void updateChatMsgHint() { if (conversation.getMode() == Conversation.MODE_MULTI) { - chatMsg.setHint("Send message to conference"); + chatMsg.setHint(getString(R.string.send_message_to_conference)); } else { switch (conversation.nextMessageEncryption) { case Message.ENCRYPTION_NONE: - chatMsg.setHint("Send plain text message"); + chatMsg.setHint(getString(R.string.send_plain_text_message)); break; case Message.ENCRYPTION_OTR: - chatMsg.setHint("Send OTR encrypted message"); + chatMsg.setHint(getString(R.string.send_otr_message)); break; case Message.ENCRYPTION_PGP: - chatMsg.setHint("Send openPGP encryted messeage"); + chatMsg.setHint(getString(R.string.send_pgp_message)); break; case Message.ENCRYPTION_DECRYPTED: - chatMsg.setHint("Send openPGP encryted messeage"); + chatMsg.setHint(getString(R.string.send_pgp_message)); break; default: break; @@ -149,6 +149,8 @@ public class ConversationFragment extends Fragment { public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final DisplayMetrics metrics = getResources().getDisplayMetrics(); + this.inflater = inflater; final View view = inflater.inflate(R.layout.fragment_conversation, @@ -177,19 +179,16 @@ public class ConversationFragment extends Fragment { private static final int SENT = 0; private static final int RECIEVED = 1; - private static final int ERROR = 2; @Override public int getViewTypeCount() { - return 3; + return 2; } @Override public int getItemViewType(int position) { - if (getItem(position).getStatus() == Message.STATUS_RECIEVED) { + if (getItem(position).getStatus() <= Message.STATUS_RECIEVED) { return RECIEVED; - } else if (getItem(position).getStatus() == Message.STATUS_ERROR) { - return ERROR; } else { return SENT; } @@ -206,20 +205,19 @@ public class ConversationFragment extends Fragment { case SENT: view = (View) inflater.inflate(R.layout.message_sent, null); - viewHolder.imageView = (ImageView) view + viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); - viewHolder.imageView.setImageBitmap(selfBitmap); - viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator); + viewHolder.contact_picture.setImageBitmap(selfBitmap); break; case RECIEVED: view = (View) inflater.inflate( R.layout.message_recieved, null); - viewHolder.imageView = (ImageView) view + viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); - viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator); + if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { - viewHolder.imageView.setImageBitmap(mBitmapCache + viewHolder.contact_picture.setImageBitmap(mBitmapCache .get(item.getConversation().getName(useSubject), item .getConversation().getContact(), getActivity() @@ -227,18 +225,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; } + viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator); + viewHolder.image = (ImageView) view.findViewById(R.id.message_image); viewHolder.messageBody = (TextView) view .findViewById(R.id.message_body); viewHolder.time = (TextView) view @@ -250,52 +242,90 @@ public class ConversationFragment extends Fragment { if (type == RECIEVED) { if (item.getConversation().getMode() == Conversation.MODE_MULTI) { if (item.getCounterpart() != null) { - viewHolder.imageView.setImageBitmap(mBitmapCache + viewHolder.contact_picture.setImageBitmap(mBitmapCache .get(item.getCounterpart(), null, getActivity() .getApplicationContext())); } else { - viewHolder.imageView.setImageBitmap(mBitmapCache + viewHolder.contact_picture.setImageBitmap(mBitmapCache .get(item.getConversation().getName(useSubject), null, getActivity() .getApplicationContext())); } } } - String body = item.getBody(); - if (body != null) { - if (item.getEncryption() == Message.ENCRYPTION_PGP) { - viewHolder.messageBody - .setText(getString(R.string.encrypted_message)); + + if (item.getEncryption() == Message.ENCRYPTION_NONE) { + viewHolder.indicator.setVisibility(View.GONE); + } else { + viewHolder.indicator.setVisibility(View.VISIBLE); + } + + + if (item.getType() == Message.TYPE_IMAGE) { + if (item.getStatus() == Message.STATUS_PREPARING) { + viewHolder.image.setVisibility(View.GONE); + viewHolder.messageBody.setVisibility(View.VISIBLE); + viewHolder.messageBody.setText(getString(R.string.preparing_image)); + viewHolder.messageBody.setTextColor(0xff33B5E5); + viewHolder.messageBody.setTypeface(null,Typeface.ITALIC); + } else if (item.getStatus() == Message.STATUS_RECIEVING) { + viewHolder.image.setVisibility(View.GONE); + viewHolder.messageBody.setVisibility(View.GONE); + viewHolder.messageBody.setVisibility(View.VISIBLE); + viewHolder.messageBody.setText(getString(R.string.receiving_image)); viewHolder.messageBody.setTextColor(0xff33B5E5); - viewHolder.messageBody.setTypeface(null, - Typeface.ITALIC); - viewHolder.indicator.setVisibility(View.VISIBLE); - } else if ((item.getEncryption() == Message.ENCRYPTION_OTR)||(item.getEncryption() == Message.ENCRYPTION_DECRYPTED)) { - viewHolder.messageBody.setText(body.trim()); - viewHolder.messageBody.setTextColor(0xff000000); - viewHolder.messageBody.setTypeface(null, - Typeface.NORMAL); - viewHolder.indicator.setVisibility(View.VISIBLE); + viewHolder.messageBody.setTypeface(null,Typeface.ITALIC); } else { - viewHolder.messageBody.setText(body.trim()); - viewHolder.messageBody.setTextColor(0xff000000); - viewHolder.messageBody.setTypeface(null, - Typeface.NORMAL); - if (item.getStatus() != Message.STATUS_ERROR) { - viewHolder.indicator.setVisibility(View.GONE); - } + viewHolder.image.setImageBitmap(activity.xmppConnectionService.getFileBackend().getThumbnailFromMessage(item,(int) (metrics.density * 288))); + viewHolder.messageBody.setVisibility(View.GONE); + viewHolder.image.setVisibility(View.VISIBLE); } } else { - viewHolder.indicator.setVisibility(View.GONE); + viewHolder.image.setVisibility(View.GONE); + viewHolder.messageBody.setVisibility(View.VISIBLE); + String body = item.getBody(); + if (body != null) { + if (item.getEncryption() == Message.ENCRYPTION_PGP) { + viewHolder.messageBody + .setText(getString(R.string.encrypted_message)); + viewHolder.messageBody.setTextColor(0xff33B5E5); + viewHolder.messageBody.setTypeface(null, + Typeface.ITALIC); + } else if ((item.getEncryption() == Message.ENCRYPTION_OTR)||(item.getEncryption() == Message.ENCRYPTION_DECRYPTED)) { + viewHolder.messageBody.setText(body.trim()); + viewHolder.messageBody.setTextColor(0xff333333); + viewHolder.messageBody.setTypeface(null, + Typeface.NORMAL); + } else { + viewHolder.messageBody.setText(body.trim()); + viewHolder.messageBody.setTextColor(0xff333333); + viewHolder.messageBody.setTypeface(null, + Typeface.NORMAL); + } + } } - if (item.getStatus() == Message.STATUS_UNSEND) { + switch (item.getStatus()) { + case Message.STATUS_UNSEND: viewHolder.time.setTypeface(null, Typeface.ITALIC); + viewHolder.time.setTextColor(0xFF8e8e8e); viewHolder.time.setText("sending\u2026"); - } else { + break; + case Message.STATUS_SEND_FAILED: + viewHolder.time.setText(getString(R.string.send_failed) + " \u00B7 " + UIHelper.readableTimeDifference(item + .getTimeSent())); + viewHolder.time.setTextColor(0xFFe92727); + viewHolder.time.setTypeface(null,Typeface.NORMAL); + break; + case Message.STATUS_SEND_REJECTED: + viewHolder.time.setText(getString(R.string.send_rejected)); + viewHolder.time.setTextColor(0xFFe92727); + viewHolder.time.setTypeface(null,Typeface.NORMAL); + break; + default: viewHolder.time.setTypeface(null, Typeface.NORMAL); - if ((item.getConversation().getMode() == Conversation.MODE_SINGLE) - || (type != RECIEVED)) { + viewHolder.time.setTextColor(0xFF8e8e8e); + if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { viewHolder.time.setText(UIHelper .readableTimeDifference(item.getTimeSent())); } else { @@ -304,6 +334,7 @@ public class ConversationFragment extends Fragment { + UIHelper.readableTimeDifference(item .getTimeSent())); } + break; } return view; } @@ -320,7 +351,7 @@ public class ConversationFragment extends Fragment { boolean showPhoneSelfContactPicture = sharedPref.getBoolean( "show_phone_selfcontact_picture", true); - return UIHelper.getSelfContactPicture(conversation.getAccount(), 200, + return UIHelper.getSelfContactPicture(conversation.getAccount(), 48, showPhoneSelfContactPicture, getActivity()); } @@ -372,11 +403,11 @@ public class ConversationFragment extends Fragment { if (success) { Toast.makeText( getActivity(), - "Your nickname has been changed", + getString(R.string.your_nick_has_been_changed), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getActivity(), - "Nichname is already in use", + getString(R.string.nick_in_use), Toast.LENGTH_SHORT).show(); } } @@ -505,7 +536,7 @@ public class ConversationFragment extends Fragment { getActivity()); builder.setTitle("No openPGP key found"); builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setMessage("There is no openPGP key assoziated with this contact"); + builder.setMessage("There is no openPGP key associated with this contact"); builder.setNegativeButton("Cancel", null); builder.setPositiveButton("Send plain text", new DialogInterface.OnClickListener() { @@ -585,10 +616,11 @@ public class ConversationFragment extends Fragment { private static class ViewHolder { + protected ImageView image; protected ImageView indicator; protected TextView time; protected TextView messageBody; - protected ImageView imageView; + protected ImageView contact_picture; } @@ -600,7 +632,12 @@ public class ConversationFragment extends Fragment { if (bitmaps.containsKey(name)) { return bitmaps.get(name); } else { - Bitmap bm = UIHelper.getContactPicture(contact, name, 200, context); + Bitmap bm; + if (contact != null){ + bm = UIHelper.getContactPicture(contact, 48, context, false); + } else { + bm = UIHelper.getContactPicture(name, 48, context, false); + } bitmaps.put(name, bm); return bm; } diff --git a/src/eu/siacs/conversations/ui/MucDetailsActivity.java b/src/eu/siacs/conversations/ui/MucDetailsActivity.java index bf36f156..c6807c61 100644 --- a/src/eu/siacs/conversations/ui/MucDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/MucDetailsActivity.java @@ -179,7 +179,7 @@ public class MucDetailsActivity extends XmppActivity { role.setText(getReadableRole(contact.getRole())); ImageView imageView = (ImageView) view .findViewById(R.id.contact_photo); - imageView.setImageBitmap(UIHelper.getContactPicture(null,contact.getName(), 90,this.getApplicationContext())); + imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 48,this.getApplicationContext(), false)); membersView.addView(view); } } diff --git a/src/eu/siacs/conversations/ui/OnPresenceSelected.java b/src/eu/siacs/conversations/ui/OnPresenceSelected.java new file mode 100644 index 00000000..7e424b2e --- /dev/null +++ b/src/eu/siacs/conversations/ui/OnPresenceSelected.java @@ -0,0 +1,5 @@ +package eu.siacs.conversations.ui; + +public interface OnPresenceSelected { + public void onPresenceSelected(boolean success, String presence); +} diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java index 51bad721..1bc9fc46 100644 --- a/src/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java @@ -81,7 +81,10 @@ public class ShareWithActivity extends XmppActivity { } }); for(final Conversation conversation : convList) { - View view = createContactView(conversation.getName(useSubject), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(useSubject), 90,this.getApplicationContext())); + View view = createContactView(conversation.getName(useSubject), + conversation.getLatestMessage().getBody().trim(), + UIHelper.getContactPicture(conversation, 48, + this.getApplicationContext(), false)); view.setOnClickListener(new OnClickListener() { @Override @@ -115,7 +118,8 @@ public class ShareWithActivity extends XmppActivity { for(int i = 0; i < contactsList.size(); ++i) { final Contact con = contactsList.get(i); - View view = createContactView(con.getDisplayName(), con.getJid(), UIHelper.getContactPicture(con,null, 90,this.getApplicationContext())); + View view = createContactView(con.getDisplayName(), con.getJid(), + UIHelper.getContactPicture(con, 48, this.getApplicationContext(), false)); view.setOnClickListener(new OnClickListener() { @Override |