aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-06 19:42:55 +0100
committerlookshe <github@lookshe.org>2016-03-06 19:42:55 +0100
commit3c400703e082a1b180b35d891b8fb3460c7d5b87 (patch)
tree28738dd90fc41b4ab71897f38d324828778ad2e3 /src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
parent72114d732427266024cdd6e27cd8d1aa60afae2f (diff)
parentf28d77dc42f6bac5a026e0b1c78562dee8de45ac (diff)
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java103
1 files changed, 76 insertions, 27 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
index e73b7cbe..b0ee32f1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
@@ -4,6 +4,7 @@ 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;
@@ -17,25 +18,27 @@ import java.util.ArrayList;
import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
+import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
+import de.thedevstack.conversationsplus.ui.listeners.ShareWithResizePictureUserDecisionListener;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
-import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
-import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
-import de.thedevstack.conversationsplus.ui.listeners.ShareWithResizePictureUserDecisionListener;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class ShareWithActivity extends XmppActivity {
- public class Share {
+ private class Share {
public List<Uri> uris = new ArrayList<>();
public boolean image;
public String account;
public String contact;
public String text;
+ public String uuid;
}
private Share share;
@@ -43,6 +46,7 @@ public class ShareWithActivity extends XmppActivity {
private static final int REQUEST_START_NEW_CONVERSATION = 0x0501;
private ListView mListView;
private List<Conversation> mConversations = new ArrayList<>();
+ private Toast mToast;
private UiCallback<Message> attachFileCallback = new UiCallback<Message>() {
@@ -53,8 +57,22 @@ public class ShareWithActivity extends XmppActivity {
}
@Override
- public void success(Message message) {
+ public void success(final Message message) {
xmppConnectionService.sendMessage(message);
+ 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();
+ }
+ }
+ });
}
@Override
@@ -69,7 +87,7 @@ public class ShareWithActivity extends XmppActivity {
if (requestCode == REQUEST_START_NEW_CONVERSATION
&& resultCode == RESULT_OK) {
share.contact = data.getStringExtra("contact");
- share.account = data.getStringExtra("account");
+ share.account = data.getStringExtra(EXTRA_ACCOUNT);
}
if (xmppConnectionServiceBound
&& share != null
@@ -131,9 +149,12 @@ public class ShareWithActivity extends XmppActivity {
return;
}
final String type = intent.getType();
+ Log.d(Config.LOGTAG, "action: "+intent.getAction()+ ", 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")) {
+ this.share.uris.clear();
this.share.uris.add(uri);
this.share.image = type.startsWith("image/") || isImage(uri);
} else {
@@ -148,7 +169,11 @@ public class ShareWithActivity extends XmppActivity {
this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
}
if (xmppConnectionServiceBound) {
- xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0);
+ if (share.uuid != null) {
+ share();
+ } else {
+ xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0);
+ }
}
}
@@ -165,7 +190,7 @@ public class ShareWithActivity extends XmppActivity {
@Override
void onBackendConnected() {
if (xmppConnectionServiceBound && share != null
- && share.contact != null && share.account != null) {
+ && ((share.contact != null && share.account != null) || share.uuid != null)) {
share();
return;
}
@@ -174,26 +199,43 @@ public class ShareWithActivity extends XmppActivity {
}
private void share() {
- 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;
+ if (share.uuid != null) {
+ conversation = xmppConnectionService.findConversationByUuid(share.uuid);
+ if (conversation == null) {
+ return;
+ }
+ }else{
+ Account account;
+ try {
+ account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account));
+ } catch (final InvalidJidException e) {
+ account = null;
+ }
+ if (account == null) {
+ return;
+ }
+
+ try {
+ conversation = xmppConnectionService
+ .findOrCreateConversation(account, Jid.fromString(share.contact), false);
+ } catch (final InvalidJidException e) {
+ return;
+ }
}
share(conversation);
}
private void share(final Conversation conversation) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
+ if (share.uuid == null) {
+ showInstallPgpDialog();
+ } else {
+ Toast.makeText(this,R.string.openkeychain_not_installed,Toast.LENGTH_SHORT).show();
+ finish();
+ }
+ return;
+ }
if (share.uris.size() != 0) {
OnPresenceSelected callback;
if (this.share.image) {
@@ -209,22 +251,25 @@ public class ShareWithActivity extends XmppActivity {
callback = new OnPresenceSelected() {
@Override
public void onPresenceSelected() {
- Toast.makeText(getApplicationContext(),
+ mToast = Toast.makeText(getApplicationContext(),
getText(R.string.preparing_file),
- Toast.LENGTH_LONG).show();
+ Toast.LENGTH_LONG);
+ mToast.show();
ShareWithActivity.this.xmppConnectionService
.attachFileToConversation(conversation, share.uris.get(0),
attachFileCallback);
- switchToConversation(conversation, null, true);
+ if (share.uuid == null) {
+ switchToConversation(conversation, null, true);
+ }
finish();
}
};
}
if (conversation.getAccount().httpUploadAvailable()) {
- callback.onPresenceSelected();
+ callback.onPresenceSelected();
} else {
- selectPresence(conversation, callback);
+ selectPresence(conversation, callback);
}
} else {
switchToConversation(conversation, this.share.text, true);
@@ -233,4 +278,8 @@ public class ShareWithActivity extends XmppActivity {
}
+ public void refreshUiReal() {
+ //nothing to do. This Activity doesn't implement any listeners
+ }
+
}