hide prepare image toasts when attaching multiple images

This commit is contained in:
Daniel Gultsch 2016-01-15 23:47:55 +01:00
parent d85854b686
commit 494a04ffb1
1 changed files with 12 additions and 11 deletions

View File

@ -112,8 +112,6 @@ public class ConversationActivity extends XmppActivity
private ArrayAdapter<Conversation> listAdapter; private ArrayAdapter<Conversation> listAdapter;
private Toast prepareFileToast;
private boolean mActivityPaused = false; private boolean mActivityPaused = false;
private AtomicBoolean mRedirected = new AtomicBoolean(false); private AtomicBoolean mRedirected = new AtomicBoolean(false);
private Pair<Integer, Intent> mPostponedActivityResult; private Pair<Integer, Intent> mPostponedActivityResult;
@ -1250,6 +1248,9 @@ public class ConversationActivity extends XmppActivity
@SuppressLint("NewApi") @SuppressLint("NewApi")
private static List<Uri> extractUriFromIntent(final Intent intent) { private static List<Uri> extractUriFromIntent(final Intent intent) {
List<Uri> uris = new ArrayList<>(); List<Uri> uris = new ArrayList<>();
if (intent == null) {
return uris;
}
Uri uri = intent.getData(); Uri uri = intent.getData();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
ClipData clipData = intent.getClipData(); ClipData clipData = intent.getClipData();
@ -1397,17 +1398,18 @@ public class ConversationActivity extends XmppActivity
if (conversation == null) { if (conversation == null) {
return; return;
} }
prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG);
prepareFileToast.show(); prepareFileToast.show();
xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() { xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() {
@Override @Override
public void success(Message message) { public void success(Message message) {
hidePrepareFileToast(); hidePrepareFileToast(prepareFileToast);
xmppConnectionService.sendMessage(message); xmppConnectionService.sendMessage(message);
} }
@Override @Override
public void error(int errorCode, Message message) { public void error(int errorCode, Message message) {
hidePrepareFileToast(prepareFileToast);
displayErrorDialog(errorCode); displayErrorDialog(errorCode);
} }
@ -1422,32 +1424,31 @@ public class ConversationActivity extends XmppActivity
if (conversation == null) { if (conversation == null) {
return; return;
} }
prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG); final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG);
prepareFileToast.show(); prepareFileToast.show();
xmppConnectionService.attachImageToConversation(conversation, uri, xmppConnectionService.attachImageToConversation(conversation, uri,
new UiCallback<Message>() { new UiCallback<Message>() {
@Override @Override
public void userInputRequried(PendingIntent pi, public void userInputRequried(PendingIntent pi, Message object) {
Message object) { hidePrepareFileToast(prepareFileToast);
hidePrepareFileToast();
} }
@Override @Override
public void success(Message message) { public void success(Message message) {
hidePrepareFileToast(); hidePrepareFileToast(prepareFileToast);
xmppConnectionService.sendMessage(message); xmppConnectionService.sendMessage(message);
} }
@Override @Override
public void error(int error, Message message) { public void error(int error, Message message) {
hidePrepareFileToast(); hidePrepareFileToast(prepareFileToast);
displayErrorDialog(error); displayErrorDialog(error);
} }
}); });
} }
private void hidePrepareFileToast() { private void hidePrepareFileToast(final Toast prepareFileToast) {
if (prepareFileToast != null) { if (prepareFileToast != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {