diff options
Diffstat (limited to 'src/eu/siacs')
29 files changed, 477 insertions, 333 deletions
diff --git a/src/eu/siacs/conversations/Config.java b/src/eu/siacs/conversations/Config.java index 04c8af3d..6219b6b0 100644 --- a/src/eu/siacs/conversations/Config.java +++ b/src/eu/siacs/conversations/Config.java @@ -16,6 +16,8 @@ public final class Config { public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP; public static final int MESSAGE_MERGE_WINDOW = 20; + + public static final boolean PARSE_EMOTICONS = false; private Config() { diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 47b1a0cb..2f678279 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -106,8 +106,8 @@ public class PgpEngine { outputFile.getAbsolutePath(), options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; - message.setBody("" + outputFile.getSize() + "," - + imageWidth + "," + imageHeight); + message.setBody(Long.toString(outputFile.getSize()) + ',' + + imageWidth + ',' + imageHeight); message.setEncryption(Message.ENCRYPTION_DECRYPTED); PgpEngine.this.mXmppConnectionService .updateMessage(message); @@ -171,8 +171,10 @@ public class PgpEngine { os.flush(); StringBuilder encryptedMessageBody = new StringBuilder(); String[] lines = os.toString().split("\n"); - for (int i = 3; i < lines.length - 1; ++i) { - encryptedMessageBody.append(lines[i].trim()); + for (int i = 2; i < lines.length - 1; ++i) { + if (!lines[i].contains("Version")) { + encryptedMessageBody.append(lines[i].trim()); + } } message.setEncryptedBody(encryptedMessageBody .toString()); @@ -295,9 +297,27 @@ public class PgpEngine { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) { case OpenPgpApi.RESULT_CODE_SUCCESS: StringBuilder signatureBuilder = new StringBuilder(); - String[] lines = os.toString().split("\n"); - for (int i = 7; i < lines.length - 1; ++i) { - signatureBuilder.append(lines[i].trim()); + try { + os.flush(); + String[] lines = os.toString().split("\n"); + boolean sig = false; + for(String line : lines) { + if (sig) { + if (line.contains("END PGP SIGNATURE")) { + sig = false; + } else { + if (!line.contains("Version")) { + signatureBuilder.append(line.trim()); + } + } + } + if (line.contains("BEGIN PGP SIGNATURE")) { + sig = true; + } + } + } catch (IOException e) { + callback.error(R.string.openpgp_error, account); + return; } account.setKey("pgp_signature", signatureBuilder.toString()); callback.success(account); diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 4c55d5ee..2097b2a4 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -16,6 +16,7 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; +import android.os.SystemClock; public class Conversation extends AbstractEntity { public static final String TABLENAME = "conversations"; @@ -42,6 +43,8 @@ public class Conversation extends AbstractEntity { private int status; private long created; private int mode; + + private long mutedTill = 0; private String nextPresence; @@ -141,9 +144,8 @@ public class Conversation extends AbstractEntity { this.messages = msgs; } - public String getName(boolean useSubject) { - if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) - && useSubject) { + public String getName() { + if (getMode() == MODE_MULTI && getMucOptions().getSubject() != null) { return getMucOptions().getSubject(); } else if (getMode() == MODE_MULTI && bookmark != null && bookmark.getName() != null) { @@ -419,4 +421,12 @@ public class Conversation extends AbstractEntity { } return false; } + + public void setMutedTill(long mutedTill) { + this.mutedTill = mutedTill; + } + + public boolean isMuted() { + return SystemClock.elapsedRealtime() < this.mutedTill; + } } diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index 84aac4f5..f36ffa90 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -150,13 +150,13 @@ public class Message extends AbstractEntity { public String getReadableBody(Context context) { if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) { - return "" + context.getText(R.string.encrypted_message_received); + return context.getText(R.string.encrypted_message_received).toString(); } else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) { - return "" + context.getText(R.string.encrypted_image_received); + return context.getText(R.string.encrypted_image_received).toString(); } else if (encryption == ENCRYPTION_DECRYPTION_FAILED) { - return "" + context.getText(R.string.decryption_failed); + return context.getText(R.string.decryption_failed).toString(); } else if (type == TYPE_IMAGE) { - return "" + context.getText(R.string.image_file); + return context.getText(R.string.image_file).toString(); } else { return body.trim(); } diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index 2958965c..72fbeeab 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -14,6 +14,7 @@ public class MucOptions { public static final int ERROR_NO_ERROR = 0; public static final int ERROR_NICK_IN_USE = 1; public static final int ERROR_ROOM_NOT_FOUND = 2; + public static final int ERROR_PASSWORD_REQUIRED = 3; public interface OnRenameListener { public void onRename(boolean success); @@ -106,6 +107,7 @@ public class MucOptions { private User self = new User(); private String subject = null; private String joinnick; + private String password = null; public MucOptions(Account account) { this.account = account; @@ -186,6 +188,8 @@ public class MucOptions { } else { this.error = ERROR_NICK_IN_USE; } + } else if (error.hasChild("not-authorized")) { + this.error = ERROR_PASSWORD_REQUIRED; } } } @@ -308,4 +312,12 @@ public class MucOptions { } return null; } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } }
\ No newline at end of file diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 3dca636e..10859345 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -435,6 +435,7 @@ public class MessageParser extends AbstractParser implements if (packet.getType() != MessagePacket.TYPE_ERROR) { mXmppConnectionService.databaseBackend.createMessage(message); } + notify = notify && !conversation.isMuted(); mXmppConnectionService.notifyUi(conversation, notify); } diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index 22871a9e..2a403fab 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -137,7 +137,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { public CopyOnWriteArrayList<Conversation> getConversations(int status) { CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<Conversation>(); SQLiteDatabase db = this.getReadableDatabase(); - String[] selectionArgs = { "" + status }; + String[] selectionArgs = { Integer.toString(status) }; Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME + " where " + Conversation.STATUS + " = ? order by " + Conversation.CREATED + " desc", selectionArgs); @@ -163,7 +163,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { + "=?", selectionArgs, null, null, Message.TIME_SENT + " DESC", String.valueOf(limit)); } else { - String[] selectionArgs = { conversation.getUuid(), "" + timestamp }; + String[] selectionArgs = { conversation.getUuid(), Long.toString(timestamp) }; cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION + "=? and " + Message.TIME_SENT + "<?", selectionArgs, null, null, Message.TIME_SENT + " DESC", diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 6e16240d..2b2aa86e 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -180,7 +180,7 @@ public class FileBackend { long size = file.getSize(); int width = scalledBitmap.getWidth(); int height = scalledBitmap.getHeight(); - message.setBody("" + size + "," + width + "," + height); + message.setBody(Long.toString(size) + ',' + width + ',' + height); return file; } catch (FileNotFoundException e) { throw new ImageCopyException(R.string.error_file_not_found); @@ -201,17 +201,20 @@ public class FileBackend { private int getRotation(Uri image) { if ("content".equals(image.getScheme())) { - Cursor cursor = context - .getContentResolver() - .query(image, - new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, - null, null, null); - - if (cursor.getCount() != 1) { + try { + Cursor cursor = context + .getContentResolver() + .query(image, + new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, + null, null, null); + if (cursor.getCount() != 1) { + return -1; + } + cursor.moveToFirst(); + return cursor.getInt(0); + } catch (IllegalArgumentException e) { return -1; } - cursor.moveToFirst(); - return cursor.getInt(0); } else { ExifInterface exif; try { @@ -376,6 +379,10 @@ public class FileBackend { if (input == null) { return null; } else { + int rotation = getRotation(image); + if (rotation > 0) { + input = rotate(input, rotation); + } return cropCenterSquare(input, size); } } catch (FileNotFoundException e) { diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 2656f7c6..a294e970 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -784,10 +784,22 @@ public class XmppConnectionService extends Service { return this.conversations; } - + public void populateWithOrderedConversations(List<Conversation> list) { + populateWithOrderedConversations(list,true); + } + + public void populateWithOrderedConversations(List<Conversation> list, boolean includeConferences) { list.clear(); - list.addAll(getConversations()); + if (includeConferences) { + list.addAll(getConversations()); + } else { + for(Conversation conversation : getConversations()) { + if (conversation.getMode() == Conversation.MODE_SINGLE) { + list.add(conversation); + } + } + } Collections.sort(list, new Comparator<Conversation>() { @Override public int compare(Conversation lhs, Conversation rhs) { @@ -1047,6 +1059,10 @@ public class XmppConnectionService extends Service { packet.setAttribute("to", conversation.getMucOptions().getJoinJid()); Element x = new Element("x"); x.setAttribute("xmlns", "http://jabber.org/protocol/muc"); + if (conversation.getMucOptions().getPassword() != null) { + Element password = x.addChild("password"); + password.setContent(conversation.getMucOptions().getPassword()); + } String sig = account.getPgpSignature(); if (sig != null) { packet.addChild("status").setContent("online"); @@ -1078,6 +1094,13 @@ public class XmppConnectionService extends Service { public void setOnRenameListener(OnRenameListener listener) { this.renameListener = listener; } + + public void providePasswordForMuc(Conversation conversation, String password) { + if (conversation.getMode() == Conversation.MODE_MULTI) { + conversation.getMucOptions().setPassword(password); + joinMuc(conversation); + } + } public void renameInMuc(final Conversation conversation, final String nick) { final MucOptions options = conversation.getMucOptions(); diff --git a/src/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/eu/siacs/conversations/ui/ChooseContactActivity.java index 83b20cb9..449fc546 100644 --- a/src/eu/siacs/conversations/ui/ChooseContactActivity.java +++ b/src/eu/siacs/conversations/ui/ChooseContactActivity.java @@ -95,8 +95,13 @@ public class ChooseContactActivity extends XmppActivity { InputMethodManager.HIDE_IMPLICIT_ONLY); Intent request = getIntent(); Intent data = new Intent(); - data.putExtra("contact", contacts.get(position).getJid()); - data.putExtra("account", request.getStringExtra("account")); + ListItem mListItem = contacts.get(position); + data.putExtra("contact", mListItem.getJid()); + String account = request.getStringExtra("account"); + if (account==null && mListItem instanceof Contact) { + account = ((Contact) mListItem).getAccount().getJid(); + } + data.putExtra("account", account); data.putExtra("conversation", request.getStringExtra("conversation")); setResult(RESULT_OK, data); diff --git a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 40c7eca8..2cfa1635 100644 --- a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -109,7 +109,7 @@ public class ConferenceDetailsActivity extends XmppActivity { break; case R.id.action_edit_subject: if (conversation != null) { - quickEdit(conversation.getName(true), new OnValueEdited() { + quickEdit(conversation.getName(), new OnValueEdited() { @Override public void onValueEdited(String value) { @@ -200,7 +200,7 @@ public class ConferenceDetailsActivity extends XmppActivity { private void populateView() { mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48)); - setTitle(conversation.getName(true)); + setTitle(conversation.getName()); mFullJid.setText(conversation.getContactJid().split("/")[0]); mYourNick.setText(conversation.getMucOptions().getActualNick()); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 6504f056..17e410f2 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -1,10 +1,7 @@ package eu.siacs.conversations.ui; -import java.io.FileNotFoundException; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.RejectedExecutionException; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Contact; @@ -15,9 +12,8 @@ import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.UIHelper; import android.net.Uri; -import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; +import android.os.SystemClock; import android.provider.MediaStore; import android.app.ActionBar; import android.app.AlertDialog; @@ -27,14 +23,8 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.IntentSender.SendIntentException; import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; -import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -46,7 +36,6 @@ import android.widget.CheckBox; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; -import android.widget.ImageView; import android.widget.Toast; public class ConversationActivity extends XmppActivity { @@ -75,8 +64,6 @@ public class ConversationActivity extends XmppActivity { private ListView listView; private boolean paneShouldBeOpen = true; - private boolean useSubject = true; - private boolean showLastseen = false; private ArrayAdapter<Conversation> listAdapter; private OnConversationUpdate onConvChanged = new OnConversationUpdate() { @@ -108,7 +95,6 @@ public class ConversationActivity extends XmppActivity { }; protected ConversationActivity activity = this; - private DisplayMetrics metrics; private Toast prepareImageToast; private Uri pendingImageUri = null; @@ -139,9 +125,6 @@ public class ConversationActivity extends XmppActivity { @Override protected void onCreate(Bundle savedInstanceState) { - - metrics = getResources().getDisplayMetrics(); - super.onCreate(savedInstanceState); setContentView(R.layout.fragment_conversations_overview); @@ -196,8 +179,7 @@ public class ConversationActivity extends XmppActivity { if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); ab.setHomeButtonEnabled(true); - ab.setTitle(getSelectedConversation().getName( - useSubject)); + ab.setTitle(getSelectedConversation().getName()); } invalidateOptionsMenu(); if (!getSelectedConversation().isRead()) { @@ -233,6 +215,7 @@ public class ConversationActivity extends XmppActivity { MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add); MenuItem menuInviteContact = (MenuItem) menu .findItem(R.id.action_invite); + MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); if ((spl.isOpen() && (spl.isSlideable()))) { menuArchive.setVisible(false); @@ -242,6 +225,7 @@ public class ConversationActivity extends XmppActivity { menuInviteContact.setVisible(false); menuAttach.setVisible(false); menuClearHistory.setVisible(false); + menuMute.setVisible(false); } else { menuAdd.setVisible(!spl.isSlideable()); if (this.getSelectedConversation() != null) { @@ -482,6 +466,9 @@ public class ConversationActivity extends XmppActivity { case R.id.action_clear_history: clearHistoryDialog(getSelectedConversation()); break; + case R.id.action_mute: + muteConversationDialog(getSelectedConversation()); + break; default: break; } @@ -523,6 +510,31 @@ public class ConversationActivity extends XmppActivity { }); builder.create().show(); } + + protected void muteConversationDialog(final Conversation conversation) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.disable_notifications_for_this_conversation); + final int[] durations = getResources().getIntArray(R.array.mute_options_durations); + builder.setItems(R.array.mute_options_descriptions, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + long till; + if (durations[which]==-1) { + till = Long.MAX_VALUE; + } else { + till = SystemClock.elapsedRealtime() + (durations[which] * 1000); + } + conversation.setMutedTill(till); + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment!=null) { + selectedFragment.updateMessages(); + } + } + }); + builder.create().show(); + } protected ConversationFragment swapConversationFragment() { ConversationFragment selectedFragment = new ConversationFragment(); @@ -576,10 +588,6 @@ public class ConversationActivity extends XmppActivity { @Override public void onStart() { super.onStart(); - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(this); - this.useSubject = preferences.getBoolean("use_subject_in_muc", true); - this.showLastseen = preferences.getBoolean("show_last_seen", false); if (this.xmppConnectionServiceBound) { this.onBackendConnected(); } @@ -755,15 +763,6 @@ public class ConversationActivity extends XmppActivity { listView.invalidateViews(); } - public boolean showLastseen() { - if (getSelectedConversation() == null) { - return false; - } else { - return this.showLastseen - && getSelectedConversation().getMode() == Conversation.MODE_SINGLE; - } - } - public void runIntent(PendingIntent pi, int requestCode) { try { this.startIntentSenderForResult(pi.getIntentSender(), requestCode, @@ -772,105 +771,6 @@ public class ConversationActivity extends XmppActivity { } } - class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { - private final WeakReference<ImageView> imageViewReference; - private Message message = null; - - public BitmapWorkerTask(ImageView imageView) { - imageViewReference = new WeakReference<ImageView>(imageView); - } - - @Override - protected Bitmap doInBackground(Message... params) { - message = params[0]; - try { - return xmppConnectionService.getFileBackend().getThumbnail( - message, (int) (metrics.density * 288), false); - } catch (FileNotFoundException e) { - return null; - } - } - - @Override - protected void onPostExecute(Bitmap bitmap) { - if (imageViewReference != null && bitmap != null) { - final ImageView imageView = imageViewReference.get(); - if (imageView != null) { - imageView.setImageBitmap(bitmap); - imageView.setBackgroundColor(0x00000000); - } - } - } - } - - public void loadBitmap(Message message, ImageView imageView) { - Bitmap bm; - try { - bm = xmppConnectionService.getFileBackend().getThumbnail(message, - (int) (metrics.density * 288), true); - } catch (FileNotFoundException e) { - bm = null; - } - if (bm != null) { - imageView.setImageBitmap(bm); - imageView.setBackgroundColor(0x00000000); - } else { - if (cancelPotentialWork(message, imageView)) { - imageView.setBackgroundColor(0xff333333); - final BitmapWorkerTask task = new BitmapWorkerTask(imageView); - final AsyncDrawable asyncDrawable = new AsyncDrawable( - getResources(), null, task); - imageView.setImageDrawable(asyncDrawable); - try { - task.execute(message); - } catch (RejectedExecutionException e) { - return; - } - } - } - } - - public static boolean cancelPotentialWork(Message message, - ImageView imageView) { - final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); - - if (bitmapWorkerTask != null) { - final Message oldMessage = bitmapWorkerTask.message; - if (oldMessage == null || message != oldMessage) { - bitmapWorkerTask.cancel(true); - } else { - return false; - } - } - return true; - } - - private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { - if (imageView != null) { - final Drawable drawable = imageView.getDrawable(); - if (drawable instanceof AsyncDrawable) { - final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; - return asyncDrawable.getBitmapWorkerTask(); - } - } - return null; - } - - static class AsyncDrawable extends BitmapDrawable { - private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference; - - public AsyncDrawable(Resources res, Bitmap bitmap, - BitmapWorkerTask bitmapWorkerTask) { - super(res, bitmap); - bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>( - bitmapWorkerTask); - } - - public BitmapWorkerTask getBitmapWorkerTask() { - return bitmapWorkerTaskReference.get(); - } - } - public void encryptTextMessage(Message message) { xmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() { diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 77049e56..4ebeea19 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -15,6 +15,7 @@ import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.EditMessage.OnEnterPressed; import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected; +import eu.siacs.conversations.ui.XmppActivity.OnValueEdited; import eu.siacs.conversations.ui.adapter.MessageAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked; @@ -26,10 +27,8 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender; -import android.content.SharedPreferences; import android.content.IntentSender.SendIntentException; import android.os.Bundle; -import android.preference.PreferenceManager; import android.text.Editable; import android.text.Selection; import android.view.Gravity; @@ -67,7 +66,6 @@ public class ConversationFragment extends Fragment { private TextView snackbarMessage; private TextView snackbarAction; - private boolean useSubject = true; private boolean messagesLoaded = false; private IntentSender askForPassphraseIntent = null; @@ -131,6 +129,25 @@ public class ConversationFragment extends Fragment { } }; + private OnClickListener enterPassword = new OnClickListener() { + + @Override + public void onClick(View v) { + MucOptions muc = conversation.getMucOptions(); + String password = muc.getPassword(); + if (password==null) { + password = ""; + } + activity.quickEdit(password, new OnValueEdited() { + + @Override + public void onValueEdited(String value) { + activity.xmppConnectionService.providePasswordForMuc(conversation,value); + } + }); + } + }; + private OnScrollListener mOnScrollListener = new OnScrollListener() { @Override @@ -290,10 +307,12 @@ public class ConversationFragment extends Fragment { if (oldString.isEmpty() || mEditMessage.getSelectionStart() == 0) { mEditMessage.getText().insert(0, nick + ": "); } else { - if (mEditMessage.getText().charAt(mEditMessage.getSelectionStart()-1)!=' ') { - nick = " "+nick; + if (mEditMessage.getText().charAt( + mEditMessage.getSelectionStart() - 1) != ' ') { + nick = " " + nick; } - mEditMessage.getText().insert(mEditMessage.getSelectionStart(), nick + " "); + mEditMessage.getText().insert(mEditMessage.getSelectionStart(), + nick + " "); } } @@ -301,9 +320,6 @@ public class ConversationFragment extends Fragment { public void onStart() { super.onStart(); this.activity = (ConversationActivity) getActivity(); - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(activity); - this.useSubject = preferences.getBoolean("use_subject_in_muc", true); if (activity.xmppConnectionServiceBound) { this.onBackendConnected(); } @@ -343,8 +359,7 @@ public class ConversationFragment extends Fragment { activity.getSlidingPaneLayout().closePane(); activity.getActionBar().setDisplayHomeAsUpEnabled(true); activity.getActionBar().setHomeButtonEnabled(true); - activity.getActionBar().setTitle( - conversation.getName(useSubject)); + activity.getActionBar().setTitle(conversation.getName()); activity.invalidateOptionsMenu(); } } @@ -390,7 +405,17 @@ public class ConversationFragment extends Fragment { final ConversationActivity activity = (ConversationActivity) getActivity(); if (this.conversation != null) { final Contact contact = this.conversation.getContact(); - if (!contact.showInRoster() + if (this.conversation.isMuted()) { + showSnackbar(R.string.notifications_disabled, R.string.enable, + new OnClickListener() { + + @Override + public void onClick(View v) { + conversation.setMutedTill(0); + updateMessages(); + } + }); + } else if (!contact.showInRoster() && contact .getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { showSnackbar(R.string.contact_added_you, R.string.add_back, @@ -432,12 +457,20 @@ public class ConversationFragment extends Fragment { } else { if (!conversation.getMucOptions().online() && conversation.getAccount().getStatus() == Account.STATUS_ONLINE) { - if (conversation.getMucOptions().getError() == MucOptions.ERROR_NICK_IN_USE) { + int error = conversation.getMucOptions().getError(); + switch (error) { + case MucOptions.ERROR_NICK_IN_USE: showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc); - } else if (conversation.getMucOptions().getError() == MucOptions.ERROR_ROOM_NOT_FOUND) { + break; + case MucOptions.ERROR_ROOM_NOT_FOUND: showSnackbar(R.string.conference_not_found, R.string.leave, leaveMuc); + case MucOptions.ERROR_PASSWORD_REQUIRED: + showSnackbar(R.string.conference_requires_password, + R.string.enter_password, enterPassword); + default: + break; } } } @@ -445,7 +478,6 @@ public class ConversationFragment extends Fragment { updateChatMsgHint(); if (!activity.shouldPaneBeOpen()) { activity.xmppConnectionService.markRead(conversation); - // TODO update notifications UIHelper.updateNotification(getActivity(), activity.getConversationList(), null, false); activity.updateConversationList(); @@ -491,6 +523,7 @@ public class ConversationFragment extends Fragment { .getOtrFingerprints(); if ((latestEncryption == Message.ENCRYPTION_OTR) && (conversation.hasValidOtrSession() + && (!conversation.isMuted()) && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!knownFingerprints .contains(conversation.getOtrFingerprint())))) { showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java index 461aaec4..93831654 100644 --- a/src/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java @@ -1,37 +1,41 @@ package eu.siacs.conversations.ui; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.ui.adapter.ConversationAdapter; import android.app.PendingIntent; import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import android.preference.PreferenceManager; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ListView; import android.widget.Toast; public class ShareWithActivity extends XmppActivity { + + private class Share { + public Uri uri; + public String account; + public String contact; + public String text; + } + + private Share share; - private LinearLayout conversations; - private LinearLayout contacts; - private boolean isImage = false; + private static final int REQUEST_START_NEW_CONVERSATION = 0x0501; + private ListView mListView; + private List<Conversation> mConversations = new ArrayList<Conversation>(); private UiCallback<Message> attachImageCallback = new UiCallback<Message>() { @@ -52,115 +56,107 @@ public class ShareWithActivity extends XmppActivity { } }; + + protected void onActivityResult(int requestCode, int resultCode, + final Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_START_NEW_CONVERSATION + && resultCode == RESULT_OK) { + share.contact = data.getStringExtra("contact"); + share.account = data.getStringExtra("account"); + Log.d(Config.LOGTAG,"contact: "+share.contact+" account:"+share.account); + } + if (xmppConnectionServiceBound && share != null && share.contact != null && share.account != null) { + share(); + } + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setHomeButtonEnabled(false); + setContentView(R.layout.share_with); setTitle(getString(R.string.title_activity_sharewith)); - contacts = (LinearLayout) findViewById(R.id.contacts); - conversations = (LinearLayout) findViewById(R.id.conversations); + mListView = (ListView) findViewById(R.id.choose_conversation_list); + ConversationAdapter mAdapter = new ConversationAdapter(this, + this.mConversations); + mListView.setAdapter(mAdapter); + mListView.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> arg0, View arg1, + int position, long arg3) { + Conversation conversation = mConversations.get(position); + if (conversation.getMode() == Conversation.MODE_SINGLE) { + share(mConversations.get(position)); + } + } + }); + + this.share = new Share(); } - - public View createContactView(String name, String msgTxt, Bitmap bm) { - View view = (View) getLayoutInflater().inflate(R.layout.contact, null); - view.setBackgroundResource(R.drawable.greybackground); - TextView contactName = (TextView) view - .findViewById(R.id.contact_display_name); - contactName.setText(name); - TextView msg = (TextView) view.findViewById(R.id.contact_jid); - msg.setText(msgTxt); - ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo); - imageView.setImageBitmap(bm); - return view; + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.share_with, menu); + return true; } @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_add: + Intent intent = new Intent(getApplicationContext(), + ChooseContactActivity.class); + startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onStart() { + super.onStart(); + if (getIntent().getType() != null && getIntent().getType() + .startsWith("image/")) { + this.share.uri = (Uri) getIntent().getParcelableExtra( + Intent.EXTRA_STREAM); + } else { + this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT); + } + } + + @Override void onBackendConnected() { - this.isImage = (getIntent().getType() != null && getIntent().getType() - .startsWith("image/")); - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(this); - boolean useSubject = preferences.getBoolean("use_subject_in_muc", true); - - Set<Contact> displayedContacts = new HashSet<Contact>(); - conversations.removeAllViews(); - List<Conversation> convList = new ArrayList<Conversation>(); - xmppConnectionService.populateWithOrderedConversations(convList); - Collections.sort(convList, new Comparator<Conversation>() { - @Override - public int compare(Conversation lhs, Conversation rhs) { - return (int) (rhs.getLatestMessage().getTimeSent() - lhs - .getLatestMessage().getTimeSent()); - } - }); - for (final Conversation conversation : convList) { - if (!isImage || conversation.getMode() == Conversation.MODE_SINGLE) { - View view = createContactView( - conversation.getName(useSubject), - conversation.getLatestMessage().getBody().trim(), - UIHelper.getContactPicture(conversation, 48, - this.getApplicationContext(), false)); - view.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - share(conversation); - } - }); - conversations.addView(view); - displayedContacts.add(conversation.getContact()); - } + if (xmppConnectionServiceBound && share != null && share.contact != null && share.account != null) { + share(); + return; } - contacts.removeAllViews(); - List<Contact> contactsList = new ArrayList<Contact>(); - for (Account account : xmppConnectionService.getAccounts()) { - for (Contact contact : account.getRoster().getContacts()) { - if (!displayedContacts.contains(contact) - && (contact.showInRoster())) { - contactsList.add(contact); - } + xmppConnectionService.populateWithOrderedConversations(mConversations, + false); + for (Conversation conversation : mConversations) { + if (conversation.getMode() == Conversation.MODE_MULTI) { + mConversations.remove(conversation); } } - - Collections.sort(contactsList, new Comparator<Contact>() { - @Override - public int compare(Contact lhs, Contact rhs) { - return lhs.getDisplayName().compareToIgnoreCase( - rhs.getDisplayName()); - } - }); - - for (int i = 0; i < contactsList.size(); ++i) { - final Contact con = contactsList.get(i); - View view = createContactView( - con.getDisplayName(), - con.getJid(), - UIHelper.getContactPicture(con, 48, - this.getApplicationContext(), false)); - view.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - Conversation conversation = xmppConnectionService - .findOrCreateConversation(con.getAccount(), - con.getJid(), false); - share(conversation); - } - }); - contacts.addView(view); + } + + private void share() { + Account account = xmppConnectionService.findAccountByJid(share.account); + if (account==null) { + return; } + Conversation conversation = xmppConnectionService.findOrCreateConversation(account, share.contact, false); + share(conversation); } private void share(final Conversation conversation) { - String sharedText = null; - if (isImage) { - final Uri uri = (Uri) getIntent().getParcelableExtra( - Intent.EXTRA_STREAM); + if (share.uri != null) { selectPresence(conversation, new OnPresenceSelected() { @Override public void onPresenceSelected() { @@ -168,7 +164,7 @@ public class ShareWithActivity extends XmppActivity { getText(R.string.preparing_image), Toast.LENGTH_LONG).show(); ShareWithActivity.this.xmppConnectionService - .attachImageToConversation(conversation, uri, + .attachImageToConversation(conversation, share.uri, attachImageCallback); switchToConversation(conversation, null, true); finish(); @@ -176,8 +172,7 @@ public class ShareWithActivity extends XmppActivity { }); } else { - sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT); - switchToConversation(conversation, sharedText, true); + switchToConversation(conversation,this.share.text, true); finish(); } diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 11376eb7..78482658 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -1,5 +1,9 @@ package eu.siacs.conversations.ui; +import java.io.FileNotFoundException; +import java.lang.ref.WeakReference; +import java.util.concurrent.RejectedExecutionException; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -19,16 +23,23 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.IntentSender.SendIntentException; +import android.content.res.Resources; import android.content.Intent; import android.content.ServiceConnection; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.IBinder; +import android.util.DisplayMetrics; import android.util.Log; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import android.widget.ImageView; public abstract class XmppActivity extends Activity { @@ -44,6 +55,8 @@ public abstract class XmppActivity extends Activity { protected int mWarningTextColor; protected int mPrimaryColor; + private DisplayMetrics metrics; + protected interface OnValueEdited { public void onValueEdited(String value); } @@ -163,6 +176,7 @@ public abstract class XmppActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + metrics = getResources().getDisplayMetrics(); ExceptionHelper.init(getApplicationContext()); mPrimaryTextColor = getResources().getColor(R.color.primarytext); mSecondaryTextColor = getResources().getColor(R.color.secondarytext); @@ -370,7 +384,7 @@ public abstract class XmppActivity extends Activity { xmppConnectionService.invite(conversation, contactJid); } Log.d(Config.LOGTAG, "inviting " + contactJid + " to " - + conversation.getName(true)); + + conversation.getName()); } } @@ -389,4 +403,103 @@ public abstract class XmppActivity extends Activity { public int getPrimaryColor() { return this.mPrimaryColor; } + + class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { + private final WeakReference<ImageView> imageViewReference; + private Message message = null; + + public BitmapWorkerTask(ImageView imageView) { + imageViewReference = new WeakReference<ImageView>(imageView); + } + + @Override + protected Bitmap doInBackground(Message... params) { + message = params[0]; + try { + return xmppConnectionService.getFileBackend().getThumbnail( + message, (int) (metrics.density * 288), false); + } catch (FileNotFoundException e) { + return null; + } + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + if (imageViewReference != null && bitmap != null) { + final ImageView imageView = imageViewReference.get(); + if (imageView != null) { + imageView.setImageBitmap(bitmap); + imageView.setBackgroundColor(0x00000000); + } + } + } + } + + public void loadBitmap(Message message, ImageView imageView) { + Bitmap bm; + try { + bm = xmppConnectionService.getFileBackend().getThumbnail(message, + (int) (metrics.density * 288), true); + } catch (FileNotFoundException e) { + bm = null; + } + if (bm != null) { + imageView.setImageBitmap(bm); + imageView.setBackgroundColor(0x00000000); + } else { + if (cancelPotentialWork(message, imageView)) { + imageView.setBackgroundColor(0xff333333); + final BitmapWorkerTask task = new BitmapWorkerTask(imageView); + final AsyncDrawable asyncDrawable = new AsyncDrawable( + getResources(), null, task); + imageView.setImageDrawable(asyncDrawable); + try { + task.execute(message); + } catch (RejectedExecutionException e) { + return; + } + } + } + } + + public static boolean cancelPotentialWork(Message message, + ImageView imageView) { + final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); + + if (bitmapWorkerTask != null) { + final Message oldMessage = bitmapWorkerTask.message; + if (oldMessage == null || message != oldMessage) { + bitmapWorkerTask.cancel(true); + } else { + return false; + } + } + return true; + } + + private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { + if (imageView != null) { + final Drawable drawable = imageView.getDrawable(); + if (drawable instanceof AsyncDrawable) { + final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; + return asyncDrawable.getBitmapWorkerTask(); + } + } + return null; + } + + static class AsyncDrawable extends BitmapDrawable { + private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference; + + public AsyncDrawable(Resources res, Bitmap bitmap, + BitmapWorkerTask bitmapWorkerTask) { + super(res, bitmap); + bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>( + bitmapWorkerTask); + } + + public BitmapWorkerTask getBitmapWorkerTask() { + return bitmapWorkerTaskReference.get(); + } + } } diff --git a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index ecae6231..6eb9846a 100644 --- a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -2,10 +2,12 @@ package eu.siacs.conversations.ui.adapter; import java.util.List; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.ui.ConversationActivity; +import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.utils.UIHelper; import android.content.Context; import android.graphics.Color; @@ -19,9 +21,9 @@ import android.widget.TextView; public class ConversationAdapter extends ArrayAdapter<Conversation> { - ConversationActivity activity; + private XmppActivity activity; - public ConversationAdapter(ConversationActivity activity, + public ConversationAdapter(XmppActivity activity, List<Conversation> conversations) { super(activity, 0, conversations); this.activity = activity; @@ -36,18 +38,21 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { parent, false); } Conversation conv = getItem(position); - if (!activity.getSlidingPaneLayout().isSlideable()) { - if (conv == activity.getSelectedConversation()) { - view.setBackgroundColor(0xffdddddd); + if (this.activity instanceof ConversationActivity) { + ConversationActivity activity = (ConversationActivity) this.activity; + if (!activity.getSlidingPaneLayout().isSlideable()) { + if (conv == activity.getSelectedConversation()) { + view.setBackgroundColor(0xffdddddd); + } else { + view.setBackgroundColor(Color.TRANSPARENT); + } } else { view.setBackgroundColor(Color.TRANSPARENT); } - } else { - view.setBackgroundColor(Color.TRANSPARENT); } TextView convName = (TextView) view .findViewById(R.id.conversation_name); - convName.setText(conv.getName(true)); + convName.setText(conv.getName()); TextView convLastMsg = (TextView) view .findViewById(R.id.conversation_lastmsg); ImageView imagePreview = (ImageView) view @@ -59,7 +64,10 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { || latestMessage.getType() == Message.TYPE_PRIVATE) { if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP) && (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) { - convLastMsg.setText(UIHelper.transformAsciiEmoticons(conv.getLatestMessage().getBody())); + String body = Config.PARSE_EMOTICONS ? UIHelper + .transformAsciiEmoticons(latestMessage.getBody()) + : latestMessage.getBody(); + convLastMsg.setText(body); } else { convLastMsg.setText(activity .getText(R.string.encrypted_message_received)); diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 553584cd..ccf25a33 100644 --- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -3,6 +3,7 @@ package eu.siacs.conversations.ui.adapter; import java.util.HashMap; import java.util.List; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -215,7 +216,10 @@ public class MessageAdapter extends ArrayAdapter<Message> { viewHolder.messageBody.setVisibility(View.VISIBLE); if (message.getBody() != null) { if (message.getType() != Message.TYPE_PRIVATE) { - viewHolder.messageBody.setText(UIHelper.transformAsciiEmoticons(message.getMergedBody())); + String body = Config.PARSE_EMOTICONS ? UIHelper + .transformAsciiEmoticons(message.getMergedBody()) + : message.getMergedBody(); + viewHolder.messageBody.setText(body); } else { String privateMarker; if (message.getStatus() <= Message.STATUS_RECEIVED) { @@ -377,7 +381,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { @Override public void onClick(View v) { String name = item.getConversation() - .getName(true); + .getName(); String read = getContext() .getString( R.string.contact_has_read_up_to_this_point, diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index 768bc063..896bdb7d 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -215,7 +215,7 @@ public class UIHelper { List<User> members = conversation.getMucOptions().getUsers(); if (members.size() == 0) { return getUnknownContactPicture( - new String[] { conversation.getName(false) }, size, + new String[] { conversation.getName() }, size, bgColor, fgColor); } ArrayList<String> names = new ArrayList<String>(); @@ -332,7 +332,6 @@ public class UIHelper { SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(context); - boolean useSubject = preferences.getBoolean("use_subject_in_muc", true); boolean showNofifications = preferences.getBoolean("show_notification", true); boolean vibrate = preferences.getBoolean("vibrate_on_notification", @@ -381,7 +380,7 @@ public class UIHelper { Conversation conversation = unread.get(0); targetUuid = conversation.getUuid(); mBuilder.setLargeIcon(conversation.getImage(context, 64)); - mBuilder.setContentTitle(conversation.getName(useSubject)); + mBuilder.setContentTitle(conversation.getName()); if (notify) { mBuilder.setTicker(conversation.getLatestMessage() .getReadableBody(context)); @@ -413,12 +412,12 @@ public class UIHelper { for (int i = 0; i < unread.size(); ++i) { targetUuid = unread.get(i).getUuid(); if (i < unread.size() - 1) { - names.append(unread.get(i).getName(useSubject) + ", "); + names.append(unread.get(i).getName() + ", "); } else { - names.append(unread.get(i).getName(useSubject)); + names.append(unread.get(i).getName()); } style.addLine(Html.fromHtml("<b>" - + unread.get(i).getName(useSubject) + + unread.get(i).getName() + "</b> " + unread.get(i).getLatestMessage() .getReadableBody(context))); diff --git a/src/eu/siacs/conversations/utils/XmlHelper.java b/src/eu/siacs/conversations/utils/XmlHelper.java new file mode 100644 index 00000000..4dee07cf --- /dev/null +++ b/src/eu/siacs/conversations/utils/XmlHelper.java @@ -0,0 +1,12 @@ +package eu.siacs.conversations.utils; + +public class XmlHelper { + public static String encodeEntities(String content) { + content = content.replace("&", "&"); + content = content.replace("<", "<"); + content = content.replace(">", ">"); + content = content.replace("\"", """); + content = content.replace("'", "'"); + return content; + } +} diff --git a/src/eu/siacs/conversations/xml/Element.java b/src/eu/siacs/conversations/xml/Element.java index d23a81ba..4e11ee2c 100644 --- a/src/eu/siacs/conversations/xml/Element.java +++ b/src/eu/siacs/conversations/xml/Element.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import eu.siacs.conversations.utils.XmlHelper; + public class Element { protected String name; protected Hashtable<String, String> attributes = new Hashtable<String, String>(); @@ -116,7 +118,7 @@ public class Element { startTag.setAtttributes(this.attributes); elementOutput.append(startTag); if (content != null) { - elementOutput.append(encodeEntities(content)); + elementOutput.append(XmlHelper.encodeEntities(content)); } else { for (Element child : children) { elementOutput.append(child.toString()); @@ -132,24 +134,15 @@ public class Element { return name; } - private String encodeEntities(String content) { - content = content.replace("&", "&"); - content = content.replace("<", "<"); - content = content.replace(">", ">"); - content = content.replace("\"", """); - content = content.replace("'", "'"); - return content; - } - public void clearChildren() { this.children.clear(); } public void setAttribute(String name, long value) { - this.setAttribute(name, "" + value); + this.setAttribute(name, Long.toString(value)); } public void setAttribute(String name, int value) { - this.setAttribute(name, "" + value); + this.setAttribute(name, Integer.toString(value)); } } diff --git a/src/eu/siacs/conversations/xml/Tag.java b/src/eu/siacs/conversations/xml/Tag.java index 2b393397..b9ef979f 100644 --- a/src/eu/siacs/conversations/xml/Tag.java +++ b/src/eu/siacs/conversations/xml/Tag.java @@ -5,6 +5,8 @@ import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; +import eu.siacs.conversations.utils.XmlHelper; + public class Tag { public static final int NO = -1; public static final int START = 0; @@ -85,7 +87,7 @@ public class Tag { tagOutput.append(' '); tagOutput.append(entry.getKey()); tagOutput.append("=\""); - tagOutput.append(entry.getValue()); + tagOutput.append(XmlHelper.encodeEntities(entry.getValue())); tagOutput.append('"'); } } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index ae6b6f72..36920929 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -763,8 +763,13 @@ public class XmppConnection implements Runnable { }); } - private void processStreamError(Tag currentTag) { - Log.d(Config.LOGTAG, "processStreamError"); + private void processStreamError(Tag currentTag) throws XmlPullParserException, IOException { + Element streamError = tagReader.readElement(currentTag); + if (streamError!=null && streamError.hasChild("conflict")) { + String resource = account.getResource().split("\\.")[0]; + account.setResource(resource+"."+nextRandomId()); + Log.d(Config.LOGTAG,account.getJid()+": switching resource due to conflict ("+account.getResource()+")"); + } } private void sendStartStream() throws IOException { diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java b/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java index 2874b9a5..3e7c7b68 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java @@ -117,9 +117,9 @@ public class JingleCandidate { Element element = new Element("candidate"); element.setAttribute("cid", this.getCid()); element.setAttribute("host", this.getHost()); - element.setAttribute("port", "" + this.getPort()); + element.setAttribute("port", Integer.toString(this.getPort())); element.setAttribute("jid", this.getJid()); - element.setAttribute("priority", "" + this.getPriority()); + element.setAttribute("priority", Integer.toString(this.getPriority())); if (this.getType() == TYPE_DIRECT) { element.setAttribute("type", "direct"); } else if (this.getType() == TYPE_PROXY) { diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 317838fd..a5cc2c49 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -95,7 +95,7 @@ public class JingleConnection { BitmapFactory.decodeFile(file.getAbsolutePath(), options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; - message.setBody("" + file.getSize() + "," + imageWidth + "," + message.setBody(Long.toString(file.getSize()) + ',' + imageWidth + ',' + imageHeight); mXmppConnectionService.databaseBackend.createMessage(message); mXmppConnectionService.markMessage(message, @@ -302,7 +302,7 @@ public class JingleConnection { } if (supportedFile) { long size = Long.parseLong(fileSize.getContent()); - message.setBody("" + size); + message.setBody(Long.toString(size)); conversation.getMessages().add(message); if (size <= this.mJingleConnectionManager .getAutoAcceptFileSize()) { @@ -630,7 +630,7 @@ public class JingleConnection { this.transportId = this.mJingleConnectionManager.nextRandomId(); content.setTransportId(this.transportId); content.ibbTransport().setAttribute("block-size", - "" + this.ibbBlockSize); + Integer.toString(this.ibbBlockSize)); packet.setContent(content); this.sendJinglePacket(packet); } @@ -652,7 +652,7 @@ public class JingleConnection { Content content = new Content("initiator", "a-file-offer"); content.setTransportId(this.transportId); content.ibbTransport().setAttribute("block-size", - "" + this.ibbBlockSize); + Integer.toString(this.ibbBlockSize)); answer.setContent(content); this.sendJinglePacket(answer); return true; diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java index 331b53de..cd87552b 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java @@ -59,7 +59,7 @@ public class JingleInbandTransport extends JingleTransport { Element open = iq.addChild("open", "http://jabber.org/protocol/ibb"); open.setAttribute("sid", this.sessionId); open.setAttribute("stanza", "iq"); - open.setAttribute("block-size", "" + this.blockSize); + open.setAttribute("block-size", Integer.toString(this.blockSize)); this.account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() { @@ -134,8 +134,8 @@ public class JingleInbandTransport extends JingleTransport { iq.setTo(this.counterpart); Element data = iq.addChild("data", "http://jabber.org/protocol/ibb"); - data.setAttribute("seq", "" + this.seq); - data.setAttribute("block-size", "" + this.blockSize); + data.setAttribute("seq", Integer.toString(this.seq)); + data.setAttribute("block-size", Integer.toString(this.blockSize)); data.setAttribute("sid", this.sessionId); data.setContent(base64); this.account.getXmppConnection().sendIqPacket(iq, diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java index e476decc..1a8ab9dd 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java @@ -58,10 +58,10 @@ public class JingleSocks5Transport extends JingleTransport { byte[] reply = new byte[2]; outputStream.write(login); inputStream.read(reply); + final String connect = Character.toString('\u0005') + '\u0001' + '\u0000' + + '\u0003' + '\u0028' + destination + '\u0000' + + '\u0000'; if (Arrays.equals(reply, expectedReply)) { - String connect = "" + '\u0005' + '\u0001' + '\u0000' - + '\u0003' + '\u0028' + destination + '\u0000' - + '\u0000'; outputStream.write(connect.getBytes()); byte[] result = new byte[2]; inputStream.read(result); diff --git a/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java index 1e8e3fd6..d19e6dfd 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java +++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java @@ -30,7 +30,7 @@ public class Content extends Element { "urn:xmpp:jingle:apps:file-transfer:3"); Element offer = description.addChild("offer"); Element file = offer.addChild("file"); - file.addChild("size").setContent("" + actualFile.getSize()); + file.addChild("size").setContent(Long.toString(actualFile.getSize())); if (otr) { file.addChild("name").setContent(actualFile.getName() + ".otr"); } else { diff --git a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java index c936891c..f93b5d87 100644 --- a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java +++ b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java @@ -7,7 +7,7 @@ public class AckPacket extends AbstractStanza { public AckPacket(int sequence, int smVersion) { super("a"); this.setAttribute("xmlns", "urn:xmpp:sm:" + smVersion); - this.setAttribute("h", "" + sequence); + this.setAttribute("h", Integer.toString(sequence)); } } diff --git a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java index df039d5a..9cdcfa5e 100644 --- a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java +++ b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java @@ -8,7 +8,7 @@ public class ResumePacket extends AbstractStanza { super("resume"); this.setAttribute("xmlns", "urn:xmpp:sm:" + smVersion); this.setAttribute("previd", id); - this.setAttribute("h", "" + sequence); + this.setAttribute("h", Integer.toString(sequence)); } } |