aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authorChristian S <christian@pix-art.de>2016-03-17 20:26:23 +0100
committerChristian S <christian@pix-art.de>2016-03-17 20:26:23 +0100
commit5ae161a593e651df09556659e129d22579548e6b (patch)
tree860883b1e4f8adde36f7ae4b52155f4bc9bdba87 /src/main/java/eu/siacs/conversations
parent92a9299a38fdb2861ec3544950e47dd9d9e82e0a (diff)
parentc4b1f6171d2bf82e44a3ba567f7732cc8beef717 (diff)
Merge branch 'siacs/master' into development
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/MucOptions.java13
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java5
-rw-r--r--src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java6
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java110
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java1
-rw-r--r--src/main/java/eu/siacs/conversations/utils/FileUtils.java11
6 files changed, 92 insertions, 54 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
index 380ed0667..ac627aaae 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/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 655dcb126..f11a70f78 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1651,9 +1651,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 828f39d84..cb164b95a 100644
--- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
@@ -5,7 +5,6 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
@@ -21,13 +20,10 @@ import android.widget.Toast;
import com.soundcloud.android.crop.Crop;
import java.io.File;
-import java.io.FileNotFoundException;
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.pep.Avatar;
@@ -184,7 +180,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 09bbe0df1..4ec43c279 100644
--- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
@@ -17,17 +17,24 @@ import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
import eu.siacs.conversations.Config;
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<>();
@@ -36,14 +43,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>() {
@@ -59,26 +69,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
@@ -107,8 +143,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() {
@@ -146,23 +181,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) {
@@ -191,8 +227,7 @@ public class ShareWithActivity extends XmppActivity {
share();
return;
}
- xmppConnectionService.populateWithOrderedConversations(mConversations,
- this.share != null && this.share.uris.size() == 0);
+ refreshUiReal();
}
private void share() {
@@ -224,6 +259,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,29 +273,21 @@ public class ShareWithActivity extends XmppActivity {
OnPresenceSelected callback = new OnPresenceSelected() {
@Override
public void onPresenceSelected() {
+ attachmentCounter.set(share.uris.size());
if (share.image) {
- mToast = Toast.makeText(getApplicationContext(),
- getText(R.string.preparing_image),
- Toast.LENGTH_LONG);
- mToast.show();
+ 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 {
- mToast = Toast.makeText(getApplicationContext(),
- getText(R.string.preparing_file),
- Toast.LENGTH_LONG);
- mToast.show();
+ replaceToast(getString(R.string.preparing_file));
ShareWithActivity.this.xmppConnectionService
.attachFileToConversation(conversation, share.uris.get(0),
attachFileCallback);
}
- if (share.uuid == null) {
- switchToConversation(conversation, null, true);
- }
- finish();
}
};
if (conversation.getAccount().httpUploadAvailable()) {
@@ -269,13 +297,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 1114560ba..74abc88b8 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -1177,6 +1177,7 @@ public abstract class XmppActivity extends Activity {
} else {
if (cancelPotentialWork(message, imageView)) {
imageView.setBackgroundColor(0xff333333);
+ imageView.setImageDrawable(null);
final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
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 ad8b8640f..6e75d41cd 100644
--- a/src/main/java/eu/siacs/conversations/utils/FileUtils.java
+++ b/src/main/java/eu/siacs/conversations/utils/FileUtils.java
@@ -10,6 +10,8 @@ import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
+import java.io.File;
+
public class FileUtils {
/**
@@ -77,7 +79,14 @@ public class FileUtils {
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(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 ("file".equalsIgnoreCase(uri.getScheme())) {