aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian S <christian@pix-art.de>2016-01-04 19:46:41 +0100
committerChristian S <christian@pix-art.de>2016-01-04 19:46:41 +0100
commitac92023e4a8e537f09059966adaf44c035743e3c (patch)
tree1734b88aef058e2040c5c40326b286f22d53bc59
parent9cce7d873ab241cf50f128bda09631d226da1d48 (diff)
parentabdb8bfb65cda02adcb6c1bcbdcd00159fc0c96a (diff)
copy commits
-rw-r--r--CHANGELOG.md5
-rw-r--r--build.gradle6
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java2
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java2
-rw-r--r--src/main/java/eu/siacs/conversations/generator/MessageGenerator.java13
-rw-r--r--src/main/java/eu/siacs/conversations/parser/AbstractParser.java8
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java7
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java22
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java3
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java67
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java9
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java122
-rw-r--r--src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java72
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java90
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java2
-rw-r--r--src/main/res/layout/enter_jid_dialog.xml (renamed from src/main/res/layout/create_contact_dialog.xml)0
-rw-r--r--src/main/res/menu/choose_contact.xml10
-rw-r--r--src/main/res/values/strings.xml2
19 files changed, 303 insertions, 143 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a08ce968f..83505761f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
###Changelog
+####Versin 1.8.4
+* prompt to trust own OMEMO devices
+* fixed rotation issues in avatar publication
+* invite non-contact JIDs to conferences
+
####Version 1.8.3
* brought text selection back
* hide settings, manage accounts and updater in all menus except in the main activity
diff --git a/build.gradle b/build.gradle
index d3bad2cf8..28429e85e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -57,9 +57,9 @@ android {
minSdkVersion 14
targetSdkVersion 23
- versionCode 114
- versionName "1.8.3"
-
+ versionCode 115
+ versionName "1.8.4"
+
project.ext.set(archivesBaseName, archivesBaseName + "-" + versionName);
}
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
index 31b23e3cb..c8253dd49 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
@@ -731,7 +731,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, identityKey);
sessions.put(address, session);
} else {
- Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Found device " + account.getJid().toBareJid() + ":" + foreignId);
+ Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Found device " + contactJid + ":" + foreignId);
if (fetchStatusMap.get(address) != FetchStatus.ERROR) {
addresses.add(address);
} else {
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index 64bbaa2b0..46865a6fd 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -281,7 +281,7 @@ public class Account extends AbstractEntity {
}
public boolean hasErrorStatus() {
- return getXmppConnection() != null && getStatus().isError() && getXmppConnection().getAttempt() >= 2;
+ return getXmppConnection() != null && getStatus().isError() && getXmppConnection().getAttempt() >= 3;
}
public String getResource() {
diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
index 0f352f53e..b849f56f4 100644
--- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
@@ -69,15 +69,6 @@ public class MessageGenerator extends AbstractGenerator {
return packet;
}
- public static void addXhtmlImImage(MessagePacket packet, Message.FileParams params) {
- Element html = packet.addChild("html","http://jabber.org/protocol/xhtml-im");
- Element body = html.addChild("body","http://www.w3.org/1999/xhtml");
- Element img = body.addChild("img");
- img.setAttribute("src", params.url.toString());
- img.setAttribute("height", params.height);
- img.setAttribute("width", params.width);
- }
-
public static void addMessageHints(MessagePacket packet) {
packet.addChild("private", "urn:xmpp:carbons:2");
packet.addChild("no-copy", "urn:xmpp:hints");
@@ -112,9 +103,7 @@ public class MessageGenerator extends AbstractGenerator {
if (message.hasFileOnRemoteHost()) {
Message.FileParams fileParams = message.getFileParams();
content = fileParams.url.toString();
- if (fileParams.width > 0 && fileParams.height > 0) {
- addXhtmlImImage(packet,fileParams);
- }
+ packet.addChild("x","jabber:x:oob").addChild("url").setContent(content);
} else {
content = message.getBody();
}
diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
index 18331796e..7d3990735 100644
--- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
@@ -11,6 +11,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.Jid;
+import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
public abstract class AbstractParser {
@@ -47,14 +48,13 @@ public abstract class AbstractParser {
return dateFormat.parse(timestamp);
}
- protected void updateLastseen(final Element packet, final Account account, final boolean presenceOverwrite) {
- updateLastseen(packet, account, packet.getAttributeAsJid("from"), presenceOverwrite);
+ protected void updateLastseen(final AbstractStanza packet, final Account account, final boolean presenceOverwrite) {
+ updateLastseen(getTimestamp(packet), account, packet.getFrom(), presenceOverwrite);
}
- protected void updateLastseen(final Element packet, final Account account, final Jid from, final boolean presenceOverwrite) {
+ protected void updateLastseen(long timestamp, final Account account, final Jid from, final boolean presenceOverwrite) {
final String presence = from == null || from.isBareJid() ? "" : from.getResourcepart();
final Contact contact = account.getRoster().getContact(from);
- final long timestamp = getTimestamp(packet);
if (timestamp >= contact.lastseen.time) {
contact.lastseen.time = timestamp;
if (!presence.isEmpty() && presenceOverwrite) {
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 23a23b2c8..345e83958 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -382,13 +382,14 @@ public class MessageParser extends AbstractParser implements
Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
message.setTrueCounterpart(trueCounterpart);
if (trueCounterpart != null) {
- updateLastseen(packet,account,trueCounterpart,false);
+ updateLastseen(timestamp, account, trueCounterpart, false);
}
if (!isTypeGroupChat) {
message.setType(Message.TYPE_PRIVATE);
}
+ } else {
+ updateLastseen(timestamp, account, packet.getFrom(), true);
}
- updateLastseen(packet, account, true);
boolean checkForDuplicates = query != null
|| (isTypeGroupChat && packet.hasChild("delay","urn:xmpp:delay"))
|| message.getType() == Message.TYPE_PRIVATE;
@@ -498,7 +499,7 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.markRead(conversation);
}
} else {
- updateLastseen(packet, account, true);
+ updateLastseen(timestamp, account, packet.getFrom(), true);
final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), displayed.getAttribute("id"), Message.STATUS_SEND_DISPLAYED);
Message message = displayedMessage == null ? null : displayedMessage.prev();
while (message != null
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 02b14c7df..b18a28444 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -42,9 +42,6 @@ import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.xmpp.pep.Avatar;
public class FileBackend {
-
- private static int IMAGE_SIZE = 1920;
-
private final SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
private XmppConnectionService mXmppConnectionService;
@@ -116,7 +113,10 @@ public class FileBackend {
}
}
- public Bitmap rotate(Bitmap bitmap, int degree) {
+ public static Bitmap rotate(Bitmap bitmap, int degree) {
+ if (degree == 0) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
@@ -226,9 +226,7 @@ public class FileBackend {
}
Bitmap scaledBitmap = resize(originalBitmap, Config.IMAGE_SIZE);
int rotation = getRotation(image);
- if (rotation > 0) {
- scaledBitmap = rotate(scaledBitmap, rotation);
- }
+ scaledBitmap = rotate(scaledBitmap, rotation);
boolean success = scaledBitmap.compress(Config.IMAGE_FORMAT, Config.IMAGE_QUALITY, os);
if (!success) {
throw new FileCopyException(R.string.error_compressing_image);
@@ -289,10 +287,7 @@ public class FileBackend {
throw new FileNotFoundException();
}
thumbnail = resize(fullsize, size);
- int rotation = getRotation(file);
- if (rotation > 0) {
- thumbnail = rotate(thumbnail, rotation);
- }
+ thumbnail = rotate(thumbnail, getRotation(file));
this.mXmppConnectionService.getBitmapCache().put(message.getUuid(),thumbnail);
}
return thumbnail;
@@ -404,10 +399,7 @@ public class FileBackend {
if (input == null) {
return null;
} else {
- int rotation = getRotation(image);
- if (rotation > 0) {
- input = rotate(input, rotation);
- }
+ input = rotate(input, getRotation(image));
return cropCenterSquare(input, size);
}
} catch (SecurityException e) {
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 28d6e3550..5c7cceb35 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -2215,8 +2215,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final UiCallback<Avatar> callback) {
final Bitmap.CompressFormat format = Config.AVATAR_FORMAT;
final int size = Config.AVATAR_SIZE;
- final Avatar avatar = getFileBackend()
- .getPepAvatar(image, size, format);
+ final Avatar avatar = getFileBackend().getPepAvatar(image, size, format);
if (avatar != null) {
avatar.height = size;
avatar.width = size;
diff --git a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
index bc23c3bab..33ba1d15a 100644
--- a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
@@ -19,12 +19,16 @@ 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.ListItem;
+import eu.siacs.conversations.xmpp.jid.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
+ private List<String> mActivatedAccounts = new ArrayList<String>();
+ private List<String> mKnownHosts;
private Set<Contact> selected;
private Set<String> filterContacts;
@@ -124,6 +128,15 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
+ @Override
+ public boolean onCreateOptionsMenu(final Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ final Intent i = getIntent();
+ boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
+ menu.findItem(R.id.action_create_contact).setVisible(showEnterJid);
+ return true;
+ }
+
protected void filterContacts(final String needle) {
getListItems().clear();
for (final Account account : xmppConnectionService.getAccounts()) {
@@ -153,4 +166,58 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public void refreshUiReal() {
//nothing to do. This Activity doesn't implement any listeners
}
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_create_contact:
+ showEnterJidDialog();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ protected void showEnterJidDialog() {
+ EnterJidDialog dialog = new EnterJidDialog(
+ this, mKnownHosts, mActivatedAccounts,
+ getString(R.string.enter_contact), getString(R.string.select),
+ null, getIntent().getStringExtra("account"), true
+ );
+
+ dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
+ @Override
+ public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
+ final Intent request = getIntent();
+ final Intent data = new Intent();
+ data.putExtra("contact", contactJid.toString());
+ data.putExtra("account", accountJid.toString());
+ data.putExtra("conversation",
+ request.getStringExtra("conversation"));
+ data.putExtra("multiple", false);
+ setResult(RESULT_OK, data);
+ finish();
+
+ return true;
+ }
+ });
+
+ dialog.show();
+ }
+
+ @Override
+ void onBackendConnected() {
+ filterContacts();
+
+ this.mActivatedAccounts.clear();
+ for (Account account : xmppConnectionService.getAccounts()) {
+ if (account.getStatus() != Account.State.DISABLED) {
+ if (Config.DOMAIN_LOCK != null) {
+ this.mActivatedAccounts.add(account.getJid().getLocalpart());
+ } else {
+ this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
+ }
+ }
+ }
+ this.mKnownHosts = xmppConnectionService.getKnownHosts();
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index d02b1d555..4f9011366 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1563,11 +1563,12 @@ public class ConversationActivity extends XmppActivity
protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
- boolean hasPendingKeys = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED,
- mSelectedConversation.getContact()).isEmpty()
- || !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
+ Contact contact = mSelectedConversation.getContact();
+ boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED).isEmpty();
+ boolean hasUndecidedContact = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED,contact).isEmpty();
+ boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0;
- if( hasPendingKeys || hasNoTrustedKeys) {
+ if(hasUndecidedOwn || hasUndecidedContact || hasPendingKeys || hasNoTrustedKeys) {
axolotlService.createSessionsIfNeeded(mSelectedConversation);
Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index f5356d24f..1545de0f3 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -670,7 +670,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
final String axolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
if (axolotlFingerprint != null) {
this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
- this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint));
+ this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint.substring(2)));
this.mAxolotlFingerprintToClipboardButton
.setVisibility(View.VISIBLE);
this.mAxolotlFingerprintToClipboardButton
@@ -679,7 +679,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
public void onClick(final View v) {
- if (copyTextToClipboard(axolotlFingerprint, R.string.omemo_fingerprint)) {
+ if (copyTextToClipboard(axolotlFingerprint.substring(2), R.string.omemo_fingerprint)) {
Toast.makeText(
EditAccountActivity.this,
R.string.toast_message_omemo_fingerprint,
diff --git a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java
new file mode 100644
index 000000000..a9bffb559
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java
@@ -0,0 +1,122 @@
+package eu.siacs.conversations.ui;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface.OnClickListener;
+import android.content.DialogInterface;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
+import android.widget.Spinner;
+
+import java.util.List;
+
+import eu.siacs.conversations.Config;
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
+
+public class EnterJidDialog {
+ public static interface OnEnterJidDialogPositiveListener {
+ public boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError;
+ }
+
+ public static class JidError extends Exception {
+ final String msg;
+
+ public JidError(final String msg) {
+ this.msg = msg;
+ }
+
+ public String toString() {
+ return msg;
+ }
+ }
+
+ protected final AlertDialog dialog;
+ protected View.OnClickListener dialogOnClick;
+ protected OnEnterJidDialogPositiveListener listener = null;
+
+ public EnterJidDialog(
+ final Context context, List<String> knownHosts, List<String> activatedAccounts,
+ final String title, final String positiveButton,
+ final String prefilledJid, final String account, boolean allowEditJid
+ ) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(title);
+ View dialogView = LayoutInflater.from(context).inflate(R.layout.enter_jid_dialog, null);
+ final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
+ final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
+ jid.setAdapter(new KnownHostsAdapter(context,android.R.layout.simple_list_item_1, knownHosts));
+ if (prefilledJid != null) {
+ jid.append(prefilledJid);
+ if (!allowEditJid) {
+ jid.setFocusable(false);
+ jid.setFocusableInTouchMode(false);
+ jid.setClickable(false);
+ jid.setCursorVisible(false);
+ }
+ }
+
+ ArrayAdapter<String> adapter;
+ if (account == null) {
+ adapter = new ArrayAdapter<>(context,
+ android.R.layout.simple_spinner_item, activatedAccounts);
+ } else {
+ adapter = new ArrayAdapter<>(context,
+ android.R.layout.simple_spinner_item, new String[] { account });
+ spinner.setEnabled(false);
+ }
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(adapter);
+
+ builder.setView(dialogView);
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(positiveButton, null);
+ this.dialog = builder.create();
+
+ this.dialogOnClick = new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ final Jid accountJid;
+ try {
+ if (Config.DOMAIN_LOCK != null) {
+ accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
+ } else {
+ accountJid = Jid.fromString((String) spinner.getSelectedItem());
+ }
+ } catch (final InvalidJidException e) {
+ return;
+ }
+ final Jid contactJid;
+ try {
+ contactJid = Jid.fromString(jid.getText().toString());
+ } catch (final InvalidJidException e) {
+ jid.setError(context.getString(R.string.invalid_jid));
+ return;
+ }
+
+ if(listener != null) {
+ try {
+ if(listener.onEnterJidDialogPositive(accountJid, contactJid)) {
+ dialog.dismiss();
+ }
+ } catch(JidError error) {
+ jid.setError(error.toString());
+ }
+ }
+ }
+ };
+ }
+
+ public void setOnEnterJidDialogPositiveListener(OnEnterJidDialogPositiveListener listener) {
+ this.listener = listener;
+ }
+
+ public void show() {
+ this.dialog.show();
+ this.dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this.dialogOnClick);
+ }
+}
diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
index 5e0c86e58..3313ce318 100644
--- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
@@ -1,3 +1,4 @@
+
package eu.siacs.conversations.ui;
import android.app.PendingIntent;
@@ -23,6 +24,8 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.persistance.FileBackend;
+import eu.siacs.conversations.utils.ExifHelper;
+import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -31,17 +34,16 @@ import eu.siacs.conversations.xmpp.pep.Avatar;
public class PublishProfilePictureActivity extends XmppActivity {
private static final int REQUEST_CHOOSE_FILE = 0xac23;
-
private ImageView avatar;
private TextView accountTextView;
private TextView hintOrWarning;
private TextView secondaryHint;
private Button cancelButton;
private Button publishButton;
-
- final static int REQUEST_CROP_PICTURE = 92374;
private Uri avatarUri;
private Uri defaultUri;
+ private Account account;
+ private boolean support = false;
private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
@Override
@@ -51,8 +53,6 @@ public class PublishProfilePictureActivity extends XmppActivity {
return true;
}
};
- private Account account;
- private boolean support = false;
private boolean mInitialAccountSetup;
private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() {
@@ -65,7 +65,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (mInitialAccountSetup) {
Intent intent = new Intent(getApplicationContext(),
StartConversationActivity.class);
- intent.putExtra("init",true);
+ intent.putExtra("init", true);
startActivity(intent);
}
Toast.makeText(PublishProfilePictureActivity.this,
@@ -140,8 +140,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
Intent attachFileIntent = new Intent();
attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
- Intent chooser = Intent.createChooser(attachFileIntent,
- getString(R.string.attach_file));
+ Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
}
});
@@ -149,32 +148,38 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
@Override
- protected void onActivityResult(int requestCode, int resultCode,
- final Intent data) {
+ protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
- if (requestCode == REQUEST_CHOOSE_FILE) {
- this.avatarUri = data.getData();
- Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
- Crop.of(this.avatarUri, destination).asSquare().start(PublishProfilePictureActivity.this);
+ switch (requestCode) {
+ case REQUEST_CHOOSE_FILE:
+ Uri source = data.getData();
+ String original = FileUtils.getPath(this, source);
+ if (original != null) {
+ source = Uri.parse("file://"+original);
+ }
+ Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
+ final int size = getPixel(192);
+ Crop.of(source, destination).asSquare().withMaxSize(size, size).start(this);
+ break;
+ case Crop.REQUEST_CROP:
+ this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
+ loadImageIntoPreview(this.avatarUri);
+ break;
}
}
- if (requestCode == Crop.REQUEST_CROP) {
- this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
- loadImageIntoPreview(this.avatarUri);
- }
}
@Override
protected void onBackendConnected() {
if (getIntent() != null) {
- Jid jid;
- try {
- jid = Jid.fromString(getIntent().getStringExtra("account"));
- } catch (InvalidJidException e) {
- jid = null;
- }
- if (jid != null) {
+ Jid jid;
+ try {
+ jid = Jid.fromString(getIntent().getStringExtra("account"));
+ } catch (InvalidJidException e) {
+ jid = null;
+ }
+ if (jid != null) {
this.account = xmppConnectionService.findAccountByJid(jid);
if (this.account.getXmppConnection() != null) {
this.support = this.account.getXmppConnection().getFeatures().pep();
@@ -182,8 +187,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (this.avatarUri == null) {
if (this.account.getAvatar() != null
|| this.defaultUri == null) {
- this.avatar.setImageBitmap(avatarService().get(account,
- getPixel(Config.AVATAR_SIZE)));
+ this.avatar.setImageBitmap(avatarService().get(account, getPixel(Config.AVATAR_SIZE)));
if (this.defaultUri != null) {
this.avatar
.setOnLongClickListener(this.backToDefaultListener);
@@ -220,8 +224,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
protected void onStart() {
super.onStart();
if (getIntent() != null) {
- this.mInitialAccountSetup = getIntent().getBooleanExtra("setup",
- false);
+ this.mInitialAccountSetup = getIntent().getBooleanExtra("setup", false);
}
if (this.mInitialAccountSetup) {
this.cancelButton.setText(R.string.skip);
@@ -231,15 +234,18 @@ public class PublishProfilePictureActivity extends XmppActivity {
private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
+ BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
+ int rotation = ExifHelper.getOrientation(getContentResolver().openInputStream(uri));
options.inSampleSize = FileBackend.calcSampleSize(options, reqSize);
options.inJustDecodeBounds = false;
- return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
+ Bitmap bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
+ return FileBackend.rotate(bm,rotation);
}
+
protected void loadImageIntoPreview(Uri uri) {
Bitmap bm = null;
- try{
- bm = loadScaledBitmap(uri, Config.AVATAR_SIZE);
+ try {
+ bm = loadScaledBitmap(uri, getPixel(Config.AVATAR_SIZE));
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index caf3d3db8..a502a0a28 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -349,69 +349,37 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@SuppressLint("InflateParams")
protected void showCreateContactDialog(final String prefilledJid, final String fingerprint) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.create_contact);
- View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null);
- final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
- final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
- jid.setAdapter(new KnownHostsAdapter(this,android.R.layout.simple_list_item_1, mKnownHosts));
- if (prefilledJid != null) {
- jid.append(prefilledJid);
- if (fingerprint!=null) {
- jid.setFocusable(false);
- jid.setFocusableInTouchMode(false);
- jid.setClickable(false);
- jid.setCursorVisible(false);
- }
- }
- populateAccountSpinner(spinner);
- builder.setView(dialogView);
- builder.setNegativeButton(R.string.cancel, null);
- builder.setPositiveButton(R.string.create, null);
- final AlertDialog dialog = builder.create();
- dialog.show();
- dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
- new View.OnClickListener() {
+ EnterJidDialog dialog = new EnterJidDialog(
+ this, mKnownHosts, mActivatedAccounts,
+ getString(R.string.create_contact), getString(R.string.create),
+ prefilledJid, null, fingerprint == null
+ );
- @Override
- public void onClick(final View v) {
- if (!xmppConnectionServiceBound) {
- return;
- }
- final Jid accountJid;
- try {
- if (Config.DOMAIN_LOCK != null) {
- accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
- } else {
- accountJid = Jid.fromString((String) spinner.getSelectedItem());
- }
- } catch (final InvalidJidException e) {
- return;
- }
- final Jid contactJid;
- try {
- contactJid = Jid.fromString(jid.getText().toString());
- } catch (final InvalidJidException e) {
- jid.setError(getString(R.string.invalid_jid));
- return;
- }
- final Account account = xmppConnectionService.findAccountByJid(accountJid);
- if (account == null) {
- dialog.dismiss();
- return;
- }
- final Contact contact = account.getRoster().getContact(contactJid);
- if (contact.showInRoster()) {
- jid.setError(getString(R.string.contact_already_exists));
- } else {
- contact.addOtrFingerprint(fingerprint);
- xmppConnectionService.createContact(contact);
- dialog.dismiss();
- switchToConversation(contact);
- }
- }
- });
+ dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
+ @Override
+ public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
+ if (!xmppConnectionServiceBound) {
+ return false;
+ }
+
+ final Account account = xmppConnectionService.findAccountByJid(accountJid);
+ if (account == null) {
+ return true;
+ }
+ final Contact contact = account.getRoster().getContact(contactJid);
+ if (contact.showInRoster()) {
+ throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
+ } else {
+ contact.addOtrFingerprint(fingerprint);
+ xmppConnectionService.createContact(contact);
+ switchToConversation(contact);
+ return true;
+ }
+ }
+ });
+
+ dialog.show();
}
@SuppressLint("InflateParams")
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index d05f50817..be6255127 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -472,6 +472,8 @@ public abstract class XmppActivity extends Activity {
intent.putExtra("filter_contacts", contacts.toArray(new String[contacts.size()]));
intent.putExtra("conversation", conversation.getUuid());
intent.putExtra("multiple", true);
+ intent.putExtra("show_enter_jid", true);
+ intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION);
}
diff --git a/src/main/res/layout/create_contact_dialog.xml b/src/main/res/layout/enter_jid_dialog.xml
index 6333e340a..6333e340a 100644
--- a/src/main/res/layout/create_contact_dialog.xml
+++ b/src/main/res/layout/enter_jid_dialog.xml
diff --git a/src/main/res/menu/choose_contact.xml b/src/main/res/menu/choose_contact.xml
index c025d00f8..94b6479be 100644
--- a/src/main/res/menu/choose_contact.xml
+++ b/src/main/res/menu/choose_contact.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_search"
@@ -8,4 +8,10 @@
android:showAsAction="collapseActionView|always"
android:title="@string/search"/>
-</menu> \ No newline at end of file
+ <item
+ android:id="@+id/action_create_contact"
+ android:icon="?attr/icon_add_person"
+ android:showAsAction="always"
+ android:title="@string/create_contact"
+ android:visible="false"/>
+</menu>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 15dd5f7f0..bbbc41534 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -226,12 +226,14 @@
<string name="conferences">Conferences</string>
<string name="search">Search</string>
<string name="create_contact">Create Contact</string>
+ <string name="enter_contact">Enter Contact</string>
<string name="join_conference">Join Conference</string>
<string name="delete_contact">Delete Contact</string>
<string name="view_contact_details">View contact details</string>
<string name="block_contact">Block contact</string>
<string name="unblock_contact">Unblock contact</string>
<string name="create">Create</string>
+ <string name="select">Select</string>
<string name="contact_already_exists">The contact already exists</string>
<string name="join">Join</string>
<string name="conference_address">Conference address</string>