reworked sharewith activity to stay open during sharing
closing the activity prematuraly caused uri permissions to be revoked
This commit is contained in:
parent
323d31ba05
commit
48be5af55f
|
@ -17,17 +17,24 @@ import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
|
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
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 {
|
private class Share {
|
||||||
public List<Uri> uris = new ArrayList<>();
|
public List<Uri> uris = new ArrayList<>();
|
||||||
|
@ -36,14 +43,17 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
public String contact;
|
public String contact;
|
||||||
public String text;
|
public String text;
|
||||||
public String uuid;
|
public String uuid;
|
||||||
|
public boolean multiple = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Share share;
|
private Share share;
|
||||||
|
|
||||||
private static final int REQUEST_START_NEW_CONVERSATION = 0x0501;
|
private static final int REQUEST_START_NEW_CONVERSATION = 0x0501;
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
|
private ConversationAdapter mAdapter;
|
||||||
private List<Conversation> mConversations = new ArrayList<>();
|
private List<Conversation> mConversations = new ArrayList<>();
|
||||||
private Toast mToast;
|
private Toast mToast;
|
||||||
|
private AtomicInteger attachmentCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
private UiCallback<Message> attachFileCallback = new UiCallback<Message>() {
|
private UiCallback<Message> attachFileCallback = new UiCallback<Message>() {
|
||||||
|
|
||||||
|
@ -59,26 +69,52 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mToast != null) {
|
if (attachmentCounter.decrementAndGet() <=0 ) {
|
||||||
mToast.cancel();
|
int resId;
|
||||||
}
|
if (share.image && share.multiple) {
|
||||||
if (share.uuid != null) {
|
resId = R.string.shared_images_with_x;
|
||||||
mToast = Toast.makeText(getApplicationContext(),
|
} else if (share.image) {
|
||||||
getString(share.image ? R.string.shared_image_with_x : R.string.shared_file_with_x,message.getConversation().getName()),
|
resId = R.string.shared_image_with_x;
|
||||||
Toast.LENGTH_SHORT);
|
} else {
|
||||||
mToast.show();
|
resId = R.string.shared_file_with_x;
|
||||||
|
}
|
||||||
|
replaceToast(getString(resId, message.getConversation().getName()));
|
||||||
|
if (share.uuid != null) {
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
switchToConversation(message.getConversation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int errorCode, Message object) {
|
public void error(final int errorCode, Message object) {
|
||||||
// TODO Auto-generated method stub
|
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) {
|
protected void onActivityResult(int requestCode, int resultCode, 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
|
||||||
|
@ -107,8 +143,7 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
setTitle(getString(R.string.title_activity_sharewith));
|
setTitle(getString(R.string.title_activity_sharewith));
|
||||||
|
|
||||||
mListView = (ListView) findViewById(R.id.choose_conversation_list);
|
mListView = (ListView) findViewById(R.id.choose_conversation_list);
|
||||||
ConversationAdapter mAdapter = new ConversationAdapter(this,
|
mAdapter = new ConversationAdapter(this, this.mConversations);
|
||||||
this.mConversations);
|
|
||||||
mListView.setAdapter(mAdapter);
|
mListView.setAdapter(mAdapter);
|
||||||
mListView.setOnItemClickListener(new OnItemClickListener() {
|
mListView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
|
@ -191,8 +226,7 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
share();
|
share();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xmppConnectionService.populateWithOrderedConversations(mConversations,
|
refreshUiReal();
|
||||||
this.share != null && this.share.uris.size() == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void share() {
|
private void share() {
|
||||||
|
@ -224,6 +258,7 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void share(final Conversation conversation) {
|
private void share(final Conversation conversation) {
|
||||||
|
mListView.setEnabled(false);
|
||||||
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
|
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
|
||||||
if (share.uuid == null) {
|
if (share.uuid == null) {
|
||||||
showInstallPgpDialog();
|
showInstallPgpDialog();
|
||||||
|
@ -237,29 +272,21 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
OnPresenceSelected callback = new OnPresenceSelected() {
|
OnPresenceSelected callback = new OnPresenceSelected() {
|
||||||
@Override
|
@Override
|
||||||
public void onPresenceSelected() {
|
public void onPresenceSelected() {
|
||||||
|
attachmentCounter.set(share.uris.size());
|
||||||
if (share.image) {
|
if (share.image) {
|
||||||
mToast = Toast.makeText(getApplicationContext(),
|
share.multiple = share.uris.size() > 1;
|
||||||
getText(R.string.preparing_image),
|
replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image));
|
||||||
Toast.LENGTH_LONG);
|
|
||||||
mToast.show();
|
|
||||||
for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) {
|
for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) {
|
||||||
ShareWithActivity.this.xmppConnectionService
|
ShareWithActivity.this.xmppConnectionService
|
||||||
.attachImageToConversation(conversation, i.next(),
|
.attachImageToConversation(conversation, i.next(),
|
||||||
attachFileCallback);
|
attachFileCallback);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mToast = Toast.makeText(getApplicationContext(),
|
replaceToast(getString(R.string.preparing_file));
|
||||||
getText(R.string.preparing_file),
|
|
||||||
Toast.LENGTH_LONG);
|
|
||||||
mToast.show();
|
|
||||||
ShareWithActivity.this.xmppConnectionService
|
ShareWithActivity.this.xmppConnectionService
|
||||||
.attachFileToConversation(conversation, share.uris.get(0),
|
.attachFileToConversation(conversation, share.uris.get(0),
|
||||||
attachFileCallback);
|
attachFileCallback);
|
||||||
}
|
}
|
||||||
if (share.uuid == null) {
|
|
||||||
switchToConversation(conversation, null, true);
|
|
||||||
}
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (conversation.getAccount().httpUploadAvailable()) {
|
if (conversation.getAccount().httpUploadAvailable()) {
|
||||||
|
@ -269,13 +296,21 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switchToConversation(conversation, this.share.text, true);
|
switchToConversation(conversation, this.share.text, true);
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshUiReal() {
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1174,6 +1174,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
} else {
|
} else {
|
||||||
if (cancelPotentialWork(message, imageView)) {
|
if (cancelPotentialWork(message, imageView)) {
|
||||||
imageView.setBackgroundColor(0xff333333);
|
imageView.setBackgroundColor(0xff333333);
|
||||||
|
imageView.setImageDrawable(null);
|
||||||
final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
|
final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
|
||||||
final AsyncDrawable asyncDrawable = new AsyncDrawable(
|
final AsyncDrawable asyncDrawable = new AsyncDrawable(
|
||||||
getResources(), null, task);
|
getResources(), null, task);
|
||||||
|
|
|
@ -72,6 +72,8 @@
|
||||||
<string name="send_failed">delivery failed</string>
|
<string name="send_failed">delivery failed</string>
|
||||||
<string name="send_rejected">rejected</string>
|
<string name="send_rejected">rejected</string>
|
||||||
<string name="preparing_image">Preparing image for transmission</string>
|
<string name="preparing_image">Preparing image for transmission</string>
|
||||||
|
<string name="preparing_images">Preparing images for transmission</string>
|
||||||
|
<string name="sharing_files_please_wait">Sharing files. Please wait…</string>
|
||||||
<string name="action_clear_history">Clear history</string>
|
<string name="action_clear_history">Clear history</string>
|
||||||
<string name="clear_conversation_history">Clear Conversation History</string>
|
<string name="clear_conversation_history">Clear Conversation History</string>
|
||||||
<string name="clear_histor_msg">Do you want to delete all messages within this Conversation?\n\n<b>Warning:</b> This will not influence messages stored on other devices or servers.</string>
|
<string name="clear_histor_msg">Do you want to delete all messages within this Conversation?\n\n<b>Warning:</b> This will not influence messages stored on other devices or servers.</string>
|
||||||
|
@ -574,6 +576,7 @@
|
||||||
<string name="load_more_messages">Load more messages</string>
|
<string name="load_more_messages">Load more messages</string>
|
||||||
<string name="shared_file_with_x">Shared file with %s</string>
|
<string name="shared_file_with_x">Shared file with %s</string>
|
||||||
<string name="shared_image_with_x">Shared image with %s</string>
|
<string name="shared_image_with_x">Shared image with %s</string>
|
||||||
|
<string name="shared_images_with_x">Shared images with %s</string>
|
||||||
<string name="no_storage_permission">Conversations need access to external storage</string>
|
<string name="no_storage_permission">Conversations need access to external storage</string>
|
||||||
<string name="sync_with_contacts">Synchronize with contacts</string>
|
<string name="sync_with_contacts">Synchronize with contacts</string>
|
||||||
<string name="sync_with_contacts_long">Conversations wants to match your XMPP roster with your contacts to show their full names and avatars.\n\nConversations will only read your contacts and match them locally without uploading them to your server.\n\nYou will now be asked to grant permission to access your contacts.</string>
|
<string name="sync_with_contacts_long">Conversations wants to match your XMPP roster with your contacts to show their full names and avatars.\n\nConversations will only read your contacts and match them locally without uploading them to your server.\n\nYou will now be asked to grant permission to access your contacts.</string>
|
||||||
|
|
Loading…
Reference in New Issue