diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java | 121 |
1 files changed, 67 insertions, 54 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java index f6a7b4c5..55a19b42 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java @@ -4,7 +4,6 @@ import android.app.PendingIntent; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -15,6 +14,7 @@ import android.widget.Toast; import java.net.URLConnection; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import de.thedevstack.conversationsplus.Config; @@ -29,7 +29,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.Jid; public class ShareWithActivity extends XmppActivity { private class Share { - public Uri uri; + public List<Uri> uris = new ArrayList<>(); public boolean image; public String account; public String contact; @@ -62,18 +62,17 @@ public class ShareWithActivity extends XmppActivity { } }; - 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 (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) { + if (xmppConnectionServiceBound + && share != null + && share.contact != null + && share.account != null) { share(); } } @@ -97,13 +96,8 @@ public class ShareWithActivity extends XmppActivity { 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.uri == null) { - share(mConversations.get(position)); - } + public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { + share(mConversations.get(position)); } }); @@ -119,29 +113,42 @@ public class ShareWithActivity extends XmppActivity { @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { - case R.id.action_add: - final Intent intent = new Intent(getApplicationContext(), - ChooseContactActivity.class); - startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION); - return true; + case R.id.action_add: + final Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class); + startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION); + return true; } return super.onOptionsItemSelected(item); } @Override public void onStart() { - final String type = getIntent().getType(); - final Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); - if (type != null && uri != null && !type.equalsIgnoreCase("text/plain")) { - this.share.uri = uri; - this.share.image = type.startsWith("image/") || isImage(uri); - } else { - this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT); + super.onStart(); + Intent intent = getIntent(); + if (intent == null) { + return; + } + final String type = intent.getType(); + if (Intent.ACTION_SEND.equals(intent.getAction())) { + final Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + if (type != null && uri != null && !type.equalsIgnoreCase("text/plain")) { + this.share.uris.add(uri); + this.share.image = type.startsWith("image/") || isImage(uri); + } else { + this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT); + } + } else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) { + this.share.image = type != null && type.startsWith("image/"); + if (!this.share.image) { + return; + } + + this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); } if (xmppConnectionServiceBound) { - xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uri == null); + xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0); } - super.onStart(); + } protected boolean isImage(Uri uri) { @@ -161,54 +168,60 @@ public class ShareWithActivity extends XmppActivity { return; } xmppConnectionService.populateWithOrderedConversations(mConversations, - this.share != null && this.share.uri == null); + this.share != null && this.share.uris.size() == 0); } private void share() { - Account account; - try { - account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account)); - } catch (final InvalidJidException e) { - account = null; - } - if (account == null) { + Account account; + try { + account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account)); + } catch (final InvalidJidException e) { + account = null; + } + if (account == null) { + return; + } + final Conversation conversation; + try { + conversation = xmppConnectionService + .findOrCreateConversation(account, Jid.fromString(share.contact), false); + } catch (final InvalidJidException e) { return; } - final Conversation conversation; - try { - conversation = xmppConnectionService - .findOrCreateConversation(account, Jid.fromString(share.contact), false); - } catch (final InvalidJidException e) { - return; - } - share(conversation); + share(conversation); } private void share(final Conversation conversation) { - if (share.uri != null) { - selectPresence(conversation, new OnPresenceSelected() { + if (share.uris.size() != 0) { + OnPresenceSelected callback = new OnPresenceSelected() { @Override public void onPresenceSelected() { if (share.image) { Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG).show(); - ShareWithActivity.this.xmppConnectionService - .attachImageToConversation(conversation, share.uri, - attachFileCallback); + for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) { + ShareWithActivity.this.xmppConnectionService + .attachImageToConversation(conversation, i.next(), + attachFileCallback); + } } else { Toast.makeText(getApplicationContext(), getText(R.string.preparing_file), Toast.LENGTH_LONG).show(); ShareWithActivity.this.xmppConnectionService - .attachFileToConversation(conversation, share.uri, - attachFileCallback); + .attachFileToConversation(conversation, share.uris.get(0), + attachFileCallback); } switchToConversation(conversation, null, true); finish(); } - }); - + }; + if (conversation.getAccount().httpUploadAvailable()) { + callback.onPresenceSelected(); + } else { + selectPresence(conversation, callback); + } } else { switchToConversation(conversation, this.share.text, true); finish(); |