aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-17 15:56:54 +0100
committerlookshe <github@lookshe.org>2016-03-17 15:56:54 +0100
commitfb00372269ab0ed9ed0fbc1bd502695ffc17dd1b (patch)
treecf0fb5a62aefaf34fd8e134fa20c91fe641c0898 /src/main/java/eu
parent25d3aba4d7dad3edffb92a06b2b018df7ca9b177 (diff)
parentc4b1f6171d2bf82e44a3ba567f7732cc8beef717 (diff)
Merge tag '1.11.1' into trz/merge_1.11.1
Conflicts: README.md build.gradle src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java src/main/java/eu/siacs/conversations/ui/XmppActivity.java src/main/java/eu/siacs/conversations/utils/FileUtils.java src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java src/main/res/values-de/strings.xml src/main/res/values-eu/strings.xml src/main/res/values-ja/strings.xml src/main/res/values-ru/strings.xml
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/MucOptions.java13
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java5
-rw-r--r--src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java142
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java10
-rw-r--r--src/main/java/eu/siacs/conversations/utils/FileUtils.java9
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java4
8 files changed, 115 insertions, 74 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
index 4fe26743..db27810f 100644
--- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
@@ -345,17 +345,8 @@ public class MucOptions {
}
public List<User> getUsers(int max) {
- ArrayList<User> users = new ArrayList<>();
- int i = 1;
- for(User user : this.users.values()) {
- users.add(user);
- if (i >= max) {
- break;
- } else {
- ++i;
- }
- }
- return users;
+ ArrayList<User> users = getUsers();
+ return users.subList(0, Math.min(max, users.size()));
}
public int getUserCount() {
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index c376fa73..e400095d 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -416,8 +416,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
Cursor cursor = db.query(ServiceDiscoveryResult.TABLENAME, null,
ServiceDiscoveryResult.HASH + "=? AND " + ServiceDiscoveryResult.VER + "=?",
selectionArgs, null, null, null);
- if (cursor.getCount() == 0)
+ if (cursor.getCount() == 0) {
+ cursor.close();
return null;
+ }
cursor.moveToFirst();
ServiceDiscoveryResult result = null;
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index e991c2d2..175df041 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1545,9 +1545,14 @@ public class ConversationActivity extends XmppActivity
protected void refreshUiReal() {
updateConversationList();
if (conversationList.size() > 0) {
+ if (!this.mConversationFragment.isAdded()) {
+ Log.d(Config.LOGTAG,"fragment NOT added to activity. detached="+Boolean.toString(mConversationFragment.isDetached()));
+ }
ConversationActivity.this.mConversationFragment.updateMessages();
updateActionBarTitle();
invalidateOptionsMenu();
+ } else {
+ Log.d(Config.LOGTAG,"not updating conversations fragment because conversations list size was 0");
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
index 04868909..57fcf4e3 100644
--- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
@@ -184,7 +184,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
return true;
} else {
- return onOptionsItemSelected(item);
+ return super.onOptionsItemSelected(item);
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
index 2aa1e89d..80e52ec2 100644
--- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
@@ -15,7 +15,9 @@ import android.widget.Toast;
import java.net.URLConnection;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
@@ -26,11 +28,17 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
-public class ShareWithActivity extends XmppActivity {
+public class ShareWithActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate {
+
+ @Override
+ public void onConversationUpdate() {
+ refreshUi();
+ }
private class Share {
public List<Uri> uris = new ArrayList<>();
@@ -39,14 +47,17 @@ public class ShareWithActivity extends XmppActivity {
public String contact;
public String text;
public String uuid;
+ public boolean multiple = false;
}
private Share share;
private static final int REQUEST_START_NEW_CONVERSATION = 0x0501;
private ListView mListView;
+ private ConversationAdapter mAdapter;
private List<Conversation> mConversations = new ArrayList<>();
private Toast mToast;
+ private AtomicInteger attachmentCounter = new AtomicInteger(0);
private UiCallback<Message> attachFileCallback = new UiCallback<Message>() {
@@ -62,26 +73,52 @@ public class ShareWithActivity extends XmppActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
- if (mToast != null) {
- mToast.cancel();
- }
- if (share.uuid != null) {
- mToast = Toast.makeText(getApplicationContext(),
- getString(share.image ? R.string.shared_image_with_x : R.string.shared_file_with_x,message.getConversation().getName()),
- Toast.LENGTH_SHORT);
- mToast.show();
+ if (attachmentCounter.decrementAndGet() <=0 ) {
+ int resId;
+ if (share.image && share.multiple) {
+ resId = R.string.shared_images_with_x;
+ } else if (share.image) {
+ resId = R.string.shared_image_with_x;
+ } else {
+ resId = R.string.shared_file_with_x;
+ }
+ replaceToast(getString(resId, message.getConversation().getName()));
+ if (share.uuid != null) {
+ finish();
+ } else {
+ switchToConversation(message.getConversation());
+ }
}
}
});
}
@Override
- public void error(int errorCode, Message object) {
- // TODO Auto-generated method stub
-
+ public void error(final int errorCode, Message object) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ replaceToast(getString(errorCode));
+ if (attachmentCounter.decrementAndGet() <=0 ) {
+ finish();
+ }
+ }
+ });
}
};
+ protected void hideToast() {
+ if (mToast != null) {
+ mToast.cancel();
+ }
+ }
+
+ protected void replaceToast(String msg) {
+ hideToast();
+ mToast = Toast.makeText(this, msg ,Toast.LENGTH_LONG);
+ mToast.show();
+ }
+
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_START_NEW_CONVERSATION
@@ -110,8 +147,7 @@ public class ShareWithActivity extends XmppActivity {
setTitle(getString(R.string.title_activity_sharewith));
mListView = (ListView) findViewById(R.id.choose_conversation_list);
- ConversationAdapter mAdapter = new ConversationAdapter(this,
- this.mConversations);
+ mAdapter = new ConversationAdapter(this, this.mConversations);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(new OnItemClickListener() {
@@ -149,23 +185,24 @@ public class ShareWithActivity extends XmppActivity {
return;
}
final String type = intent.getType();
- Log.d(Config.LOGTAG, "action: "+intent.getAction()+ ", type:"+type);
+ final String action = intent.getAction();
+ Log.d(Config.LOGTAG, "action: "+action+ ", type:"+type);
share.uuid = intent.getStringExtra("uuid");
- if (Intent.ACTION_SEND.equals(intent.getAction())) {
- final Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
- if (type != null && uri != null && !type.equalsIgnoreCase("text/plain")) {
+ if (Intent.ACTION_SEND.equals(action)) {
+ final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
+ final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
+ if (type != null && uri != null && text == null) {
this.share.uris.clear();
this.share.uris.add(uri);
this.share.image = type.startsWith("image/") || isImage(uri);
} else {
- this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
+ this.share.text = text;
}
- } else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
+ } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
this.share.image = type != null && type.startsWith("image/");
if (!this.share.image) {
return;
}
-
this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
}
if (xmppConnectionServiceBound) {
@@ -194,8 +231,7 @@ public class ShareWithActivity extends XmppActivity {
share();
return;
}
- xmppConnectionService.populateWithOrderedConversations(mConversations,
- this.share != null && this.share.uris.size() == 0);
+ refreshUiReal();
}
private void share() {
@@ -227,6 +263,7 @@ public class ShareWithActivity extends XmppActivity {
}
private void share(final Conversation conversation) {
+ mListView.setEnabled(false);
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
if (share.uuid == null) {
showInstallPgpDialog();
@@ -237,35 +274,26 @@ public class ShareWithActivity extends XmppActivity {
return;
}
if (share.uris.size() != 0) {
- OnPresenceSelected callback;
- if (this.share.image) {
- callback = new OnPresenceSelected() {
- @Override
- public void onPresenceSelected() {
- ResizePictureUserDecisionListener userDecisionListener = new ShareWithResizePictureUserDecisionListener(ShareWithActivity.this, conversation, xmppConnectionService, share.uris);
- UserDecisionDialog userDecisionDialog = new UserDecisionDialog(ShareWithActivity.this, R.string.userdecision_question_resize_picture, userDecisionListener);
- userDecisionDialog.decide(ConversationsPlusPreferences.resizePicture());
- }
- };
- } else {
- callback = new OnPresenceSelected() {
- @Override
- public void onPresenceSelected() {
- mToast = Toast.makeText(getApplicationContext(),
- getText(R.string.preparing_file),
- Toast.LENGTH_LONG);
- mToast.show();
- ShareWithActivity.this.xmppConnectionService
- .attachFileToConversation(conversation, share.uris.get(0),
- attachFileCallback);
- if (share.uuid == null) {
- switchToConversation(conversation, null, true);
+ OnPresenceSelected callback = new OnPresenceSelected() {
+ @Override
+ public void onPresenceSelected() {
+ attachmentCounter.set(share.uris.size());
+ if (share.image) {
+ share.multiple = share.uris.size() > 1;
+ replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image));
+ for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) {
+ ShareWithActivity.this.xmppConnectionService
+ .attachImageToConversation(conversation, i.next(),
+ attachFileCallback);
+ }
+ } else {
+ replaceToast(getString(R.string.preparing_file));
+ ShareWithActivity.this.xmppConnectionService
+ .attachFileToConversation(conversation, share.uris.get(0),
+ attachFileCallback);
}
- finish();
- }
- };
- }
-
+ }
+ };
if (conversation.getAccount().httpUploadAvailable()) {
callback.onPresenceSelected();
} else {
@@ -273,13 +301,21 @@ public class ShareWithActivity extends XmppActivity {
}
} else {
switchToConversation(conversation, this.share.text, true);
- finish();
}
}
public void refreshUiReal() {
- //nothing to do. This Activity doesn't implement any listeners
+ xmppConnectionService.populateWithOrderedConversations(mConversations, this.share != null && this.share.uris.size() == 0);
+ mAdapter.notifyDataSetChanged();
}
+ @Override
+ public void onBackPressed() {
+ if (attachmentCounter.get() >= 1) {
+ replaceToast(getString(R.string.sharing_files_please_wait));
+ } else {
+ super.onBackPressed();
+ }
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 0677fbd2..a01abb5b 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -744,7 +744,7 @@ public abstract class XmppActivity extends Activity {
case UNTRUSTED:
case TRUSTED:
case TRUSTED_X509:
- trustToggle.setChecked(trust.trusted());
+ trustToggle.setChecked(trust.trusted(), false);
trustToggle.setEnabled(trust != XmppAxolotlSession.Trust.TRUSTED_X509);
if (trust == XmppAxolotlSession.Trust.TRUSTED_X509) {
trustToggle.setOnClickListener(null);
@@ -753,7 +753,7 @@ public abstract class XmppActivity extends Activity {
keyType.setTextColor(getSecondaryTextColor());
break;
case UNDECIDED:
- trustToggle.setChecked(false);
+ trustToggle.setChecked(false, false);
trustToggle.setEnabled(false);
key.setTextColor(getPrimaryTextColor());
keyType.setTextColor(getSecondaryTextColor());
@@ -761,7 +761,7 @@ public abstract class XmppActivity extends Activity {
case INACTIVE_UNTRUSTED:
case INACTIVE_UNDECIDED:
trustToggle.setOnClickListener(null);
- trustToggle.setChecked(false);
+ trustToggle.setChecked(false, false);
trustToggle.setEnabled(false);
key.setTextColor(getTertiaryTextColor());
keyType.setTextColor(getTertiaryTextColor());
@@ -769,7 +769,7 @@ public abstract class XmppActivity extends Activity {
case INACTIVE_TRUSTED:
case INACTIVE_TRUSTED_X509:
trustToggle.setOnClickListener(null);
- trustToggle.setChecked(true);
+ trustToggle.setChecked(true, false);
trustToggle.setEnabled(false);
key.setTextColor(getTertiaryTextColor());
keyType.setTextColor(getTertiaryTextColor());
@@ -1181,7 +1181,7 @@ public abstract class XmppActivity extends Activity {
} else {
if (cancelPotentialWork(message, imageView)) {
imageView.setBackgroundColor(0xff333333);
-
+ imageView.setImageDrawable(null);
final BitmapWorkerTask task = new BitmapWorkerTask(imageView, setSize);
final AsyncDrawable asyncDrawable = new AsyncDrawable(
getResources(), null, task);
diff --git a/src/main/java/eu/siacs/conversations/utils/FileUtils.java b/src/main/java/eu/siacs/conversations/utils/FileUtils.java
index b12c990b..0edaf9a9 100644
--- a/src/main/java/eu/siacs/conversations/utils/FileUtils.java
+++ b/src/main/java/eu/siacs/conversations/utils/FileUtils.java
@@ -79,7 +79,14 @@ public final class FileUtils {
}
// MediaStore (and general)
else if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
- return getDataColumn(context, uri, null, null);
+ String path = getDataColumn(context, uri, null, null);
+ if (path != null) {
+ File file = new File(path);
+ if (!file.canRead()) {
+ return null;
+ }
+ }
+ return path;
}
// File
else if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index fa381668..9d167edd 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -890,11 +890,11 @@ public class XmppConnection implements Runnable {
sendPostBindInitialization();
}
} else {
- Logging.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure");
+ Logging.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure. (no jid)");
disconnect(true);
}
} else {
- Logging.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure");
+ Logging.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure ("+packet.toString());
disconnect(true);
}
}