fixed share with activity to account for http file upload

This commit is contained in:
Daniel Gultsch 2015-07-02 23:51:59 +02:00
parent e4d1bd415d
commit c745fbb562
2 changed files with 38 additions and 43 deletions

View file

@ -1046,13 +1046,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
populateWithOrderedConversations(list, true); populateWithOrderedConversations(list, true);
} }
public void populateWithOrderedConversations(final List<Conversation> list, boolean includeConferences) { public void populateWithOrderedConversations(final List<Conversation> list, boolean includeNoFileUpload) {
list.clear(); list.clear();
if (includeConferences) { if (includeNoFileUpload) {
list.addAll(getConversations()); list.addAll(getConversations());
} else { } else {
for (Conversation conversation : getConversations()) { for (Conversation conversation : getConversations()) {
if (conversation.getMode() == Conversation.MODE_SINGLE) { if (conversation.getMode() == Conversation.MODE_SINGLE
|| conversation.getAccount().httpUploadAvailable()) {
list.add(conversation); list.add(conversation);
} }
} }

View file

@ -4,7 +4,6 @@ import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -13,10 +12,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import java.io.UnsupportedEncodingException;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLDecoder;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -66,18 +62,17 @@ public class ShareWithActivity extends XmppActivity {
} }
}; };
protected void onActivityResult(int requestCode, int resultCode, protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
final Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_START_NEW_CONVERSATION if (requestCode == REQUEST_START_NEW_CONVERSATION
&& resultCode == RESULT_OK) { && resultCode == RESULT_OK) {
share.contact = data.getStringExtra("contact"); share.contact = data.getStringExtra("contact");
share.account = data.getStringExtra("account"); share.account = data.getStringExtra("account");
Log.d(Config.LOGTAG, "contact: " + share.contact + " account:"
+ share.account);
} }
if (xmppConnectionServiceBound && share != null if (xmppConnectionServiceBound
&& share.contact != null && share.account != null) { && share != null
&& share.contact != null
&& share.account != null) {
share(); share();
} }
} }
@ -101,13 +96,8 @@ public class ShareWithActivity extends XmppActivity {
mListView.setOnItemClickListener(new OnItemClickListener() { mListView.setOnItemClickListener(new OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> arg0, View arg1, public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
int position, long arg3) { share(mConversations.get(position));
Conversation conversation = mConversations.get(position);
if (conversation.getMode() == Conversation.MODE_SINGLE
|| share.uris.size() == 0) {
share(mConversations.get(position));
}
} }
}); });
@ -123,11 +113,10 @@ public class ShareWithActivity extends XmppActivity {
@Override @Override
public boolean onOptionsItemSelected(final MenuItem item) { public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_add: case R.id.action_add:
final Intent intent = new Intent(getApplicationContext(), final Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);
ChooseContactActivity.class); startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION);
startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION); return true;
return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -157,7 +146,7 @@ public class ShareWithActivity extends XmppActivity {
this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
} }
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.image); xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0);
} }
} }
@ -183,28 +172,28 @@ public class ShareWithActivity extends XmppActivity {
} }
private void share() { private void share() {
Account account; Account account;
try { try {
account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account)); account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account));
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
account = null; account = null;
} }
if (account == null) { if (account == null) {
return; return;
} }
final Conversation conversation; final Conversation conversation;
try { try {
conversation = xmppConnectionService conversation = xmppConnectionService
.findOrCreateConversation(account, Jid.fromString(share.contact), false); .findOrCreateConversation(account, Jid.fromString(share.contact), false);
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
return; return;
} }
share(conversation); share(conversation);
} }
private void share(final Conversation conversation) { private void share(final Conversation conversation) {
if (share.uris.size() != 0) { if (share.uris.size() != 0) {
selectPresence(conversation, new OnPresenceSelected() { OnPresenceSelected callback = new OnPresenceSelected() {
@Override @Override
public void onPresenceSelected() { public void onPresenceSelected() {
if (share.image) { if (share.image) {
@ -227,7 +216,12 @@ public class ShareWithActivity extends XmppActivity {
switchToConversation(conversation, null, true); switchToConversation(conversation, null, true);
finish(); finish();
} }
}); };
if (conversation.getAccount().httpUploadAvailable()) {
callback.onPresenceSelected();
} else {
selectPresence(conversation, callback);
}
} else { } else {
switchToConversation(conversation, this.share.text, true); switchToConversation(conversation, this.share.text, true);
finish(); finish();